mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Get and Set gpio config
This commit is contained in:
parent
7e3f06b76e
commit
a5d24eae46
@ -9,6 +9,7 @@
|
||||
#include "hasp_ota.h"
|
||||
#include "hasp_spiffs.h"
|
||||
#include "hasp_telnet.h"
|
||||
#include "hasp_gpio.h"
|
||||
//#include "hasp_eeprom.h"
|
||||
#include "hasp.h"
|
||||
|
||||
@ -242,6 +243,15 @@ void configWriteConfig()
|
||||
writefile = true;
|
||||
}
|
||||
#endif
|
||||
#if HASP_USE_GPIO > 0
|
||||
if(settings[F("gpio")].as<JsonObject>().isNull()) settings.createNestedObject(F("gpio"));
|
||||
changed = gpioGetConfig(settings[F("gpio")]);
|
||||
if(changed) {
|
||||
Log.verbose(F("GPIO: Settings changed"));
|
||||
configOutput(settings[F("gpio")]);
|
||||
writefile = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(settings[F("debug")].as<JsonObject>().isNull()) settings.createNestedObject(F("debug"));
|
||||
changed = debugGetConfig(settings[F("debug")]);
|
||||
@ -367,6 +377,10 @@ void configSetup()
|
||||
#if HASP_USE_HTTP > 0
|
||||
Log.verbose(F("Loading HTTP settings"));
|
||||
httpSetConfig(settings[F("http")]);
|
||||
#endif
|
||||
#if HASP_USE_GPIO > 0
|
||||
Log.verbose(F("Loading GPIO settings"));
|
||||
gpioSetConfig(settings[F("gpio")]);
|
||||
#endif
|
||||
// }
|
||||
Log.notice(F("User configuration loaded"));
|
||||
@ -386,11 +400,36 @@ void configOutput(const JsonObject & settings)
|
||||
|
||||
String password((char *)0);
|
||||
password.reserve(128);
|
||||
password = F("\"pass\":\"");
|
||||
password += settings[F("pass")].as<String>();
|
||||
password += F("\"");
|
||||
|
||||
if(password.length() > 2) output.replace(password, passmask);
|
||||
String pass = F("pass");
|
||||
if(!settings[pass].isNull()) {
|
||||
password = F("\"pass\":\"");
|
||||
password += settings[pass].as<String>();
|
||||
password += F("\"");
|
||||
output.replace(password, passmask);
|
||||
}
|
||||
|
||||
if(!settings[F("wifi")][pass].isNull()) {
|
||||
password = F("\"pass\":\"");
|
||||
password += settings[F("wifi")][pass].as<String>();
|
||||
password += F("\"");
|
||||
output.replace(password, passmask);
|
||||
}
|
||||
|
||||
if(!settings[F("mqtt")][pass].isNull()) {
|
||||
password = F("\"pass\":\"");
|
||||
password += settings[F("mqtt")][pass].as<String>();
|
||||
password += F("\"");
|
||||
output.replace(password, passmask);
|
||||
}
|
||||
|
||||
if(!settings[F("http")][pass].isNull()) {
|
||||
password = F("\"pass\":\"");
|
||||
password += settings[F("http")][pass].as<String>();
|
||||
password += F("\"");
|
||||
output.replace(password, passmask);
|
||||
}
|
||||
|
||||
Log.trace(F("CONF: %s"), output.c_str());
|
||||
}
|
||||
|
||||
@ -399,7 +438,7 @@ bool configClear()
|
||||
#if defined(STM32F4xx)
|
||||
Log.verbose(F("CONF: Clearing EEPROM"));
|
||||
char buffer[1024 + 128];
|
||||
memset(buffer, 1 ,sizeof(buffer));
|
||||
memset(buffer, 1, sizeof(buffer));
|
||||
if(sizeof(buffer) > 0) {
|
||||
uint16_t i;
|
||||
for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]);
|
||||
|
@ -29,6 +29,7 @@ const char F_GUI_CALIBRATION[] PROGMEM = "calibration";
|
||||
const char F_GUI_BACKLIGHTPIN[] PROGMEM = "bcklpin";
|
||||
const char F_GUI_POINTER[] PROGMEM = "pointer";
|
||||
const char F_DEBUG_TELEPERIOD[] PROGMEM = "teleperiod";
|
||||
const char F_GPIO_CONFIG[] PROGMEM = "config";
|
||||
|
||||
const char HASP_CONFIG_FILE[] PROGMEM = "/config.json";
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "hasp_conf.h"
|
||||
#include "hasp_gpio.h"
|
||||
#include "hasp_config.h"
|
||||
#include "hasp_dispatch.h"
|
||||
#include "hasp.h"
|
||||
|
||||
@ -191,8 +192,8 @@ void gpioSetup()
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// gpioConfig[0] = {D2, 0, HASP_GPIO_SWITCH, INPUT};
|
||||
// gpioConfig[1] = {D1, 1, HASP_GPIO_RELAY, OUTPUT};
|
||||
gpioConfig[0] = {D2, 0, HASP_GPIO_SWITCH, INPUT};
|
||||
gpioConfig[1] = {D1, 1, HASP_GPIO_RELAY, OUTPUT};
|
||||
|
||||
// gpioAddButton(D2, INPUT, HIGH, 1);
|
||||
// pinMode(D1, OUTPUT);
|
||||
@ -293,3 +294,79 @@ void gpio_set_group_outputs(uint8_t groupid, uint8_t eventid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
bool gpioGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
/* Check Gpio array has changed */
|
||||
JsonArray array = settings[FPSTR(F_GPIO_CONFIG)].as<JsonArray>();
|
||||
uint8_t i = 0;
|
||||
for(JsonVariant v : array) {
|
||||
if(i < HASP_NUM_GPIO_CONFIG) {
|
||||
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
|
||||
(gpioConfig[i].gpio_function << 24);
|
||||
Log.verbose(F("GPIO CONF: %d: %d <=> %d"), i, cur_val, v.as<uint32_t>());
|
||||
|
||||
if(cur_val != v.as<uint32_t>()) changed = true;
|
||||
v.set(cur_val);
|
||||
} else {
|
||||
changed = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Build new Gpio array if the count is not correct */
|
||||
if(i != HASP_NUM_GPIO_CONFIG) {
|
||||
array = settings[FPSTR(F_GPIO_CONFIG)].to<JsonArray>(); // Clear JsonArray
|
||||
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
|
||||
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
|
||||
(gpioConfig[i].gpio_function << 24);
|
||||
array.add(cur_val);
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(changed) configOutput(settings);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** Set GPIO Configuration.
|
||||
*
|
||||
* Read the settings from json and sets the application variables.
|
||||
*
|
||||
* @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements.
|
||||
*
|
||||
* @param[in] settings JsonObject with the config settings.
|
||||
**/
|
||||
bool gpioSetConfig(const JsonObject & settings)
|
||||
{
|
||||
configOutput(settings);
|
||||
bool changed = false;
|
||||
|
||||
if(!settings[FPSTR(F_GPIO_CONFIG)].isNull()) {
|
||||
bool status = false;
|
||||
int i = 0;
|
||||
|
||||
JsonArray array = settings[FPSTR(F_GPIO_CONFIG)].as<JsonArray>();
|
||||
for(JsonVariant v : array) {
|
||||
uint32_t new_val = v.as<uint32_t>();
|
||||
|
||||
if(i < HASP_NUM_GPIO_CONFIG) {
|
||||
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
|
||||
(gpioConfig[i].gpio_function << 24);
|
||||
if(cur_val != new_val) status = true;
|
||||
|
||||
gpioConfig[i].pin = new_val & 0xFF;
|
||||
gpioConfig[i].group = new_val >> 8 & 0xFF;
|
||||
gpioConfig[i].type = new_val >> 16 & 0xFF;
|
||||
gpioConfig[i].gpio_function = new_val >> 24 & 0xFF;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
changed |= status;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ void gpioSetup(void);
|
||||
void IRAM_ATTR gpioLoop(void);
|
||||
void gpio_set_group_outputs(uint8_t groupid, uint8_t eventid);
|
||||
|
||||
bool gpioGetConfig(const JsonObject & settings);
|
||||
bool gpioSetConfig(const JsonObject & settings);
|
||||
|
||||
#define HASP_GPIO_FREE 0x00
|
||||
#define HASP_GPIO_USED 0x01
|
||||
#define HASP_GPIO_SWITCH 0x02
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HASP_GUI_H
|
||||
#define HASP_GUI_H
|
||||
|
||||
#include "TFT_eSPI.h"
|
||||
//#include "TFT_eSPI.h"
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user