Skip to content

Commit

Permalink
Popups followup (#450)
Browse files Browse the repository at this point in the history
* Popups refactoring follow up
  • Loading branch information
ajjjjjjjj authored Dec 23, 2024
1 parent 0a597df commit 09d4500
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
3 changes: 2 additions & 1 deletion radio/src/gui/128x64/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void showAlertBox(const char * title, const char * text, const char * action , u

lcdRefresh();
lcdSetContrast();
clearKeyEvents();
waitKeysReleased();
resetBacklightTimeout();
checkBacklight();
}
Expand All @@ -101,6 +101,7 @@ void runPopupWarning(event_t event)
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, warningInfoFlags);
}
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+4*FH+2, warningType == WARNING_TYPE_ASTERISK ? STR_EXIT : STR_POPUPS_ENTER_EXIT);

switch (event) {
case EVT_KEY_BREAK(KEY_ENTER):
if (warningType == WARNING_TYPE_ASTERISK)
Expand Down
15 changes: 14 additions & 1 deletion radio/src/gui/128x64/popups.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ enum

inline void POPUP_WARNING(const char * s)
{
// killAllEvents();
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_ASTERISK;
Expand All @@ -117,6 +118,7 @@ enum

inline void POPUP_INPUT(const char * s, PopupFunc func)
{
// killAllEvents();
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_INPUT;
Expand All @@ -130,6 +132,17 @@ enum
warningInfoFlags = flags;
}

inline bool isEventCaughtByPopup()
{
if (warningText && warningType != WARNING_TYPE_WAIT)
return true;

if (popupMenuItemsCount > 0)
return true;

return false;
}

inline void POPUP_MENU_ADD_ITEM(const char * s)
{
popupMenuOffsetType = MENU_OFFSET_INTERNAL;
Expand Down Expand Up @@ -157,7 +170,7 @@ inline void POPUP_MENU_TITLE(const char * s)
inline void POPUP_MENU_START(PopupMenuHandler handler)
{
if (handler != popupMenuHandler) {
// killAllEvents(); // not ported yet
// killAllEvents();
AUDIO_KEY_PRESS();
popupMenuHandler = handler;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void menuRadioSetup(event_t event)
g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode;
checkThrottleStick();
resumePulses();
clearKeyEvents();
waitKeysReleased();
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/212x64/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void showAlertBox(const char * title, const char * text, const char * action, ui
AUDIO_ERROR_MESSAGE(sound);
lcdRefresh();
lcdSetContrast();
clearKeyEvents();
waitKeysReleased();
resetBacklightTimeout();
checkBacklight();
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/212x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ void menuRadioSetup(event_t event)
g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode;
checkThrottleStick();
resumePulses();
clearKeyEvents();
waitKeysReleased();
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/common/stdlcd/view_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void readModelNotes()
char *buf = strcat_modelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
strcpy(buf, TEXT_EXT);

clearKeyEvents();
waitKeysReleased();
event_t event = EVT_ENTRY;
while (event != EVT_KEY_BREAK(KEY_EXIT)) {
lcdRefreshWait();
Expand Down
9 changes: 8 additions & 1 deletion radio/src/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ void killEvents(event_t event) {
}
}

bool clearKeyEvents() {
void killAllEvents()
{
for (uint8_t key = 0; key < DIM(keys); key++) {
keys[key].killEvents();
}
}

bool waitKeysReleased() {

// loop until all keys are up
#if !defined(BOOT)
Expand Down
6 changes: 2 additions & 4 deletions radio/src/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ inline void putEvent(event_t evt)

void pauseEvents(event_t event);
void killEvents(event_t event);

bool clearKeyEvents();
void killAllEvents();
bool waitKeysReleased();
event_t getEvent(bool trim=false);
bool keyDown();



#endif // _KEYS_H_
8 changes: 2 additions & 6 deletions radio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,20 @@ void guiMain(event_t evt)
menuEvent = 0;
}

handleGui(isEventCaughtByPopup() ? 0 : evt);

if (warningText) {
// show warning on top of the normal menus
handleGui(0); // suppress events, they are handled by the warning
DISPLAY_WARNING(evt);
}
else if (popupMenuItemsCount > 0) {
// popup menu is active display it on top of normal menus
handleGui(0); // suppress events, they are handled by the popup
const char * result = runPopupMenu(evt);
if (result) {
TRACE("popupMenuHandler(%s)", result);
popupMenuHandler(result);
}
}
else {
// normal menus
handleGui(evt);
}

lcdRefresh();
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void checkAll() {
}
#endif

if (!clearKeyEvents()) {
if (!waitKeysReleased()) {
showMessageBox(STR_KEYSTUCK);
tmr10ms_t tgtime = get_tmr10ms() + 500;
while (tgtime != get_tmr10ms()) {
Expand Down
2 changes: 1 addition & 1 deletion radio/src/switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ void checkSwitches()

lcdRefresh();
lcdSetContrast();
clearKeyEvents();
waitKeysReleased();

last_bad_switches = switches_states;
}
Expand Down

0 comments on commit 09d4500

Please sign in to comment.