Skip to content

Commit

Permalink
set keys again both for new guis and new scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausMu committed May 9, 2024
1 parent 17ee1f0 commit 8f0ceeb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
19 changes: 15 additions & 4 deletions Platformio/src/applicationInternal/gui/guiRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ void register_gui(
// Can be overwritten by scenes to have their own gui_list.
main_gui_list.insert(main_gui_list.end(), {std::string(a_name)});

// Whenever a new gui is registered, a new gui command could have been defined.
// But this new gui command could have been already been used before in the key definition of another gui. The command at this time was 0, which is undefined.
// So we have to set the keys again for all guis that have been registered before.
// Loop over all registered guis and call setKeys()
setKeysForAllRegisteredGUIsAndScenes();

}

void setKeysForAllRegisteredGUIsAndScenes() {
// Whenever a new gui or scene is registered, a new gui or scene command could have been defined in the gui or scene.
// But this new command could have already been used before in the key definition of another gui or scene. The command at this time was 0, which is undefined.
// So we have to set the keys again for all guis and scenes that have been registered before.
// 1. set again the defaultKeys
register_scene_defaultKeys();
// 2. loop over all registered scenes and call setKeys()
for (std::map<std::string, scene_definition>::iterator it = registered_scenes.begin(); it != registered_scenes.end(); ++it) {
it->second.this_scene_setKeys();
}
// 3. loop over all registered guis and call setKeys()
for (std::map<std::string, gui_definition>::iterator it = registered_guis_byName_map.begin(); it != registered_guis_byName_map.end(); ++it) {
if (it->second.this_gui_setKeys != NULL) {
it->second.this_gui_setKeys();
Expand Down
2 changes: 2 additions & 0 deletions Platformio/src/applicationInternal/gui/guiRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ void register_gui(
key_commands_short a_key_commands_short = NULL,
key_commands_long a_key_commands_long = NULL
);

void setKeysForAllRegisteredGUIsAndScenes();
28 changes: 1 addition & 27 deletions Platformio/src/applicationInternal/scenes/sceneRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
// scenes
#include "scenes/scene__default.h"

// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
struct scene_definition {
scene_setKeys this_scene_setKeys;
scene_start_sequence this_scene_start_sequence;
scene_end_sequence this_scene_end_sequence;
key_repeatModes this_key_repeatModes;
key_commands_short this_key_commands_short;
key_commands_long this_key_commands_long;
gui_list this_gui_list;
uint16_t this_activate_scene_command;
};

std::map<std::string, scene_definition> registered_scenes;
t_scene_list scenes_on_sceneSelectionGUI;

Expand Down Expand Up @@ -51,21 +39,7 @@ void register_scene(
// Can be overwritten in main.cpp
scenes_on_sceneSelectionGUI.insert(scenes_on_sceneSelectionGUI.end(), {std::string(a_scene_name)});

// Whenever a new scene is registered, normally a new scene command has been defined immediately before (e.g. see register_scene_TV()).
// But this new scene command could have been already been used before in the key definition of another scene or a gui. The command at this time was 0, which is undefined.
// So we have to set the keys again for all scenes and guis that have been registered before.
// 1. set again the defaultKeys
register_scene_defaultKeys();
// 2. loop over all registered scenes and call setKeys()
for (std::map<std::string, scene_definition>::iterator it = registered_scenes.begin(); it != registered_scenes.end(); ++it) {
it->second.this_scene_setKeys();
}
// 3. loop over all registered guis and call setKeys()
for (std::map<std::string, gui_definition>::iterator it = registered_guis_byName_map.begin(); it != registered_guis_byName_map.end(); ++it) {
if (it->second.this_gui_setKeys != NULL) {
it->second.this_gui_setKeys();
}
}
setKeysForAllRegisteredGUIsAndScenes();

}

Expand Down
14 changes: 14 additions & 0 deletions Platformio/src/applicationInternal/scenes/sceneRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ typedef void (*scene_end_sequence)(void);
typedef t_gui_list *gui_list;
typedef t_scene_list *scene_list;

// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
struct scene_definition {
scene_setKeys this_scene_setKeys;
scene_start_sequence this_scene_start_sequence;
scene_end_sequence this_scene_end_sequence;
key_repeatModes this_key_repeatModes;
key_commands_short this_key_commands_short;
key_commands_long this_key_commands_long;
gui_list this_gui_list;
uint16_t this_activate_scene_command;
};

extern std::map<std::string, scene_definition> registered_scenes;

void register_scene(
std::string a_scene_name,
scene_setKeys a_scene_setKeys,
Expand Down
1 change: 0 additions & 1 deletion Platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int main(int argc, char *argv[]) {
register_keyboardCommands();

// Register the GUIs. They will be displayed in the order they have been registered.
// GUIs must be registered before the scenes, because only the scenes re-register key bindings to commands which have been defined after the key binding (see register_scene())
register_gui_sceneSelection();
register_gui_irReceiver();
register_gui_settings();
Expand Down

0 comments on commit 8f0ceeb

Please sign in to comment.