diff --git a/Platformio/src/commandHandler.cpp b/Platformio/src/commandHandler.cpp index 2d76561..f6329d9 100644 --- a/Platformio/src/commandHandler.cpp +++ b/Platformio/src/commandHandler.cpp @@ -75,6 +75,22 @@ void executeCommandWithData(std::string command, commandData commandData, std::s break; } + case IR_SONY: { + if (additionalPayload != "") { + // https://cplusplus.com/reference/string/stoull/ + std::string::size_type sz = 0; // alias of size_t + const uint64_t data = std::stoull(additionalPayload, &sz, 0); + // // https://stackoverflow.com/questions/42356939/c-convert-string-to-uint64-t + // std::istringstream iss(additionalPayload); + // iss >> payload; + Serial.printf("execute: will send IR SONY, data %s (%" PRIu64 ")\r\n", additionalPayload.c_str(), data); + IrSender.sendSony(data, 15); + } else { + Serial.printf("execute: cannot send IR SONY, because payload is empty\r\n"); + } + break; + } + #ifdef ENABLE_WIFI_AND_MQTT case MQTT: { auto current = commandData.commandPayloads.begin(); diff --git a/Platformio/src/commandHandler.h b/Platformio/src/commandHandler.h index 6f228ed..1aecb90 100644 --- a/Platformio/src/commandHandler.h +++ b/Platformio/src/commandHandler.h @@ -106,6 +106,7 @@ enum commandHandlers { IR_GC, IR_NEC, IR_SAMSUNG, + IR_SONY, #ifdef ENABLE_WIFI_AND_MQTT MQTT, #endif diff --git a/Platformio/src/device_appleTV/device_appleTV.cpp b/Platformio/src/device_appleTV/device_appleTV.cpp new file mode 100644 index 0000000..af009ae --- /dev/null +++ b/Platformio/src/device_appleTV/device_appleTV.cpp @@ -0,0 +1,6 @@ +#include "commandHandler.h" +#include "device_appleTV/device_appleTV.h" + +void init_appleTV_commands() { + commands[APPLETV_GUI_EVENT_USER_DATA] = makeCommandData(IR_SONY, {}); // payload must be set when calling commandHandler +} diff --git a/Platformio/src/device_appleTV/device_appleTV.h b/Platformio/src/device_appleTV/device_appleTV.h new file mode 100644 index 0000000..6b25178 --- /dev/null +++ b/Platformio/src/device_appleTV/device_appleTV.h @@ -0,0 +1,8 @@ +#ifndef __DEVICE_APPLETV_H__ +#define __DEVICE_APPLETV_H__ + +#define APPLETV_GUI_EVENT_USER_DATA "AppleTV_gui_event_user_data" + +void init_appleTV_commands(); + +#endif /*__DEVICE_APPLETV_H__*/ diff --git a/Platformio/src/device_appleTV/gui_appleTV.cpp b/Platformio/src/device_appleTV/gui_appleTV.cpp index f20ff7e..3b65349 100644 --- a/Platformio/src/device_appleTV/gui_appleTV.cpp +++ b/Platformio/src/device_appleTV/gui_appleTV.cpp @@ -1,8 +1,9 @@ #include // #include "assets.c" +#include "device_appleTV/device_appleTV.h" #include "gui_general/gui.h" #include "hardware/tft.h" -#include "hardware/infrared_sender.h" +#include "commandHandler.h" // LVGL declarations LV_IMG_DECLARE(appleTvIcon); @@ -12,7 +13,7 @@ LV_IMG_DECLARE(appleBackIcon); // Apple Key Event handler static void appleKey_event_cb(lv_event_t* e) { // Send IR command based on the event user data - IrSender.sendSony(50 + (int)e->user_data, 15); + executeCommand(APPLETV_GUI_EVENT_USER_DATA, std::to_string(50 + (int)e->user_data)); Serial.println(50 + (int)e->user_data); } diff --git a/Platformio/src/device_smarthome/device_smarthome.cpp b/Platformio/src/device_smarthome/device_smarthome.cpp new file mode 100644 index 0000000..536febb --- /dev/null +++ b/Platformio/src/device_smarthome/device_smarthome.cpp @@ -0,0 +1,9 @@ +#include "commandHandler.h" +#include "device_smarthome/device_smarthome.h" + +void init_smarthome_mqtt_commands() { + commands[SMARTHOME_MQTT_BULB1_SET] = makeCommandData(MQTT, {"bulb1_set" }); // payload must be set when calling commandHandler + commands[SMARTHOME_MQTT_BULB2_SET] = makeCommandData(MQTT, {"bulb2_set" }); // payload must be set when calling commandHandler + commands[SMARTHOME_MQTT_BULB1_BRIGHTNESS_SET] = makeCommandData(MQTT, {"bulb1_setbrightness" }); // payload must be set when calling commandHandler + commands[SMARTHOME_MQTT_BULB2_BRIGHTNESS_SET] = makeCommandData(MQTT, {"bulb2_setbrightness" }); // payload must be set when calling commandHandler +} diff --git a/Platformio/src/device_smarthome/device_smarthome.h b/Platformio/src/device_smarthome/device_smarthome.h new file mode 100644 index 0000000..a1f272e --- /dev/null +++ b/Platformio/src/device_smarthome/device_smarthome.h @@ -0,0 +1,11 @@ +#ifndef __DEVICE_SMARTHOME_H__ +#define __DEVICE_SMARTHOME_H__ + +#define SMARTHOME_MQTT_BULB1_SET "Smarthome_mqtt_bulb1_set" +#define SMARTHOME_MQTT_BULB2_SET "Smarthome_mqtt_bulb2_set" +#define SMARTHOME_MQTT_BULB1_BRIGHTNESS_SET "Smarthome_mqtt_bulb1_brightness_set" +#define SMARTHOME_MQTT_BULB2_BRIGHTNESS_SET "Smarthome_mqtt_bulb2_brightness_set" + +void init_smarthome_mqtt_commands(); + +#endif /*__DEVICE_SMARTHOME_H__*/ diff --git a/Platformio/src/device_smarthome/gui_smarthome.cpp b/Platformio/src/device_smarthome/gui_smarthome.cpp index 9f424c4..7ac5114 100644 --- a/Platformio/src/device_smarthome/gui_smarthome.cpp +++ b/Platformio/src/device_smarthome/gui_smarthome.cpp @@ -1,8 +1,9 @@ +#include #include // #include "assets.c" #include "gui_general/gui.h" #include "hardware/tft.h" -#include "hardware/mqtt.h" +#include "device_smarthome/device_smarthome.h" #include "commandHandler.h" // LVGL declarations @@ -10,25 +11,26 @@ LV_IMG_DECLARE(lightbulb); // Smart Home Toggle Event handler static void smartHomeToggle_event_cb(lv_event_t * e){ - char payload[8]; - if(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)) strcpy(payload,"true"); - else strcpy(payload,"false"); + std::string payload; + if (lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)) payload = "true"; + else payload = "false"; // Publish an MQTT message based on the event user data #ifdef ENABLE_WIFI_AND_MQTT - if((int)e->user_data == 1) publishMQTTMessage("bulb1_set", payload); - if((int)e->user_data == 2) publishMQTTMessage("bulb2_set", payload); + if((int)e->user_data == 1) executeCommand(SMARTHOME_MQTT_BULB1_SET, payload); + if((int)e->user_data == 2) executeCommand(SMARTHOME_MQTT_BULB2_SET, payload); #endif } -// Smart Home Toggle Event handler +// Smart Home Slider Event handler static void smartHomeSlider_event_cb(lv_event_t * e){ lv_obj_t * slider = lv_event_get_target(e); char payload[8]; dtostrf(lv_slider_get_value(slider), 1, 2, payload); + std::string payload_str(payload); // Publish an MQTT message based on the event user data #ifdef ENABLE_WIFI_AND_MQTT - if((int)e->user_data == 1) publishMQTTMessage("bulb1_setbrightness", payload); - if((int)e->user_data == 2) publishMQTTMessage("bulb2_setbrightness", payload); + if((int)e->user_data == 1) executeCommand(SMARTHOME_MQTT_BULB1_BRIGHTNESS_SET, payload); + if((int)e->user_data == 2) executeCommand(SMARTHOME_MQTT_BULB2_BRIGHTNESS_SET, payload); #endif } diff --git a/Platformio/src/main.cpp b/Platformio/src/main.cpp index 5cb0722..b37ed8f 100644 --- a/Platformio/src/main.cpp +++ b/Platformio/src/main.cpp @@ -13,6 +13,8 @@ #include "hardware/user_led.h" #include "device_samsungTV/device_samsungTV.h" #include "device_yamahaAmp/device_yamahaAmp.h" +#include "device_appleTV/device_appleTV.h" +#include "device_smarthome/device_smarthome.h" #include "device_keyboard_mqtt/device_keyboard_mqtt.h" #include "device_keyboard_ble/device_keyboard_ble.h" #include "gui_general/gui.h" @@ -58,6 +60,8 @@ void setup() { // setup command list init_samsung_commands(); init_yamaha_commands(); + init_smarthome_mqtt_commands(); + init_appleTV_commands(); #ifdef ENABLE_KEYBOARD_MQTT init_keyboard_mqtt_commands(); #endif