added devices for appleTV and smarthome

This commit is contained in:
KlausMu 2024-01-26 18:52:09 +01:00
parent d8471b0ef0
commit b1f03b1842
9 changed files with 69 additions and 11 deletions

View file

@ -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();

View file

@ -106,6 +106,7 @@ enum commandHandlers {
IR_GC,
IR_NEC,
IR_SAMSUNG,
IR_SONY,
#ifdef ENABLE_WIFI_AND_MQTT
MQTT,
#endif

View file

@ -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
}

View file

@ -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__*/

View file

@ -1,8 +1,9 @@
#include <lvgl.h>
// #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);
}

View file

@ -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
}

View file

@ -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__*/

View file

@ -1,8 +1,9 @@
#include <string>
#include <lvgl.h>
// #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
}

View file

@ -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