mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +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_object.h"
|
||||
#include "hasp.h"
|
||||
#include "hasp_utilities.h"
|
||||
|
||||
#if HASP_USE_DEBUG > 0
|
||||
#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 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)
|
||||
{
|
||||
#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);
|
||||
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,
|
||||
const char * data);
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp_attribute.h"
|
||||
|
||||
const char ** btnmatrix_default_map; // memory pointer to lvgl default btnmatrix map
|
||||
|
||||
// ##################### Object Finders ########################################################
|
||||
|
||||
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:
|
||||
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;
|
||||
return;
|
||||
default:
|
||||
@ -538,7 +540,12 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
|
||||
/* ----- Basic Objects ------ */
|
||||
case LV_HASP_BTNMATRIX:
|
||||
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;
|
||||
case LV_HASP_TABLE:
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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_BTNMATRIX = 1,
|
||||
LV_HASP_LINE = 3,
|
||||
LV_HASP_TABLE = 2,
|
||||
LV_HASP_CALENDER = 81,
|
||||
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_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 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);
|
||||
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_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
|
||||
delay(250);
|
||||
guiStart();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/* Storage Loops */
|
||||
/*
|
||||
#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();
|
||||
networkLoop();
|
||||
guiLoop();
|
||||
|
||||
/* Application Loops */
|
||||
// haspLoop();
|
||||
debugLoop();
|
||||
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioLoop();
|
||||
#endif // GPIO
|
||||
|
||||
/* Network Services Loops */
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
ethernetLoop();
|
||||
#endif // ETHERNET
|
||||
haspLoop();
|
||||
|
||||
#if HASP_USE_MQTT > 0
|
||||
mqttLoop();
|
||||
#endif // MQTT
|
||||
|
||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||
slaveLoop();
|
||||
#endif // TASMOTASLAVE
|
||||
|
||||
#if HASP_USE_HTTP > 0
|
||||
httpLoop();
|
||||
#endif // HTTP
|
||||
|
||||
#if HASP_USE_MDNS > 0
|
||||
mdnsLoop();
|
||||
#endif // MDNS
|
||||
#if HASP_USE_GPIO > 0
|
||||
gpioLoop();
|
||||
#endif // GPIO
|
||||
|
||||
#if HASP_USE_OTA > 0
|
||||
otaLoop();
|
||||
#endif // OTA
|
||||
|
||||
#if HASP_USE_TELNET > 0
|
||||
telnetLoop();
|
||||
#endif // TELNET
|
||||
#if HASP_USE_MDNS > 0
|
||||
mdnsLoop();
|
||||
#endif // MDNS
|
||||
|
||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||
slaveLoop();
|
||||
#endif // TASMOTASLAVE
|
||||
#if HASP_USE_TELNET > 0
|
||||
telnetLoop(); // Console
|
||||
#endif // TELNET
|
||||
|
||||
debugLoop(); // Console
|
||||
|
||||
/* Timer Loop */
|
||||
if(millis() - mainLastLoopTime >= 1000) {
|
||||
/* Runs Every Second */
|
||||
haspEverySecond();
|
||||
debugEverySecond(); // statusupdate
|
||||
|
||||
#if HASP_USE_OTA > 0
|
||||
otaEverySecond(); // progressbar
|
||||
#endif
|
||||
|
||||
/* Runs Every 5 Seconds */
|
||||
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
|
||||
#if HASP_USE_WIFI > 0
|
||||
isConnected = wifiEvery5Seconds();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_ETHERNET > 0
|
||||
isConnected = ethernetEvery5Seconds();
|
||||
#endif
|
||||
isConnected = networkEvery5Seconds(); // Check connection
|
||||
|
||||
#if HASP_USE_HTTP > 0
|
||||
// httpEvery5Seconds();
|
||||
|
Loading…
x
Reference in New Issue
Block a user