From 177787da182fad74b8339bd92a797221dd213924 Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 3 Dec 2019 16:31:58 +0100 Subject: [PATCH] Fix timer displays in telem view (#7146) Fix timer displays in telem view --- radio/src/gui/128x64/lcd.cpp | 38 ++++++++++++++++++++++ radio/src/gui/128x64/lcd.h | 1 + radio/src/gui/128x64/view_main.cpp | 43 ++----------------------- radio/src/gui/128x64/view_telemetry.cpp | 10 +++--- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/radio/src/gui/128x64/lcd.cpp b/radio/src/gui/128x64/lcd.cpp index 4c671b3ad..15d543e72 100644 --- a/radio/src/gui/128x64/lcd.cpp +++ b/radio/src/gui/128x64/lcd.cpp @@ -875,6 +875,44 @@ void drawDate(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags att) } } +void drawTimerWithMode(coord_t x, coord_t y, uint8_t index, LcdFlags att) +{ + const TimerData &timer = g_model.timers[index]; + + if (timer.mode) { + const TimerState &timerState = timersStates[index]; + const uint8_t negative = (timerState.val < 0 ? BLINK | INVERS : 0); + if (timerState.val < 60 * 60) { // display MM:SS + div_t qr = div((int) abs(timerState.val), 60); + lcdDrawNumber(x - 5, y, qr.rem, att | LEADING0 | negative, 2); + lcdDrawText(lcdLastLeftPos, y, ":", att | BLINK | negative); + lcdDrawNumber(lcdLastLeftPos, y, qr.quot, att | negative); + if (negative) + lcdDrawText(lcdLastLeftPos, y, "-", att | negative); + } + else if (timerState.val < (99 * 60 * 60) + (59 * 60)) { // display HHhMM + div_t qr = div((int) (abs(timerState.val) / 60), 60); + lcdDrawNumber(x - 5, y, qr.rem, att | LEADING0, 2); + lcdDrawText(lcdLastLeftPos, y, "h", att); + lcdDrawNumber(lcdLastLeftPos, y, qr.quot, att); + if (negative) + lcdDrawText(lcdLastLeftPos, y, "-", att); + } + else { //display HHHH for crazy large persistent timers + lcdDrawText(x - 5, y, "h", att); + lcdDrawNumber(lcdLastLeftPos, y, timerState.val / 3600, att); + } + uint8_t xLabel = (negative ? x - 56 : x - 49); + uint8_t len = zlen(timer.name, LEN_TIMER_NAME); + if (len > 0) { + lcdDrawSizedText(xLabel, y + FH, timer.name, len, RIGHT | ZCHAR); + } + else { + drawTimerMode(xLabel, y + FH, timer.mode, RIGHT); + } + } +} + void drawTelemScreenDate(coord_t x, coord_t y, source_t sensor, LcdFlags att) { y+=3; diff --git a/radio/src/gui/128x64/lcd.h b/radio/src/gui/128x64/lcd.h index 1bbfc4b5b..3e7e609ac 100644 --- a/radio/src/gui/128x64/lcd.h +++ b/radio/src/gui/128x64/lcd.h @@ -112,6 +112,7 @@ void lcdDrawSizedText(coord_t x, coord_t y, const char * s, unsigned char len, L void lcdDrawText(coord_t x, coord_t y, const char * s); void lcdDrawSizedText(coord_t x, coord_t y, const char * s, unsigned char len); void lcdDrawTextAlignedLeft(coord_t y, const char * s); +void drawTimerWithMode(coord_t x, coord_t y, uint8_t index, LcdFlags att); #define lcdDrawTextAlignedCenter(y, s) lcdDrawText((LCD_W-sizeof(s)*FW+FW+1)/2, y, s) diff --git a/radio/src/gui/128x64/view_main.cpp b/radio/src/gui/128x64/view_main.cpp index 802c0bd2f..308ba4290 100644 --- a/radio/src/gui/128x64/view_main.cpp +++ b/radio/src/gui/128x64/view_main.cpp @@ -177,45 +177,6 @@ void displayTrims(uint8_t phase) } } -void drawTimerWithMode(coord_t x, coord_t y, uint8_t index) -{ - const TimerData & timer = g_model.timers[index]; - - if (timer.mode) { - const TimerState & timerState = timersStates[index]; - const uint8_t negative = (timerState.val<0 ? BLINK | INVERS : 0); - LcdFlags att = RIGHT | DBLSIZE; - if (timerState.val < 60 * 60) { // display MM:SS - div_t qr = div((int)abs(timerState.val), 60); - lcdDrawNumber(x - 5, y, qr.rem, att | LEADING0 | negative, 2); - lcdDrawText(lcdLastLeftPos, y, ":", att|BLINK | negative); - lcdDrawNumber(lcdLastLeftPos, y, qr.quot, att | negative); - if (negative) - lcdDrawText(lcdLastLeftPos, y, "-", att | negative); - } - else if (timerState.val < (99 * 60 * 60) + (59 * 60)) { // display HHhMM - div_t qr = div((int)(abs(timerState.val) / 60), 60); - lcdDrawNumber(x - 5, y, qr.rem, att | LEADING0, 2); - lcdDrawText(lcdLastLeftPos, y, "h", att); - lcdDrawNumber(lcdLastLeftPos, y, qr.quot, att); - if (negative) - lcdDrawText(lcdLastLeftPos, y, "-", att); - } - else { //display HHHH for crazy large persistent timers - lcdDrawText(x - 5, y, "h", att); - lcdDrawNumber(lcdLastLeftPos, y, timerState.val / 3600, att); - } - uint8_t xLabel = (negative ? x-56 : x-49); - uint8_t len = zlen(timer.name, LEN_TIMER_NAME); - if (len > 0) { - lcdDrawSizedText(xLabel, y+FH, timer.name, len, RIGHT | ZCHAR); - } - else { - drawTimerMode(xLabel, y+FH, timer.mode, RIGHT); - } - } -} - void displayBattVoltage() { #if defined(BATTGRAPH) @@ -461,7 +422,7 @@ void menuMainView(event_t event) displayVoltageOrAlarm(); // Timer 1 - drawTimerWithMode(125, 2*FH, 0); + drawTimerWithMode(125, 2*FH, 0, RIGHT | DBLSIZE); // Trims sliders displayTrims(mode); @@ -599,7 +560,7 @@ void menuMainView(event_t event) } else { // Timer2 - drawTimerWithMode(87, 5*FH, 1); + drawTimerWithMode(87, 5*FH, 1, RIGHT | DBLSIZE); } // And ! in case of unexpected shutdown diff --git a/radio/src/gui/128x64/view_telemetry.cpp b/radio/src/gui/128x64/view_telemetry.cpp index b840a622e..84a0cbf77 100644 --- a/radio/src/gui/128x64/view_telemetry.cpp +++ b/radio/src/gui/128x64/view_telemetry.cpp @@ -45,8 +45,6 @@ void displayRssiLine() } } - - uint8_t barCoord(int16_t value, int16_t min, int16_t max) { if (value <= min) @@ -57,7 +55,6 @@ uint8_t barCoord(int16_t value, int16_t min, int16_t max) return ((int32_t)(BAR_WIDTH-1) * (value - min)) / (max - min); } - bool displayGaugesTelemetryScreen(TelemetryScreenData & screen) { // Custom Screen with gauges @@ -125,9 +122,11 @@ bool displayNumbersTelemetryScreen(TelemetryScreenData & screen) if (field) { LcdFlags att = (i==3 ? RIGHT|NO_UNIT : RIGHT|MIDSIZE|NO_UNIT); coord_t pos[] = {0, 65, 130}; - if (field >= MIXSRC_FIRST_TIMER && field <= MIXSRC_LAST_TIMER && i!=3) { + if (field >= MIXSRC_FIRST_TIMER && field <= MIXSRC_LAST_TIMER && i != 3) { // there is not enough space on LCD for displaying "Tmr1" or "Tmr2" and still see the - sign, we write "T1" or "T2" instead drawStringWithIndex(pos[j], 1+FH+2*FH*i, "T", field-MIXSRC_FIRST_TIMER+1, 0); + drawTimerWithMode(pos[j+1] + 2, 1+FH+2*FH*i, field - MIXSRC_FIRST_TIMER, RIGHT | DBLSIZE); + continue; } else if (field >= MIXSRC_FIRST_TELEM && isGPSSensor(1+(field-MIXSRC_FIRST_TELEM)/3) && telemetryItems[(field-MIXSRC_FIRST_TELEM)/3].isAvailable()) { // we don't display GPS name, no space for it @@ -146,7 +145,8 @@ bool displayNumbersTelemetryScreen(TelemetryScreenData & screen) att |= INVERS|BLINK; } } - if(isSensorUnit(1+(field-MIXSRC_FIRST_TELEM)/3, UNIT_DATETIME) && field >= MIXSRC_FIRST_TELEM) { + + if (isSensorUnit(1+(field-MIXSRC_FIRST_TELEM)/3, UNIT_DATETIME) && field >= MIXSRC_FIRST_TELEM) { drawTelemScreenDate(pos[j+1]-36, 6+FH+2*FH*i, field, SMLSIZE|NO_UNIT); } else {