mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Code cleanup
This commit is contained in:
parent
69ed03793b
commit
ce20726ffb
@ -30,14 +30,15 @@ default_envs =
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
; -- Shared library dependencies in all environments
|
; -- Shared library dependencies in all environments
|
||||||
lib_deps =
|
lib_deps =
|
||||||
lvgl/lvgl @ ^7.7.2 ; Not in library yet
|
lvgl/lvgl @ ^7.7.2 ; from PIO library
|
||||||
bodmer/TFT_eSPI @ ^2.3.4 ; Tft SPI drivers
|
bodmer/TFT_eSPI @ ^2.3.4 ; Tft SPI drivers
|
||||||
PubSubClient @ ^2.8.0 ; MQTT client
|
bxparks/AceButton @ ^1.7.1 ; GPIO button library
|
||||||
ArduinoJson @ ^6.17.2 ; Json(l) parser
|
bblanchon/ArduinoJson @ ^6.17.2 ; Json(l) parser
|
||||||
StreamUtils @ ^1.5.0 ; for EEPromStream
|
bblanchon/StreamUtils @ ^1.5.0 ; for EEPromStream
|
||||||
AceButton @ ^1.7.0
|
knolleary/PubSubClient @ ^2.8.0 ; MQTT client
|
||||||
https://github.com/fvanroie/ConsoleInput.git
|
https://github.com/fvanroie/ConsoleInput.git
|
||||||
https://github.com/andrethomas/TasmotaSlave.git
|
https://github.com/andrethomas/TasmotaSlave.git
|
||||||
; ------ Unused / Test libraries
|
; ------ Unused / Test libraries
|
||||||
@ -47,17 +48,17 @@ lib_deps =
|
|||||||
;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
|
;https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
|
||||||
;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip
|
;https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip
|
||||||
|
|
||||||
lib_ignore =
|
; lib_ignore =
|
||||||
https://github.com/littlevgl/lvgl.git
|
; https://github.com/littlevgl/lvgl.git
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
;-Os ; Code Size Optimization
|
;-Os ; Code Size Optimization
|
||||||
-Og ; Code Debug Optimization
|
-Og ; Code Debug Optimization
|
||||||
;-w ; Suppress warnings
|
;-w ; Suppress warnings
|
||||||
-D CORE_DEBUG_LEVEL=1 ; 0=Silent, 1=Errors
|
-D CORE_DEBUG_LEVEL=2 ; 0=Silent, 1=Errors, 2=Warnings
|
||||||
-I include ; include lv_conf.h and hasp_conf.h
|
-I include ; include lv_conf.h and hasp_conf.h
|
||||||
; -- littlevgl build options ------------------------------
|
; -- littlevgl build options ------------------------------
|
||||||
-D LV_CONF_INCLUDE_SIMPLE
|
-D LV_CONF_INCLUDE_SIMPLE ; for lvgl
|
||||||
-D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers
|
-D LV_LVGL_H_INCLUDE_SIMPLE ; for lv_drivers
|
||||||
; -- littlevgl build options ------------------------------
|
; -- littlevgl build options ------------------------------
|
||||||
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
|
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
For full license information read the LICENSE file in the project folder */
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
|
|
||||||
|
- Log.fatal() - A fatal exception is caught, the program should halt with while(1){}
|
||||||
|
- Log.error() - An important but non-fatal error occured, this error should be checked and not ignored
|
||||||
|
- Log.warning() - Send at the end of a function to indicate failure of the sub process, can be ignored
|
||||||
|
|
||||||
|
- Log.notice() - Information at the START of an action to notify another function is now running
|
||||||
|
- Log.trace() - Send at the END of a function to indicate successful completion of the sub process
|
||||||
|
- Log.verbose() - Send DEBUG information DURING a subprocess
|
||||||
|
|
||||||
|
=========================================================================== */
|
||||||
|
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
#include "ConsoleInput.h"
|
#include "ConsoleInput.h"
|
||||||
@ -139,7 +151,12 @@ void debugSetup()
|
|||||||
{
|
{
|
||||||
// memset(serialInputBuffer, 0, sizeof(serialInputBuffer));
|
// memset(serialInputBuffer, 0, sizeof(serialInputBuffer));
|
||||||
// serialInputIndex = 0;
|
// serialInputIndex = 0;
|
||||||
|
Log.error(TAG_DEBG, F("Setting the console parser"));
|
||||||
console.setLineCallback(dispatchTextLine);
|
console.setLineCallback(dispatchTextLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void debugStartSyslog()
|
||||||
|
{
|
||||||
|
|
||||||
#if HASP_USE_SYSLOG > 0
|
#if HASP_USE_SYSLOG > 0
|
||||||
// syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD);
|
// syslog = new Syslog(syslogClient, debugSyslogProtocol == 0 ? SYSLOG_PROTO_IETF : SYSLOG_PROTO_BSD);
|
||||||
@ -150,16 +167,29 @@ void debugSetup()
|
|||||||
// syslog->defaultPriority(priority);
|
// syslog->defaultPriority(priority);
|
||||||
|
|
||||||
if(strlen(debugSyslogHost) > 0) {
|
if(strlen(debugSyslogHost) > 0) {
|
||||||
syslogClient = new WiFiUDP();
|
if(!syslogClient) syslogClient = new WiFiUDP();
|
||||||
|
|
||||||
if(syslogClient) {
|
if(syslogClient) {
|
||||||
if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) {
|
if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) {
|
||||||
Log.registerOutput(2, syslogClient, LOG_LEVEL_VERBOSE, true);
|
Log.registerOutput(2, syslogClient, LOG_LEVEL_VERBOSE, true);
|
||||||
|
Log.trace(TAG_DEBG, F("Syslog client started"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.error(TAG_DEBG, F("Failed to start syslog client"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debugStopSyslog()
|
||||||
|
{
|
||||||
|
#if HASP_USE_SYSLOG > 0
|
||||||
|
if(strlen(debugSyslogHost) > 0) {
|
||||||
|
Log.unregisterOutput(2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void debugStop()
|
void debugStop()
|
||||||
{
|
{
|
||||||
if(debugSerialStarted) Serial.flush();
|
if(debugSerialStarted) Serial.flush();
|
||||||
@ -561,7 +591,11 @@ void debugPrintSuffix(uint8_t tag, int level, Print * _logOutput)
|
|||||||
else
|
else
|
||||||
_logOutput->println();
|
_logOutput->println();
|
||||||
|
|
||||||
_logOutput->print("hasp > ");
|
if(_logOutput == &Serial) {
|
||||||
|
console.update();
|
||||||
|
} else {
|
||||||
|
_logOutput->print("hasp > ");
|
||||||
|
}
|
||||||
|
|
||||||
// if(_logOutput == &Serial) debugPrintPrompt();
|
// if(_logOutput == &Serial) debugPrintPrompt();
|
||||||
// syslogSend(level, debugOutput);
|
// syslogSend(level, debugOutput);
|
||||||
@ -638,19 +672,14 @@ void debugLoop()
|
|||||||
switch(keypress) {
|
switch(keypress) {
|
||||||
|
|
||||||
case ConsoleInput::KEY_PAGE_UP:
|
case ConsoleInput::KEY_PAGE_UP:
|
||||||
console.println(F("PAGE_UP pressed"));
|
|
||||||
dispatchPagePrev();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ConsoleInput::KEY_PAGE_DOWN:
|
|
||||||
console.println(F("PAGE_DOWN pressed"));
|
|
||||||
dispatchPageNext();
|
dispatchPageNext();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ConsoleInput::KEY_PAGE_DOWN:
|
||||||
|
dispatchPagePrev();
|
||||||
|
break;
|
||||||
|
|
||||||
case(ConsoleInput::KEY_FN)...(ConsoleInput::KEY_FN + 12):
|
case(ConsoleInput::KEY_FN)...(ConsoleInput::KEY_FN + 12):
|
||||||
console.print(F("F"));
|
|
||||||
console.print(keypress - ConsoleInput::KEY_FN);
|
|
||||||
console.println(F(" pressed"));
|
|
||||||
haspSetPage(keypress - ConsoleInput::KEY_FN - 1);
|
haspSetPage(keypress - ConsoleInput::KEY_FN - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,31 @@
|
|||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
|
void debugHaspHeader(Print * output);
|
||||||
|
|
||||||
|
void debugPreSetup(JsonObject settings);
|
||||||
|
void debugSetup();
|
||||||
|
void debugLoop(void);
|
||||||
|
void debugEverySecond(void);
|
||||||
|
void debugStart(void);
|
||||||
|
void debugStop(void);
|
||||||
|
|
||||||
|
void debugStartSyslog(void);
|
||||||
|
void debugStopSyslog(void);
|
||||||
|
|
||||||
|
void serialPrintln(String & debugText, uint8_t level);
|
||||||
|
void serialPrintln(const char * debugText, uint8_t level);
|
||||||
|
|
||||||
|
void syslogSend(uint8_t log, const char * debugText);
|
||||||
|
|
||||||
|
bool debugGetConfig(const JsonObject & settings);
|
||||||
|
bool debugSetConfig(const JsonObject & settings);
|
||||||
|
|
||||||
|
// void debugPrintPrefix(int level, Print * _logOutput);
|
||||||
|
// void debugPrintSuffix(int level, Print * _logOutput);
|
||||||
|
// void debugSendOuput(const char * buffer);
|
||||||
|
void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, const char * descr);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TAG_MAIN = 0,
|
TAG_MAIN = 0,
|
||||||
TAG_HASP = 1,
|
TAG_HASP = 1,
|
||||||
@ -44,26 +69,4 @@ enum {
|
|||||||
TAG_FONT = 92
|
TAG_FONT = 92
|
||||||
};
|
};
|
||||||
|
|
||||||
void debugHaspHeader(Print * output);
|
|
||||||
|
|
||||||
void debugPreSetup(JsonObject settings);
|
|
||||||
void debugSetup();
|
|
||||||
void debugLoop(void);
|
|
||||||
void debugEverySecond(void);
|
|
||||||
void debugStart(void);
|
|
||||||
void debugStop(void);
|
|
||||||
|
|
||||||
void serialPrintln(String & debugText, uint8_t level);
|
|
||||||
void serialPrintln(const char * debugText, uint8_t level);
|
|
||||||
|
|
||||||
void syslogSend(uint8_t log, const char * debugText);
|
|
||||||
|
|
||||||
bool debugGetConfig(const JsonObject & settings);
|
|
||||||
bool debugSetConfig(const JsonObject & settings);
|
|
||||||
|
|
||||||
// void debugPrintPrefix(int level, Print * _logOutput);
|
|
||||||
// void debugPrintSuffix(int level, Print * _logOutput);
|
|
||||||
// void debugSendOuput(const char * buffer);
|
|
||||||
void debugLvgl(lv_log_level_t level, const char * file, uint32_t line, const char * funcname, const char * descr);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -142,7 +142,7 @@ void dispatchCommand(const char * topic, const char * payload)
|
|||||||
if(strlen(payload) == 0) {
|
if(strlen(payload) == 0) {
|
||||||
// dispatchTextLine(topic); // Could cause an infinite loop!
|
// dispatchTextLine(topic); // Could cause an infinite loop!
|
||||||
}
|
}
|
||||||
Log.warning(TAG_MSGR, F(LOG_CMND_CTR "Command not found %s => %s"), topic, payload);
|
Log.warning(TAG_MSGR, F("Command '%s' not found => %s"), topic, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,9 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
|
|||||||
for(i = 0; i < HASP_NUM_INPUTS; i++) {
|
for(i = 0; i < HASP_NUM_INPUTS; i++) {
|
||||||
|
|
||||||
if(!button[i]) {
|
if(!button[i]) {
|
||||||
|
Log.notice(TAG_GPIO, F("Creating Button%d on pin %d (index %d) mode %d default %d"), i, pin, index,
|
||||||
|
input_mode, default_state);
|
||||||
|
|
||||||
button[i] = new AceButton(pin, default_state, index);
|
button[i] = new AceButton(pin, default_state, index);
|
||||||
// button[i]->init(pin, default_state, index);
|
// button[i]->init(pin, default_state, index);
|
||||||
|
|
||||||
@ -134,15 +137,15 @@ void gpioAddButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8
|
|||||||
buttonConfig->clearFeature(
|
buttonConfig->clearFeature(
|
||||||
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
||||||
|
|
||||||
Log.trace(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index,
|
Log.trace(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index,
|
||||||
input_mode, default_state);
|
input_mode, default_state);
|
||||||
gpioUsedInputCount = i + 1;
|
gpioUsedInputCount = i + 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index,
|
Log.error(TAG_GPIO, F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin,
|
||||||
HASP_NUM_INPUTS);
|
index, HASP_NUM_INPUTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t index)
|
void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state, uint8_t index)
|
||||||
@ -165,15 +168,15 @@ void gpioAddTouchButton(uint8_t pin, uint8_t input_mode, uint8_t default_state,
|
|||||||
buttonConfig->clearFeature(
|
buttonConfig->clearFeature(
|
||||||
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
ButtonConfig::kFeatureSuppressClickBeforeDoubleClick); // Causes annoying pauses
|
||||||
|
|
||||||
Log.trace(TAG_GPIO,F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index,
|
Log.trace(TAG_GPIO, F("Button%d created on pin %d (index %d) mode %d default %d"), i, pin, index,
|
||||||
input_mode, default_state);
|
input_mode, default_state);
|
||||||
gpioUsedInputCount = i + 1;
|
gpioUsedInputCount = i + 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.error(TAG_GPIO,F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin, index,
|
Log.error(TAG_GPIO, F("Failed to create Button%d pin %d (index %d). All %d slots available are in use!"), i, pin,
|
||||||
HASP_NUM_INPUTS);
|
index, HASP_NUM_INPUTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpioSetup()
|
void gpioSetup()
|
||||||
@ -420,8 +423,8 @@ bool gpioSavePinConfig(uint8_t config_num, uint8_t pin, uint8_t type, uint8_t gr
|
|||||||
gpioConfig[config_num].type = type;
|
gpioConfig[config_num].type = type;
|
||||||
gpioConfig[config_num].group = group;
|
gpioConfig[config_num].group = group;
|
||||||
gpioConfig[config_num].gpio_function = pinfunc;
|
gpioConfig[config_num].gpio_function = pinfunc;
|
||||||
Log.notice(TAG_GPIO,F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type, group,
|
Log.notice(TAG_GPIO, F("Saving Pin config #%d pin %d - type %d - group %d - func %d"), config_num, pin, type,
|
||||||
pinfunc);
|
group, pinfunc);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,7 +579,7 @@ bool gpioGetConfig(const JsonObject & settings)
|
|||||||
if(i < HASP_NUM_GPIO_CONFIG) {
|
if(i < HASP_NUM_GPIO_CONFIG) {
|
||||||
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
|
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
|
||||||
(gpioConfig[i].gpio_function << 24);
|
(gpioConfig[i].gpio_function << 24);
|
||||||
Log.trace(TAG_GPIO,F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as<uint32_t>());
|
Log.trace(TAG_GPIO, F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as<uint32_t>());
|
||||||
|
|
||||||
if(cur_val != v.as<uint32_t>()) changed = true;
|
if(cur_val != v.as<uint32_t>()) changed = true;
|
||||||
v.set(cur_val);
|
v.set(cur_val);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user