mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-23 11:16:45 +00:00
Xplatform changes and add settings struct
This commit is contained in:
parent
367458469b
commit
19a1ce5eb0
@ -1,47 +1,59 @@
|
||||
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||
For full license information read the LICENSE file in the project folder */
|
||||
|
||||
#include "ArduinoLog.h"
|
||||
#include <stdint.h>
|
||||
|
||||
//#include "ArduinoLog.h"
|
||||
#include "hasp_conf.h"
|
||||
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp_object.h"
|
||||
#include "hasp.h"
|
||||
#include "hasp_utilities.h"
|
||||
#include "hasp_parser.h"
|
||||
#include "hasp_attribute.h"
|
||||
|
||||
//#include "hasp_gui.h"
|
||||
|
||||
#if HASP_USE_DEBUG > 0
|
||||
#include "StringStream.h"
|
||||
#include "CharStream.h"
|
||||
#include "../hasp_debug.h"
|
||||
|
||||
#include "hasp_debug.h"
|
||||
#include "hasp_gui.h"
|
||||
#include "hasp_oobe.h"
|
||||
#include "hasp_gpio.h"
|
||||
#include "hasp_hal.h"
|
||||
#if WINDOWS
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "../mqtt/hasp_mqtt.h"
|
||||
#else
|
||||
#include "StringStream.h"
|
||||
#include "CharStream.h"
|
||||
|
||||
#include "svc/hasp_ota.h"
|
||||
#include "svc/hasp_mqtt.h"
|
||||
#include "net/hasp_network.h" // for network_get_status()
|
||||
#else
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "hasp_oobe.h"
|
||||
#include "hasp_gui.h" // for screenshot
|
||||
#include "sys/gpio/hasp_gpio.h"
|
||||
#include "hal/hasp_hal.h"
|
||||
|
||||
#include "svc/hasp_ota.h"
|
||||
#include "mqtt/hasp_mqtt.h"
|
||||
#include "sys/net/hasp_network.h" // for network_get_status()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HASP_USE_CONFIG > 0
|
||||
#include "hasp_config.h"
|
||||
#endif
|
||||
|
||||
extern unsigned long debugLastMillis; // UpdateStatus timer
|
||||
extern uint8_t hasp_sleep_state;
|
||||
|
||||
dispatch_conf_t dispatch_setings = {.teleperiod = 300};
|
||||
|
||||
uint32_t dispatchLastMillis;
|
||||
uint8_t nCommands = 0;
|
||||
haspCommand_t commands[17];
|
||||
|
||||
struct moodlight_t
|
||||
{
|
||||
byte power;
|
||||
byte r, g, b;
|
||||
uint8_t power;
|
||||
uint8_t r, g, b;
|
||||
};
|
||||
moodlight_t moodlight;
|
||||
|
||||
@ -599,7 +611,9 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t *
|
||||
{
|
||||
if(groupid > 0) {
|
||||
LOG_VERBOSE(TAG_MSGR, F("GROUP %d value %d"), groupid, value);
|
||||
#if USE_GPIO
|
||||
gpio_set_normalized_group_value(groupid, value);
|
||||
#endif
|
||||
// object_set_group_state(groupid, value, obj);
|
||||
}
|
||||
}
|
||||
@ -627,11 +641,11 @@ void dispatch_parse_json(const char *, const char * payload)
|
||||
|
||||
} else if(json.is<JsonArray>()) { // handle json as an array of commands
|
||||
JsonArray arr = json.as<JsonArray>();
|
||||
guiStop();
|
||||
// guiStop();
|
||||
for(JsonVariant command : arr) {
|
||||
dispatch_text_line(command.as<String>().c_str());
|
||||
dispatch_text_line(command.as<const char *>());
|
||||
}
|
||||
guiStart();
|
||||
// guiStart();
|
||||
} else if(json.is<JsonObject>()) { // handle json as a jsonl
|
||||
uint8_t savedPage = haspGetPage();
|
||||
hasp_new_object(json.as<JsonObject>(), savedPage);
|
||||
@ -642,15 +656,15 @@ void dispatch_parse_json(const char *, const char * payload)
|
||||
} else if(json.is<char *>()) { // handle json as a single command
|
||||
dispatch_text_line(json.as<char *>());
|
||||
|
||||
} else if(json.is<String>()) { // handle json as a single command
|
||||
dispatch_text_line(json.as<String>().c_str());
|
||||
// } else if(json.is<String>()) { // handle json as a single command
|
||||
// dispatch_text_line(json.as<String>().c_str());
|
||||
|
||||
} else {
|
||||
LOG_WARNING(TAG_MSGR, F(D_DISPATCH_COMMAND_NOT_FOUND), payload);
|
||||
}
|
||||
}
|
||||
|
||||
#if HASP_USE_CONFIG > 0
|
||||
#ifdef ARDUINO
|
||||
void dispatch_parse_jsonl(Stream & stream)
|
||||
#else
|
||||
void dispatch_parse_jsonl(std::istringstream & stream)
|
||||
@ -660,7 +674,10 @@ void dispatch_parse_jsonl(std::istringstream & stream)
|
||||
size_t line = 1;
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128); // max ~256 characters per line
|
||||
DeserializationError jsonError = deserializeJson(jsonl, stream);
|
||||
|
||||
#ifdef ARDUINO
|
||||
stream.setTimeout(25);
|
||||
#endif
|
||||
|
||||
// guiStop();
|
||||
while(jsonError == DeserializationError::Ok) {
|
||||
@ -703,7 +720,7 @@ void dispatch_output_current_page()
|
||||
void dispatch_page(const char *, const char * page)
|
||||
{
|
||||
if(strlen(page) > 0) {
|
||||
if(hasp_util_is_only_digits(page)) {
|
||||
if(Utilities::is_only_digits(page)) {
|
||||
uint8_t pageid = atoi(page);
|
||||
haspSetPage(pageid);
|
||||
} else {
|
||||
@ -781,7 +798,7 @@ void dispatch_moodlight(const char * topic, const char * payload)
|
||||
dispatch_json_error(TAG_MSGR, jsonError);
|
||||
} else {
|
||||
|
||||
if(!json[F("power")].isNull()) moodlight.power = hasp_util_is_true(json[F("power")].as<String>().c_str());
|
||||
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("g")].isNull()) moodlight.r = json[F("g")].as<uint8_t>();
|
||||
@ -789,17 +806,19 @@ void dispatch_moodlight(const char * topic, const char * payload)
|
||||
|
||||
if(!json[F("color")].isNull()) {
|
||||
lv_color32_t color;
|
||||
if(haspPayloadToColor(json[F("color")].as<String>().c_str(), color)) {
|
||||
if(Parser::haspPayloadToColor(json[F("color")].as<const char *>(), color)) {
|
||||
moodlight.r = color.ch.red;
|
||||
moodlight.g = color.ch.green;
|
||||
moodlight.b = color.ch.blue;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_GPIO
|
||||
if(moodlight.power)
|
||||
gpio_set_moodlight(moodlight.r, moodlight.g, moodlight.b);
|
||||
else
|
||||
gpio_set_moodlight(0, 0, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -814,7 +833,7 @@ void dispatch_moodlight(const char * topic, const char * payload)
|
||||
void dispatch_backlight(const char *, const char * payload)
|
||||
{
|
||||
// Set the current state
|
||||
if(strlen(payload) != 0) guiSetBacklight(hasp_util_is_true(payload));
|
||||
if(strlen(payload) != 0) guiSetBacklight(Utilities::is_true(payload));
|
||||
|
||||
// Return the current state
|
||||
char buffer[4];
|
||||
@ -834,9 +853,9 @@ void dispatch_web_update(const char *, const char * espOtaUrl)
|
||||
void dispatch_reboot(bool saveConfig)
|
||||
{
|
||||
#if HASP_USE_CONFIG > 0
|
||||
if(saveConfig) configWriteConfig();
|
||||
if(saveConfig) configWrite();
|
||||
#endif
|
||||
#if HASP_USE_MQTT > 0
|
||||
#if HASP_USE_MQTT > 0 && defined(ARDUINO)
|
||||
mqttStop(); // Stop the MQTT Client first
|
||||
#endif
|
||||
#if HASP_USE_CONFIG > 0
|
||||
@ -847,7 +866,13 @@ void dispatch_reboot(bool saveConfig)
|
||||
#endif
|
||||
LOG_VERBOSE(TAG_MSGR, F("-------------------------------------"));
|
||||
LOG_TRACE(TAG_MSGR, F(D_DISPATCH_REBOOT));
|
||||
|
||||
#if WINDOWS
|
||||
fflush(stdout);
|
||||
#else
|
||||
Serial.flush();
|
||||
#endif
|
||||
|
||||
halRestartMcu();
|
||||
}
|
||||
|
||||
@ -869,33 +894,34 @@ void dispatch_output_statusupdate(const char *, const char *)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
haspGetVersion(buffer, sizeof(buffer));
|
||||
snprintf_P(data, sizeof(data),
|
||||
PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
mqttGetNodename().c_str(), buffer, long(millis() / 1000));
|
||||
/* haspGetVersion(buffer, sizeof(buffer));
|
||||
snprintf_P(data, sizeof(data),
|
||||
PSTR("{\"node\":\"%s\",\"status\":\"available\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||
mqttGetNodename().c_str(), buffer, long(millis() / 1000));
|
||||
|
||||
#if HASP_USE_WIFI > 0
|
||||
network_get_statusupdate(buffer, sizeof(buffer));
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
halGetFreeHeap(), 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);
|
||||
#if HASP_USE_WIFI > 0
|
||||
network_get_statusupdate(buffer, sizeof(buffer));
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"heapFree\":%u,\"heapFrag\":%u,\"espCore\":\"%s\","),
|
||||
halGetFreeHeap(), 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);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000);
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"espVcc\":%.2f,"), (float)ESP.getVcc() / 1000);
|
||||
strcat(data, buffer);
|
||||
#endif
|
||||
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
strcat(data, buffer);
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("\"tftDriver\":\"%s\",\"tftWidth\":%u,\"tftHeight\":%u}"),
|
||||
halDisplayDriverName().c_str(), (TFT_WIDTH), (TFT_HEIGHT));
|
||||
strcat(data, buffer);
|
||||
*/
|
||||
}
|
||||
mqtt_send_state(F("statusupdate"), data);
|
||||
debugLastMillis = millis();
|
||||
dispatchLastMillis = millis();
|
||||
|
||||
/* if(updateEspAvailable) {
|
||||
mqttStatusPayload += F("\"updateEspAvailable\":true,");
|
||||
@ -976,3 +1002,28 @@ void dispatchLoop()
|
||||
{
|
||||
// Not used
|
||||
}
|
||||
|
||||
#if 1 || ARDUINO
|
||||
void everySecond()
|
||||
{
|
||||
if(dispatch_setings.teleperiod > 0 && (millis() - dispatchLastMillis) >= dispatch_setings.teleperiod * 1000) {
|
||||
dispatchLastMillis = millis();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#include <chrono>
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
void everySecond()
|
||||
{
|
||||
if(dispatch_setings.teleperiod > 0) {
|
||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
||||
std::chrono::seconds elapsed = std::chrono::duration_cast<std::chrono::seconds>(end - begin);
|
||||
|
||||
if(elapsed.count() >= dispatch_setings.teleperiod) {
|
||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||
dispatch_output_statusupdate(NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -7,6 +7,10 @@
|
||||
#include "ArduinoJson.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
struct dispatch_conf_t {
|
||||
uint16_t teleperiod;
|
||||
};
|
||||
|
||||
enum hasp_event_t { // even = released, odd = pressed
|
||||
HASP_EVENT_OFF = 0,
|
||||
HASP_EVENT_ON = 1,
|
||||
@ -30,7 +34,13 @@ void dispatchStop(void);
|
||||
/* ===== Special Event Processors ===== */
|
||||
void dispatch_topic_payload(const char * topic, const char * payload);
|
||||
void dispatch_text_line(const char * cmnd);
|
||||
void dispatch_parse_jsonl(Stream & stream);
|
||||
|
||||
#ifdef ARDUINO
|
||||
void dispatch_parse_jsonl(Stream &stream);
|
||||
#else
|
||||
void dispatch_parse_jsonl(std::istringstream &stream);
|
||||
#endif
|
||||
|
||||
void dispatch_clear_page(const char * page);
|
||||
void dispatch_json_error(uint8_t tag, DeserializationError & jsonError);
|
||||
|
||||
|
117
src/hasp_gui.cpp
117
src/hasp_gui.cpp
@ -51,14 +51,21 @@ File pFileOut;
|
||||
|
||||
// static void IRAM_ATTR lv_tick_handler(void);
|
||||
|
||||
static bool guiShowPointer = false;
|
||||
static bool guiBacklightIsOn = true;
|
||||
static int8_t guiDimLevel = -1;
|
||||
static int8_t guiBacklightPin = TFT_BCKL;
|
||||
static uint8_t guiTickPeriod = 20;
|
||||
static uint8_t guiRotation = TFT_ROTATION;
|
||||
static uint8_t guiInvertDisplay = INVERT_COLORS;
|
||||
static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
|
||||
// static bool guiShowPointer = false;
|
||||
// static int8_t guiBacklightPin = TFT_BCKL;
|
||||
// static uint8_t guiTickPeriod = 20;
|
||||
// static uint8_t guiRotation = TFT_ROTATION;
|
||||
// static uint8_t guiInvertDisplay = INVERT_COLORS;
|
||||
// static uint16_t calData[5] = {0, 65535, 0, 65535, 0};
|
||||
|
||||
gui_conf_t gui_settings = {.show_pointer = false,
|
||||
.backlight_pin =TFT_BCKL,
|
||||
.rotation = TFT_ROTATION,
|
||||
.invert_display = INVERT_COLORS,
|
||||
.cal_data = {0, 65535, 0, 65535, 0}};
|
||||
|
||||
static int8_t guiDimLevel = 100;
|
||||
bool guiBacklightIsOn;
|
||||
|
||||
// #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
// static Ticker tick; /* timer for interrupt handler */
|
||||
@ -197,7 +204,7 @@ boolean Touch_getXY(uint16_t * x, uint16_t * y, boolean showTouch)
|
||||
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
|
||||
if(pressed) {
|
||||
|
||||
switch(guiRotation) {
|
||||
switch(gui_settings.rotation) {
|
||||
case 0: // portrait
|
||||
*x = map(p.x, coords[0], coords[1], 0, tft.width());
|
||||
*y = map(p.y, coords[2], coords[3], 0, tft.height());
|
||||
@ -225,11 +232,11 @@ void guiCalibrate()
|
||||
{
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0
|
||||
#ifdef TOUCH_CS
|
||||
tft_espi_calibrate(calData);
|
||||
tft_espi_calibrate(gui_settings.cal_data);
|
||||
#endif
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
Serial.print(calData[i]);
|
||||
Serial.print(gui_settings.cal_data[i]);
|
||||
if(i < 4) Serial.print(", ");
|
||||
}
|
||||
|
||||
@ -308,17 +315,17 @@ void guiSetup()
|
||||
#endif
|
||||
|
||||
/* Setup Backlight Control Pin */
|
||||
if(guiBacklightPin >= 0) {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), guiBacklightPin);
|
||||
if(gui_settings.backlight_pin >= 0) {
|
||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), gui_settings.backlight_pin);
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||
ledcAttachPin(guiBacklightPin, BACKLIGHT_CHANNEL);
|
||||
ledcAttachPin(gui_settings.backlight_pin, BACKLIGHT_CHANNEL);
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
pinMode(guiBacklightPin, OUTPUT);
|
||||
pinMode(gui_settings.backlight_pin, OUTPUT);
|
||||
#endif
|
||||
}
|
||||
LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), guiRotation);
|
||||
LOG_VERBOSE(TAG_GUI, F("Rotation : %d"), gui_settings.rotation);
|
||||
|
||||
LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
|
||||
PSTR(LVGL_VERSION_INFO));
|
||||
@ -336,10 +343,12 @@ void guiSetup()
|
||||
/* Initialize the display driver */
|
||||
lv_disp_drv_t disp_drv;
|
||||
lv_disp_drv_init(&disp_drv);
|
||||
drv_display_init(&disp_drv, guiRotation, guiInvertDisplay); // Set display driver callback & rotation
|
||||
drv_display_init(&disp_drv, gui_settings.rotation,
|
||||
gui_settings.invert_display); // Set display driver callback & rotation
|
||||
disp_drv.buffer = &disp_buf;
|
||||
|
||||
if(guiRotation == 0 || guiRotation == 2 || guiRotation == 4 || guiRotation == 6) {
|
||||
if(gui_settings.rotation == 0 || gui_settings.rotation == 2 || gui_settings.rotation == 4 ||
|
||||
gui_settings.rotation == 6) {
|
||||
/* 1/3=Landscape or 0/2=Portrait orientation */
|
||||
// Normal width & height
|
||||
disp_drv.hor_res = TFT_WIDTH;
|
||||
@ -376,7 +385,7 @@ void guiSetup()
|
||||
mouse_indev->driver.type = LV_INDEV_TYPE_POINTER;
|
||||
|
||||
/*Set a cursor for the mouse*/
|
||||
if(guiShowPointer) {
|
||||
if(gui_settings.show_pointer) {
|
||||
// lv_obj_t * label = lv_label_create(lv_layer_sys(), NULL);
|
||||
// lv_label_set_text(label, "<");
|
||||
// lv_indev_set_cursor(mouse_indev, label); // connect the object to the driver
|
||||
@ -398,7 +407,7 @@ void guiSetup()
|
||||
#endif
|
||||
lv_indev_set_cursor(mouse_indev, cursor); /*Connect the image object to the driver*/
|
||||
}
|
||||
drv_touch_init(guiRotation); // Touch driver
|
||||
drv_touch_init(gui_settings.rotation); // Touch driver
|
||||
|
||||
// guiStart(); // Ticker
|
||||
}
|
||||
@ -448,14 +457,14 @@ void guiSetBacklight(bool lighton)
|
||||
{
|
||||
guiBacklightIsOn = lighton;
|
||||
|
||||
if(!lighton) hasp_enable_wakeup_touch();
|
||||
if(!lighton) hasp_enable_wakeup_touch();
|
||||
|
||||
if(guiBacklightPin >= 0) {
|
||||
if(gui_settings.backlight_pin >= 0) {
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWrite(BACKLIGHT_CHANNEL, lighton ? map(guiDimLevel, 0, 100, 0, 4095) : 0); // ledChannel and value
|
||||
#else
|
||||
analogWrite(guiBacklightPin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0);
|
||||
analogWrite(gui_settings.backlight_pin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
@ -465,7 +474,7 @@ if(!lighton) hasp_enable_wakeup_touch();
|
||||
|
||||
void guiSetDim(int8_t level)
|
||||
{
|
||||
if(guiBacklightPin >= 0) {
|
||||
if(gui_settings.backlight_pin >= 0) {
|
||||
guiDimLevel = level >= 0 ? level : 0;
|
||||
guiDimLevel = guiDimLevel <= 100 ? guiDimLevel : 100;
|
||||
|
||||
@ -473,7 +482,7 @@ void guiSetDim(int8_t level)
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWrite(BACKLIGHT_CHANNEL, map(guiDimLevel, 0, 100, 0, 4095)); // ledChannel and value
|
||||
#else
|
||||
analogWrite(guiBacklightPin, map(guiDimLevel, 0, 100, 0, 1023));
|
||||
analogWrite(gui_settings.backlight_pin, map(guiDimLevel, 0, 100, 0, 1023));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -496,8 +505,8 @@ bool guiGetConfig(const JsonObject & settings)
|
||||
uint16_t guiSleepTime2;
|
||||
hasp_get_sleep_time(guiSleepTime1, guiSleepTime2);
|
||||
|
||||
if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod;
|
||||
// if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as<uint8_t>()) changed = true;
|
||||
// settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod;
|
||||
|
||||
if(guiSleepTime1 != settings[FPSTR(FP_GUI_IDLEPERIOD1)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_IDLEPERIOD1)] = guiSleepTime1;
|
||||
@ -505,31 +514,31 @@ bool guiGetConfig(const JsonObject & settings)
|
||||
if(guiSleepTime2 != settings[FPSTR(FP_GUI_IDLEPERIOD2)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_IDLEPERIOD2)] = guiSleepTime2;
|
||||
|
||||
if(guiBacklightPin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = guiBacklightPin;
|
||||
if(gui_settings.backlight_pin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = gui_settings.backlight_pin;
|
||||
|
||||
if(guiRotation != settings[FPSTR(FP_GUI_ROTATION)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_ROTATION)] = guiRotation;
|
||||
if(gui_settings.rotation != settings[FPSTR(FP_GUI_ROTATION)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_ROTATION)] = gui_settings.rotation;
|
||||
|
||||
if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_POINTER)] = guiShowPointer;
|
||||
if(gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_POINTER)] = gui_settings.show_pointer;
|
||||
|
||||
if(guiInvertDisplay != settings[FPSTR(FP_GUI_INVERT)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_INVERT)] = guiInvertDisplay;
|
||||
if(gui_settings.invert_display != settings[FPSTR(FP_GUI_INVERT)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_INVERT)] = gui_settings.invert_display;
|
||||
|
||||
/* Check CalData array has changed */
|
||||
JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as<JsonArray>();
|
||||
uint8_t i = 0;
|
||||
for(JsonVariant v : array) {
|
||||
LOG_VERBOSE(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as<uint16_t>());
|
||||
LOG_VERBOSE(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, gui_settings.cal_data[i], v.as<uint16_t>());
|
||||
if(i < 5) {
|
||||
if(calData[i] != v.as<uint16_t>()) changed = true;
|
||||
v.set(calData[i]);
|
||||
if(gui_settings.cal_data[i] != v.as<uint16_t>()) changed = true;
|
||||
v.set(gui_settings.cal_data[i]);
|
||||
} else {
|
||||
changed = true;
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
tft_espi_set_touch(calData);
|
||||
tft_espi_set_touch(gui_settings.cal_data);
|
||||
#endif
|
||||
}
|
||||
i++;
|
||||
@ -539,12 +548,12 @@ bool guiGetConfig(const JsonObject & settings)
|
||||
if(i != 5) {
|
||||
array = settings[FPSTR(FP_GUI_CALIBRATION)].to<JsonArray>(); // Clear JsonArray
|
||||
for(int i = 0; i < 5; i++) {
|
||||
array.add(calData[i]);
|
||||
array.add(gui_settings.cal_data[i]);
|
||||
}
|
||||
changed = true;
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
tft_espi_set_touch(calData);
|
||||
tft_espi_set_touch(gui_settings.cal_data);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -569,22 +578,22 @@ bool guiSetConfig(const JsonObject & settings)
|
||||
|
||||
hasp_get_sleep_time(guiSleepTime1, guiSleepTime2);
|
||||
|
||||
changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod"));
|
||||
changed |= configSet(guiBacklightPin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
|
||||
// changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod"));
|
||||
changed |= configSet(gui_settings.backlight_pin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
|
||||
changed |= configSet(guiSleepTime1, settings[FPSTR(FP_GUI_IDLEPERIOD1)], F("guiSleepTime1"));
|
||||
changed |= configSet(guiSleepTime2, settings[FPSTR(FP_GUI_IDLEPERIOD2)], F("guiSleepTime2"));
|
||||
changed |= configSet(guiRotation, settings[FPSTR(FP_GUI_ROTATION)], F("guiRotation"));
|
||||
changed |= configSet(guiInvertDisplay, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay"));
|
||||
changed |= configSet(gui_settings.rotation, settings[FPSTR(FP_GUI_ROTATION)], F("gui_settings.rotation"));
|
||||
changed |= configSet(gui_settings.invert_display, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay"));
|
||||
|
||||
hasp_set_sleep_time(guiSleepTime1, guiSleepTime2);
|
||||
|
||||
if(!settings[FPSTR(FP_GUI_POINTER)].isNull()) {
|
||||
if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) {
|
||||
if(gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) {
|
||||
LOG_VERBOSE(TAG_GUI, F("guiShowPointer set"));
|
||||
}
|
||||
changed |= guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
changed |= gui_settings.show_pointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
|
||||
guiShowPointer = settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
gui_settings.show_pointer = settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
}
|
||||
|
||||
if(!settings[FPSTR(FP_GUI_CALIBRATION)].isNull()) {
|
||||
@ -594,15 +603,15 @@ bool guiSetConfig(const JsonObject & settings)
|
||||
JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as<JsonArray>();
|
||||
for(JsonVariant v : array) {
|
||||
if(i < 5) {
|
||||
if(calData[i] != v.as<uint16_t>()) status = true;
|
||||
calData[i] = v.as<uint16_t>();
|
||||
if(gui_settings.cal_data[i] != v.as<uint16_t>()) status = true;
|
||||
gui_settings.cal_data[i] = v.as<uint16_t>();
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if(calData[0] != 0 || calData[1] != 65535 || calData[2] != 0 || calData[3] != 65535) {
|
||||
LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), calData[0], calData[1], calData[2], calData[3],
|
||||
calData[4]);
|
||||
if(gui_settings.cal_data[0] != 0 || gui_settings.cal_data[1] != 65535 || gui_settings.cal_data[2] != 0 || gui_settings.cal_data[3] != 65535) {
|
||||
LOG_VERBOSE(TAG_GUI, F("calData set [%u, %u, %u, %u, %u]"), gui_settings.cal_data[0], gui_settings.cal_data[1], gui_settings.cal_data[2], gui_settings.cal_data[3],
|
||||
gui_settings.cal_data[4]);
|
||||
oobeSetAutoCalibrate(false);
|
||||
} else {
|
||||
LOG_TRACE(TAG_GUI, F("First Touch Calibration enabled"));
|
||||
@ -610,7 +619,7 @@ bool guiSetConfig(const JsonObject & settings)
|
||||
}
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && USE_TFT_ESPI > 0 && defined(TOUCH_CS)
|
||||
if(status) tft_espi_set_touch(calData);
|
||||
if(status) tft_espi_set_touch(gui_settings.cal_data);
|
||||
#endif
|
||||
changed |= status;
|
||||
}
|
||||
|
@ -7,6 +7,15 @@
|
||||
#include "ArduinoJson.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
struct gui_conf_t
|
||||
{
|
||||
bool show_pointer;
|
||||
int8_t backlight_pin;
|
||||
uint8_t rotation;
|
||||
uint8_t invert_display;
|
||||
uint16_t cal_data[5];
|
||||
};
|
||||
|
||||
/* ===== Default Event Processors ===== */
|
||||
void guiSetup();
|
||||
void guiLoop(void);
|
||||
@ -21,7 +30,7 @@ void guiTakeScreenshot(); // webclient
|
||||
|
||||
/* ===== Getter and Setter Functions ===== */
|
||||
void guiSetDim(int8_t level);
|
||||
int8_t guiGetDim(void);
|
||||
int8_t guiGetDim();
|
||||
void guiSetBacklight(bool lighton);
|
||||
bool guiGetBacklight();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user