diff --git a/Platformio/src/applicationInternal/gui/guiRegistry.cpp b/Platformio/src/applicationInternal/gui/guiRegistry.cpp index b2c30fd..ed628a4 100644 --- a/Platformio/src/applicationInternal/gui/guiRegistry.cpp +++ b/Platformio/src/applicationInternal/gui/guiRegistry.cpp @@ -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::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::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(); diff --git a/Platformio/src/applicationInternal/gui/guiRegistry.h b/Platformio/src/applicationInternal/gui/guiRegistry.h index c4a6296..26b81a6 100644 --- a/Platformio/src/applicationInternal/gui/guiRegistry.h +++ b/Platformio/src/applicationInternal/gui/guiRegistry.h @@ -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(); \ No newline at end of file diff --git a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp index 74f354e..81df397 100644 --- a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp +++ b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp @@ -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 registered_scenes; t_scene_list scenes_on_sceneSelectionGUI; @@ -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::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::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(); } diff --git a/Platformio/src/applicationInternal/scenes/sceneRegistry.h b/Platformio/src/applicationInternal/scenes/sceneRegistry.h index a89d43e..8ff50c4 100644 --- a/Platformio/src/applicationInternal/scenes/sceneRegistry.h +++ b/Platformio/src/applicationInternal/scenes/sceneRegistry.h @@ -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 registered_scenes; + void register_scene( std::string a_scene_name, scene_setKeys a_scene_setKeys, diff --git a/Platformio/src/main.cpp b/Platformio/src/main.cpp index f39b5ab..13962b7 100644 --- a/Platformio/src/main.cpp +++ b/Platformio/src/main.cpp @@ -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();