Skip to content

Commit bcf4751

Browse files
pfeerickclaude
andauthored
fix(color): USB SD card mode may crash to emergency mode (#7657) (#7678)
Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent fd27e23 commit bcf4751

3 files changed

Lines changed: 26 additions & 23 deletions

File tree

radio/src/gui/colorlcd/libui/mainwindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "layout.h"
2424
#include "etx_lv_theme.h"
2525
#include "sdcard.h"
26+
#include "view_main.h"
2627

2728
// timers_driver.h
2829
uint32_t timersGetMsTick();
@@ -57,6 +58,8 @@ void MainWindow::run(bool trash)
5758
{
5859
auto start = timersGetMsTick();
5960

61+
ViewMain::checkWidgetSelectTimeout();
62+
6063
auto opaque = Layer::getFirstOpaque();
6164
if (opaque) {
6265
opaque->checkEvents();

radio/src/gui/colorlcd/mainview/view_main.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,25 +297,20 @@ void ViewMain::onCancel()
297297

298298
void ViewMain::refreshWidgetSelectTimer()
299299
{
300-
if (!widget_select_timer) {
301-
widget_select_timer = lv_timer_create(ViewMain::ws_timer, 10 * 1000, this);
302-
} else {
303-
lv_timer_reset(widget_select_timer);
304-
}
300+
widgetSelectCancelTime = get_tmr10ms() + 1000; // 10 seconds
305301
}
306302

307-
bool ViewMain::enableWidgetSelect(bool enable)
303+
void ViewMain::enableWidgetSelect(bool enable)
308304
{
309305
TRACE("enableWidgetSelect(%d)", enable);
310-
// TODO: start timer
311-
if (widget_select == enable) return false;
306+
if (widget_select == enable) return;
312307
widget_select = enable;
313308

314309
lv_obj_t* tile = lv_tileview_get_tile_act(tile_view);
315-
if (!tile) return true;
310+
if (!tile) return;
316311

317312
auto cont_obj = lv_obj_get_child(tile, 0);
318-
if (!cont_obj) return true;
313+
if (!cont_obj) return;
319314

320315
auto cont = (WidgetsContainer*)lv_obj_get_user_data(cont_obj);
321316

@@ -329,30 +324,33 @@ bool ViewMain::enableWidgetSelect(bool enable)
329324
lv_obj_clear_flag(tile_view, LV_OBJ_FLAG_SCROLLABLE);
330325
lv_obj_clear_flag(tile_view, LV_OBJ_FLAG_SCROLL_CHAIN_HOR);
331326
lv_obj_clear_flag(tile_view, LV_OBJ_FLAG_SCROLL_CHAIN_VER);
327+
328+
refreshWidgetSelectTimer();
332329
} else {
333330
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_SCROLLABLE);
334331
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_SCROLL_CHAIN_HOR);
335332
lv_obj_add_flag(tile_view, LV_OBJ_FLAG_SCROLL_CHAIN_VER);
336333

337-
if (widget_select_timer) {
338-
lv_timer_del(widget_select_timer);
339-
widget_select_timer = nullptr;
340-
}
334+
widgetSelectCancelTime = 0;
341335
}
342-
343-
return true;
344336
}
345337

346338
void ViewMain::openMenu()
347339
{
348340
viewMainMenu = new ViewMainMenu(this, [=]() { viewMainMenu = nullptr; });
349341
}
350342

351-
void ViewMain::ws_timer(lv_timer_t* t)
343+
void ViewMain::checkWidgetSelectTimeout()
352344
{
353-
ViewMain* view = (ViewMain*)t->user_data;
354-
if (!view) return;
355-
view->enableWidgetSelect(false);
345+
if (_instance) _instance->_checkWidgetSelectTimeout();
346+
}
347+
348+
void ViewMain::_checkWidgetSelectTimeout()
349+
{
350+
if (deleted()) return;
351+
352+
if (widget_select && widgetSelectCancelTime < get_tmr10ms())
353+
enableWidgetSelect(false);
356354
}
357355

358356
bool ViewMain::onLongPress()

radio/src/gui/colorlcd/mainview/view_main.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ViewMain : public NavWindow
5454
void enableTopbar();
5555
void disableTopbar();
5656
void updateTopbarVisibility();
57-
bool enableWidgetSelect(bool enable);
57+
void enableWidgetSelect(bool enable);
5858

5959
// Get the available space in the middle of the screen
6060
// (without topbar)
@@ -87,14 +87,16 @@ class ViewMain : public NavWindow
8787
void runBackground();
8888
void refreshWidgetSelectTimer();
8989

90+
static void checkWidgetSelectTimeout();
91+
9092
protected:
9193
static ViewMain* _instance;
9294

9395
bool isVisible = true;
9496
lv_obj_t* tile_view = nullptr;
9597
TopBar* topbar = nullptr;
9698
bool widget_select = false;
97-
lv_timer_t* widget_select_timer = nullptr;
99+
tmr10ms_t widgetSelectCancelTime = 0;
98100
ViewMainMenu* viewMainMenu = nullptr;
99101

100102
// Widget setup requires special permissions ;-)
@@ -105,7 +107,7 @@ class ViewMain : public NavWindow
105107
void setTopbarVisible(float visible);
106108
void setEdgeTxButtonVisible(float visible);
107109

108-
static void ws_timer(lv_timer_t* t);
110+
void _checkWidgetSelectTimeout();
109111

110112
#if defined(HARDWARE_KEYS)
111113
void onPressSYS() override;

0 commit comments

Comments
 (0)