Move dispatchSetup to haspSetup

This commit is contained in:
fvanroie 2021-02-26 23:52:54 +01:00
parent 6d6e1b99ef
commit da00c41a21
4 changed files with 48 additions and 47 deletions

View File

@ -319,6 +319,7 @@ static void custom_font_apply_cb(lv_theme_t* th, lv_obj_t* obj, lv_theme_style_t
*/ */
void haspSetup(void) void haspSetup(void)
{ {
dispatchSetup();
haspDevice.set_backlight_level(haspStartDim); haspDevice.set_backlight_level(haspStartDim);
/******* File System Test ********************************************************************/ /******* File System Test ********************************************************************/

View File

@ -40,48 +40,10 @@
extern uint8_t hasp_sleep_state; extern uint8_t hasp_sleep_state;
dispatch_conf_t dispatch_setings = {.teleperiod = 10}; dispatch_conf_t dispatch_setings = {.teleperiod = 10};
uint32_t dispatchLastMillis; uint32_t dispatchLastMillis;
uint8_t nCommands = 0;
/* Declare all Command Handlers */ haspCommand_t commands[17];
void dispatch_parse_json(const char*, const char* payload);
void dispatch_parse_jsonl(const char*, const char* payload);
void dispatch_page(const char*, const char* payload);
void dispatch_wakeup(const char*, const char* payload);
void dispatch_output_statusupdate(const char*, const char* payload);
void dispatch_clear_page(const char*, const char* payload);
void dispatch_dim(const char*, const char* payload);
void dispatch_backlight(const char*, const char* payload);
void dispatch_moodlight(const char*, const char* payload);
void dispatch_calibrate(const char*, const char* payload);
void dispatch_web_update(const char*, const char* payload);
void dispatch_reboot(const char*, const char* payload);
void dispatch_screenshot(const char*, const char* payload);
void dispatch_factory_reset(const char*, const char* payload);
/* Map Commands to Command Handlers */
haspCommand_t commands[] = {
{PSTR("json"), dispatch_parse_json},
{PSTR("page"), dispatch_page},
{PSTR("wakeup"), dispatch_wakeup},
{PSTR("statusupdate"), dispatch_output_statusupdate},
{PSTR("clearpage"), dispatch_clear_page},
{PSTR("jsonl"), dispatch_parse_jsonl},
{PSTR("dim"), dispatch_dim},
{PSTR("brightness"), dispatch_dim},
{PSTR("light"), dispatch_backlight},
{PSTR("moodlight"), dispatch_moodlight},
{PSTR("calibrate"), dispatch_calibrate},
{PSTR("update"), dispatch_web_update},
{PSTR("reboot"), dispatch_reboot},
{PSTR("restart"), dispatch_reboot},
{PSTR("screenshot"), dispatch_screenshot},
#if HASP_USE_CONFIG > 0
{PSTR("setupap"), oobeFakeSetup},
#endif
{PSTR("factoryreset"), dispatch_factory_reset}
};
struct moodlight_t struct moodlight_t
{ {
@ -97,6 +59,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const
void dispatch_screenshot(const char*, const char* filename) void dispatch_screenshot(const char*, const char* filename)
{ {
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
if(strlen(filename) == 0) { // no filename given if(strlen(filename) == 0) { // no filename given
char tempfile[32]; char tempfile[32];
memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile)); memcpy_P(tempfile, PSTR("/screenshot.bmp"), sizeof(tempfile));
@ -237,7 +200,7 @@ void dispatch_command(const char* topic, const char* payload)
/* ================================= Standard payload commands ======================================= */ /* ================================= Standard payload commands ======================================= */
// check and execute commands from commands array // check and execute commands from commands array
for(int i = 0; i < sizeof(commands) / sizeof(haspCommand_t); i++) { for(int i = 0; i < nCommands; i++) {
if(!strcasecmp_P(topic, commands[i].p_cmdstr)) { if(!strcasecmp_P(topic, commands[i].p_cmdstr)) {
// LOG_DEBUG(TAG_MSGR, F("Command %d found in array !!!"), i); // LOG_DEBUG(TAG_MSGR, F("Command %d found in array !!!"), i);
commands[i].func(topic, payload); /* execute command */ commands[i].func(topic, payload); /* execute command */
@ -938,6 +901,7 @@ void dispatch_current_state()
void dispatch_output_statusupdate(const char*, const char*) void dispatch_output_statusupdate(const char*, const char*)
{ {
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
char data[3 * 128]; char data[3 * 128];
{ {
char buffer[128]; char buffer[128];
@ -1006,8 +970,46 @@ void dispatch_factory_reset(const char*, const char*)
/******************************************* Commands builder *******************************************/ /******************************************* Commands builder *******************************************/
static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*))
{
if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) {
LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands);
while(1) {
}
} else {
commands[nCommands].p_cmdstr = p_cmdstr;
commands[nCommands].func = func;
nCommands++;
}
}
void dispatchSetup() void dispatchSetup()
{} {
// In order of importance : commands are NOT case-sensitive
// The command.func() call will receive the full topic and payload parameters!
/* WARNING: remember to expand the commands array when adding new commands */
dispatch_add_command(PSTR("json"), dispatch_parse_json);
dispatch_add_command(PSTR("page"), dispatch_page);
dispatch_add_command(PSTR("wakeup"), dispatch_wakeup);
dispatch_add_command(PSTR("statusupdate"), dispatch_output_statusupdate);
dispatch_add_command(PSTR("clearpage"), dispatch_clear_page);
dispatch_add_command(PSTR("jsonl"), dispatch_parse_jsonl);
dispatch_add_command(PSTR("dim"), dispatch_dim);
dispatch_add_command(PSTR("brightness"), dispatch_dim);
dispatch_add_command(PSTR("light"), dispatch_backlight);
dispatch_add_command(PSTR("moodlight"), dispatch_moodlight);
dispatch_add_command(PSTR("calibrate"), dispatch_calibrate);
dispatch_add_command(PSTR("update"), dispatch_web_update);
dispatch_add_command(PSTR("reboot"), dispatch_reboot);
dispatch_add_command(PSTR("restart"), dispatch_reboot);
dispatch_add_command(PSTR("screenshot"), dispatch_screenshot);
dispatch_add_command(PSTR("factoryreset"), dispatch_factory_reset);
#if HASP_USE_CONFIG > 0
dispatch_add_command(PSTR("setupap"), oobeFakeSetup);
#endif
/* WARNING: remember to expand the commands array when adding new commands */
}
void dispatchLoop() void dispatchLoop()
{ {

View File

@ -57,7 +57,6 @@ void setup()
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart() configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
#endif #endif
dispatchSetup();
guiSetup(); guiSetup();
debugSetup(); // Init the console debugSetup(); // Init the console
@ -100,7 +99,7 @@ void setup()
telnetSetup(); telnetSetup();
#endif #endif
#if HASP_USE_TASMOTA_CLINET > 0 #if HASP_USE_TASMOTA_CLIENT > 0
slaveSetup(); slaveSetup();
#endif #endif

View File

@ -103,9 +103,8 @@ void setup()
lv_log_register_print_cb(debugLvglLogEvent); lv_log_register_print_cb(debugLvglLogEvent);
lv_init(); lv_init();
haspDevice.init(); haspDevice.init(); // hardware setup
// hal_setup(); // hal_setup();
dispatchSetup();
guiSetup(); guiSetup();
// debugSetup(); // Init the console // debugSetup(); // Init the console