introduction of a scene registry
This commit is contained in:
parent
3265eef33b
commit
eef110f733
19 changed files with 647 additions and 141 deletions
|
@ -7,22 +7,19 @@
|
|||
#include "device_keyboard_mqtt/device_keyboard_mqtt.h"
|
||||
#include "device_keyboard_ble/device_keyboard_ble.h"
|
||||
#include "commandHandler.h"
|
||||
#include "scenes/sceneHandler.h"
|
||||
|
||||
std::map<std::string, commandData> commands;
|
||||
byte allDevsPowered = 0;
|
||||
String currentScene = "";
|
||||
|
||||
commandData makeCommandData(commandHandlers a, std::list<std::string> b) {
|
||||
commandData c = {a, b};
|
||||
return c;
|
||||
}
|
||||
|
||||
void init_deviceIndependantCommands() {
|
||||
// put commands here if you want
|
||||
commands[ALLDEVICES_POWER_TOGGLE] = makeCommandData(SPECIAL, {""});
|
||||
commands[SCENE_TV] = makeCommandData(SPECIAL, {""});
|
||||
commands[SCENE_FIRETV] = makeCommandData(SPECIAL, {""});
|
||||
commands[SCENE_CHROMECAST] = makeCommandData(SPECIAL, {""});
|
||||
void register_specialCommands() {
|
||||
// put SPECIAL commands here if you want
|
||||
commands[MY_SPECIAL_COMMAND] = makeCommandData(SPECIAL, {""});
|
||||
|
||||
}
|
||||
|
||||
void executeCommandWithData(std::string command, commandData commandData, std::string additionalPayload = "") {
|
||||
|
@ -142,71 +139,17 @@ void executeCommandWithData(std::string command, commandData commandData, std::s
|
|||
}
|
||||
#endif
|
||||
|
||||
case SCENE: {
|
||||
// let the sceneHandler do the scene stuff
|
||||
Serial.printf("execute: will send scene command to the sceneHandler\r\n");
|
||||
handleScene(command, commandData, additionalPayload);
|
||||
break;
|
||||
}
|
||||
|
||||
case SPECIAL: {
|
||||
|
||||
if (command == ALLDEVICES_POWER_TOGGLE) {
|
||||
// this variant toggles power state, dependant on the value of allDevsPowered
|
||||
// currently we do not toggle, but switch all devices off
|
||||
// if (allDevsPowered == 0) {
|
||||
// executeCommand(SAMSUNG_POWER_ON);
|
||||
// delay(500);
|
||||
// executeCommand(YAMAHA_POWER_ON);
|
||||
// delay(4500);
|
||||
// currentScene = "";
|
||||
// allDevsPowered = 1;
|
||||
// } else {
|
||||
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);
|
||||
currentScene = "";
|
||||
allDevsPowered = 0;
|
||||
// }
|
||||
|
||||
} else if (command == SCENE_TV) {
|
||||
executeCommand(SAMSUNG_POWER_ON);
|
||||
delay(500);
|
||||
executeCommand(YAMAHA_POWER_ON);
|
||||
delay(1500);
|
||||
executeCommand(YAMAHA_INPUT_DVD);
|
||||
delay(3000);
|
||||
executeCommand(SAMSUNG_INPUT_TV);
|
||||
|
||||
currentScene = SCENE_TV;
|
||||
allDevsPowered = 1;
|
||||
|
||||
} else if (command == SCENE_FIRETV) {
|
||||
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);
|
||||
|
||||
currentScene = SCENE_FIRETV;
|
||||
allDevsPowered = 1;
|
||||
|
||||
} else if (command == SCENE_CHROMECAST) {
|
||||
executeCommand(SAMSUNG_POWER_ON);
|
||||
delay(500);
|
||||
executeCommand(YAMAHA_POWER_ON);
|
||||
delay(1500);
|
||||
executeCommand(YAMAHA_INPUT_DVD);
|
||||
delay(3000);
|
||||
executeCommand(SAMSUNG_INPUT_HDMI_1);
|
||||
|
||||
currentScene = SCENE_CHROMECAST;
|
||||
allDevsPowered = 1;
|
||||
if (command == MY_SPECIAL_COMMAND) {
|
||||
// do your special command here
|
||||
Serial.printf("execute: could execute a special command here, if you define one\r\n");
|
||||
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -93,16 +93,11 @@
|
|||
// #pragma message "2 The value is: " XSTR(KEYBOARD_MQTT_UP)
|
||||
// #pragma message "3 The value is: " XSTR(KEYBOARD_UP)
|
||||
|
||||
#define ALLDEVICES_POWER_TOGGLE "AllDevices_power_toggle"
|
||||
#define SCENE_TV "Scene_tv"
|
||||
#define SCENE_FIRETV "Scene_firetv"
|
||||
#define SCENE_CHROMECAST "Scene_chromecast"
|
||||
|
||||
extern byte allDevsPowered;
|
||||
extern String currentScene; // Current scene that is active
|
||||
#define MY_SPECIAL_COMMAND "My_special_command"
|
||||
|
||||
enum commandHandlers {
|
||||
SPECIAL,
|
||||
SCENE
|
||||
IR_GC,
|
||||
IR_NEC,
|
||||
IR_SAMSUNG,
|
||||
|
@ -125,7 +120,7 @@ commandData makeCommandData(commandHandlers a, std::list<std::string> b);
|
|||
|
||||
extern std::map<std::string, commandData> commands;
|
||||
|
||||
void init_deviceIndependantCommands();
|
||||
void register_specialCommands();
|
||||
void executeCommand(std::string command, std::string additionalPayload = "");
|
||||
|
||||
#endif /*__COMMANDHANDLER_H__*/
|
||||
|
|
|
@ -10,6 +10,7 @@ lv_obj_t* WifiLabel = NULL;
|
|||
lv_obj_t* BluetoothLabel;
|
||||
lv_obj_t* objBattPercentage;
|
||||
lv_obj_t* objBattIcon;
|
||||
lv_obj_t* SceneLabel;
|
||||
byte currentScreen = 1; // Current Device to control (allows switching mappings between devices)
|
||||
|
||||
// LVGL declarations
|
||||
|
@ -192,6 +193,12 @@ void init_gui(void) {
|
|||
lv_obj_align(BluetoothLabel, LV_ALIGN_LEFT_MID, 12, 0);
|
||||
lv_obj_set_style_text_font(BluetoothLabel, &lv_font_montserrat_12, LV_PART_MAIN);
|
||||
|
||||
// Scene ------------------------------------------------------------------------
|
||||
SceneLabel = lv_label_create(statusbar);
|
||||
lv_label_set_text(SceneLabel, "");
|
||||
lv_obj_align(SceneLabel, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_style_text_font(SceneLabel, &lv_font_montserrat_12, LV_PART_MAIN);
|
||||
|
||||
// Battery ----------------------------------------------------------------------
|
||||
objBattPercentage = lv_label_create(statusbar);
|
||||
lv_label_set_text(objBattPercentage, "");
|
||||
|
|
|
@ -9,6 +9,7 @@ LV_IMG_DECLARE(high_brightness);
|
|||
LV_IMG_DECLARE(low_brightness);
|
||||
extern lv_obj_t* objBattPercentage;
|
||||
extern lv_obj_t* objBattIcon;
|
||||
extern lv_obj_t* SceneLabel;
|
||||
extern lv_color_t color_primary;
|
||||
|
||||
extern lv_obj_t* WifiLabel;
|
||||
|
|
|
@ -6,7 +6,13 @@
|
|||
#include "hardware/mqtt.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/sceneHandler.h"
|
||||
|
||||
const byte ROWS = 5; //five rows
|
||||
const byte COLS = 5; //five columns
|
||||
|
@ -54,51 +60,7 @@ void init_keys(void) {
|
|||
pinMode(SW_E, INPUT);
|
||||
}
|
||||
|
||||
enum repeatModes {
|
||||
// if you short press or hold a key on the keypad, only one single command from keyCommands_short is sent
|
||||
// -> best used if you do not want a command to be sent more than once, even if you press the key (too) long, e.g. when toggling power
|
||||
SHORT,
|
||||
// if you hold a key on the keypad, a command from keyCommands_short is sent repeatedly
|
||||
// -> best used e.g. for holding the key for "volume up"
|
||||
SHORT_REPEATED,
|
||||
// if you short press a key, a command from keyCommands_short is sent once.
|
||||
// if you hold a key on the keypad, a command from keyCommands_long is sent (no command from keyCommands_short before)
|
||||
// -> best used if a long key press should send a different command than a short press
|
||||
SHORTorLONG,
|
||||
};
|
||||
|
||||
std::map<char, repeatModes> keyRepeatModes {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> keyCommands_short {
|
||||
{'o', ALLDEVICES_POWER_TOGGLE},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', KEYBOARD_FASTFORWARD_LONG},
|
||||
};
|
||||
|
||||
KeyState lastKeyState[ROWS][COLS] = {
|
||||
KeyState lastKeyState[ROWS][COLS] = {
|
||||
{IDLE,IDLE,IDLE,IDLE,IDLE},
|
||||
{IDLE,IDLE,IDLE,IDLE,IDLE},
|
||||
{IDLE,IDLE,IDLE,IDLE,IDLE},
|
||||
|
@ -126,9 +88,10 @@ void doShortPress(char keyChar, int keyCode){
|
|||
if ((currentMillis - lastTimeSent[keyCode/ROWS][keyCode%ROWS]) > repeatRate) {
|
||||
lastTimeSent[keyCode/ROWS][keyCode%ROWS] = currentMillis;
|
||||
|
||||
if (keyCommands_short.count(keyChar) > 0) {
|
||||
Serial.printf("key: key '%c', will use command '%s'\r\n", keyChar, keyCommands_short[keyChar].c_str());
|
||||
executeCommand(keyCommands_short[keyChar]);
|
||||
std::string command = get_command_short(currentScene, keyChar);
|
||||
if (command != COMMAND_UNKNOWN) {
|
||||
Serial.printf("key: key '%c', will use command '%s'\r\n", keyChar, command.c_str());
|
||||
executeCommand(command);
|
||||
} else {
|
||||
Serial.printf("key: key '%c', but no command defined\r\n", keyChar);
|
||||
}
|
||||
|
@ -136,9 +99,10 @@ void doShortPress(char keyChar, int keyCode){
|
|||
}
|
||||
|
||||
void doLongPress(char keyChar, int keyCode){
|
||||
if (key_commands_long.count(keyChar) > 0) {
|
||||
Serial.printf("key: key '%c' (long press), will use command '%s'\r\n", keyChar, key_commands_long[keyChar].c_str());
|
||||
executeCommand(key_commands_long[keyChar]);
|
||||
std::string command = get_command_long(currentScene, keyChar);
|
||||
if (command != COMMAND_UNKNOWN) {
|
||||
Serial.printf("key: key '%c' (long press), will use command '%s'\r\n", keyChar, command.c_str());
|
||||
executeCommand(command);
|
||||
} else {
|
||||
Serial.printf("key: key '%c' (long press), but no command defined\r\n", keyChar);
|
||||
}
|
||||
|
@ -161,11 +125,11 @@ void keypad_loop(void) {
|
|||
if (customKeypad.key[i].kstate == PRESSED) {
|
||||
// Serial.println("pressed");
|
||||
|
||||
if ((keyRepeatModes[keyChar] == SHORT) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) {
|
||||
if ((get_key_repeatMode(currentScene, keyChar) == SHORT) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) {
|
||||
// Serial.printf("key: PRESSED of SHORT key %c (%d)\r\n", keyChar, keyCode);
|
||||
doShortPress(keyChar, keyCode);
|
||||
|
||||
} else if ((keyRepeatModes[keyChar] == SHORT_REPEATED) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) { // here do not repeat it too early, do the repeat only in HOLD
|
||||
} else if ((get_key_repeatMode(currentScene, keyChar) == SHORT_REPEATED) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != PRESSED)) { // here do not repeat it too early, do the repeat only in HOLD
|
||||
// Serial.printf("key: PRESSED of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode);
|
||||
doShortPress(keyChar, keyCode);
|
||||
|
||||
|
@ -175,13 +139,13 @@ void keypad_loop(void) {
|
|||
} else if (customKeypad.key[i].kstate == HOLD) {
|
||||
// Serial.println("hold");
|
||||
|
||||
if ((keyRepeatModes[keyChar] == SHORTorLONG) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != HOLD)) {
|
||||
if ((get_key_repeatMode(currentScene, keyChar) == SHORTorLONG) && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != HOLD)) {
|
||||
// Serial.printf("key: HOLD of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode);
|
||||
// Serial.printf("will set keyIsHold to TRUE for keycode %d\r\n", keyCode);
|
||||
keyIsHold[keyCode/ROWS][keyCode%ROWS] = true;
|
||||
doLongPress(keyChar, keyCode);
|
||||
|
||||
} else if (keyRepeatModes[keyChar] == SHORT_REPEATED) { // this is the only case where we do not check the lastKeyState, because here it is intended to repeat the action
|
||||
} else if (get_key_repeatMode(currentScene, keyChar) == SHORT_REPEATED) { // this is the only case where we do not check the lastKeyState, because here it is intended to repeat the action
|
||||
// Serial.printf("key: HOLD of SHORT_REPEATED key %c (%d)\r\n", keyChar, keyCode);
|
||||
doShortPress(keyChar, keyCode);
|
||||
|
||||
|
@ -190,7 +154,7 @@ void keypad_loop(void) {
|
|||
|
||||
} else if (customKeypad.key[i].kstate == RELEASED) {
|
||||
// Serial.println("released");
|
||||
if ((keyRepeatModes[keyChar] == SHORTorLONG) && !keyIsHold[keyCode/ROWS][keyCode%ROWS] && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != RELEASED)) {
|
||||
if ((get_key_repeatMode(currentScene, keyChar) == SHORTorLONG) && !keyIsHold[keyCode/ROWS][keyCode%ROWS] && (lastKeyState[keyCode/ROWS][keyCode%ROWS] != RELEASED)) {
|
||||
// Serial.printf("value of keyIsHold for keycode %d is %d\r\n", keyCode, keyIsHold[keyCode/ROWS][keyCode%ROWS]);
|
||||
// Serial.printf("key: RELEASED of SHORTorLONG key %c (%d)\r\n", keyChar, keyCode);
|
||||
doShortPress(keyChar, keyCode);
|
||||
|
|
|
@ -16,6 +16,20 @@
|
|||
|
||||
#define BUTTON_PIN_BITMASK 0b1110110000000000000000000010000000000000 //IO34+IO35+IO37+IO38+IO39(+IO13)
|
||||
|
||||
enum repeatModes {
|
||||
REPEAT_MODE_UNKNOWN,
|
||||
// if you short press or hold a key on the keypad, only one single command from keyCommands_short is sent
|
||||
// -> best used if you do not want a command to be sent more than once, even if you press the key (too) long, e.g. when toggling power
|
||||
SHORT,
|
||||
// if you hold a key on the keypad, a command from keyCommands_short is sent repeatedly
|
||||
// -> best used e.g. for holding the key for "volume up"
|
||||
SHORT_REPEATED,
|
||||
// if you short press a key, a command from keyCommands_short is sent once.
|
||||
// if you hold a key on the keypad, a command from keyCommands_long is sent (no command from keyCommands_short before)
|
||||
// -> best used if a long key press should send a different command than a short press
|
||||
SHORTorLONG,
|
||||
};
|
||||
|
||||
void init_keys(void);
|
||||
void keypad_loop(void);
|
||||
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
#include "device_appleTV/gui_appleTV.h"
|
||||
#include "device_smarthome/gui_smarthome.h"
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
// scenes
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "scenes/sceneHandler.h"
|
||||
// misc
|
||||
#include "preferences_storage.h"
|
||||
#include "commandHandler.h"
|
||||
|
@ -48,10 +54,6 @@ void setup() {
|
|||
init_userled();
|
||||
// init TFT
|
||||
init_tft();
|
||||
// init WiFi
|
||||
#ifdef ENABLE_WIFI_AND_MQTT
|
||||
init_mqtt();
|
||||
#endif
|
||||
// setup the Inertial Measurement Unit (IMU) for motion detection
|
||||
// needs to be after init_tft()) because of I2C
|
||||
setup_IMU();
|
||||
|
@ -69,7 +71,7 @@ void setup() {
|
|||
#ifdef ENABLE_KEYBOARD_BLE
|
||||
register_device_keyboard_ble();
|
||||
#endif
|
||||
init_deviceIndependantCommands();
|
||||
register_specialCommands();
|
||||
|
||||
// register the GUIs. They will be displayed in the order they are registered.
|
||||
register_gui_irReceiver();
|
||||
|
@ -81,6 +83,18 @@ void setup() {
|
|||
init_gui();
|
||||
gui_loop(); // Run the LVGL UI once before the loop takes over
|
||||
|
||||
// register the scenes
|
||||
register_scene_allOff();
|
||||
register_scene_TV();
|
||||
register_scene_fireTV();
|
||||
register_scene_chromecast();
|
||||
setLabelCurrentScene();
|
||||
|
||||
// init WiFi - needs to be after gui because WifiLabel must be available
|
||||
#ifdef ENABLE_WIFI_AND_MQTT
|
||||
init_mqtt();
|
||||
#endif
|
||||
|
||||
Serial.print("Setup finished in ");
|
||||
Serial.print(millis());
|
||||
Serial.println("ms.");
|
||||
|
|
55
Platformio/src/scenes/sceneHandler.cpp
Normal file
55
Platformio/src/scenes/sceneHandler.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <string>
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
#include "gui_general_and_keys/guiBase.h"
|
||||
|
||||
std::string currentScene = "";
|
||||
|
||||
void handleScene(std::string command, commandData commandData, std::string additionalPayload = "") {
|
||||
|
||||
auto current = commandData.commandPayloads.begin();
|
||||
std::string scene_name = *current;
|
||||
|
||||
// check if we know the new scene
|
||||
if (!sceneExists(scene_name)) {
|
||||
Serial.printf("scene: cannot start scene %s, because it is unknown\r\n", scene_name.c_str());
|
||||
return;
|
||||
} else {
|
||||
Serial.printf("scene: will switch from old scene %s to new scene %s\r\n", currentScene.c_str(), scene_name.c_str());
|
||||
}
|
||||
|
||||
lv_label_set_text(SceneLabel, "changing...");
|
||||
gui_loop();
|
||||
|
||||
// end old scene
|
||||
if (!sceneExists(currentScene) && (currentScene != "")) {
|
||||
Serial.printf("scene: WARNING: cannot end scene %s, because it is unknown\r\n", currentScene.c_str());
|
||||
|
||||
} else {
|
||||
if (currentScene != "") {
|
||||
Serial.printf("scene: will call end sequence for scene %s\r\n", currentScene.c_str());
|
||||
scene_end_sequence_from_registry(currentScene);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// start new scene
|
||||
Serial.printf("scene: will call start sequence for scene %s\r\n", scene_name.c_str());
|
||||
scene_start_sequence_from_registry(scene_name);
|
||||
|
||||
currentScene = scene_name;
|
||||
|
||||
lv_label_set_text(SceneLabel, currentScene.c_str());
|
||||
|
||||
Serial.printf("scene: scene handling finished, new scene %s is active\r\n", currentScene.c_str());
|
||||
}
|
||||
|
||||
void setLabelCurrentScene() {
|
||||
lv_label_set_text(SceneLabel, currentScene.c_str());
|
||||
}
|
12
Platformio/src/scenes/sceneHandler.h
Normal file
12
Platformio/src/scenes/sceneHandler.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __SCENEHANDLER_H__
|
||||
#define __SCENEHANDLER_H__
|
||||
|
||||
#include <string>
|
||||
#include "commandHandler.h"
|
||||
|
||||
extern std::string currentScene; // Current scene that is active
|
||||
|
||||
void handleScene(std::string command, commandData commandData, std::string additionalPayload = "");
|
||||
void setLabelCurrentScene();
|
||||
|
||||
#endif /*__SCENEHANDLER_H__*/
|
139
Platformio/src/scenes/sceneRegistry.cpp
Normal file
139
Platformio/src/scenes/sceneRegistry.cpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
#include "scenes/sceneregistry.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
std::map<char, repeatModes> key_repeatModes_default {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_short_default {
|
||||
{'o', SCENE_ALLOFF},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long_default {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', KEYBOARD_FASTFORWARD_LONG},
|
||||
};
|
||||
|
||||
// https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work
|
||||
struct scene_definition {
|
||||
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;
|
||||
};
|
||||
|
||||
std::map<std::string, scene_definition> registered_scenes;
|
||||
|
||||
void register_scene(
|
||||
std::string a_scene_name,
|
||||
scene_start_sequence a_scene_start_sequence,
|
||||
scene_end_sequence a_scene_end_sequence,
|
||||
key_repeatModes a_key_repeatModes,
|
||||
key_commands_short a_key_commands_short,
|
||||
key_commands_long a_key_commands_long) {
|
||||
|
||||
registered_scenes[a_scene_name] = scene_definition{
|
||||
a_scene_start_sequence,
|
||||
a_scene_end_sequence,
|
||||
a_key_repeatModes,
|
||||
a_key_commands_short,
|
||||
a_key_commands_long
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bool sceneExists(std::string sceneName) {
|
||||
return (registered_scenes.count(sceneName) > 0);
|
||||
}
|
||||
|
||||
void scene_start_sequence_from_registry(std::string sceneName) {
|
||||
registered_scenes[sceneName].this_scene_start_sequence();
|
||||
}
|
||||
|
||||
void scene_end_sequence_from_registry(std::string sceneName) {
|
||||
registered_scenes[sceneName].this_scene_end_sequence();
|
||||
}
|
||||
|
||||
repeatModes get_key_repeatMode(std::string sceneName, char keyChar) {
|
||||
// look if the map of the current scene has a definition for it
|
||||
if (registered_scenes[sceneName].this_key_repeatModes->count(keyChar) > 0) {
|
||||
// Serial.printf("get_key_repeatMode: will use key from scene %s\r\n", sceneName.c_str());
|
||||
return registered_scenes[sceneName].this_key_repeatModes->at(keyChar);
|
||||
|
||||
// look if there is a default definition
|
||||
} else if (key_repeatModes_default.count(keyChar) > 0) {
|
||||
// Serial.printf("get_key_repeatMode: will use default key\r\n");
|
||||
return key_repeatModes_default[keyChar];
|
||||
|
||||
// no key definition found
|
||||
} else {
|
||||
// Serial.printf("get_key_repeatMode: WARNING no key definition found\r\n");
|
||||
return REPEAT_MODE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_command_short(std::string sceneName, char keyChar) {
|
||||
// look if the map of the current scene has a definition for it
|
||||
if (registered_scenes[sceneName].this_key_commands_short->count(keyChar) > 0) {
|
||||
Serial.printf("get_command_short: will use key from scene %s\r\n", sceneName.c_str());
|
||||
return registered_scenes[sceneName].this_key_commands_short->at(keyChar);
|
||||
|
||||
// look if there is a default definition
|
||||
} else if (key_commands_short_default.count(keyChar) > 0) {
|
||||
Serial.printf("get_command_short: will use default key\r\n");
|
||||
return key_commands_short_default[keyChar];
|
||||
|
||||
// no key definition found
|
||||
} else {
|
||||
Serial.printf("get_command_short: WARNING no key definition found\r\n");
|
||||
return COMMAND_UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string get_command_long(std::string sceneName, char keyChar) {
|
||||
// look if the map of the current scene has a definition for it
|
||||
if (registered_scenes[sceneName].this_key_commands_long->count(keyChar) > 0) {
|
||||
Serial.printf("get_command_long: will use key from scene %s\r\n", sceneName.c_str());
|
||||
return registered_scenes[sceneName].this_key_commands_long->at(keyChar);
|
||||
|
||||
// look if there is a default definition
|
||||
} else if (key_commands_long_default.count(keyChar) > 0) {
|
||||
Serial.printf("get_command_long: will use default key\r\n");
|
||||
return key_commands_long_default[keyChar];
|
||||
|
||||
// no key definition found
|
||||
} else {
|
||||
Serial.printf("get_command_long: WARNING no key definition found\r\n");
|
||||
return COMMAND_UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
30
Platformio/src/scenes/sceneRegistry.h
Normal file
30
Platformio/src/scenes/sceneRegistry.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef __SCENE_REGISTRY_H__
|
||||
#define __SCENE_REGISTRY_H__
|
||||
|
||||
#include <map>
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
|
||||
typedef void (*scene_start_sequence)(void);
|
||||
typedef void (*scene_end_sequence)(void);
|
||||
typedef std::map<char, repeatModes> *key_repeatModes;
|
||||
typedef std::map<char, std::string> *key_commands_short;
|
||||
typedef std::map<char, std::string> *key_commands_long;
|
||||
|
||||
void register_scene(
|
||||
std::string a_scene_name,
|
||||
scene_start_sequence a_scene_start_sequence,
|
||||
scene_end_sequence a_scene_end_sequence,
|
||||
key_repeatModes a_key_repeatModes,
|
||||
key_commands_short a_key_commands_short,
|
||||
key_commands_long a_key_commands_long);
|
||||
|
||||
#define COMMAND_UNKNOWN "command_unknown"
|
||||
|
||||
bool sceneExists(std::string sceneName);
|
||||
void scene_start_sequence_from_registry(std::string sceneName);
|
||||
void scene_end_sequence_from_registry(std::string sceneName);
|
||||
repeatModes get_key_repeatMode(std::string sceneName, char keyChar);
|
||||
std::string get_command_short(std::string sceneName, char keyChar);
|
||||
std::string get_command_long(std::string sceneName, char keyChar);
|
||||
|
||||
#endif /*__SCENE_REGISTRY_H__*/
|
70
Platformio/src/scenes/scene_TV.cpp
Normal file
70
Platformio/src/scenes/scene_TV.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include <map>
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
std::map<char, repeatModes> key_repeatModes_TV {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_short_TV {
|
||||
{'o', SCENE_ALLOFF},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long_TV {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', KEYBOARD_FASTFORWARD_LONG},
|
||||
};
|
||||
|
||||
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_scene(
|
||||
scene_name_TV,
|
||||
& scene_start_sequence_TV,
|
||||
& scene_end_sequence_TV,
|
||||
& key_repeatModes_TV,
|
||||
& key_commands_short_TV,
|
||||
& key_commands_long_TV);
|
||||
|
||||
commands[SCENE_TV] = makeCommandData(SCENE, {scene_name_TV});
|
||||
}
|
8
Platformio/src/scenes/scene_TV.h
Normal file
8
Platformio/src/scenes/scene_TV.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __SCENE_TV_H__
|
||||
#define __SCENE_TV_H__
|
||||
|
||||
#define SCENE_TV "Scene_tv"
|
||||
|
||||
void register_scene_TV(void);
|
||||
|
||||
#endif /*__SCENE_TV_H__*/
|
81
Platformio/src/scenes/scene_allOff.cpp
Normal file
81
Platformio/src/scenes/scene_allOff.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include <map>
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
std::map<char, repeatModes> key_repeatModes_allOff {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_short_allOff {
|
||||
{'o', SCENE_ALLOFF},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long_allOff {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', KEYBOARD_FASTFORWARD_LONG},
|
||||
};
|
||||
|
||||
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_scene(
|
||||
scene_name_allOff,
|
||||
& scene_start_sequence_allOff,
|
||||
& scene_end_sequence_allOff,
|
||||
& key_repeatModes_allOff,
|
||||
& key_commands_short_allOff,
|
||||
& key_commands_long_allOff);
|
||||
|
||||
commands[SCENE_ALLOFF] = makeCommandData(SCENE, {scene_name_allOff});
|
||||
}
|
8
Platformio/src/scenes/scene_allOff.h
Normal file
8
Platformio/src/scenes/scene_allOff.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __SCENE_ALLOFF_H__
|
||||
#define __SCENE_ALLOFF_H__
|
||||
|
||||
#define SCENE_ALLOFF "Scene_allOff"
|
||||
|
||||
void register_scene_allOff(void);
|
||||
|
||||
#endif /*__SCENE_ALLOFF_H__*/
|
70
Platformio/src/scenes/scene_chromecast.cpp
Normal file
70
Platformio/src/scenes/scene_chromecast.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include <map>
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
std::map<char, repeatModes> key_repeatModes_chromecast {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_short_chromecast {
|
||||
{'o', SCENE_ALLOFF},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long_chromecast {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', KEYBOARD_FASTFORWARD_LONG},
|
||||
};
|
||||
|
||||
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_scene(
|
||||
scene_name_chromecast,
|
||||
& scene_start_sequence_chromecast,
|
||||
& scene_end_sequence_chromecast,
|
||||
& key_repeatModes_chromecast,
|
||||
& key_commands_short_chromecast,
|
||||
& key_commands_long_chromecast);
|
||||
|
||||
commands[SCENE_CHROMECAST] = makeCommandData(SCENE, {scene_name_chromecast});
|
||||
}
|
8
Platformio/src/scenes/scene_chromecast.h
Normal file
8
Platformio/src/scenes/scene_chromecast.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __SCENE_CHROMECAST_H__
|
||||
#define __SCENE_CHROMECAST_H__
|
||||
|
||||
#define SCENE_CHROMECAST "Scene_chromecast"
|
||||
|
||||
void register_scene_chromecast(void);
|
||||
|
||||
#endif /*__SCENE_CHROMECAST_H__*/
|
79
Platformio/src/scenes/scene_fireTV.cpp
Normal file
79
Platformio/src/scenes/scene_fireTV.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include <map>
|
||||
#include "gui_general_and_keys/keys.h"
|
||||
#include "device_samsungTV/device_samsungTV.h"
|
||||
#include "device_yamahaAmp/device_yamahaAmp.h"
|
||||
#include "scenes/sceneRegistry.h"
|
||||
#include "scenes/scene_allOff.h"
|
||||
#include "scenes/scene_TV.h"
|
||||
#include "scenes/scene_fireTV.h"
|
||||
#include "scenes/scene_chromecast.h"
|
||||
#include "commandHandler.h"
|
||||
|
||||
std::map<char, repeatModes> key_repeatModes_fireTV {
|
||||
{'o', SHORT },
|
||||
{'=', SHORT }, {'<', SHORTorLONG }, {'p', SHORT }, {'>', SHORTorLONG },
|
||||
{'c', SHORT }, {'i', SHORT },
|
||||
{'u', SHORT },
|
||||
{'l', SHORT }, {'k', SHORT }, {'r', SHORT },
|
||||
{'d', SHORT },
|
||||
{'b', SHORT }, {'s', SHORT },
|
||||
{'+', SHORT_REPEATED}, {'m', SHORT }, {'^', SHORT },
|
||||
{'-', SHORT_REPEATED}, {'e', SHORT }, {'v', SHORT },
|
||||
{'1', SHORT }, {'2', SHORT }, {'3', SHORT }, {'4', SHORT },
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_short_fireTV {
|
||||
{'o', SCENE_ALLOFF},
|
||||
/*{'=', KEYBOARD_PLAYPAUSE},*/ {'<', KEYBOARD_REWIND}, {'p', KEYBOARD_PLAYPAUSE}, {'>', KEYBOARD_FASTFORWARD},
|
||||
{'c', KEYBOARD_HOME}, {'i', KEYBOARD_MENU},
|
||||
{'u', KEYBOARD_UP},
|
||||
{'l', KEYBOARD_LEFT}, {'k', KEYBOARD_SELECT}, {'r', KEYBOARD_RIGHT},
|
||||
{'d', KEYBOARD_DOWN},
|
||||
/* {'b', }, */ {'s', KEYBOARD_BACK},
|
||||
{'+', YAMAHA_VOL_PLUS}, {'m', YAMAHA_MUTE_TOGGLE}, {'^', SAMSUNG_CHANNEL_UP},
|
||||
{'-', YAMAHA_VOL_MINUS}, /* {'e', }, */ {'v', SAMSUNG_CHANNEL_DOWN},
|
||||
{'1', SCENE_TV}, {'2', SCENE_FIRETV}, {'3', SCENE_CHROMECAST}, {'4', YAMAHA_STANDARD},
|
||||
};
|
||||
|
||||
std::map<char, std::string> key_commands_long_fireTV {
|
||||
{'<', KEYBOARD_REWIND_LONG},
|
||||
{'>', 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_scene(
|
||||
scene_name_fireTV,
|
||||
& scene_start_sequence_fireTV,
|
||||
& scene_end_sequence_fireTV,
|
||||
& key_repeatModes_fireTV,
|
||||
& key_commands_short_fireTV,
|
||||
& key_commands_long_fireTV);
|
||||
|
||||
commands[SCENE_FIRETV] = makeCommandData(SCENE, {scene_name_fireTV});
|
||||
}
|
8
Platformio/src/scenes/scene_fireTV.h
Normal file
8
Platformio/src/scenes/scene_fireTV.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef __SCENE_FIRETV_H__
|
||||
#define __SCENE_FIRETV_H__
|
||||
|
||||
#define SCENE_FIRETV "Scene_firetv"
|
||||
|
||||
void register_scene_fireTV(void);
|
||||
|
||||
#endif /*__SCENE_FIRETV_H__*/
|
Loading…
Add table
Reference in a new issue