Skip to content

Commit 09d4500

Browse files
authored
Popups followup (#450)
* Popups refactoring follow up
1 parent 0a597df commit 09d4500

File tree

11 files changed

+34
-19
lines changed

11 files changed

+34
-19
lines changed

radio/src/gui/128x64/popups.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void showAlertBox(const char * title, const char * text, const char * action , u
8888

8989
lcdRefresh();
9090
lcdSetContrast();
91-
clearKeyEvents();
91+
waitKeysReleased();
9292
resetBacklightTimeout();
9393
checkBacklight();
9494
}
@@ -101,6 +101,7 @@ void runPopupWarning(event_t event)
101101
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, warningInfoFlags);
102102
}
103103
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+4*FH+2, warningType == WARNING_TYPE_ASTERISK ? STR_EXIT : STR_POPUPS_ENTER_EXIT);
104+
104105
switch (event) {
105106
case EVT_KEY_BREAK(KEY_ENTER):
106107
if (warningType == WARNING_TYPE_ASTERISK)

radio/src/gui/128x64/popups.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ enum
9797

9898
inline void POPUP_WARNING(const char * s)
9999
{
100+
// killAllEvents();
100101
warningText = s;
101102
warningInfoText = nullptr;
102103
warningType = WARNING_TYPE_ASTERISK;
@@ -117,6 +118,7 @@ enum
117118

118119
inline void POPUP_INPUT(const char * s, PopupFunc func)
119120
{
121+
// killAllEvents();
120122
warningText = s;
121123
warningInfoText = nullptr;
122124
warningType = WARNING_TYPE_INPUT;
@@ -130,6 +132,17 @@ enum
130132
warningInfoFlags = flags;
131133
}
132134

135+
inline bool isEventCaughtByPopup()
136+
{
137+
if (warningText && warningType != WARNING_TYPE_WAIT)
138+
return true;
139+
140+
if (popupMenuItemsCount > 0)
141+
return true;
142+
143+
return false;
144+
}
145+
133146
inline void POPUP_MENU_ADD_ITEM(const char * s)
134147
{
135148
popupMenuOffsetType = MENU_OFFSET_INTERNAL;
@@ -157,7 +170,7 @@ inline void POPUP_MENU_TITLE(const char * s)
157170
inline void POPUP_MENU_START(PopupMenuHandler handler)
158171
{
159172
if (handler != popupMenuHandler) {
160-
// killAllEvents(); // not ported yet
173+
// killAllEvents();
161174
AUDIO_KEY_PRESS();
162175
popupMenuHandler = handler;
163176
}

radio/src/gui/128x64/radio_setup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ void menuRadioSetup(event_t event)
614614
g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode;
615615
checkThrottleStick();
616616
resumePulses();
617-
clearKeyEvents();
617+
waitKeysReleased();
618618
}
619619
break;
620620
}

radio/src/gui/212x64/popups.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void showAlertBox(const char * title, const char * text, const char * action, ui
7979
AUDIO_ERROR_MESSAGE(sound);
8080
lcdRefresh();
8181
lcdSetContrast();
82-
clearKeyEvents();
82+
waitKeysReleased();
8383
resetBacklightTimeout();
8484
checkBacklight();
8585
}

radio/src/gui/212x64/radio_setup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void menuRadioSetup(event_t event)
503503
g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode;
504504
checkThrottleStick();
505505
resumePulses();
506-
clearKeyEvents();
506+
waitKeysReleased();
507507
}
508508
break;
509509
}

radio/src/gui/common/stdlcd/view_text.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void readModelNotes()
110110
char *buf = strcat_modelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
111111
strcpy(buf, TEXT_EXT);
112112

113-
clearKeyEvents();
113+
waitKeysReleased();
114114
event_t event = EVT_ENTRY;
115115
while (event != EVT_KEY_BREAK(KEY_EXIT)) {
116116
lcdRefreshWait();

radio/src/keys.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ void killEvents(event_t event) {
166166
}
167167
}
168168

169-
bool clearKeyEvents() {
169+
void killAllEvents()
170+
{
171+
for (uint8_t key = 0; key < DIM(keys); key++) {
172+
keys[key].killEvents();
173+
}
174+
}
175+
176+
bool waitKeysReleased() {
170177

171178
// loop until all keys are up
172179
#if !defined(BOOT)

radio/src/keys.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,9 @@ inline void putEvent(event_t evt)
110110

111111
void pauseEvents(event_t event);
112112
void killEvents(event_t event);
113-
114-
bool clearKeyEvents();
113+
void killAllEvents();
114+
bool waitKeysReleased();
115115
event_t getEvent(bool trim=false);
116116
bool keyDown();
117117

118-
119-
120118
#endif // _KEYS_H_

radio/src/main.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -381,24 +381,20 @@ void guiMain(event_t evt)
381381
menuEvent = 0;
382382
}
383383

384+
handleGui(isEventCaughtByPopup() ? 0 : evt);
385+
384386
if (warningText) {
385387
// show warning on top of the normal menus
386-
handleGui(0); // suppress events, they are handled by the warning
387388
DISPLAY_WARNING(evt);
388389
}
389390
else if (popupMenuItemsCount > 0) {
390391
// popup menu is active display it on top of normal menus
391-
handleGui(0); // suppress events, they are handled by the popup
392392
const char * result = runPopupMenu(evt);
393393
if (result) {
394394
TRACE("popupMenuHandler(%s)", result);
395395
popupMenuHandler(result);
396396
}
397397
}
398-
else {
399-
// normal menus
400-
handleGui(evt);
401-
}
402398

403399
lcdRefresh();
404400
}

radio/src/opentx.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ void checkAll() {
858858
}
859859
#endif
860860

861-
if (!clearKeyEvents()) {
861+
if (!waitKeysReleased()) {
862862
showMessageBox(STR_KEYSTUCK);
863863
tmr10ms_t tgtime = get_tmr10ms() + 500;
864864
while (tgtime != get_tmr10ms()) {

radio/src/switches.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ void checkSwitches()
719719

720720
lcdRefresh();
721721
lcdSetContrast();
722-
clearKeyEvents();
722+
waitKeysReleased();
723723

724724
last_bad_switches = switches_states;
725725
}

0 commit comments

Comments
 (0)