More settings rework

This commit is contained in:
Ben V. Brown
2023-07-19 23:13:13 +10:00
parent 5120235e2e
commit b38a5396f0
6 changed files with 149 additions and 106 deletions

View File

@@ -28,19 +28,20 @@ static uint16_t str_display_len(const char *const str) {
return count;
}
uint16_t ScrollMessage::messageWidth(const char *message) { return FONT_12_WIDTH * str_display_len(message); }
/**
* Calculate the width in pixels of the message string, in the large
* font and taking into account multi-byte chars.
*
* @param message The null-terminated message string.
*/
uint16_t messageWidth(const char *message) { return FONT_12_WIDTH * str_display_len(message); }
bool ScrollMessage::drawUpdate(const char *message, TickType_t currentTick) {
bool lcdRefresh = false;
void drawScrollingText(const char *message, TickType_t currentTickOffset) {
if (messageStart == 0) {
messageStart = currentTick;
lcdRefresh = true;
}
int16_t messageOffset;
uint16_t msgWidth = messageWidth(message);
if (msgWidth > OLED_WIDTH) {
messageOffset = ((currentTick - messageStart) / (getSettingValue(SettingsOptions::DescriptionScrollSpeed) == 1 ? TICKS_100MS / 10 : (TICKS_100MS / 5)));
messageOffset = (currentTickOffset / (getSettingValue(SettingsOptions::DescriptionScrollSpeed) == 1 ? TICKS_100MS / 10 : (TICKS_100MS / 5)));
messageOffset %= msgWidth + OLED_WIDTH; // Roll around at the end
if (messageOffset < OLED_WIDTH) {
// Snap the message to the left edge.
@@ -54,15 +55,7 @@ bool ScrollMessage::drawUpdate(const char *message, TickType_t currentTick) {
messageOffset = (OLED_WIDTH - msgWidth) / 2 + msgWidth;
}
if (lastOffset != messageOffset) {
OLED::clearScreen();
//^ Rolling offset based on time
OLED::setCursor((OLED_WIDTH - messageOffset), 0);
OLED::print(message, FontStyle::LARGE);
lastOffset = messageOffset;
lcdRefresh = true;
}
return lcdRefresh;
//^ Rolling offset based on time
OLED::setCursor((OLED_WIDTH - messageOffset), 0);
OLED::print(message, FontStyle::LARGE);
}