Post latest updates

This commit is contained in:
fvanroie 2021-02-17 22:12:56 +01:00
parent 4a993392fd
commit 046ecb0b7a
7 changed files with 469 additions and 312 deletions

View File

@ -1,12 +1,12 @@
--- ---
Language: Cpp Language: Cpp
# BasedOnStyle: LLVM # BasedOnStyle: LLVM
AccessModifierOffset: -2 AccessModifierOffset: -2
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false AlignEscapedNewlinesLeft: false
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false AllowShortBlocksOnASingleLine: false
@ -21,51 +21,51 @@ AlwaysBreakTemplateDeclarations: false
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
BreakBeforeBraces: Custom BreakBeforeBraces: Custom
BraceWrapping: BraceWrapping:
AfterClass: false AfterClass: false
AfterControlStatement: false AfterControlStatement: false
AfterEnum: false AfterEnum: false
AfterFunction: true AfterFunction: true
AfterNamespace: false AfterNamespace: false
AfterObjCDeclaration: false AfterObjCDeclaration: false
AfterStruct: true AfterStruct: true
AfterUnion: true AfterUnion: true
BeforeCatch: false BeforeCatch: false
BeforeElse: false BeforeElse: false
IndentBraces: false IndentBraces: false
SplitEmptyFunction: false SplitEmptyFunction: false
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true BreakStringLiterals: true
ColumnLimit: 120 ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:' CommentPragmas: "^ IWYU pragma:"
ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
Cpp11BracedListStyle: true Cpp11BracedListStyle: true
DerivePointerAlignment: false DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
IncludeCategories: IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2 Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)' - Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3 Priority: 3
- Regex: '.*' - Regex: ".*"
Priority: 1 Priority: 1
IncludeIsMainRegex: '$' IncludeIsMainRegex: "$"
IndentCaseLabels: true IndentCaseLabels: true
IndentWidth: 4 IndentWidth: 4
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
# IndentPPDirectives: BeforeHash # IndentPPDirectives: BeforeHash
JavaScriptQuotes: Leave JavaScriptQuotes: Leave
JavaScriptWrapImports: true JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: '' MacroBlockBegin: ""
MacroBlockEnd: '' MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: None NamespaceIndentation: None
ObjCBlockIndentWidth: 2 ObjCBlockIndentWidth: 2
@ -77,21 +77,20 @@ PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000 PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000 PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60 PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle PointerAlignment: Left
ReflowComments: true ReflowComments: true
SortIncludes: false SortIncludes: false
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never SpaceBeforeParens: Never
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
SpacesInContainerLiterals: false SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false SpacesInCStyleCastParentheses: false
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
Standard: Cpp11 Standard: Cpp11
TabWidth: 4 TabWidth: 4
UseTab: Never UseTab: Never
...

View File

@ -7,86 +7,86 @@
#define HASP_USE_APP 1 #define HASP_USE_APP 1
#ifndef HASP_USE_DEBUG #ifndef HASP_USE_DEBUG
#define HASP_USE_DEBUG 1 #define HASP_USE_DEBUG 1
#endif #endif
/* Network Services */ /* Network Services */
#ifndef HASP_USE_ETHERNET #ifndef HASP_USE_ETHERNET
#define HASP_USE_ETHERNET 0 #define HASP_USE_ETHERNET 0
#endif #endif
#ifndef HASP_USE_WIFI #ifndef HASP_USE_WIFI
#define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0) #define HASP_USE_WIFI (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_WIFI > 0)
#endif #endif
#define HASP_HAS_NETWORK \ #define HASP_HAS_NETWORK \
(ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0) (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0 || HASP_USE_ETHERNET > 0 || HASP_USE_WIFI > 0)
#ifndef HASP_USE_OTA #ifndef HASP_USE_OTA
#define HASP_USE_OTA (HASP_HAS_NETWORK) #define HASP_USE_OTA (HASP_HAS_NETWORK)
#endif #endif
#ifndef HASP_USE_MQTT #ifndef HASP_USE_MQTT
#define HASP_USE_MQTT (HASP_HAS_NETWORK) #define HASP_USE_MQTT (HASP_HAS_NETWORK)
#endif #endif
#ifndef HASP_USE_HTTP #ifndef HASP_USE_HTTP
#define HASP_USE_HTTP (HASP_HAS_NETWORK) #define HASP_USE_HTTP (HASP_HAS_NETWORK)
#endif #endif
#ifndef HASP_USE_MDNS #ifndef HASP_USE_MDNS
#define HASP_USE_MDNS (HASP_HAS_NETWORK) #define HASP_USE_MDNS (HASP_HAS_NETWORK)
#endif #endif
#ifndef HASP_USE_SYSLOG #ifndef HASP_USE_SYSLOG
#define HASP_USE_SYSLOG (HASP_HAS_NETWORK) #define HASP_USE_SYSLOG (HASP_HAS_NETWORK)
#endif #endif
#ifndef HASP_USE_TELNET #ifndef HASP_USE_TELNET
#define HASP_USE_TELNET 0 #define HASP_USE_TELNET 0
#endif #endif
/* Filesystem */ /* Filesystem */
#define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0) #define HASP_HAS_FILESYSTEM (ARDUINO_ARCH_ESP32 > 0 || ARDUINO_ARCH_ESP8266 > 0)
#ifndef HASP_USE_SPIFFS #ifndef HASP_USE_SPIFFS
#ifndef HASP_USE_LITTLEFS #ifndef HASP_USE_LITTLEFS
#define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM) #define HASP_USE_SPIFFS (HASP_HAS_FILESYSTEM)
#else #else
#define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0) #define HASP_USE_SPIFFS (HASP_USE_LITTLEFS <= 0)
#endif #endif
#endif #endif
#ifndef HASP_USE_LITTLEFS #ifndef HASP_USE_LITTLEFS
#define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0) #define HASP_USE_LITTLEFS (HASP_USE_SPIFFS <= 0)
#endif #endif
#ifndef HASP_USE_EEPROM #ifndef HASP_USE_EEPROM
#define HASP_USE_EEPROM 1 #define HASP_USE_EEPROM 1
#endif #endif
#ifndef HASP_USE_SDCARD #ifndef HASP_USE_SDCARD
#define HASP_USE_SDCARD 0 #define HASP_USE_SDCARD 0
#endif #endif
#ifndef HASP_USE_GPIO #ifndef HASP_USE_GPIO
#define HASP_USE_GPIO 1 #define HASP_USE_GPIO 1
#endif #endif
#ifndef HASP_USE_QRCODE #ifndef HASP_USE_QRCODE
#define HASP_USE_QRCODE 1 #define HASP_USE_QRCODE 1
#endif #endif
#ifndef HASP_USE_PNGDECODE #ifndef HASP_USE_PNGDECODE
#define HASP_USE_PNGDECODE 0 #define HASP_USE_PNGDECODE 0
#endif #endif
#ifndef HASP_NUM_GPIO_CONFIG #ifndef HASP_NUM_GPIO_CONFIG
#define HASP_NUM_GPIO_CONFIG 8 #define HASP_NUM_GPIO_CONFIG 8
#endif #endif
#ifndef HASP_NUM_INPUTS #ifndef HASP_NUM_INPUTS
#define HASP_NUM_INPUTS 4 // Number of ACE Buttons #define HASP_NUM_INPUTS 4 // Number of ACE Buttons
#endif #endif
// #ifndef HASP_NUM_OUTPUTS // #ifndef HASP_NUM_OUTPUTS
@ -94,188 +94,188 @@
// #endif // #endif
#ifndef HASP_NUM_PAGES #ifndef HASP_NUM_PAGES
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#define HASP_NUM_PAGES 4 #define HASP_NUM_PAGES 4
#else #else
#define HASP_NUM_PAGES 12 #define HASP_NUM_PAGES 12
#endif #endif
#endif #endif
#define HASP_OBJECT_NOTATION "p%ub%u" #define HASP_OBJECT_NOTATION "p%ub%u"
/* Includes */ /* Includes */
#ifdef WINDOWS #ifdef WINDOWS
#include "winsock2.h" #include "winsock2.h"
#include "Windows.h" #include "Windows.h"
#else #else
#include "Arduino.h" #include "Arduino.h"
#endif #endif
#if HASP_USE_SPIFFS > 0 #if HASP_USE_SPIFFS > 0
// #if defined(ARDUINO_ARCH_ESP32) // #if defined(ARDUINO_ARCH_ESP32)
// #include "SPIFFS.h" // #include "SPIFFS.h"
// #endif // #endif
// #include <FS.h> // Include the SPIFFS library // #include <FS.h> // Include the SPIFFS library
#include "hasp_filesystem.h" #include "hasp_filesystem.h"
#endif #endif
#if HASP_USE_LITTLEFS > 0 #if HASP_USE_LITTLEFS > 0
// #if defined(ARDUINO_ARCH_ESP32) // #if defined(ARDUINO_ARCH_ESP32)
// #include "LITTLEFS.h" // #include "LITTLEFS.h"
// #elif defined(ARDUINO_ARCH_ESP8266) // #elif defined(ARDUINO_ARCH_ESP8266)
// #include <FS.h> // Include the FS library // #include <FS.h> // Include the FS library
// #include <LittleFS.h> // #include <LittleFS.h>
// #endif // #endif
#include "hasp_filesystem.h" #include "hasp_filesystem.h"
#endif #endif
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
#include "lv_zifont.h" #include "lv_zifont.h"
#endif #endif
#endif #endif
#if HASP_USE_EEPROM > 0 #if HASP_USE_EEPROM > 0
#include "hasp_eeprom.h" #include "hasp_eeprom.h"
#endif #endif
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
#include "sys/net/hasp_wifi.h" #include "sys/net/hasp_wifi.h"
#if defined(STM32F4xx) #if defined(STM32F4xx)
#include "WiFiSpi.h" #include "WiFiSpi.h"
static WiFiSpiClass WiFi; static WiFiSpiClass WiFi;
#endif #endif
#endif // HASP_USE_WIFI #endif // HASP_USE_WIFI
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#include <ETH.h> #include <ETH.h>
#define ETH_ADDR 0 #define ETH_ADDR 0
#define ETH_POWER_PIN -1 #define ETH_POWER_PIN -1
#define ETH_MDC_PIN 23 #define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18 #define ETH_MDIO_PIN 18
#define NRST 5 #define NRST 5
#define ETH_TYPE ETH_PHY_LAN8720 #define ETH_TYPE ETH_PHY_LAN8720
#define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT #define ETH_CLKMODE ETH_CLOCK_GPIO17_OUT
#include "net/hasp_ethernet_esp32.h" #include "net/hasp_ethernet_esp32.h"
#warning Using ESP32 Ethernet LAN8720 #warning Using ESP32 Ethernet LAN8720
#else #else
#if USE_BUILTIN_ETHERNET > 0 #if USE_BUILTIN_ETHERNET > 0
#include <LwIP.h> #include <LwIP.h>
#include <STM32Ethernet.h> #include <STM32Ethernet.h>
#warning Use built-in STM32 Ethernet #warning Use built-in STM32 Ethernet
#elif USE_UIP_ETHERNET #elif USE_UIP_ETHERNET
#include <UIPEthernet.h> #include <UIPEthernet.h>
#include <utility/logging.h> #include <utility/logging.h>
#warning Use ENC28J60 Ethernet shield #warning Use ENC28J60 Ethernet shield
#else #else
#include "Ethernet.h" #include "Ethernet.h"
#warning Use W5x00 Ethernet shield #warning Use W5x00 Ethernet shield
#endif #endif
#include "net/hasp_ethernet_stm32.h" #include "net/hasp_ethernet_stm32.h"
#endif #endif
#endif #endif
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
#include "mqtt/hasp_mqtt.h" #include "mqtt/hasp_mqtt.h"
#ifdef WINDOWS #ifdef WINDOWS
#define USE_PAHO #define USE_PAHO
#else #else
#define USE_PUBSUBCLIENT #define USE_PUBSUBCLIENT
#endif #endif
#endif #endif
#if HASP_USE_GPIO > 0 #if HASP_USE_GPIO > 0
#include "sys/gpio/hasp_gpio.h" #include "sys/gpio/hasp_gpio.h"
#endif #endif
#if HASP_USE_HTTP > 0 #if HASP_USE_HTTP > 0
#include "svc/hasp_http.h" #include "sys/svc/hasp_http.h"
#endif #endif
#if HASP_USE_TELNET > 0 #if HASP_USE_TELNET > 0
#include "svc/hasp_telnet.h" #include "sys/svc/hasp_telnet.h"
#endif #endif
#if HASP_USE_MDNS > 0 #if HASP_USE_MDNS > 0
#include "svc/hasp_mdns.h" #include "sys/svc/hasp_mdns.h"
#endif #endif
#if HASP_USE_OTA > 0 #if HASP_USE_OTA > 0
#include "svc/hasp_ota.h" #include "sys/svc/hasp_ota.h"
#ifndef HASP_OTA_PORT #ifndef HASP_OTA_PORT
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
#define HASP_OTA_PORT 3232 #define HASP_OTA_PORT 3232
#elif defined(ARDUINO_ARCH_ESP8266) #elif defined(ARDUINO_ARCH_ESP8266)
#define HASP_OTA_PORT 8266 #define HASP_OTA_PORT 8266
#endif #endif
#endif #endif
#endif #endif
#if HASP_USE_TASMOTA_SLAVE > 0 #if HASP_USE_TASMOTA_CLIENT > 0
#include "svc/hasp_slave.h" #include "sys/svc/hasp_slave.h"
#endif #endif
#ifdef WINDOWS #ifdef WINDOWS
#ifndef FPSTR #ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper*>(pstr_pointer))
#endif #endif
#ifndef __FlashStringHelper #ifndef __FlashStringHelper
#define __FlashStringHelper char #define __FlashStringHelper char
#endif #endif
#ifndef FPSTR #ifndef FPSTR
#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer)) #define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper*>(pstr_pointer))
#endif #endif
#ifndef PGM_P #ifndef PGM_P
#define PGM_P const char * #define PGM_P const char*
#endif #endif
#ifndef F #ifndef F
#define F(x) (x) #define F(x) (x)
#endif #endif
#ifndef PSTR #ifndef PSTR
#define PSTR(x) x #define PSTR(x) x
#endif #endif
#ifndef PROGMEM #ifndef PROGMEM
#define PROGMEM #define PROGMEM
#endif #endif
#endif #endif
#ifdef WINDOWS #ifdef WINDOWS
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <Windows.h> #include <Windows.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#define snprintf_P snprintf #define snprintf_P snprintf
#define memcpy_P memcpy #define memcpy_P memcpy
#define strcasecmp_P strcmp // TODO: should be strcasecmp #define strcasecmp_P strcmp // TODO: should be strcasecmp
#define strcmp_P strcmp #define strcmp_P strcmp
#define strstr_P strstr #define strstr_P strstr
#define halRestartMcu() #define halRestartMcu()
#define delay Sleep #define delay Sleep
#define millis SDL_GetTicks #define millis SDL_GetTicks
#define DEC 10 #define DEC 10
#define HEX 16 #define HEX 16
#define BIN 2 #define BIN 2
#define guiGetDim() 255 #define guiGetDim() 255
#define guiSetDim(x) #define guiSetDim(x)
#define guiGetBacklight() 1 #define guiGetBacklight() 1
#define guiSetBacklight(x) #define guiSetBacklight(x)
#define guiCalibrate() //#define guiCalibrate()
#endif #endif
#endif // HASP_CONF_H #endif // HASP_CONF_H

View File

@ -59,11 +59,11 @@ struct moodlight_t
}; };
moodlight_t moodlight; moodlight_t moodlight;
static void dispatch_config(const char * topic, const char * payload); static void dispatch_config(const char* topic, const char* payload);
// void dispatch_group_value(uint8_t groupid, int16_t state, lv_obj_t * obj); // void dispatch_group_value(uint8_t groupid, int16_t state, 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);
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
@ -99,16 +99,16 @@ bool dispatch_factory_reset()
return formated && erased; return formated && erased;
} }
void dispatch_json_error(uint8_t tag, DeserializationError & jsonError) void dispatch_json_error(uint8_t tag, DeserializationError& jsonError)
{ {
LOG_ERROR(tag, F(D_JSON_FAILED " %s"), jsonError.c_str()); LOG_ERROR(tag, F(D_JSON_FAILED " %s"), jsonError.c_str());
} }
// p[x].b[y].attr=value // p[x].b[y].attr=value
static inline bool dispatch_parse_button_attribute(const char * topic_p, const char * payload) static inline bool dispatch_parse_button_attribute(const char* topic_p, const char* payload)
{ {
long num; long num;
char * pEnd; char* pEnd;
uint8_t pageid, objid; uint8_t pageid, objid;
if(*topic_p != 'p' && *topic_p != 'P') return false; // obligated p if(*topic_p != 'p' && *topic_p != 'P') return false; // obligated p
@ -202,7 +202,7 @@ static inline bool dispatch_parse_button_attribute(const char * topic_p, const c
} }
// objectattribute=value // objectattribute=value
void dispatch_command(const char * topic, const char * payload) void dispatch_command(const char* topic, const char* payload)
{ {
/* ================================= Standard payload commands ======================================= */ /* ================================= Standard payload commands ======================================= */
@ -260,34 +260,34 @@ void dispatch_command(const char * topic, const char * payload)
} }
// Strip command/config prefix from the topic and process the payload // Strip command/config prefix from the topic and process the payload
void dispatch_topic_payload(const char * topic, const char * payload) void dispatch_topic_payload(const char* topic, const char* payload)
{ {
// LOG_VERBOSE(TAG_MSGR,F("TOPIC: short topic: %s"), topic); // LOG_VERBOSE(TAG_MSGR,F("TOPIC: short topic: %s"), topic);
if(!strcmp_P(topic, PSTR("command"))) { if(!strcmp_P(topic, PSTR("command"))) {
dispatch_text_line((char *)payload); dispatch_text_line((char*)payload);
return; return;
} }
if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/ if(topic == strstr_P(topic, PSTR("command/"))) { // startsWith command/
topic += 8u; topic += 8u;
dispatch_command(topic, (char *)payload); dispatch_command(topic, (char*)payload);
return; return;
} }
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith command/ if(topic == strstr_P(topic, PSTR("config/"))) { // startsWith command/
topic += 7u; topic += 7u;
dispatch_config(topic, (char *)payload); dispatch_config(topic, (char*)payload);
return; return;
} }
#endif #endif
dispatch_command(topic, (char *)payload); // dispatch as is dispatch_command(topic, (char*)payload); // dispatch as is
} }
// Parse one line of text and execute the command // Parse one line of text and execute the command
void dispatch_text_line(const char * cmnd) void dispatch_text_line(const char* cmnd)
{ {
size_t pos1 = std::string(cmnd).find("="); size_t pos1 = std::string(cmnd).find("=");
size_t pos2 = std::string(cmnd).find(" "); size_t pos2 = std::string(cmnd).find(" ");
@ -350,7 +350,7 @@ void dispatch_output_group_state(uint8_t groupid, uint16_t state)
dispatch_state_msg(F("output"), payload); dispatch_state_msg(F("output"), payload);
} }
void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char* attribute, const char* data)
{ {
if(!attribute || !data) return; if(!attribute || !data) return;
@ -360,7 +360,7 @@ void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char *
mqtt_send_object_state(pageid, btnid, payload); mqtt_send_object_state(pageid, btnid, payload);
} }
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val) void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char* attribute, int32_t val)
{ {
if(!attribute) return; if(!attribute) return;
@ -370,7 +370,7 @@ void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char *
mqtt_send_object_state(pageid, btnid, payload); mqtt_send_object_state(pageid, btnid, payload);
} }
void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g, void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char* attribute, uint8_t r, uint8_t g,
uint8_t b) uint8_t b)
{ {
if(!attribute) return; if(!attribute) return;
@ -384,7 +384,7 @@ void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
// Get or Set a part of the config.json file // Get or Set a part of the config.json file
static void dispatch_config(const char * topic, const char * payload) static void dispatch_config(const char* topic, const char* payload)
{ {
DynamicJsonDocument doc(128 * 2); DynamicJsonDocument doc(128 * 2);
char buffer[128 * 2]; char buffer[128 * 2];
@ -494,7 +494,7 @@ bool dispatch_get_event_state(uint8_t eventid)
} }
// Map events to their description string // Map events to their description string
void dispatch_get_event_name(uint8_t eventid, char * buffer, size_t size) void dispatch_get_event_name(uint8_t eventid, char* buffer, size_t size)
{ {
switch(eventid) { switch(eventid) {
case HASP_EVENT_ON: case HASP_EVENT_ON:
@ -543,7 +543,7 @@ void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid)
} }
#endif #endif
void dispatch_object_event(lv_obj_t * obj, uint8_t eventid) void dispatch_object_event(lv_obj_t* obj, uint8_t eventid)
{ {
char topic[8]; char topic[8];
char payload[8]; char payload[8];
@ -559,7 +559,7 @@ void dispatch_object_event(lv_obj_t * obj, uint8_t eventid)
// dispatch_group_onoff(obj->user_data.groupid, dispatch_get_event_state(eventid), obj); // dispatch_group_onoff(obj->user_data.groupid, dispatch_get_event_state(eventid), obj);
} }
void dispatch_object_value_changed(lv_obj_t * obj, int16_t state) void dispatch_object_value_changed(lv_obj_t* obj, int16_t state)
{ {
char topic[4]; char topic[4];
@ -569,7 +569,7 @@ void dispatch_object_value_changed(lv_obj_t * obj, int16_t state)
} }
/********************************************** Output States ******************************************/ /********************************************** Output States ******************************************/
static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, const char * payload) static inline void dispatch_state_msg(const __FlashStringHelper* subtopic, const char* payload)
{ {
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT) #if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_CLIENT)
LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload); LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload);
@ -609,7 +609,7 @@ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, cons
// // dispatch_output_group_state(groupid, payload); // // dispatch_output_group_state(groupid, payload);
// } // }
void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * obj) void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t* obj)
{ {
if(groupid > 0) { if(groupid > 0) {
LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value); LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value);
@ -622,7 +622,7 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t *
/********************************************** Native Commands ****************************************/ /********************************************** Native Commands ****************************************/
void dispatch_parse_json(const char *, const char * payload) void dispatch_parse_json(const char*, const char* payload)
{ // Parse an incoming JSON array into individual commands { // Parse an incoming JSON array into individual commands
/* if(strPayload.endsWith(",]")) { /* if(strPayload.endsWith(",]")) {
// Trailing null array elements are an artifact of older Home Assistant automations // Trailing null array elements are an artifact of older Home Assistant automations
@ -645,18 +645,18 @@ void dispatch_parse_json(const char *, const char * payload)
JsonArray arr = json.as<JsonArray>(); JsonArray arr = json.as<JsonArray>();
// guiStop(); // guiStop();
for(JsonVariant command : arr) { for(JsonVariant command : arr) {
dispatch_text_line(command.as<const char *>()); dispatch_text_line(command.as<const char*>());
} }
// guiStart(); // guiStart();
} else if(json.is<JsonObject>()) { // handle json as a jsonl } else if(json.is<JsonObject>()) { // handle json as a jsonl
uint8_t savedPage = haspGetPage(); uint8_t savedPage = haspGetPage();
hasp_new_object(json.as<JsonObject>(), savedPage); hasp_new_object(json.as<JsonObject>(), savedPage);
} else if(json.is<const char *>()) { // handle json as a single command } else if(json.is<const char*>()) { // handle json as a single command
dispatch_text_line(json.as<const char *>()); dispatch_text_line(json.as<const char*>());
} else if(json.is<char *>()) { // handle json as a single command } else if(json.is<char*>()) { // handle json as a single command
dispatch_text_line(json.as<char *>()); dispatch_text_line(json.as<char*>());
// } else if(json.is<String>()) { // handle json as a single command // } else if(json.is<String>()) { // handle json as a single command
// dispatch_text_line(json.as<String>().c_str()); // dispatch_text_line(json.as<String>().c_str());
@ -667,9 +667,9 @@ void dispatch_parse_json(const char *, const char * payload)
} }
#ifdef ARDUINO #ifdef ARDUINO
void dispatch_parse_jsonl(Stream & stream) void dispatch_parse_jsonl(Stream& stream)
#else #else
void dispatch_parse_jsonl(std::istringstream & stream) void dispatch_parse_jsonl(std::istringstream& stream)
#endif #endif
{ {
uint8_t savedPage = haspGetPage(); uint8_t savedPage = haspGetPage();
@ -698,14 +698,14 @@ void dispatch_parse_jsonl(std::istringstream & stream)
} }
} }
void dispatch_parse_jsonl(const char *, const char * payload) void dispatch_parse_jsonl(const char*, const char* payload)
{ {
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
CharStream stream((char *)payload); CharStream stream((char*)payload);
// stream.setTimeout(10); // stream.setTimeout(10);
dispatch_parse_jsonl(stream); dispatch_parse_jsonl(stream);
#else #else
std::istringstream stream((char *)payload); std::istringstream stream((char*)payload);
dispatch_parse_jsonl(stream); dispatch_parse_jsonl(stream);
#endif #endif
} }
@ -719,7 +719,7 @@ void dispatch_output_current_page()
} }
// Get or Set a page // Get or Set a page
void dispatch_page(const char *, const char * page) void dispatch_page(const char*, const char* page)
{ {
if(strlen(page) > 0) { if(strlen(page) > 0) {
if(Utilities::is_only_digits(page)) { if(Utilities::is_only_digits(page)) {
@ -766,14 +766,14 @@ void dispatch_page_prev()
} }
// Clears a page id or the current page if empty // Clears a page id or the current page if empty
void dispatch_clear_page(const char *, const char * page) void dispatch_clear_page(const char*, const char* page)
{ {
uint8_t pageid = haspGetPage(); uint8_t pageid = haspGetPage();
if(strlen(page) > 0) pageid = atoi(page); if(strlen(page) > 0) pageid = atoi(page);
haspClearPage(pageid); haspClearPage(pageid);
} }
void dispatch_dim(const char *, const char * level) void dispatch_dim(const char*, const char* level)
{ {
// Set the current state // Set the current state
if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level)); if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level));
@ -783,7 +783,7 @@ void dispatch_dim(const char *, const char * level)
dispatch_state_msg(F("dim"), payload); dispatch_state_msg(F("dim"), payload);
} }
void dispatch_moodlight(const char * topic, const char * payload) void dispatch_moodlight(const char* topic, const char* payload)
{ {
// Set the current state // Set the current state
if(strlen(payload) != 0) { if(strlen(payload) != 0) {
@ -800,7 +800,7 @@ void dispatch_moodlight(const char * topic, const char * payload)
dispatch_json_error(TAG_MSGR, jsonError); dispatch_json_error(TAG_MSGR, jsonError);
} else { } else {
if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as<const char *>()); if(!json[F("power")].isNull()) moodlight.power = Utilities::is_true(json[F("power")].as<const char*>());
if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as<uint8_t>(); if(!json[F("r")].isNull()) moodlight.r = json[F("r")].as<uint8_t>();
if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as<uint8_t>(); if(!json[F("g")].isNull()) moodlight.r = json[F("g")].as<uint8_t>();
@ -808,7 +808,7 @@ void dispatch_moodlight(const char * topic, const char * payload)
if(!json[F("color")].isNull()) { if(!json[F("color")].isNull()) {
lv_color32_t color; lv_color32_t color;
if(Parser::haspPayloadToColor(json[F("color")].as<const char *>(), color)) { if(Parser::haspPayloadToColor(json[F("color")].as<const char*>(), color)) {
moodlight.r = color.ch.red; moodlight.r = color.ch.red;
moodlight.g = color.ch.green; moodlight.g = color.ch.green;
moodlight.b = color.ch.blue; moodlight.b = color.ch.blue;
@ -832,7 +832,7 @@ void dispatch_moodlight(const char * topic, const char * payload)
dispatch_state_msg(F("moodlight"), buffer); dispatch_state_msg(F("moodlight"), buffer);
} }
void dispatch_backlight(const char *, const char * payload) void dispatch_backlight(const char*, const char* payload)
{ {
// Set the current state // Set the current state
if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload)); if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload));
@ -843,7 +843,7 @@ void dispatch_backlight(const char *, const char * payload)
dispatch_state_msg(F("light"), buffer); dispatch_state_msg(F("light"), buffer);
} }
void dispatch_web_update(const char *, const char * espOtaUrl) void dispatch_web_update(const char*, const char* espOtaUrl)
{ {
#if HASP_USE_OTA > 0 #if HASP_USE_OTA > 0
LOG_TRACE(TAG_MSGR, F(D_OTA_CHECK_UPDATE), espOtaUrl); LOG_TRACE(TAG_MSGR, F(D_OTA_CHECK_UPDATE), espOtaUrl);
@ -889,40 +889,38 @@ void dispatch_current_state()
/******************************************* Command Wrapper Functions *********************************/ /******************************************* Command Wrapper Functions *********************************/
// Periodically publish a JSON string indicating system status // Periodically publish a JSON string indicating system status
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];
haspGetVersion(buffer, sizeof(buffer)); haspGetVersion(buffer, sizeof(buffer));
snprintf_P(data, sizeof(data), snprintf_P(data, sizeof(data),
PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"), PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
mqttGetNodename().c_str(), buffer, long(millis() / 1000)); mqttGetNodename().c_str(), buffer, long(millis() / 1000));
#if HASP_USE_WIFI > 0 #if HASP_USE_WIFI > 0
network_get_statusupdate(buffer, sizeof(buffer)); network_get_statusupdate(buffer, sizeof(buffer));
strcat(data, buffer); strcat(data, buffer);
#endif #endif
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","), snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
halGetFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str()); haspDevice.get_free_heap(), haspDevice.get_heap_fragmentation(), halGetCoreVersion().c_str());
strcat(data, buffer); strcat(data, buffer);
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"), snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
haspGetPage(), (HASP_NUM_PAGES)); haspGetPage(), (HASP_NUM_PAGES));
strcat(data, buffer); strcat(data, buffer);
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000); snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000);
strcat(data, buffer); strcat(data, buffer);
#endif #endif
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"), snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT)); halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
strcat(data, buffer); strcat(data, buffer);
*/
} }
mqtt_send_state(F("statusupdate"), data); mqtt_send_state(F("statusupdate"), data);
dispatchLastMillis = millis(); dispatchLastMillis = millis();
@ -937,22 +935,22 @@ void dispatch_output_statusupdate(const char *, const char *)
#endif #endif
} }
void dispatch_calibrate(const char * topic = NULL, const char * payload = NULL) void dispatch_calibrate(const char* topic = NULL, const char* payload = NULL)
{ {
guiCalibrate(); guiCalibrate();
} }
void dispatch_wakeup(const char *, const char *) void dispatch_wakeup(const char*, const char*)
{ {
lv_disp_trig_activity(NULL); lv_disp_trig_activity(NULL);
} }
void dispatch_reboot(const char *, const char *) void dispatch_reboot(const char*, const char*)
{ {
dispatch_reboot(true); dispatch_reboot(true);
} }
void dispatch_factory_reset(const char *, const char *) void dispatch_factory_reset(const char*, const char*)
{ {
dispatch_factory_reset(); dispatch_factory_reset();
delay(500); delay(500);
@ -961,7 +959,7 @@ 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 *)) static void dispatch_add_command(const char* p_cmdstr, void (*func)(const char*, const char*))
{ {
if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) { if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) {
LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands); LOG_FATAL(TAG_MSGR, F("CMD_OVERFLOW %d"), nCommands);

194
src/main_arduino copy.cpp Normal file
View File

@ -0,0 +1,194 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if 0 && ARDUINO
#include <Arduino.h>
#include "lvgl.h"
#include "hasp_conf.h" // load first
#if HASP_USE_CONFIG > 0
#include "hasp_debug.h"
#endif
#if HASP_USE_CONFIG > 0
#include "hasp_config.h"
#include "hasp_gui.h"
#endif
#include "hasp_oobe.h"
#include "hasp/hasp_dispatch.h"
#include "hasp/hasp.h"
#include "sys/net/hasp_network.h"
#include "dev/device.h"
bool isConnected;
uint8_t mainLoopCounter = 0;
unsigned long mainLastLoopTime = 0;
void setup()
{
hal_setup();
haspDevice.init();
/****************************
* Storage initializations
***************************/
#if HASP_USE_EEPROM > 0
eepromSetup(); // Don't start at boot, only at write
#endif
// #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
// filesystemSetup(); // FS mount is done in configSetup()
// #endif
// #if HASP_USE_SDCARD > 0
// sdcardSetup();
// #endif
/****************************
* Read & Apply User Configuration
***************************/
#if HASP_USE_CONFIG > 0
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
#endif
dispatchSetup();
guiSetup();
debugSetup(); // Init the console
#if HASP_USE_GPIO > 0
gpioSetup();
#endif
/****************************
* Apply User Configuration
***************************/
#if HASP_USE_MQTT > 0
mqttSetup(); // Load Hostname before starting WiFi
#endif
#if HASP_USE_WIFI > 0 || HASP_USE_ETHERNET > 0
networkSetup();
#endif
#if HASP_USE_CONFIG > 0
if(!oobeSetup())
#endif
{
haspSetup();
}
#if HASP_USE_MDNS > 0
mdnsSetup();
#endif
#if HASP_USE_OTA > 0
otaSetup();
#endif
#if HASP_USE_HTTP > 0
httpSetup();
#endif
#if HASP_USE_TELNET > 0
telnetSetup();
#endif
#if HASP_USE_TASMOTA_CLIENT > 0
slaveSetup();
#endif
mainLastLoopTime = millis() - 1000; // reset loop counter
delay(250);
guiStart();
}
void loop()
{
networkLoop();
guiLoop();
haspLoop();
#if HASP_USE_MQTT > 0
mqttLoop();
#endif // MQTT
#if HASP_USE_TASMOTA_CLIENT > 0
slaveLoop();
#endif // TASMOTASLAVE
#if HASP_USE_HTTP > 0
httpLoop();
#endif // HTTP
#if HASP_USE_GPIO > 0
gpioLoop();
#endif // GPIO
#if HASP_USE_OTA > 0
otaLoop();
#endif // OTA
#if HASP_USE_MDNS > 0
mdnsLoop();
#endif // MDNS
#if HASP_USE_TELNET > 0
telnetLoop(); // Console
#endif // TELNET
debugLoop(); // Console
haspDevice.loop();
/* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) {
/* Runs Every Second */
haspEverySecond(); // sleep timer
debugEverySecond(); // statusupdate
#if HASP_USE_OTA > 0
otaEverySecond(); // progressbar
#endif
/* Runs Every 5 Seconds */
if(mainLoopCounter == 0 || mainLoopCounter == 5) {
isConnected = networkEvery5Seconds(); // Check connection
#if HASP_USE_HTTP > 0
// httpEvery5Seconds();
#endif
#if HASP_USE_MQTT > 0
mqttEvery5Seconds(isConnected);
#endif
#if HASP_USE_GPIO > 0
// gpioEvery5Seconds();
#endif
haspDevice.loop_5s();
}
/* Reset loop counter every 10 seconds */
if(mainLoopCounter >= 9) {
mainLoopCounter = 0;
} else {
mainLoopCounter++;
}
mainLastLoopTime += 1000;
}
#ifdef ARDUINO_ARCH_ESP8266
delay(2);
#else
delay(6);
#endif
}
#endif

View File

@ -33,7 +33,7 @@ void setup()
{ {
// hal_setup(); // hal_setup();
haspDevice.pre_setup(); haspDevice.init();
/**************************** /****************************
* Storage initializations * Storage initializations
@ -100,7 +100,7 @@ void setup()
telnetSetup(); telnetSetup();
#endif #endif
#if HASP_USE_TASMOTA_SLAVE > 0 #if HASP_USE_TASMOTA_CLINET > 0
slaveSetup(); slaveSetup();
#endif #endif
@ -111,51 +111,24 @@ void setup()
void loop() void loop()
{ {
networkLoop();
guiLoop(); guiLoop();
haspLoop(); haspLoop();
networkLoop();
#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
httpLoop();
#endif // HTTP
#if HASP_USE_GPIO > 0
gpioLoop();
#endif // GPIO
#if HASP_USE_OTA > 0
otaLoop();
#endif // OTA
#if HASP_USE_MDNS > 0
mdnsLoop();
#endif // MDNS
#if HASP_USE_TELNET > 0
telnetLoop(); // Console
#endif // TELNET
debugLoop(); // Console debugLoop(); // Console
haspDevice.loop(); haspDevice.loop();
/* Timer Loop */ /* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) { if(millis() - mainLastLoopTime >= 1000) {
/* Runs Every Second */ /* Runs Every Second */
haspEverySecond(); // sleep timer haspEverySecond(); // sleep timer
debugEverySecond(); // statusupdate debugEverySecond(); // statusupdate
#if HASP_USE_OTA > 0
otaEverySecond(); // progressbar
#endif
/* Runs Every 5 Seconds */ /* Runs Every 5 Seconds */
if(mainLoopCounter == 0 || mainLoopCounter == 5) { if(mainLoopCounter == 0 || mainLoopCounter == 5) {
isConnected = networkEvery5Seconds(); // Check connection isConnected = networkEvery5Seconds(); // Check connection

View File

@ -3,19 +3,22 @@
#ifdef WINDOWS #ifdef WINDOWS
#include "lvgl.h" #include "hasp_conf.h"
#include "app_hal.h"
#include "hasp_conf.h" #include "lvgl.h"
#include "hasp_debug.h" #include "app_hal.h"
#include "hasp/hasp_dispatch.h" #include "hasp_debug.h"
#include "hasp/hasp.h" #include "hasp_gui.h"
#include "dev/device.h" #include "hasp/hasp_dispatch.h"
#include "app_hal.h" #include "hasp/hasp.h"
#include "dev/device.h"
bool isConnected; bool isConnected;
bool isRunning = 1;
uint8_t mainLoopCounter = 0; uint8_t mainLoopCounter = 0;
unsigned long mainLastLoopTime = 0; unsigned long mainLastLoopTime = 0;
@ -27,26 +30,26 @@ void debugLvglLogEvent(lv_log_level_t level, const char * file, uint32_t line, c
void setup() void setup()
{ {
printf("%s %d\n", __FILE__, __LINE__); // Load Settings
fflush(stdout);
// Init debug log
// debug_init();
// Initialize lvgl environment
lv_init(); lv_init();
lv_log_register_print_cb(debugLvglLogEvent); lv_log_register_print_cb(debugLvglLogEvent);
printf("%s %d\n", __FILE__, __LINE__); haspDevice.init();
fflush(stdout);
hal_setup(); hal_setup();
guiSetup();
printf("%s %d\n", __FILE__, __LINE__);
haspDevice.pre_setup();
printf("%s %d\n", __FILE__, __LINE__);
dispatchSetup(); dispatchSetup();
// debugSetup(); // Init the console // debugSetup(); // Init the console
#if HASP_USE_MQTT > 0 #if HASP_USE_MQTT > 0
printf("%s %d\n", __FILE__, __LINE__); printf("%s %d\n", __FILE__, __LINE__);
mqttSetup(); // Load Hostname before starting WiFi mqttSetup(); // Load Hostname before starting WiFi
#endif #endif
printf("%s %d\n", __FILE__, __LINE__); printf("%s %d\n", __FILE__, __LINE__);
haspSetup(); haspSetup();
@ -62,15 +65,16 @@ void loop()
// debugLoop(); // Console // debugLoop(); // Console
haspDevice.loop(); haspDevice.loop();
guiLoop();
/* Timer Loop */ /* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) { if(millis() - mainLastLoopTime >= 1000) {
/* Runs Every Second */ /* Runs Every Second */
haspEverySecond(); // sleep timer haspEverySecond(); // sleep timer
#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) {
@ -90,32 +94,21 @@ void loop()
delay(6); delay(6);
} }
#ifdef WINDOWS #ifdef WINDOWS
int main(int argv, char ** args) int main(int argv, char ** args)
{ {
printf("%s %d\n", __FILE__, __LINE__); // printf("%s %d\n", __FILE__, __LINE__);
fflush(stdout); // fflush(stdout);
setup(); setup();
std::cout << "HSetup OK\n";
while(isRunning) {
while(1) { loop();
SDL_Delay(5); // std::cout << "HSetup OK\n";
lv_task_handler();
fflush(stdout);
} }
std::cout << "Hloop OK\n";
return 0; return 0;
} }
#else #endif
void loop()
{
delay(5);
lv_task_handler();
}
#endif
#endif #endif

View File

@ -117,7 +117,7 @@ bool networkEverySecond(void)
return true; return true;
} }
void network_get_statusupdate(char * buffer, size_t len) void network_get_statusupdate(char* buffer, size_t len)
{ {
#if HASP_USE_ETHERNET > 0 #if HASP_USE_ETHERNET > 0
ethernet_get_statusupdate(buffer, len); ethernet_get_statusupdate(buffer, len);