mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-21 10:16:34 +00:00
tasmotaslave impovements
This commit is contained in:
parent
554849714d
commit
2785880a09
@ -8,7 +8,7 @@ lolin24 =
|
||||
-D ILI9341_DRIVER=1
|
||||
-D TFT_WIDTH=240
|
||||
-D TFT_HEIGHT=320
|
||||
-D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree
|
||||
-D TFT_ROTATION=2 ; 0=0, 1=90, 2=180 or 3=270 degree
|
||||
-D SPI_FREQUENCY=40000000
|
||||
-D SPI_TOUCH_FREQUENCY=2500000
|
||||
-D SPI_READ_FREQUENCY=20000000
|
||||
|
@ -665,7 +665,7 @@ void haspClearPage(uint16_t pageid)
|
||||
Log.warning(F("HASP: Cannot clear a layer"));
|
||||
} else {
|
||||
Log.notice(F("HASP: Clearing page %u"), pageid);
|
||||
lv_page_clean(pages[pageid]);
|
||||
lv_obj_clean(pages[pageid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ static void button_event_cb(AceButton * button, uint8_t eventType, uint8_t butto
|
||||
|
||||
void buttonSetup(void)
|
||||
{
|
||||
// button[0] = new Button(2);
|
||||
button[0] = new AceButton(HASP_INPUT_PIN, LOW, 0);
|
||||
button[1] = new AceButton(3, HIGH, 1);
|
||||
button[2] = new AceButton(4, HIGH, 2);
|
||||
|
||||
|
@ -9,6 +9,6 @@ void gpioSetup()
|
||||
#endif
|
||||
#if defined(STM32_CORE_VERSION)
|
||||
pinMode(HASP_OUTPUT_PIN, OUTPUT);
|
||||
pinMode(HASP_INPUT_PIN, INPUT_PULLUP);
|
||||
pinMode(HASP_INPUT_PIN, INPUT_PULLDOWN);
|
||||
#endif
|
||||
}
|
@ -7,6 +7,10 @@
|
||||
#include "ArduinoLog.h"
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp_gui.h"
|
||||
#include "hasp_hal.h"
|
||||
#include "hasp_tft.h"
|
||||
#include "hasp_config.h"
|
||||
#include "hasp.h"
|
||||
#include "tasmotaSlave.h"
|
||||
|
||||
// set RX and TX pins
|
||||
@ -62,54 +66,63 @@ void slave_send_input(uint8_t id, const char * payload)
|
||||
Log.notice(F("TAS PUB: %sstate/input%u = %s"), slaveNodeTopic, id, payload);
|
||||
}
|
||||
|
||||
// void slave_send_statusupdate()
|
||||
// { // Periodically publish a JSON string indicating system status
|
||||
// char data[3 * 128];
|
||||
// {
|
||||
// char buffer[128];
|
||||
// snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
// haspGetVersion().c_str(), long(millis() / 1000));
|
||||
// strcat(buffer, data);
|
||||
// snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
// ESP.getFreeHeap(), halGetHeapFragmentation(), halGetCoreVersion().c_str());
|
||||
// strcat(data, buffer);
|
||||
// snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u}"),
|
||||
// haspGetPage(), (HASP_NUM_PAGES));
|
||||
// strcat(data, buffer);
|
||||
// snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
// tftDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
// strcat(data, buffer);
|
||||
// }
|
||||
// slave_send_state(F("statusupdate"), data);
|
||||
// debugLastMillis = millis();
|
||||
// }
|
||||
void TASMO_TELE_JSON()
|
||||
{ // Periodically publish a JSON string indicating system status
|
||||
char data[3 * 128];
|
||||
{
|
||||
char buffer[128];
|
||||
snprintf_P(data, sizeof(data), PSTR("{\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
haspGetVersion().c_str(), long(millis() / 1000));
|
||||
strcat(buffer, data);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espCanUpdate\":\"false\",\"page\":%u,\"numPages\":%u,"),
|
||||
haspGetPage(), (HASP_NUM_PAGES));
|
||||
strcat(data, buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
tftDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
strcat(data, buffer);
|
||||
}
|
||||
slave.sendJSON((char*)data);
|
||||
// slave_send_state(F("statusupdate"), data);
|
||||
// debugLastMillis = millis();
|
||||
}
|
||||
|
||||
void TASMO_DATA_RECEIVE(char *data)
|
||||
{
|
||||
Log.verbose(F("TAS: Slave IN [%s]"), data);
|
||||
|
||||
char slvCmd[20],slvVal[60];
|
||||
memset(slvCmd, 0 ,sizeof(slvCmd));
|
||||
memset(slvVal, 0 ,sizeof(slvVal));
|
||||
sscanf(data,"%s %s", slvCmd, slvVal);
|
||||
char dataType[3];
|
||||
memset(dataType, 0 ,sizeof(dataType));
|
||||
snprintf_P(dataType, sizeof(dataType), data);
|
||||
Log.verbose(F("TAS: dataType [%s]"), dataType);
|
||||
|
||||
Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal);
|
||||
|
||||
if (!strcmp(slvCmd, "calData")){
|
||||
if (strlen(slvVal) != 0) {
|
||||
char cBuffer[strlen(slvVal) + 24];
|
||||
memset(cBuffer, 0 ,sizeof(cBuffer));
|
||||
snprintf_P(cBuffer, sizeof(cBuffer), PSTR("{'calibration':[%s]}"), slvVal);
|
||||
dispatchConfig("gui",cBuffer);
|
||||
} else {
|
||||
dispatchConfig("gui","");
|
||||
}
|
||||
} else if (!strcmp(slvCmd, "jsonl")) {
|
||||
dispatchJsonl(slvVal);
|
||||
if (!strcmp(dataType, "p[")){ //
|
||||
dispatchCommand(data);
|
||||
} else if (!strcmp(dataType, "[\"")) {
|
||||
dispatchJson(data);
|
||||
} else {
|
||||
char cBuffer[strlen(data)+1];
|
||||
snprintf_P(cBuffer, sizeof(cBuffer), PSTR("%s=%s"), slvCmd, slvVal);
|
||||
dispatchCommand(cBuffer);
|
||||
char slvCmd[20],slvVal[60];
|
||||
memset(slvCmd, 0 ,sizeof(slvCmd));
|
||||
memset(slvVal, 0 ,sizeof(slvVal));
|
||||
sscanf(data,"%[^=] =%s", slvCmd, slvVal);
|
||||
|
||||
Log.verbose(F("TAS: Cmd[%s] Val[%s]"), slvCmd, slvVal);
|
||||
|
||||
if (!strcmp(slvCmd, "calData")){
|
||||
if (strlen(slvVal) != 0) {
|
||||
char cBuffer[strlen(slvVal) + 24];
|
||||
memset(cBuffer, 0 ,sizeof(cBuffer));
|
||||
snprintf_P(cBuffer, sizeof(cBuffer), PSTR("{'calibration':[%s]}"), slvVal);
|
||||
dispatchConfig("gui",cBuffer);
|
||||
} else {
|
||||
dispatchConfig("gui","");
|
||||
}
|
||||
} else if (!strcmp(slvCmd, "jsonl")) {
|
||||
dispatchJsonl(slvVal);
|
||||
} else if (!strcmp(slvCmd, "clearpage")) {
|
||||
dispatchClearPage(slvVal);
|
||||
} else {
|
||||
dispatchCommand(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,6 +143,7 @@ void slaveSetup()
|
||||
{
|
||||
Serial2.begin(HASP_SLAVE_SPEED);
|
||||
// slave.attach_FUNC_EVERY_SECOND(TASMO_EVERY_SECOND);
|
||||
slave.attach_FUNC_JSON(TASMO_TELE_JSON);
|
||||
slave.attach_FUNC_COMMAND_SEND(TASMO_DATA_RECEIVE);
|
||||
|
||||
Log.notice(F("TAS: HASP SLAVE LOADED"));
|
||||
|
@ -103,10 +103,13 @@ void loop()
|
||||
/* Graphics Loops */
|
||||
// tftLoop();
|
||||
guiLoop();
|
||||
|
||||
/* Application Loops */
|
||||
// haspLoop();
|
||||
|
||||
#if HASP_USE_BUTTON
|
||||
buttonLoop();
|
||||
#endif // BUTTON
|
||||
|
||||
/* Network Services Loops */
|
||||
#if HASP_USE_WIFI
|
||||
|
||||
@ -126,10 +129,6 @@ void loop()
|
||||
mdnsLoop();
|
||||
#endif // MDNS
|
||||
|
||||
#if HASP_USE_BUTTON
|
||||
buttonLoop();
|
||||
#endif // BUTTON
|
||||
|
||||
#if HASP_USE_OTA
|
||||
otaLoop();
|
||||
#endif // OTA
|
||||
|
Loading…
x
Reference in New Issue
Block a user