mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Add service and theme commands for testing purposes
This commit is contained in:
parent
f671a8beb0
commit
d99e848e19
@ -26,6 +26,7 @@
|
|||||||
#include "lv_fs_if.h"
|
#include "lv_fs_if.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
|
#include "font/hasp_font_loader.h"
|
||||||
//#include "hasp_filesystem.h" included in hasp_conf.h
|
//#include "hasp_filesystem.h" included in hasp_conf.h
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ lv_style_t style_mbox_bg; /*Black bg. style with opacity*/
|
|||||||
lv_obj_t* kb;
|
lv_obj_t* kb;
|
||||||
// lv_font_t * defaultFont;
|
// lv_font_t * defaultFont;
|
||||||
|
|
||||||
static lv_font_t* haspFonts[4] = {nullptr, nullptr, nullptr, nullptr};
|
static lv_font_t* haspFonts[12] = {nullptr};
|
||||||
uint8_t current_page = 1;
|
uint8_t current_page = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +93,7 @@ uint8_t current_page = 1;
|
|||||||
*/
|
*/
|
||||||
lv_font_t* hasp_get_font(uint8_t fontid)
|
lv_font_t* hasp_get_font(uint8_t fontid)
|
||||||
{
|
{
|
||||||
if(fontid >= 4) {
|
if(fontid >= sizeof(haspFonts) / sizeof(haspFonts[0])) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
return haspFonts[fontid];
|
return haspFonts[fontid];
|
||||||
@ -300,6 +301,84 @@ static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t
|
|||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hasp_set_theme(uint8_t themeid)
|
||||||
|
{
|
||||||
|
lv_theme_t* th = NULL;
|
||||||
|
lv_color_t color_primary = lv_color_hsv_to_rgb(haspThemeHue, 100, 100);
|
||||||
|
lv_color_t color_secondary = lv_color_hsv_to_rgb(haspThemeHue, 100, 100);
|
||||||
|
|
||||||
|
/* ********** Theme Initializations ********** */
|
||||||
|
if(themeid == 8) themeid = 1; // update old HASP id
|
||||||
|
if(themeid == 9) themeid = 5; // update old material id
|
||||||
|
if(themeid < 0 || themeid > 5) return; // check bounds
|
||||||
|
|
||||||
|
#if(LV_USE_THEME_HASP == 1)
|
||||||
|
uint32_t hasp_flags = LV_THEME_HASP_FLAG_LIGHT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if(LV_USE_THEME_MATERIAL == 1)
|
||||||
|
// LV_THEME_MATERIAL_FLAG_NO_TRANSITION : disable transitions(state change animations)
|
||||||
|
// LV_THEME_MATERIAL_FLAG_NO_FOCUS: disable indication of focused state)
|
||||||
|
uint32_t material_flags = LV_THEME_MATERIAL_FLAG_LIGHT + LV_THEME_MATERIAL_FLAG_NO_TRANSITION;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch(themeid) {
|
||||||
|
#if(LV_USE_THEME_EMPTY == 1)
|
||||||
|
case 0:
|
||||||
|
th = lv_theme_empty_init(lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
||||||
|
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
||||||
|
haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if(LV_USE_THEME_HASP == 1)
|
||||||
|
case 2: // Dark
|
||||||
|
hasp_flags = LV_THEME_HASP_FLAG_DARK;
|
||||||
|
case 1: // Light
|
||||||
|
case 8: // Light (old id)
|
||||||
|
th = lv_theme_hasp_init(color_primary, color_secondary, hasp_flags + LV_THEME_HASP_FLAG_NO_FOCUS,
|
||||||
|
haspFonts[0], haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if(LV_USE_THEME_MONO == 1)
|
||||||
|
case 3:
|
||||||
|
th = lv_theme_mono_init(color_primary, color_secondary, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1],
|
||||||
|
haspFonts[2], haspFonts[3]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_USE_THEME_MATERIAL == 1
|
||||||
|
case 5: // Dark
|
||||||
|
material_flags = LV_THEME_MATERIAL_FLAG_DARK + LV_THEME_MATERIAL_FLAG_NO_TRANSITION;
|
||||||
|
case 4: // Light
|
||||||
|
case 9: // Light (old id)
|
||||||
|
th =
|
||||||
|
lv_theme_material_init(color_primary, color_secondary, material_flags + LV_THEME_MATERIAL_FLAG_NO_FOCUS,
|
||||||
|
haspFonts[0], haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_USE_THEME_TEMPLATE == 1
|
||||||
|
case 7:
|
||||||
|
th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
||||||
|
haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
LOG_ERROR(TAG_HASP, F("Unknown theme selected"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(th) {
|
||||||
|
lv_theme_set_act(th);
|
||||||
|
LOG_INFO(TAG_HASP, F("Custom theme loaded"));
|
||||||
|
} else {
|
||||||
|
LOG_ERROR(TAG_HASP, F("Theme could not be loaded"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a demo application
|
* Create a demo application
|
||||||
*/
|
*/
|
||||||
@ -362,99 +441,17 @@ void haspSetup(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(haspFonts[0] == nullptr) haspFonts[0] = LV_THEME_DEFAULT_FONT_SMALL;
|
if(haspFonts[0] == nullptr) haspFonts[0] = &HASP_FONT_1; // LV_THEME_DEFAULT_FONT_SMALL;
|
||||||
if(haspFonts[1] == nullptr) haspFonts[1] = LV_THEME_DEFAULT_FONT_NORMAL;
|
if(haspFonts[1] == nullptr) haspFonts[1] = &HASP_FONT_2; // LV_THEME_DEFAULT_FONT_NORMAL;
|
||||||
if(haspFonts[2] == nullptr) haspFonts[2] = LV_THEME_DEFAULT_FONT_SUBTITLE;
|
if(haspFonts[2] == nullptr) haspFonts[2] = &HASP_FONT_3; // LV_THEME_DEFAULT_FONT_SUBTITLE;
|
||||||
if(haspFonts[3] == nullptr) haspFonts[3] = LV_THEME_DEFAULT_FONT_TITLE;
|
if(haspFonts[3] == nullptr) haspFonts[3] = &HASP_FONT_4; // LV_THEME_DEFAULT_FONT_TITLE;
|
||||||
|
|
||||||
// haspFonts[0] = lv_font_load("E:/font_1.fnt");
|
// haspFonts[0] = lv_font_load("E:/font_1.fnt");
|
||||||
// haspFonts[2] = lv_font_load("E:/font_2.fnt");
|
// haspFonts[2] = lv_font_load("E:/font_2.fnt");
|
||||||
// haspFonts[3] = lv_font_load("E:/font_3.fnt");
|
|
||||||
|
|
||||||
/* ********** Theme Initializations ********** */
|
// haspFonts[3] = hasp_font_load("L:/robotocondensed_60_latin1.bin");
|
||||||
if(haspThemeId == 8) haspThemeId = 1; // update old HASP id
|
|
||||||
if(haspThemeId == 9) haspThemeId = 5; // update old material id
|
|
||||||
if(haspThemeId < 0 || haspThemeId > 5) haspThemeId = 1; // check bounds
|
|
||||||
|
|
||||||
lv_theme_t* th = NULL;
|
hasp_set_theme(haspThemeId);
|
||||||
#if(LV_USE_THEME_HASP == 1)
|
|
||||||
lv_theme_hasp_flag_t hasp_flags = LV_THEME_HASP_FLAG_LIGHT;
|
|
||||||
#endif
|
|
||||||
#if(LV_USE_THEME_MATERIAL == 1)
|
|
||||||
lv_theme_material_flag_t material_flags = LV_THEME_MATERIAL_FLAG_LIGHT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch(haspThemeId) {
|
|
||||||
#if(LV_USE_THEME_EMPTY == 1)
|
|
||||||
case 0:
|
|
||||||
th = lv_theme_empty_init(lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
|
||||||
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
|
||||||
haspFonts[1], haspFonts[2], haspFonts[3]);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if(LV_USE_THEME_HASP == 1)
|
|
||||||
case 2: // Dark
|
|
||||||
hasp_flags = LV_THEME_HASP_FLAG_DARK;
|
|
||||||
case 1: // Light
|
|
||||||
case 8: // Light (old id)
|
|
||||||
th = lv_theme_hasp_init(
|
|
||||||
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
|
||||||
hasp_flags + LV_THEME_HASP_FLAG_NO_FOCUS, haspFonts[0], haspFonts[1], haspFonts[2], haspFonts[3]);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LV_USE_THEME_ALIEN == 1
|
|
||||||
case 1:
|
|
||||||
th = lv_theme_alien_init(haspThemeHue, defaultFont);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LV_USE_THEME_NIGHT == 1
|
|
||||||
case 2:
|
|
||||||
th = lv_theme_night_init(haspThemeHue, defaultFont); // heavy
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if(LV_USE_THEME_MONO == 1)
|
|
||||||
case 3:
|
|
||||||
th = lv_theme_mono_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0], haspFonts[1],
|
|
||||||
haspFonts[2], haspFonts[3]);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// LV_THEME_MATERIAL_FLAG_NO_TRANSITION : disable transitions(state change animations)
|
|
||||||
// LV_THEME_MATERIAL_FLAG_NO_FOCUS: disable indication of focused state)
|
|
||||||
#if LV_USE_THEME_MATERIAL == 1
|
|
||||||
case 5: // Dark
|
|
||||||
material_flags = LV_THEME_MATERIAL_FLAG_DARK;
|
|
||||||
case 4: // Light
|
|
||||||
case 9: // Light (old id)
|
|
||||||
th = lv_theme_material_init(
|
|
||||||
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
|
||||||
material_flags + LV_THEME_MATERIAL_FLAG_NO_FOCUS + LV_THEME_MATERIAL_FLAG_NO_TRANSITION, haspFonts[0],
|
|
||||||
haspFonts[1], haspFonts[2], haspFonts[3]);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LV_USE_THEME_TEMPLATE == 1
|
|
||||||
case 7:
|
|
||||||
th = lv_theme_template_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
|
||||||
haspFonts[1], haspFonts[2], haspFonts[3]);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
LOG_ERROR(TAG_HASP, F("Unknown theme selected"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(th) {
|
|
||||||
lv_theme_set_act(th);
|
|
||||||
LOG_INFO(TAG_HASP, F("Custom theme loaded"));
|
|
||||||
} else {
|
|
||||||
LOG_ERROR(TAG_HASP, F("Theme could not be loaded"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create all screens using the theme */
|
/* Create all screens using the theme */
|
||||||
|
|
||||||
@ -467,6 +464,11 @@ void haspSetup(void)
|
|||||||
hasp_init();
|
hasp_init();
|
||||||
hasp_load_json();
|
hasp_load_json();
|
||||||
haspPages.set(haspStartPage, LV_SCR_LOAD_ANIM_FADE_ON);
|
haspPages.set(haspStartPage, LV_SCR_LOAD_ANIM_FADE_ON);
|
||||||
|
|
||||||
|
// lv_obj_t* obj = lv_datetime_create(haspPages.get_obj(haspPages.get()), NULL);
|
||||||
|
// obj->user_data.objid = LV_HASP_DATETIME;
|
||||||
|
// obj->user_data.id = 199;
|
||||||
|
// lv_datetime_set_text_fmt(obj,"%A, %B %d");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
|
@ -75,6 +75,7 @@ void hasp_init(void);
|
|||||||
void hasp_load_json(void);
|
void hasp_load_json(void);
|
||||||
|
|
||||||
void hasp_get_info(JsonDocument& info);
|
void hasp_get_info(JsonDocument& info);
|
||||||
|
void hasp_set_theme(uint8_t themeid);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
@ -40,7 +40,7 @@ dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
|||||||
|
|
||||||
uint16_t dispatchSecondsToNextTeleperiod = 0;
|
uint16_t dispatchSecondsToNextTeleperiod = 0;
|
||||||
uint8_t nCommands = 0;
|
uint8_t nCommands = 0;
|
||||||
haspCommand_t commands[22];
|
haspCommand_t commands[24];
|
||||||
|
|
||||||
moodlight_t moodlight = {.brightness = 255};
|
moodlight_t moodlight = {.brightness = 255};
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ void dispatch_config(const char* topic, const char* payload)
|
|||||||
mdnsGetConfig(settings);
|
mdnsGetConfig(settings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
|
||||||
else if(strcasecmp_P(topic, PSTR("http")) == 0) {
|
else if(strcasecmp_P(topic, PSTR("http")) == 0) {
|
||||||
if(update)
|
if(update)
|
||||||
httpSetConfig(settings);
|
httpSetConfig(settings);
|
||||||
@ -866,6 +866,64 @@ void dispatch_reboot(bool saveConfig)
|
|||||||
|
|
||||||
/******************************************* Command Wrapper Functions *********************************/
|
/******************************************* Command Wrapper Functions *********************************/
|
||||||
|
|
||||||
|
// Periodically publish a JSON string indicating system status
|
||||||
|
void dispatch_send_sensordata(const char*, const char*)
|
||||||
|
{
|
||||||
|
#if HASP_USE_MQTT > 0
|
||||||
|
|
||||||
|
StaticJsonDocument<1024> doc;
|
||||||
|
|
||||||
|
time_t rawtime;
|
||||||
|
time(&rawtime);
|
||||||
|
char buffer[80];
|
||||||
|
struct tm* timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
|
strftime(buffer, sizeof(buffer), "%FT%T", timeinfo);
|
||||||
|
doc[F("time")] = buffer;
|
||||||
|
|
||||||
|
long uptime = haspDevice.get_uptime();
|
||||||
|
doc[F("uptimeSec")] = (uint32_t)uptime;
|
||||||
|
|
||||||
|
uint32_t seconds = uptime % 60;
|
||||||
|
uint32_t minutes = uptime / 60;
|
||||||
|
uint32_t hours = minutes / 60;
|
||||||
|
uint32_t days = hours / 24;
|
||||||
|
minutes = minutes % 60;
|
||||||
|
hours = hours % 24;
|
||||||
|
snprintf_P(buffer, sizeof(buffer), PSTR("%dT%02d:%02d:%02d"), days, hours, minutes, seconds);
|
||||||
|
doc[F("uptime")] = buffer;
|
||||||
|
|
||||||
|
haspDevice.get_sensors(doc);
|
||||||
|
|
||||||
|
// JsonObject input = doc.createNestedObject(F("input"));
|
||||||
|
// JsonArray relay = doc.createNestedArray(F("power"));
|
||||||
|
// JsonArray led = doc.createNestedArray(F("light"));
|
||||||
|
// JsonArray dimmer = doc.createNestedArray(F("dim"));
|
||||||
|
|
||||||
|
// #if HASP_USE_GPIO > 0
|
||||||
|
// gpio_discovery(input, relay, led, dimmer);
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
char data[1024];
|
||||||
|
size_t len = serializeJson(doc, data);
|
||||||
|
|
||||||
|
switch(mqtt_send_discovery(data, len)) {
|
||||||
|
case MQTT_ERR_OK:
|
||||||
|
LOG_TRACE(TAG_MQTT_PUB, F(MQTT_TOPIC_DISCOVERY " => %s"), data);
|
||||||
|
break;
|
||||||
|
case MQTT_ERR_PUB_FAIL:
|
||||||
|
LOG_ERROR(TAG_MQTT_PUB, F(D_MQTT_FAILED " " MQTT_TOPIC_DISCOVERY " => %s"), data);
|
||||||
|
break;
|
||||||
|
case MQTT_ERR_NO_CONN:
|
||||||
|
LOG_ERROR(TAG_MQTT, F(D_MQTT_NOT_CONNECTED));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_ERROR(TAG_MQTT, F(D_ERROR_UNKNOWN));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Periodically publish a JSON string indicating system status
|
// Periodically publish a JSON string indicating system status
|
||||||
void dispatch_send_discovery(const char*, const char*)
|
void dispatch_send_discovery(const char*, const char*)
|
||||||
{
|
{
|
||||||
@ -1038,6 +1096,25 @@ void dispatch_factory_reset(const char*, const char*)
|
|||||||
dispatch_reboot(false); // don't save running config
|
dispatch_reboot(false); // don't save running config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispatch_theme(const char*, const char* themeid)
|
||||||
|
{
|
||||||
|
hasp_set_theme(atoi(themeid));
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispatch_service(const char*, const char* payload)
|
||||||
|
{
|
||||||
|
if(!strcmp_P(payload, "start telnet")) {
|
||||||
|
telnetStart();
|
||||||
|
} else if(!strcmp_P(payload, "stop telnet")) {
|
||||||
|
telnetStop();
|
||||||
|
} else if(!strcmp_P(payload, "start http")) {
|
||||||
|
httpStart();
|
||||||
|
} else if(!strcmp_P(payload, "stop http")) {
|
||||||
|
httpStop();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************* Commands builder *******************************************/
|
/******************************************* Commands builder *******************************************/
|
||||||
|
|
||||||
static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*))
|
static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*))
|
||||||
@ -1073,6 +1150,8 @@ void dispatchSetup()
|
|||||||
dispatch_add_command(PSTR("dim"), dispatch_backlight_obsolete); // dim
|
dispatch_add_command(PSTR("dim"), dispatch_backlight_obsolete); // dim
|
||||||
dispatch_add_command(PSTR("brightness"), dispatch_backlight_obsolete); // dim
|
dispatch_add_command(PSTR("brightness"), dispatch_backlight_obsolete); // dim
|
||||||
dispatch_add_command(PSTR("light"), dispatch_backlight_obsolete);
|
dispatch_add_command(PSTR("light"), dispatch_backlight_obsolete);
|
||||||
|
dispatch_add_command(PSTR("theme"), dispatch_theme);
|
||||||
|
dispatch_add_command(PSTR("service"), dispatch_service);
|
||||||
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup_obsolete);
|
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup_obsolete);
|
||||||
dispatch_add_command(PSTR("calibrate"), dispatch_calibrate);
|
dispatch_add_command(PSTR("calibrate"), dispatch_calibrate);
|
||||||
dispatch_add_command(PSTR("update"), dispatch_web_update);
|
dispatch_add_command(PSTR("update"), dispatch_web_update);
|
||||||
@ -1106,6 +1185,7 @@ void dispatchEverySecond()
|
|||||||
} else if(dispatch_setings.teleperiod > 0 && mqttIsConnected()) {
|
} else if(dispatch_setings.teleperiod > 0 && mqttIsConnected()) {
|
||||||
dispatch_statusupdate(NULL, NULL);
|
dispatch_statusupdate(NULL, NULL);
|
||||||
dispatch_send_discovery(NULL, NULL);
|
dispatch_send_discovery(NULL, NULL);
|
||||||
|
dispatch_send_sensordata(NULL, NULL);
|
||||||
dispatchSecondsToNextTeleperiod = dispatch_setings.teleperiod;
|
dispatchSecondsToNextTeleperiod = dispatch_setings.teleperiod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user