diff --git a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp index 5f0d0db..f4aedf4 100644 --- a/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp +++ b/Platformio/src/applicationInternal/scenes/sceneRegistry.cpp @@ -8,6 +8,7 @@ // 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; @@ -19,6 +20,7 @@ std::map registered_scenes; void register_scene( std::string a_scene_name, + scene_setKeys a_scene_setKeys, scene_start_sequence a_scene_start_sequence, scene_end_sequence a_scene_end_sequence, key_repeatModes a_key_repeatModes, @@ -26,6 +28,7 @@ void register_scene( key_commands_long a_key_commands_long) { registered_scenes[a_scene_name] = scene_definition{ + a_scene_setKeys, a_scene_start_sequence, a_scene_end_sequence, a_key_repeatModes, @@ -33,6 +36,16 @@ void register_scene( a_key_commands_long }; + // 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. The command at this time was 0, which is undefined. + // So we have to set the keys again for all 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(); + } + } bool sceneExists(std::string sceneName) { diff --git a/Platformio/src/applicationInternal/scenes/sceneRegistry.h b/Platformio/src/applicationInternal/scenes/sceneRegistry.h index c49c3f9..4b96c99 100644 --- a/Platformio/src/applicationInternal/scenes/sceneRegistry.h +++ b/Platformio/src/applicationInternal/scenes/sceneRegistry.h @@ -5,6 +5,7 @@ #include #include "applicationInternal/keys.h" +typedef void (*scene_setKeys)(void); typedef void (*scene_start_sequence)(void); typedef void (*scene_end_sequence)(void); typedef std::map *key_repeatModes; @@ -13,6 +14,7 @@ typedef std::map *key_commands_long; void register_scene( std::string a_scene_name, + scene_setKeys a_scene_setKeys, scene_start_sequence a_scene_start_sequence, scene_end_sequence a_scene_end_sequence, key_repeatModes a_key_repeatModes, diff --git a/Platformio/src/main.cpp b/Platformio/src/main.cpp index 7cbffc3..5f68fcc 100644 --- a/Platformio/src/main.cpp +++ b/Platformio/src/main.cpp @@ -91,14 +91,7 @@ int main(int argc, char *argv[]) { init_gui(); gui_loop(); // Run the LVGL UI once before the loop takes over - // register the scenes - // First the commands of all scenes have to be registered, so that they get their unique ids. - // Later they will be used in register_scenes_*, where the commands will be used when defining the key_commands_* - register_scene_allOff_commands(); - register_scene_TV_commands(); - register_scene_fireTV_commands(); - register_scene_chromecast_commands(); - // now the scenes and their key_commands_* can be defined + // register the scenes and their key_commands_* register_scene_defaultKeys(); register_scene_allOff(); register_scene_TV(); diff --git a/Platformio/src/scenes/scene_TV.cpp b/Platformio/src/scenes/scene_TV.cpp index 8c4c2ce..3ea7a6f 100644 --- a/Platformio/src/scenes/scene_TV.cpp +++ b/Platformio/src/scenes/scene_TV.cpp @@ -14,29 +14,7 @@ std::map key_repeatModes_TV; std::map key_commands_short_TV; std::map key_commands_long_TV; -void scene_start_sequence_TV(void) { - executeCommand(SAMSUNG_POWER_ON); - delay(500); - executeCommand(YAMAHA_POWER_ON); - delay(1500); - executeCommand(YAMAHA_INPUT_DVD); - delay(3000); - executeCommand(SAMSUNG_INPUT_TV); - -} - -void scene_end_sequence_TV(void) { - -} - -std::string scene_name_TV = "TV"; - -void register_scene_TV_commands(void) { - register_command(&SCENE_TV , makeCommandData(SCENE, {scene_name_TV})); -} - -void register_scene_TV(void) { - +void scene_setKeys_TV() { key_repeatModes_TV = { {KEY_STOP, SHORT_REPEATED }, {KEY_REWI, SHORT }, {KEY_PLAY, SHORT }, {KEY_FORW, SHORT_REPEATED }, @@ -68,8 +46,31 @@ void register_scene_TV(void) { }; +} + +void scene_start_sequence_TV(void) { + executeCommand(SAMSUNG_POWER_ON); + delay(500); + executeCommand(YAMAHA_POWER_ON); + delay(1500); + executeCommand(YAMAHA_INPUT_DVD); + delay(3000); + executeCommand(SAMSUNG_INPUT_TV); + +} + +void scene_end_sequence_TV(void) { + +} + +std::string scene_name_TV = "TV"; + +void register_scene_TV(void) { + register_command(&SCENE_TV , makeCommandData(SCENE, {scene_name_TV})); + register_scene( scene_name_TV, + & scene_setKeys_TV, & scene_start_sequence_TV, & scene_end_sequence_TV, & key_repeatModes_TV, diff --git a/Platformio/src/scenes/scene_allOff.cpp b/Platformio/src/scenes/scene_allOff.cpp index cf52154..f4e8a8f 100644 --- a/Platformio/src/scenes/scene_allOff.cpp +++ b/Platformio/src/scenes/scene_allOff.cpp @@ -14,39 +14,7 @@ std::map key_repeatModes_allOff; std::map key_commands_short_allOff; std::map key_commands_long_allOff; -void scene_start_sequence_allOff(void) { - executeCommand(SAMSUNG_POWER_OFF); - delay(500); - executeCommand(YAMAHA_POWER_OFF); - delay(500); - // repeat IR to be sure - executeCommand(SAMSUNG_POWER_OFF); - delay(500); - executeCommand(YAMAHA_POWER_OFF); - delay(500); - // repeat IR to be sure - executeCommand(SAMSUNG_POWER_OFF); - delay(500); - executeCommand(YAMAHA_POWER_OFF); - delay(500); - // you cannot power off FireTV, but at least you can stop the currently running app - executeCommand(KEYBOARD_HOME); - delay(500); - executeCommand(KEYBOARD_HOME); - -} - -void scene_end_sequence_allOff(void) { - -} - -std::string scene_name_allOff = "Off"; - -void register_scene_allOff_commands(void) { - register_command(&SCENE_ALLOFF , makeCommandData(SCENE, {scene_name_allOff})); -} - -void register_scene_allOff(void) { +void scene_setKeys_allOff() { key_repeatModes_allOff = { @@ -78,8 +46,42 @@ void register_scene_allOff(void) { }; +} + +void scene_start_sequence_allOff(void) { + executeCommand(SAMSUNG_POWER_OFF); + delay(500); + executeCommand(YAMAHA_POWER_OFF); + delay(500); + // repeat IR to be sure + executeCommand(SAMSUNG_POWER_OFF); + delay(500); + executeCommand(YAMAHA_POWER_OFF); + delay(500); + // repeat IR to be sure + executeCommand(SAMSUNG_POWER_OFF); + delay(500); + executeCommand(YAMAHA_POWER_OFF); + delay(500); + // you cannot power off FireTV, but at least you can stop the currently running app + executeCommand(KEYBOARD_HOME); + delay(500); + executeCommand(KEYBOARD_HOME); + +} + +void scene_end_sequence_allOff(void) { + +} + +std::string scene_name_allOff = "Off"; + +void register_scene_allOff(void) { + register_command(&SCENE_ALLOFF , makeCommandData(SCENE, {scene_name_allOff})); + register_scene( scene_name_allOff, + & scene_setKeys_allOff, & scene_start_sequence_allOff, & scene_end_sequence_allOff, & key_repeatModes_allOff, diff --git a/Platformio/src/scenes/scene_chromecast.cpp b/Platformio/src/scenes/scene_chromecast.cpp index 5d27176..78361c0 100644 --- a/Platformio/src/scenes/scene_chromecast.cpp +++ b/Platformio/src/scenes/scene_chromecast.cpp @@ -14,28 +14,7 @@ std::map key_repeatModes_chromecast; std::map key_commands_short_chromecast; std::map key_commands_long_chromecast; -void scene_start_sequence_chromecast(void) { - executeCommand(SAMSUNG_POWER_ON); - delay(500); - executeCommand(YAMAHA_POWER_ON); - delay(1500); - executeCommand(YAMAHA_INPUT_DVD); - delay(3000); - executeCommand(SAMSUNG_INPUT_HDMI_1); - -} - -void scene_end_sequence_chromecast(void) { - -} - -std::string scene_name_chromecast = "Chromecast"; - -void register_scene_chromecast_commands(void) { - register_command(&SCENE_CHROMECAST , makeCommandData(SCENE, {scene_name_chromecast})); -} - -void register_scene_chromecast(void) { +void scene_setKeys_chromecast() { key_repeatModes_chromecast = { @@ -67,8 +46,31 @@ void register_scene_chromecast(void) { }; +} + +void scene_start_sequence_chromecast(void) { + executeCommand(SAMSUNG_POWER_ON); + delay(500); + executeCommand(YAMAHA_POWER_ON); + delay(1500); + executeCommand(YAMAHA_INPUT_DVD); + delay(3000); + executeCommand(SAMSUNG_INPUT_HDMI_1); + +} + +void scene_end_sequence_chromecast(void) { + +} + +std::string scene_name_chromecast = "Chromecast"; + +void register_scene_chromecast(void) { + register_command(&SCENE_CHROMECAST , makeCommandData(SCENE, {scene_name_chromecast})); + register_scene( scene_name_chromecast, + & scene_setKeys_chromecast, & scene_start_sequence_chromecast, & scene_end_sequence_chromecast, & key_repeatModes_chromecast, diff --git a/Platformio/src/scenes/scene_fireTV.cpp b/Platformio/src/scenes/scene_fireTV.cpp index 5e4742e..4f2a61f 100644 --- a/Platformio/src/scenes/scene_fireTV.cpp +++ b/Platformio/src/scenes/scene_fireTV.cpp @@ -14,37 +14,7 @@ std::map key_repeatModes_fireTV; std::map key_commands_short_fireTV; std::map key_commands_long_fireTV; -void scene_start_sequence_fireTV(void) { - executeCommand(SAMSUNG_POWER_ON); - delay(500); - executeCommand(YAMAHA_POWER_ON); - delay(1500); - executeCommand(YAMAHA_INPUT_DTV); - delay(3000); - executeCommand(SAMSUNG_INPUT_HDMI_2); - delay(100); - - executeCommand(KEYBOARD_HOME); - delay(500); - executeCommand(KEYBOARD_HOME); - -} - -void scene_end_sequence_fireTV(void) { - // you cannot power off FireTV, but at least you can stop the currently running app - executeCommand(KEYBOARD_HOME); - delay(500); - executeCommand(KEYBOARD_HOME); - -} - -std::string scene_name_fireTV = "Fire TV"; - -void register_scene_fireTV_commands(void) { - register_command(&SCENE_FIRETV , makeCommandData(SCENE, {scene_name_fireTV})); -} - -void register_scene_fireTV(void) { +void scene_setKeys_fireTV() { key_repeatModes_fireTV = { {KEY_REWI, SHORTorLONG }, {KEY_PLAY, SHORT }, {KEY_FORW, SHORTorLONG }, @@ -76,8 +46,40 @@ void register_scene_fireTV(void) { {KEY_FORW, KEYBOARD_FASTFORWARD_LONG}, }; +} + +void scene_start_sequence_fireTV(void) { + executeCommand(SAMSUNG_POWER_ON); + delay(500); + executeCommand(YAMAHA_POWER_ON); + delay(1500); + executeCommand(YAMAHA_INPUT_DTV); + delay(3000); + executeCommand(SAMSUNG_INPUT_HDMI_2); + delay(100); + + executeCommand(KEYBOARD_HOME); + delay(500); + executeCommand(KEYBOARD_HOME); + +} + +void scene_end_sequence_fireTV(void) { + // you cannot power off FireTV, but at least you can stop the currently running app + executeCommand(KEYBOARD_HOME); + delay(500); + executeCommand(KEYBOARD_HOME); + +} + +std::string scene_name_fireTV = "Fire TV"; + +void register_scene_fireTV(void) { + register_command(&SCENE_FIRETV , makeCommandData(SCENE, {scene_name_fireTV})); + register_scene( scene_name_fireTV, + & scene_setKeys_fireTV, & scene_start_sequence_fireTV, & scene_end_sequence_fireTV, & key_repeatModes_fireTV,