Skip to content

Commit bf6fa05

Browse files
authored
fix(color): timer widget warning flash and minus sign for negative values (#7939)
1 parent 64c7221 commit bf6fa05

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

‎radio/src/gui/colorlcd/widgets/timer.cpp‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class TimerWidget : public Widget
8383
lv_obj_set_pos(digits0, D0_X, D0_Y);
8484
digits1 = createDigitsLabel();
8585
lv_obj_set_pos(digits1, D1_X, D1_Y);
86+
minusLabel = etx_label_create(lvobj, FONT_XL_INDEX);
87+
lv_label_set_text(minusLabel, "-");
88+
etx_txt_color(minusLabel, COLOR_THEME_SECONDARY1_INDEX);
89+
etx_txt_color(minusLabel, COLOR_THEME_SECONDARY2_INDEX,
90+
LV_PART_MAIN | ETX_NAME_TXT_WARNING);
91+
lv_obj_align_to(minusLabel, digits0, LV_ALIGN_OUT_LEFT_TOP, 0, 0);
92+
lv_obj_add_flag(minusLabel, LV_OBJ_FLAG_HIDDEN);
8693

8794
timerArc = lv_arc_create(lvobj);
8895
lv_arc_set_rotation(timerArc, 270);
@@ -145,6 +152,11 @@ class TimerWidget : public Widget
145152
lv_label_set_text(unit0, sUnit0);
146153
lv_label_set_text(unit1, sUnit1);
147154

155+
if (val < 0)
156+
lv_obj_clear_flag(minusLabel, LV_OBJ_FLAG_HIDDEN);
157+
else
158+
lv_obj_add_flag(minusLabel, LV_OBJ_FLAG_HIDDEN);
159+
148160
if (lastValue > 0 && lastStartValue > 0) {
149161
lv_obj_clear_flag(timerArc, LV_OBJ_FLAG_HIDDEN);
150162
timerIcon->hide();
@@ -157,7 +169,7 @@ class TimerWidget : public Widget
157169

158170
TimerOptions timerOptions;
159171
timerOptions.options = (abs(val) >= 3600) ? SHOW_TIME : SHOW_TIMER;
160-
getTimerString(str, abs(val), timerOptions);
172+
getTimerString(str, val, timerOptions);
161173
lv_label_set_text(valLabel, str);
162174

163175
if (width() <= SMALL_TXT_MAX_W && height() <= SMALL_TXT_MAX_H && abs(val) >= 3600)
@@ -168,15 +180,20 @@ class TimerWidget : public Widget
168180
lv_obj_add_flag(timerArc, LV_OBJ_FLAG_HIDDEN);
169181
timerIcon->hide();
170182
}
183+
}
171184

172-
// Set colors if timer has elapsed.
173-
if (lastValue < 0 && lastValue % 2) {
185+
// Set colors if timer has elapsed.
186+
bool warning = (lastValue < 0) && BLINK_ON_PHASE;
187+
if (warning != lastWarning) {
188+
lastWarning = warning;
189+
if (warning) {
174190
if (isLarge) {
175191
lv_obj_add_state(nameLabel, ETX_NAME_TXT_WARNING);
176192
lv_obj_add_state(digits0, ETX_NAME_TXT_WARNING);
177193
lv_obj_add_state(digits1, ETX_NAME_TXT_WARNING);
178194
lv_obj_add_state(unit0, ETX_NAME_TXT_WARNING);
179195
lv_obj_add_state(unit1, ETX_NAME_TXT_WARNING);
196+
lv_obj_add_state(minusLabel, ETX_NAME_TXT_WARNING);
180197
lv_obj_clear_state(lvobj, ETX_STATE_BG_WARNING);
181198
timerBg->setColor(COLOR_THEME_WARNING_INDEX);
182199
timerIcon->setColor(COLOR_THEME_SECONDARY2_INDEX);
@@ -190,6 +207,7 @@ class TimerWidget : public Widget
190207
lv_obj_clear_state(digits1, ETX_NAME_TXT_WARNING);
191208
lv_obj_clear_state(unit0, ETX_NAME_TXT_WARNING);
192209
lv_obj_clear_state(unit1, ETX_NAME_TXT_WARNING);
210+
lv_obj_clear_state(minusLabel, ETX_NAME_TXT_WARNING);
193211
timerBg->setColor(COLOR_THEME_PRIMARY2_INDEX);
194212
timerIcon->setColor(COLOR_THEME_SECONDARY1_INDEX);
195213
}
@@ -222,6 +240,7 @@ class TimerWidget : public Widget
222240
protected:
223241
tmrval_t lastValue = 0;
224242
uint32_t lastStartValue = -1;
243+
int8_t lastWarning = -1;
225244
bool isLarge = false;
226245
lv_style_t style;
227246
lv_obj_t* nameLabel = nullptr;
@@ -230,6 +249,7 @@ class TimerWidget : public Widget
230249
lv_obj_t* digits1 = nullptr;
231250
lv_obj_t* unit0 = nullptr;
232251
lv_obj_t* unit1 = nullptr;
252+
lv_obj_t* minusLabel = nullptr;
233253
lv_obj_t* timerArc = nullptr;
234254
StaticIcon* timerBg = nullptr;
235255
StaticIcon* timerIcon = nullptr;
@@ -248,6 +268,10 @@ class TimerWidget : public Widget
248268

249269
bool hasName = ZLEN(timerData.name) > 0;
250270

271+
// Force value and color refresh
272+
lastStartValue = -1;
273+
lastWarning = -1;
274+
251275
if (width() >= TMR_LRG_W && height() >= TMR_LRG_H) {
252276
isLarge = true;
253277
if (hasName)
@@ -275,6 +299,7 @@ class TimerWidget : public Widget
275299
lv_obj_add_flag(digits1, LV_OBJ_FLAG_HIDDEN);
276300
lv_obj_add_flag(unit0, LV_OBJ_FLAG_HIDDEN);
277301
lv_obj_add_flag(unit1, LV_OBJ_FLAG_HIDDEN);
302+
lv_obj_add_flag(minusLabel, LV_OBJ_FLAG_HIDDEN);
278303
timerBg->hide();
279304
}
280305

0 commit comments

Comments
 (0)