mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Re-arrange main and utilities
This commit is contained in:
parent
9a0d4fc0bb
commit
1e503d5e06
@ -7,6 +7,7 @@
|
|||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_object.h"
|
#include "hasp_object.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
#include "hasp_utilities.h"
|
||||||
|
|
||||||
#if HASP_USE_DEBUG > 0
|
#if HASP_USE_DEBUG > 0
|
||||||
#include "StringStream.h"
|
#include "StringStream.h"
|
||||||
@ -39,12 +40,6 @@ static void dispatch_config(const char * topic, const char * payload);
|
|||||||
static void dispatch_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * obj);
|
static void dispatch_group_state(uint8_t groupid, uint8_t eventid, lv_obj_t * obj);
|
||||||
static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload);
|
static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload);
|
||||||
|
|
||||||
bool is_true(const char * s)
|
|
||||||
{
|
|
||||||
return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) ||
|
|
||||||
!strcmp_P(s, PSTR("1")));
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -51,7 +51,6 @@ void dispatch_gpio_event(uint8_t pin, uint8_t group, uint8_t eventid);
|
|||||||
void dispatch_object_event(lv_obj_t * obj, uint8_t eventid);
|
void dispatch_object_event(lv_obj_t * obj, uint8_t eventid);
|
||||||
bool dispatch_get_event_state(uint8_t eventid);
|
bool dispatch_get_event_state(uint8_t eventid);
|
||||||
|
|
||||||
bool is_true(const char * s);
|
|
||||||
void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute,
|
void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute,
|
||||||
const char * data);
|
const char * data);
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include "hasp_dispatch.h"
|
#include "hasp_dispatch.h"
|
||||||
#include "hasp_attribute.h"
|
#include "hasp_attribute.h"
|
||||||
|
|
||||||
|
const char ** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map
|
||||||
|
|
||||||
// ##################### Object Finders ########################################################
|
// ##################### Object Finders ########################################################
|
||||||
|
|
||||||
lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid)
|
lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid)
|
||||||
@ -316,7 +318,7 @@ void IRAM_ATTR btn_event_handler(lv_obj_t * obj, lv_event_t event)
|
|||||||
|
|
||||||
case LV_EVENT_DELETE:
|
case LV_EVENT_DELETE:
|
||||||
Log.verbose(TAG_HASP, F("Object deleted Event %d occured"), event);
|
Log.verbose(TAG_HASP, F("Object deleted Event %d occured"), event);
|
||||||
// TODO:free and destroy persistent memory allocated for certain objects
|
hasp_object_delete(obj); // free and destroy persistent memory allocated for certain objects
|
||||||
last_press_was_short = false;
|
last_press_was_short = false;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
@ -538,7 +540,12 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
|||||||
/* ----- Basic Objects ------ */
|
/* ----- Basic Objects ------ */
|
||||||
case LV_HASP_BTNMATRIX:
|
case LV_HASP_BTNMATRIX:
|
||||||
obj = lv_btnmatrix_create(parent_obj, NULL);
|
obj = lv_btnmatrix_create(parent_obj, NULL);
|
||||||
if(obj) lv_obj_set_event_cb(obj, btnmap_event_handler);
|
if(obj) {
|
||||||
|
lv_obj_set_event_cb(obj, btnmap_event_handler);
|
||||||
|
|
||||||
|
lv_btnmatrix_ext_t * ext = (lv_btnmatrix_ext_t *)lv_obj_get_ext_attr(obj);
|
||||||
|
btnmatrix_default_map = ext->map_p; // store the pointer to the default lvgl btnmap
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case LV_HASP_TABLE:
|
case LV_HASP_TABLE:
|
||||||
obj = lv_table_create(parent_obj, NULL);
|
obj = lv_table_create(parent_obj, NULL);
|
||||||
@ -812,3 +819,18 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
|||||||
// Log.verbose(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str());
|
// Log.verbose(TAG_HASP,F(" * %s => %s"), keyValue.key().c_str(), v.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hasp_object_delete(lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
switch(obj->user_data.objid) {
|
||||||
|
case LV_HASP_LINE: {
|
||||||
|
line_clear_points(obj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LV_HASP_BTNMATRIX:
|
||||||
|
btnmatrix_clear_map(obj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: delete value_str data for all parts
|
||||||
|
}
|
@ -35,6 +35,7 @@ enum lv_hasp_obj_type_t {
|
|||||||
LV_HASP_CANVAS = 62,
|
LV_HASP_CANVAS = 62,
|
||||||
|
|
||||||
LV_HASP_BTNMATRIX = 1,
|
LV_HASP_BTNMATRIX = 1,
|
||||||
|
LV_HASP_LINE = 3,
|
||||||
LV_HASP_TABLE = 2,
|
LV_HASP_TABLE = 2,
|
||||||
LV_HASP_CALENDER = 81,
|
LV_HASP_CALENDER = 81,
|
||||||
LV_HASP_CHART = 80,
|
LV_HASP_CHART = 80,
|
||||||
@ -50,9 +51,10 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id);
|
|||||||
lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid);
|
lv_obj_t * hasp_find_obj_from_parent_id(lv_obj_t * parent, uint8_t objid);
|
||||||
// lv_obj_t * hasp_find_obj_from_page_id(uint8_t pageid, uint8_t objid);
|
// lv_obj_t * hasp_find_obj_from_page_id(uint8_t pageid, uint8_t objid);
|
||||||
bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid);
|
bool hasp_find_id_from_obj(lv_obj_t * obj, uint8_t * pageid, uint8_t * objid);
|
||||||
//bool check_obj_type_str(const char * lvobjtype, lv_hasp_obj_type_t haspobjtype);
|
// bool check_obj_type_str(const char * lvobjtype, lv_hasp_obj_type_t haspobjtype);
|
||||||
bool check_obj_type(lv_obj_t * obj, lv_hasp_obj_type_t haspobjtype);
|
bool check_obj_type(lv_obj_t * obj, lv_hasp_obj_type_t haspobjtype);
|
||||||
void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level);
|
void hasp_object_tree(lv_obj_t * parent, uint8_t pageid, uint16_t level);
|
||||||
|
void hasp_object_delete(lv_obj_t * obj);
|
||||||
|
|
||||||
void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const char * data);
|
void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const char * data);
|
||||||
void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t val);
|
void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t val);
|
||||||
|
25
src/hasp/hasp_utilities.cpp
Normal file
25
src/hasp/hasp_utilities.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <cctype>
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "hasp_utilities.h"
|
||||||
|
|
||||||
|
/* 16-bit hashing function http://www.cse.yorku.ca/~oz/hash.html */
|
||||||
|
/* all possible attributes are hashed and checked if they are unique */
|
||||||
|
uint16_t sdbm(const char * str)
|
||||||
|
{
|
||||||
|
uint16_t hash = 0;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
// while(c = *str++) hash = c + (hash << 6) + (hash << 16) - hash;
|
||||||
|
while((c = *str++)) {
|
||||||
|
hash = tolower(c) + (hash << 6) - hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_true(const char * s)
|
||||||
|
{
|
||||||
|
return (!strcasecmp_P(s, PSTR("true")) || !strcasecmp_P(s, PSTR("on")) || !strcasecmp_P(s, PSTR("yes")) ||
|
||||||
|
!strcmp_P(s, PSTR("1")));
|
||||||
|
}
|
12
src/hasp/hasp_utilities.h
Normal file
12
src/hasp/hasp_utilities.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
#ifndef HASP_UTILITIES_H
|
||||||
|
#define HASP_UTILITIES_H
|
||||||
|
|
||||||
|
#include "lvgl.h"
|
||||||
|
|
||||||
|
uint16_t sdbm(const char * str);
|
||||||
|
bool is_true(const char * s);
|
||||||
|
|
||||||
|
#endif
|
68
src/main.cpp
68
src/main.cpp
@ -90,86 +90,58 @@ void setup()
|
|||||||
|
|
||||||
mainLastLoopTime = millis() - 1000; // reset loop counter
|
mainLastLoopTime = millis() - 1000; // reset loop counter
|
||||||
delay(250);
|
delay(250);
|
||||||
|
guiStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
/* Storage Loops */
|
networkLoop();
|
||||||
/*
|
|
||||||
#if HASP_USE_EEPROM>0
|
|
||||||
// eepromLoop(); // Not used
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS>0
|
|
||||||
// spiffsLoop(); // Not used
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_SDCARD>0
|
|
||||||
// sdcardLoop(); // Not used
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// configLoop(); // Not used
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Graphics Loops */
|
|
||||||
// tftLoop();
|
|
||||||
guiLoop();
|
guiLoop();
|
||||||
|
haspLoop();
|
||||||
/* Application Loops */
|
|
||||||
// haspLoop();
|
|
||||||
debugLoop();
|
|
||||||
|
|
||||||
#if HASP_USE_GPIO > 0
|
|
||||||
gpioLoop();
|
|
||||||
#endif // GPIO
|
|
||||||
|
|
||||||
/* Network Services Loops */
|
|
||||||
#if HASP_USE_ETHERNET > 0
|
|
||||||
ethernetLoop();
|
|
||||||
#endif // ETHERNET
|
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqttLoop();
|
mqttLoop();
|
||||||
#endif // MQTT
|
#endif // MQTT
|
||||||
|
|
||||||
|
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||||
|
slaveLoop();
|
||||||
|
#endif // TASMOTASLAVE
|
||||||
|
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
httpLoop();
|
httpLoop();
|
||||||
#endif // HTTP
|
#endif // HTTP
|
||||||
|
|
||||||
#if HASP_USE_MDNS > 0
|
#if HASP_USE_GPIO > 0
|
||||||
mdnsLoop();
|
gpioLoop();
|
||||||
#endif // MDNS
|
#endif // GPIO
|
||||||
|
|
||||||
#if HASP_USE_OTA > 0
|
#if HASP_USE_OTA > 0
|
||||||
otaLoop();
|
otaLoop();
|
||||||
#endif // OTA
|
#endif // OTA
|
||||||
|
|
||||||
#if HASP_USE_TELNET > 0
|
#if HASP_USE_MDNS > 0
|
||||||
telnetLoop();
|
mdnsLoop();
|
||||||
#endif // TELNET
|
#endif // MDNS
|
||||||
|
|
||||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
#if HASP_USE_TELNET > 0
|
||||||
slaveLoop();
|
telnetLoop(); // Console
|
||||||
#endif // TASMOTASLAVE
|
#endif // TELNET
|
||||||
|
|
||||||
|
debugLoop(); // Console
|
||||||
|
|
||||||
/* Timer Loop */
|
/* Timer Loop */
|
||||||
if(millis() - mainLastLoopTime >= 1000) {
|
if(millis() - mainLastLoopTime >= 1000) {
|
||||||
/* Runs Every Second */
|
/* Runs Every Second */
|
||||||
haspEverySecond();
|
haspEverySecond();
|
||||||
debugEverySecond(); // statusupdate
|
debugEverySecond(); // statusupdate
|
||||||
|
|
||||||
#if HASP_USE_OTA > 0
|
#if HASP_USE_OTA > 0
|
||||||
otaEverySecond(); // progressbar
|
otaEverySecond(); // progressbar
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Runs Every 5 Seconds */
|
/* Runs Every 5 Seconds */
|
||||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
||||||
#if HASP_USE_WIFI > 0
|
isConnected = networkEvery5Seconds(); // Check connection
|
||||||
isConnected = wifiEvery5Seconds();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_ETHERNET > 0
|
|
||||||
isConnected = ethernetEvery5Seconds();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
// httpEvery5Seconds();
|
// httpEvery5Seconds();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user