2017-02-19 16:49:17 +00:00
|
|
|
/*
|
2017-05-13 12:02:10 +01:00
|
|
|
settings.ino - user settings for Sonoff-Tasmota
|
|
|
|
|
2019-01-01 12:55:01 +00:00
|
|
|
Copyright (C) 2019 Theo Arends
|
2017-05-13 12:02:10 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-19 16:49:17 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-30 12:32:53 +01:00
|
|
|
#ifndef DOMOTICZ_UPDATE_TIMER
|
2019-04-09 12:56:19 +01:00
|
|
|
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional)
|
2017-12-28 12:43:51 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EMULATION
|
2019-04-09 12:56:19 +01:00
|
|
|
#define EMULATION EMUL_NONE // [Emulation] Select Belkin WeMo (single relay/light) or Hue Bridge emulation (multi relay/light) (EMUL_NONE, EMUL_WEMO or EMUL_HUE)
|
2017-09-30 12:32:53 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-09 12:56:19 +01:00
|
|
|
#ifndef MTX_ADDRESS1 // Add Display Support for up to eigth Matrices
|
|
|
|
#define MTX_ADDRESS1 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS2
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS2 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS3
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS3 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS4
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS4 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS5
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS5 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS6
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS6 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS7
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS7 0
|
2018-01-07 14:15:01 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MTX_ADDRESS8
|
2019-04-09 12:56:19 +01:00
|
|
|
#define MTX_ADDRESS8 0
|
2018-01-07 13:56:23 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-17 13:09:39 +00:00
|
|
|
#ifndef HOME_ASSISTANT_DISCOVERY_ENABLE
|
|
|
|
#define HOME_ASSISTANT_DISCOVERY_ENABLE 0
|
|
|
|
#endif
|
|
|
|
|
2018-04-05 11:49:43 +01:00
|
|
|
#ifndef LATITUDE
|
2019-04-09 12:56:19 +01:00
|
|
|
#define LATITUDE 48.858360 // [Latitude] Your location to be used with sunrise and sunset
|
2018-04-05 11:49:43 +01:00
|
|
|
#endif
|
|
|
|
#ifndef LONGITUDE
|
2019-04-09 12:56:19 +01:00
|
|
|
#define LONGITUDE 2.294442 // [Longitude] Your location to be used with sunrise and sunset
|
2018-04-05 11:49:43 +01:00
|
|
|
#endif
|
|
|
|
|
2019-03-30 09:02:22 +00:00
|
|
|
#ifndef WORKING_PERIOD
|
2019-04-09 12:56:19 +01:00
|
|
|
#define WORKING_PERIOD 5 // Working period of the SDS Sensor, Takes a reading every X Minutes
|
2019-03-30 09:02:22 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-09 12:56:19 +01:00
|
|
|
#ifndef COLOR_TEXT
|
|
|
|
#define COLOR_TEXT "#000" // Global text color - Black
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BACKGROUND
|
|
|
|
#define COLOR_BACKGROUND "#fff" // Global background color - White
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_FORM
|
|
|
|
#define COLOR_FORM "#f2f2f2" // Form background color - Greyish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_INPUT_TEXT
|
|
|
|
#define COLOR_INPUT_TEXT "#000" // Input text color - Black
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_INPUT
|
|
|
|
#define COLOR_INPUT "#fff" // Input background color - White
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_CONSOLE_TEXT
|
|
|
|
#define COLOR_CONSOLE_TEXT "#000" // Console text color - Black
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_CONSOLE
|
|
|
|
#define COLOR_CONSOLE "#fff" // Console background color - White
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_TEXT_WARNING
|
|
|
|
#define COLOR_TEXT_WARNING "#f00" // Warning text color - Red
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_TEXT_SUCCESS
|
|
|
|
#define COLOR_TEXT_SUCCESS "#008000" // Success text color - Green
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_TEXT
|
|
|
|
#define COLOR_BUTTON_TEXT "#fff" // Button text color - White
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON
|
|
|
|
#define COLOR_BUTTON "#1fa3ec" // Button color - Blueish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_HOVER
|
|
|
|
#define COLOR_BUTTON_HOVER "#0e70a4" // Button color when hovered over - Darker blueish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_RESET
|
|
|
|
#define COLOR_BUTTON_RESET "#d43535" // Restart/Reset/Delete button color - Redish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_RESET_HOVER
|
|
|
|
#define COLOR_BUTTON_RESET_HOVER "#931f1f" // Restart/Reset/Delete button color when hovered over - Darker redish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_SAVE
|
|
|
|
#define COLOR_BUTTON_SAVE "#47c266" // Save button color - Greenish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_BUTTON_SAVE_HOVER
|
|
|
|
#define COLOR_BUTTON_SAVE_HOVER "#5aaf6f" // Save button color when hovered over - Darker greenish
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_TIMER_TAB_TEXT
|
|
|
|
#define COLOR_TIMER_TAB_TEXT "#fff" // Config timer tab text color - White
|
|
|
|
#endif
|
|
|
|
#ifndef COLOR_TIMER_TAB_BACKGROUND
|
|
|
|
#define COLOR_TIMER_TAB_BACKGROUND "#999" // Config timer tab background color - Light grey
|
|
|
|
#endif
|
2019-06-03 08:49:33 +01:00
|
|
|
#ifndef IR_RCV_MIN_UNKNOWN_SIZE
|
|
|
|
#define IR_RCV_MIN_UNKNOWN_SIZE 6 // Set the smallest sized "UNKNOWN" message packets we actually care about (default 6, max 255)
|
|
|
|
#endif
|
2019-07-08 15:50:23 +01:00
|
|
|
#ifndef ENERGY_OVERTEMP
|
|
|
|
#define ENERGY_OVERTEMP 90 // Overtemp in Celsius
|
|
|
|
#endif
|
2019-08-25 22:10:19 +01:00
|
|
|
#ifndef TUYA_DIMMER_MAX
|
|
|
|
#define TUYA_DIMMER_MAX 100
|
|
|
|
#endif
|
2019-08-27 16:01:12 +01:00
|
|
|
#ifndef ENERGY_TARIFF1_HOUR
|
|
|
|
#define ENERGY_TARIFF1_HOUR 23 // Start hour "nighttime" or "off-peak" tariff
|
|
|
|
#endif
|
|
|
|
#ifndef ENERGY_TARIFF2_HOUR
|
|
|
|
#define ENERGY_TARIFF2_HOUR 7 // Start hour "daytime" or "standard" tariff
|
|
|
|
#endif
|
|
|
|
#ifndef ENERGY_TARIFF_WEEKEND
|
|
|
|
#define ENERGY_TARIFF_WEEKEND 1 // 0 = No difference in weekend, 1 = off-peak during weekend
|
|
|
|
#endif
|
2019-04-09 12:56:19 +01:00
|
|
|
|
|
|
|
enum WebColors {
|
|
|
|
COL_TEXT, COL_BACKGROUND, COL_FORM,
|
|
|
|
COL_INPUT_TEXT, COL_INPUT, COL_CONSOLE_TEXT, COL_CONSOLE,
|
|
|
|
COL_TEXT_WARNING, COL_TEXT_SUCCESS,
|
|
|
|
COL_BUTTON_TEXT, COL_BUTTON, COL_BUTTON_HOVER, COL_BUTTON_RESET, COL_BUTTON_RESET_HOVER, COL_BUTTON_SAVE, COL_BUTTON_SAVE_HOVER,
|
|
|
|
COL_TIMER_TAB_TEXT, COL_TIMER_TAB_BACKGROUND,
|
|
|
|
COL_LAST };
|
|
|
|
|
|
|
|
const char kWebColors[] PROGMEM =
|
|
|
|
COLOR_TEXT "|" COLOR_BACKGROUND "|" COLOR_FORM "|"
|
|
|
|
COLOR_INPUT_TEXT "|" COLOR_INPUT "|" COLOR_CONSOLE_TEXT "|" COLOR_CONSOLE "|"
|
|
|
|
COLOR_TEXT_WARNING "|" COLOR_TEXT_SUCCESS "|"
|
|
|
|
COLOR_BUTTON_TEXT "|" COLOR_BUTTON "|" COLOR_BUTTON_HOVER "|" COLOR_BUTTON_RESET "|" COLOR_BUTTON_RESET_HOVER "|" COLOR_BUTTON_SAVE "|" COLOR_BUTTON_SAVE_HOVER "|"
|
|
|
|
COLOR_TIMER_TAB_TEXT "|" COLOR_TIMER_TAB_BACKGROUND;
|
|
|
|
|
2017-02-28 15:01:48 +00:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* RTC memory
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2019-03-31 10:59:04 +01:00
|
|
|
const uint16_t RTC_MEM_VALID = 0xA55A;
|
2017-02-28 15:01:48 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
uint32_t rtc_settings_crc = 0;
|
2017-02-28 15:01:48 +00:00
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint32_t GetRtcSettingsCrc(void)
|
2017-02-28 15:01:48 +00:00
|
|
|
{
|
2018-06-02 15:59:09 +01:00
|
|
|
uint32_t crc = 0;
|
2017-10-18 17:22:34 +01:00
|
|
|
uint8_t *bytes = (uint8_t*)&RtcSettings;
|
2017-02-28 15:01:48 +00:00
|
|
|
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < sizeof(RTCMEM); i++) {
|
2018-06-02 15:59:09 +01:00
|
|
|
crc += bytes[i]*(i+1);
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
return crc;
|
2017-02-28 15:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void RtcSettingsSave(void)
|
2017-02-28 15:01:48 +00:00
|
|
|
{
|
2018-06-02 15:59:09 +01:00
|
|
|
if (GetRtcSettingsCrc() != rtc_settings_crc) {
|
2017-10-18 17:22:34 +01:00
|
|
|
RtcSettings.valid = RTC_MEM_VALID;
|
|
|
|
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM));
|
2018-06-02 15:59:09 +01:00
|
|
|
rtc_settings_crc = GetRtcSettingsCrc();
|
2017-02-28 15:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void RtcSettingsLoad(void)
|
2017-02-28 15:01:48 +00:00
|
|
|
{
|
2018-09-24 17:16:35 +01:00
|
|
|
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM)); // 0x290
|
2017-10-18 17:22:34 +01:00
|
|
|
if (RtcSettings.valid != RTC_MEM_VALID) {
|
|
|
|
memset(&RtcSettings, 0, sizeof(RTCMEM));
|
|
|
|
RtcSettings.valid = RTC_MEM_VALID;
|
2017-12-16 14:51:45 +00:00
|
|
|
RtcSettings.energy_kWhtoday = Settings.energy_kWhtoday;
|
|
|
|
RtcSettings.energy_kWhtotal = Settings.energy_kWhtotal;
|
2019-08-25 13:58:45 +01:00
|
|
|
RtcSettings.energy_usage = Settings.energy_usage;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_COUNTERS; i++) {
|
2017-10-18 17:22:34 +01:00
|
|
|
RtcSettings.pulse_counter[i] = Settings.pulse_counter[i];
|
2017-05-17 21:49:22 +01:00
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
RtcSettings.power = Settings.power;
|
|
|
|
RtcSettingsSave();
|
2017-02-28 15:01:48 +00:00
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
rtc_settings_crc = GetRtcSettingsCrc();
|
2017-02-28 15:01:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool RtcSettingsValid(void)
|
2017-02-28 15:01:48 +00:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
return (RTC_MEM_VALID == RtcSettings.valid);
|
2017-02-28 15:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 15:22:34 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
uint32_t rtc_reboot_crc = 0;
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint32_t GetRtcRebootCrc(void)
|
2018-09-04 15:22:34 +01:00
|
|
|
{
|
|
|
|
uint32_t crc = 0;
|
|
|
|
uint8_t *bytes = (uint8_t*)&RtcReboot;
|
|
|
|
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < sizeof(RTCRBT); i++) {
|
2018-09-04 15:22:34 +01:00
|
|
|
crc += bytes[i]*(i+1);
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void RtcRebootSave(void)
|
2018-09-04 15:22:34 +01:00
|
|
|
{
|
|
|
|
if (GetRtcRebootCrc() != rtc_reboot_crc) {
|
|
|
|
RtcReboot.valid = RTC_MEM_VALID;
|
|
|
|
ESP.rtcUserMemoryWrite(100 - sizeof(RTCRBT), (uint32_t*)&RtcReboot, sizeof(RTCRBT));
|
|
|
|
rtc_reboot_crc = GetRtcRebootCrc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void RtcRebootLoad(void)
|
2018-09-04 15:22:34 +01:00
|
|
|
{
|
2018-09-24 17:16:35 +01:00
|
|
|
ESP.rtcUserMemoryRead(100 - sizeof(RTCRBT), (uint32_t*)&RtcReboot, sizeof(RTCRBT)); // 0x280
|
2018-09-04 15:22:34 +01:00
|
|
|
if (RtcReboot.valid != RTC_MEM_VALID) {
|
|
|
|
memset(&RtcReboot, 0, sizeof(RTCRBT));
|
|
|
|
RtcReboot.valid = RTC_MEM_VALID;
|
|
|
|
// RtcReboot.fast_reboot_count = 0; // Explicit by memset
|
|
|
|
RtcRebootSave();
|
|
|
|
}
|
|
|
|
rtc_reboot_crc = GetRtcRebootCrc();
|
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool RtcRebootValid(void)
|
2018-08-30 13:27:33 +01:00
|
|
|
{
|
2018-09-04 15:22:34 +01:00
|
|
|
return (RTC_MEM_VALID == RtcReboot.valid);
|
2018-08-30 13:27:33 +01:00
|
|
|
}
|
|
|
|
|
2017-02-19 16:49:17 +00:00
|
|
|
/*********************************************************************************************\
|
2017-04-24 17:25:53 +01:00
|
|
|
* Config - Flash
|
2017-02-19 16:49:17 +00:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "spi_flash.h"
|
|
|
|
}
|
|
|
|
#include "eboot_command.h"
|
|
|
|
|
2019-05-30 22:28:22 +01:00
|
|
|
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2) || defined(ARDUINO_ESP8266_RELEASE_2_5_0) || defined(ARDUINO_ESP8266_RELEASE_2_5_1) || defined(ARDUINO_ESP8266_RELEASE_2_5_2)
|
2017-04-24 17:25:53 +01:00
|
|
|
|
2019-05-30 22:28:22 +01:00
|
|
|
extern "C" uint32_t _SPIFFS_end;
|
2018-02-15 11:29:07 +00:00
|
|
|
// From libraries/EEPROM/EEPROM.cpp EEPROMClass
|
2019-03-31 10:59:04 +01:00
|
|
|
const uint32_t SPIFFS_END = ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2019-05-30 22:28:22 +01:00
|
|
|
#else // Core > 2.5.2 and STAGE
|
|
|
|
|
|
|
|
extern "C" uint32_t _FS_end;
|
|
|
|
// From libraries/EEPROM/EEPROM.cpp EEPROMClass
|
|
|
|
const uint32_t SPIFFS_END = ((uint32_t)&_FS_end - 0x40200000) / SPI_FLASH_SEC_SIZE;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 17:25:53 +01:00
|
|
|
// Version 4.2 config = eeprom area
|
2019-03-31 10:59:04 +01:00
|
|
|
const uint32_t SETTINGS_LOCATION = SPIFFS_END; // No need for SPIFFS as it uses EEPROM area
|
2017-06-19 21:54:49 +01:00
|
|
|
// Version 5.2 allow for more flash space
|
2019-03-31 10:59:04 +01:00
|
|
|
const uint8_t CFG_ROTATES = 8; // Number of flash sectors used (handles uploads)
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
uint32_t settings_location = SETTINGS_LOCATION;
|
2019-09-05 15:56:02 +01:00
|
|
|
//uint32_t settings_crc32 = 0;
|
|
|
|
uint16_t settings_crc = 0;
|
2019-03-26 17:26:50 +00:00
|
|
|
uint8_t *settings_buffer = nullptr;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
/*
|
|
|
|
* Based on cores/esp8266/Updater.cpp
|
|
|
|
*/
|
2018-11-14 13:32:09 +00:00
|
|
|
void SetFlashModeDout(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
|
|
|
uint8_t *_buffer;
|
|
|
|
uint32_t address;
|
|
|
|
|
2017-08-08 15:31:43 +01:00
|
|
|
eboot_command ebcmd;
|
|
|
|
eboot_command_read(&ebcmd);
|
|
|
|
address = ebcmd.args[0];
|
2017-02-19 16:49:17 +00:00
|
|
|
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
|
2018-02-24 15:37:33 +00:00
|
|
|
|
|
|
|
if (ESP.flashRead(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE)) {
|
2017-08-08 15:31:43 +01:00
|
|
|
if (_buffer[2] != 3) { // DOUT
|
|
|
|
_buffer[2] = 3;
|
2018-02-24 15:37:33 +00:00
|
|
|
if (ESP.flashEraseSector(address / FLASH_SECTOR_SIZE)) ESP.flashWrite(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE);
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] _buffer;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsBufferFree(void)
|
2018-05-24 13:25:52 +01:00
|
|
|
{
|
2019-03-26 17:26:50 +00:00
|
|
|
if (settings_buffer != nullptr) {
|
2018-05-24 13:25:52 +01:00
|
|
|
free(settings_buffer);
|
2019-03-26 17:26:50 +00:00
|
|
|
settings_buffer = nullptr;
|
2018-05-24 13:25:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
bool SettingsBufferAlloc(void)
|
2018-05-24 13:25:52 +01:00
|
|
|
{
|
|
|
|
SettingsBufferFree();
|
|
|
|
if (!(settings_buffer = (uint8_t *)malloc(sizeof(Settings)))) {
|
|
|
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_UPLOAD_ERR_2)); // Not enough (memory) space
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint16_t GetSettingsCrc(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2018-06-02 15:59:09 +01:00
|
|
|
uint16_t crc = 0;
|
2017-10-18 17:22:34 +01:00
|
|
|
uint8_t *bytes = (uint8_t*)&Settings;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2019-08-25 13:58:45 +01:00
|
|
|
// Fix miscalculation if previous Settings was 3584 and current Settings is 4096 as of 0x06060007
|
|
|
|
uint32_t size = (Settings.version < 0x06060007) ? 3584 : sizeof(SYSCFG);
|
|
|
|
for (uint32_t i = 0; i < size; i++) {
|
2018-06-02 15:59:09 +01:00
|
|
|
if ((i < 14) || (i > 15)) { crc += bytes[i]*(i+1); } // Skip crc
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
return crc;
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 15:56:02 +01:00
|
|
|
uint32_t GetSettingsCrc32(void)
|
|
|
|
{
|
|
|
|
// https://create.stephan-brumme.com/crc32/#bitwise
|
|
|
|
uint32_t crc = 0;
|
|
|
|
uint8_t *bytes = (uint8_t*)&Settings;
|
|
|
|
|
|
|
|
uint32_t length = sizeof(SYSCFG) -4; // Skip crc
|
|
|
|
while (length--) {
|
|
|
|
crc ^= *bytes++;
|
|
|
|
for (uint32_t j = 0; j < 8; j++) {
|
|
|
|
crc = (crc >> 1) ^ (-int(crc & 1) & 0xEDB88320);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ~crc;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsSaveAll(void)
|
2017-11-21 15:06:51 +00:00
|
|
|
{
|
|
|
|
if (Settings.flag.save_state) {
|
|
|
|
Settings.power = power;
|
|
|
|
} else {
|
|
|
|
Settings.power = 0;
|
|
|
|
}
|
2017-12-25 16:41:12 +00:00
|
|
|
XsnsCall(FUNC_SAVE_BEFORE_RESTART);
|
2019-05-19 13:59:07 +01:00
|
|
|
XdrvCall(FUNC_SAVE_BEFORE_RESTART);
|
2017-11-21 15:06:51 +00:00
|
|
|
SettingsSave(0);
|
|
|
|
}
|
|
|
|
|
2017-02-19 16:49:17 +00:00
|
|
|
/*********************************************************************************************\
|
2017-04-24 17:25:53 +01:00
|
|
|
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
2017-02-19 16:49:17 +00:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
uint32_t GetSettingsAddress(void)
|
2017-06-25 22:01:41 +01:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
return settings_location * SPI_FLASH_SEC_SIZE;
|
2017-06-25 22:01:41 +01:00
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
void SettingsSave(uint8_t rotate)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2017-06-30 16:54:19 +01:00
|
|
|
/* Save configuration in eeprom or one of 7 slots below
|
2017-09-02 13:37:02 +01:00
|
|
|
*
|
2017-06-30 16:54:19 +01:00
|
|
|
* rotate 0 = Save in next flash slot
|
|
|
|
* rotate 1 = Save only in eeprom flash slot until SetOption12 0 or restart
|
2017-07-25 17:05:47 +01:00
|
|
|
* rotate 2 = Save in eeprom flash slot, erase next flash slots and continue depending on stop_flash_rotate
|
2017-06-30 16:54:19 +01:00
|
|
|
* stop_flash_rotate 0 = Allow flash slot rotation (SetOption12 0)
|
|
|
|
* stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1)
|
|
|
|
*/
|
2019-02-08 13:55:45 +00:00
|
|
|
#ifndef FIRMWARE_MINIMAL
|
2018-06-02 15:59:09 +01:00
|
|
|
if ((GetSettingsCrc() != settings_crc) || rotate) {
|
2017-07-25 17:05:47 +01:00
|
|
|
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
|
|
|
|
stop_flash_rotate = 1;
|
2017-06-25 22:01:41 +01:00
|
|
|
}
|
2017-07-25 17:05:47 +01:00
|
|
|
if (2 == rotate) { // Use eeprom flash slot and erase next flash slots if stop_flash_rotate is off (default)
|
2017-10-18 17:22:34 +01:00
|
|
|
settings_location = SETTINGS_LOCATION +1;
|
2017-06-30 16:54:19 +01:00
|
|
|
}
|
2017-06-25 22:01:41 +01:00
|
|
|
if (stop_flash_rotate) {
|
2017-10-18 17:22:34 +01:00
|
|
|
settings_location = SETTINGS_LOCATION;
|
2017-06-19 21:54:49 +01:00
|
|
|
} else {
|
2017-10-18 17:22:34 +01:00
|
|
|
settings_location--;
|
|
|
|
if (settings_location <= (SETTINGS_LOCATION - CFG_ROTATES)) {
|
|
|
|
settings_location = SETTINGS_LOCATION;
|
2017-06-19 21:54:49 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.save_flag++;
|
2019-09-05 15:56:02 +01:00
|
|
|
if (UtcTime() > START_VALID_TIME) {
|
|
|
|
Settings.cfg_timestamp = UtcTime();
|
|
|
|
} else {
|
|
|
|
Settings.cfg_timestamp++;
|
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.cfg_size = sizeof(SYSCFG);
|
2019-09-05 15:56:02 +01:00
|
|
|
// Settings.cfg_crc32 = GetSettingsCrc32();
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.cfg_crc = GetSettingsCrc();
|
2019-01-04 15:05:52 +00:00
|
|
|
|
2019-04-02 19:53:17 +01:00
|
|
|
ESP.flashEraseSector(settings_location);
|
|
|
|
ESP.flashWrite(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
2019-01-04 15:05:52 +00:00
|
|
|
|
2017-06-30 16:54:19 +01:00
|
|
|
if (!stop_flash_rotate && rotate) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 1; i < CFG_ROTATES; i++) {
|
2018-02-24 15:37:33 +00:00
|
|
|
ESP.flashEraseSector(settings_location -i); // Delete previous configurations by resetting to 0xFF
|
2017-06-19 21:54:49 +01:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 14:15:42 +00:00
|
|
|
|
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"), settings_location, Settings.save_flag, sizeof(SYSCFG));
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
settings_crc = Settings.cfg_crc;
|
2019-09-05 15:56:02 +01:00
|
|
|
// settings_crc32 = Settings.cfg_crc32;
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
2019-02-08 13:55:45 +00:00
|
|
|
#endif // FIRMWARE_MINIMAL
|
2017-10-18 17:22:34 +01:00
|
|
|
RtcSettingsSave();
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsLoad(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2019-01-30 15:27:17 +00:00
|
|
|
// Load configuration from eeprom or one of 7 slots below if first valid load does not stop_flash_rotate
|
2017-04-24 17:25:53 +01:00
|
|
|
struct SYSCFGH {
|
2018-06-02 15:59:09 +01:00
|
|
|
uint16_t cfg_holder; // 000
|
|
|
|
uint16_t cfg_size; // 002
|
|
|
|
unsigned long save_flag; // 004
|
2017-10-18 17:22:34 +01:00
|
|
|
} _SettingsH;
|
2019-01-30 15:27:17 +00:00
|
|
|
unsigned long save_flag = 0;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2019-01-30 15:27:17 +00:00
|
|
|
settings_location = 0;
|
|
|
|
uint32_t flash_location = SETTINGS_LOCATION +1;
|
2019-04-02 14:47:39 +01:00
|
|
|
uint16_t cfg_holder = 0;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < CFG_ROTATES; i++) {
|
2019-01-30 15:27:17 +00:00
|
|
|
flash_location--;
|
|
|
|
ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
|
|
|
|
|
|
|
bool valid = false;
|
|
|
|
if (Settings.version > 0x06000000) {
|
2019-04-02 14:47:39 +01:00
|
|
|
bool almost_valid = (Settings.cfg_crc == GetSettingsCrc());
|
|
|
|
// Sometimes CRC on pages below FB, overwritten by OTA, is fine but Settings are still invalid. So check cfg_holder too
|
|
|
|
if (almost_valid && (0 == cfg_holder)) { cfg_holder = Settings.cfg_holder; } // At FB always active cfg_holder
|
|
|
|
valid = (cfg_holder == Settings.cfg_holder);
|
2019-01-30 15:27:17 +00:00
|
|
|
} else {
|
|
|
|
ESP.flashRead((flash_location -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
|
|
|
|
valid = (Settings.cfg_holder == _SettingsH.cfg_holder);
|
|
|
|
}
|
|
|
|
if (valid) {
|
|
|
|
if (Settings.save_flag > save_flag) {
|
|
|
|
save_flag = Settings.save_flag;
|
|
|
|
settings_location = flash_location;
|
2019-02-01 13:05:55 +00:00
|
|
|
if (Settings.flag.stop_flash_rotate && (0 == i)) { // Stop only if eeprom area should be used and it is valid
|
2019-01-30 15:27:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
2019-01-30 15:27:17 +00:00
|
|
|
|
2017-06-19 21:54:49 +01:00
|
|
|
delay(1);
|
|
|
|
}
|
2019-01-30 15:27:17 +00:00
|
|
|
if (settings_location > 0) {
|
|
|
|
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
2019-04-02 14:47:39 +01:00
|
|
|
AddLog_P2(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag);
|
2019-01-30 15:27:17 +00:00
|
|
|
}
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2019-02-08 13:55:45 +00:00
|
|
|
#ifndef FIRMWARE_MINIMAL
|
2019-01-30 15:27:17 +00:00
|
|
|
if (!settings_location || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h
|
|
|
|
SettingsDefault();
|
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
settings_crc = GetSettingsCrc();
|
2019-02-08 13:55:45 +00:00
|
|
|
#endif // FIRMWARE_MINIMAL
|
2017-02-28 15:01:48 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
RtcSettingsLoad();
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-24 15:37:33 +00:00
|
|
|
void SettingsErase(uint8_t type)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2018-02-24 15:37:33 +00:00
|
|
|
/*
|
|
|
|
0 = Erase from program end until end of physical flash
|
|
|
|
1 = Erase SDK parameter area at end of linker memory model (0x0FDxxx - 0x0FFFFF) solving possible wifi errors
|
|
|
|
*/
|
|
|
|
|
2019-02-08 13:55:45 +00:00
|
|
|
#ifndef FIRMWARE_MINIMAL
|
2018-02-24 15:37:33 +00:00
|
|
|
bool result;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
|
|
|
uint32_t _sectorStart = (ESP.getSketchSize() / SPI_FLASH_SEC_SIZE) + 1;
|
|
|
|
uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE;
|
2018-02-24 15:37:33 +00:00
|
|
|
if (1 == type) {
|
|
|
|
_sectorStart = SETTINGS_LOCATION +2; // SDK parameter area above EEPROM area (0x0FDxxx - 0x0FFFFF)
|
|
|
|
_sectorEnd = SETTINGS_LOCATION +5;
|
|
|
|
}
|
|
|
|
|
2019-01-28 13:08:33 +00:00
|
|
|
bool _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2019-03-08 14:15:42 +00:00
|
|
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart);
|
2017-02-19 16:49:17 +00:00
|
|
|
|
|
|
|
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
2018-02-24 15:37:33 +00:00
|
|
|
result = ESP.flashEraseSector(_sector);
|
2017-02-19 16:49:17 +00:00
|
|
|
if (_serialoutput) {
|
2017-09-02 13:37:02 +01:00
|
|
|
Serial.print(F(D_LOG_APPLICATION D_ERASED_SECTOR " "));
|
2017-02-19 16:49:17 +00:00
|
|
|
Serial.print(_sector);
|
2018-02-24 15:37:33 +00:00
|
|
|
if (result) {
|
2017-09-02 13:37:02 +01:00
|
|
|
Serial.println(F(" " D_OK));
|
2017-02-19 16:49:17 +00:00
|
|
|
} else {
|
2017-09-02 13:37:02 +01:00
|
|
|
Serial.println(F(" " D_ERROR));
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
delay(10);
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
OsWatchLoop();
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
2019-02-08 13:55:45 +00:00
|
|
|
#endif // FIRMWARE_MINIMAL
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2018-02-24 15:37:33 +00:00
|
|
|
// Copied from 2.4.0 as 2.3.0 is incomplete
|
|
|
|
bool SettingsEraseConfig(void) {
|
|
|
|
const size_t cfgSize = 0x4000;
|
|
|
|
size_t cfgAddr = ESP.getFlashChipSize() - cfgSize;
|
|
|
|
|
|
|
|
for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) {
|
|
|
|
if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsSdkErase(void)
|
2018-02-24 15:37:33 +00:00
|
|
|
{
|
|
|
|
WiFi.disconnect(true); // Delete SDK wifi config
|
|
|
|
SettingsErase(1);
|
|
|
|
SettingsEraseConfig();
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
2017-02-19 16:49:17 +00:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefault(void)
|
2017-05-03 17:19:13 +01:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_USE_DEFAULTS));
|
|
|
|
SettingsDefaultSet1();
|
|
|
|
SettingsDefaultSet2();
|
|
|
|
SettingsSave(2);
|
2017-05-03 17:19:13 +01:00
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefaultSet1(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
memset(&Settings, 0x00, sizeof(SYSCFG));
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.cfg_holder = (uint16_t)CFG_HOLDER;
|
|
|
|
Settings.cfg_size = sizeof(SYSCFG);
|
2017-10-18 17:22:34 +01:00
|
|
|
// Settings.save_flag = 0;
|
|
|
|
Settings.version = VERSION;
|
|
|
|
// Settings.bootcount = 0;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.cfg_crc = 0;
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefaultSet2(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
memset((char*)&Settings +16, 0x00, sizeof(SYSCFG) -16);
|
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.flag.value_units = 0;
|
|
|
|
// Settings.flag.stop_flash_rotate = 0;
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.save_data = SAVE_DATA;
|
2019-01-30 14:14:24 +00:00
|
|
|
Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET;
|
2019-02-24 23:48:03 +00:00
|
|
|
Settings.param[P_RGB_REMAP] = RGB_REMAP_RGBW;
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.sleep = APP_SLEEP;
|
2018-12-01 17:53:42 +00:00
|
|
|
if (Settings.sleep < 50) {
|
|
|
|
Settings.sleep = 50; // Default to 50 for sleep, for now
|
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Module
|
|
|
|
// Settings.flag.interlock = 0;
|
2019-01-27 10:02:12 +00:00
|
|
|
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.module = MODULE;
|
2019-02-11 18:21:49 +00:00
|
|
|
ModuleDefault(WEMOS);
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; }
|
2018-06-02 15:59:09 +01:00
|
|
|
strlcpy(Settings.friendlyname[0], FRIENDLY_NAME, sizeof(Settings.friendlyname[0]));
|
|
|
|
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
|
|
|
|
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
|
|
|
|
strlcpy(Settings.friendlyname[3], FRIENDLY_NAME"4", sizeof(Settings.friendlyname[3]));
|
2017-10-18 17:22:34 +01:00
|
|
|
strlcpy(Settings.ota_url, OTA_URL, sizeof(Settings.ota_url));
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Power
|
|
|
|
Settings.flag.save_state = SAVE_STATE;
|
|
|
|
Settings.power = APP_POWER;
|
|
|
|
Settings.poweronstate = APP_POWERON_STATE;
|
|
|
|
Settings.blinktime = APP_BLINKTIME;
|
|
|
|
Settings.blinkcount = APP_BLINKCOUNT;
|
|
|
|
Settings.ledstate = APP_LEDSTATE;
|
2019-04-10 13:26:36 +01:00
|
|
|
Settings.ledmask = APP_LEDMASK;
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.pulse_timer[0] = APP_PULSETIME;
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; }
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Serial
|
2019-08-28 11:02:27 +01:00
|
|
|
Settings.baudrate = APP_BAUDRATE / 300;
|
|
|
|
Settings.sbaudrate = SOFT_BAUDRATE / 300;
|
2018-03-20 13:31:11 +00:00
|
|
|
Settings.serial_delimiter = 0xff;
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.seriallog_level = SERIAL_LOG_LEVEL;
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Wifi
|
|
|
|
ParseIp(&Settings.ip_address[0], WIFI_IP_ADDRESS);
|
|
|
|
ParseIp(&Settings.ip_address[1], WIFI_GATEWAY);
|
|
|
|
ParseIp(&Settings.ip_address[2], WIFI_SUBNETMASK);
|
|
|
|
ParseIp(&Settings.ip_address[3], WIFI_DNS);
|
|
|
|
Settings.sta_config = WIFI_CONFIG_TOOL;
|
2017-10-18 17:22:34 +01:00
|
|
|
// Settings.sta_active = 0;
|
|
|
|
strlcpy(Settings.sta_ssid[0], STA_SSID1, sizeof(Settings.sta_ssid[0]));
|
|
|
|
strlcpy(Settings.sta_pwd[0], STA_PASS1, sizeof(Settings.sta_pwd[0]));
|
|
|
|
strlcpy(Settings.sta_ssid[1], STA_SSID2, sizeof(Settings.sta_ssid[1]));
|
|
|
|
strlcpy(Settings.sta_pwd[1], STA_PASS2, sizeof(Settings.sta_pwd[1]));
|
|
|
|
strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname));
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Syslog
|
2017-10-18 17:22:34 +01:00
|
|
|
strlcpy(Settings.syslog_host, SYS_LOG_HOST, sizeof(Settings.syslog_host));
|
|
|
|
Settings.syslog_port = SYS_LOG_PORT;
|
|
|
|
Settings.syslog_level = SYS_LOG_LEVEL;
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Webserver
|
|
|
|
Settings.flag2.emulation = EMULATION;
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.webserver = WEB_SERVER;
|
|
|
|
Settings.weblog_level = WEB_LOG_LEVEL;
|
2018-06-02 15:59:09 +01:00
|
|
|
strlcpy(Settings.web_password, WEB_PASSWORD, sizeof(Settings.web_password));
|
2019-01-14 09:57:01 +00:00
|
|
|
Settings.flag3.mdns_enabled = MDNS_ENABLED;
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// Button
|
|
|
|
// Settings.flag.button_restrict = 0;
|
|
|
|
// Settings.flag.button_swap = 0;
|
|
|
|
// Settings.flag.button_single = 0;
|
|
|
|
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
2017-10-18 17:22:34 +01:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Switch
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_SWITCHES; i++) { Settings.switchmode[i] = SWITCH_MODE; }
|
2018-06-02 15:59:09 +01:00
|
|
|
|
|
|
|
// MQTT
|
|
|
|
Settings.flag.mqtt_enabled = MQTT_USE;
|
|
|
|
// Settings.flag.mqtt_response = 0;
|
|
|
|
Settings.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
|
|
|
|
Settings.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
|
|
|
|
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
2018-12-08 07:44:59 +00:00
|
|
|
Settings.flag3.button_switch_force_local = MQTT_BUTTON_SWITCH_FORCE_LOCAL;
|
2019-02-17 21:05:02 +00:00
|
|
|
Settings.flag3.hass_tele_on_power = TELE_ON_POWER;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.flag.mqtt_sensor_retain = 0;
|
|
|
|
// Settings.flag.mqtt_offline = 0;
|
|
|
|
// Settings.flag.mqtt_serial = 0;
|
|
|
|
// Settings.flag.device_index_enable = 0;
|
|
|
|
strlcpy(Settings.mqtt_host, MQTT_HOST, sizeof(Settings.mqtt_host));
|
|
|
|
Settings.mqtt_port = MQTT_PORT;
|
|
|
|
strlcpy(Settings.mqtt_client, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client));
|
|
|
|
strlcpy(Settings.mqtt_user, MQTT_USER, sizeof(Settings.mqtt_user));
|
|
|
|
strlcpy(Settings.mqtt_pwd, MQTT_PASS, sizeof(Settings.mqtt_pwd));
|
|
|
|
strlcpy(Settings.mqtt_topic, MQTT_TOPIC, sizeof(Settings.mqtt_topic));
|
2018-08-05 19:01:50 +01:00
|
|
|
strlcpy(Settings.button_topic, MQTT_BUTTON_TOPIC, sizeof(Settings.button_topic));
|
|
|
|
strlcpy(Settings.switch_topic, MQTT_SWITCH_TOPIC, sizeof(Settings.switch_topic));
|
2018-06-02 15:59:09 +01:00
|
|
|
strlcpy(Settings.mqtt_grptopic, MQTT_GRPTOPIC, sizeof(Settings.mqtt_grptopic));
|
|
|
|
strlcpy(Settings.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(Settings.mqtt_fulltopic));
|
|
|
|
Settings.mqtt_retry = MQTT_RETRY_SECS;
|
|
|
|
strlcpy(Settings.mqtt_prefix[0], SUB_PREFIX, sizeof(Settings.mqtt_prefix[0]));
|
|
|
|
strlcpy(Settings.mqtt_prefix[1], PUB_PREFIX, sizeof(Settings.mqtt_prefix[1]));
|
|
|
|
strlcpy(Settings.mqtt_prefix[2], PUB_PREFIX2, sizeof(Settings.mqtt_prefix[2]));
|
|
|
|
strlcpy(Settings.state_text[0], MQTT_STATUS_OFF, sizeof(Settings.state_text[0]));
|
|
|
|
strlcpy(Settings.state_text[1], MQTT_STATUS_ON, sizeof(Settings.state_text[1]));
|
|
|
|
strlcpy(Settings.state_text[2], MQTT_CMND_TOGGLE, sizeof(Settings.state_text[2]));
|
|
|
|
strlcpy(Settings.state_text[3], MQTT_CMND_HOLD, sizeof(Settings.state_text[3]));
|
2018-03-09 17:08:17 +00:00
|
|
|
char fingerprint[60];
|
|
|
|
strlcpy(fingerprint, MQTT_FINGERPRINT1, sizeof(fingerprint));
|
|
|
|
char *p = fingerprint;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 20; i++) {
|
2018-03-09 17:08:17 +00:00
|
|
|
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
|
|
|
|
}
|
|
|
|
strlcpy(fingerprint, MQTT_FINGERPRINT2, sizeof(fingerprint));
|
|
|
|
p = fingerprint;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 20; i++) {
|
2018-03-09 17:08:17 +00:00
|
|
|
Settings.mqtt_fingerprint[1][i] = strtol(p, &p, 16);
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.tele_period = TELE_PERIOD;
|
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Energy
|
|
|
|
Settings.flag2.current_resolution = 3;
|
|
|
|
// Settings.flag2.voltage_resolution = 0;
|
|
|
|
// Settings.flag2.wattage_resolution = 0;
|
|
|
|
Settings.flag2.energy_resolution = ENERGY_RESOLUTION;
|
|
|
|
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
2019-05-24 14:04:48 +01:00
|
|
|
// Settings.energy_power_delta = 0;
|
2018-02-03 22:25:05 +00:00
|
|
|
Settings.energy_power_calibration = HLW_PREF_PULSE;
|
|
|
|
Settings.energy_voltage_calibration = HLW_UREF_PULSE;
|
|
|
|
Settings.energy_current_calibration = HLW_IREF_PULSE;
|
2017-12-16 14:51:45 +00:00
|
|
|
// Settings.energy_kWhtoday = 0;
|
|
|
|
// Settings.energy_kWhyesterday = 0;
|
|
|
|
// Settings.energy_kWhdoy = 0;
|
|
|
|
// Settings.energy_min_power = 0;
|
|
|
|
// Settings.energy_max_power = 0;
|
|
|
|
// Settings.energy_min_voltage = 0;
|
|
|
|
// Settings.energy_max_voltage = 0;
|
|
|
|
// Settings.energy_min_current = 0;
|
|
|
|
// Settings.energy_max_current = 0;
|
2018-03-21 08:27:05 +00:00
|
|
|
// Settings.energy_max_power_limit = 0; // MaxPowerLimit
|
2017-12-16 14:51:45 +00:00
|
|
|
Settings.energy_max_power_limit_hold = MAX_POWER_HOLD;
|
|
|
|
Settings.energy_max_power_limit_window = MAX_POWER_WINDOW;
|
2018-03-21 08:27:05 +00:00
|
|
|
// Settings.energy_max_power_safe_limit = 0; // MaxSafePowerLimit
|
2017-12-16 14:51:45 +00:00
|
|
|
Settings.energy_max_power_safe_limit_hold = SAFE_POWER_HOLD;
|
|
|
|
Settings.energy_max_power_safe_limit_window = SAFE_POWER_WINDOW;
|
2018-03-21 08:27:05 +00:00
|
|
|
// Settings.energy_max_energy = 0; // MaxEnergy
|
|
|
|
// Settings.energy_max_energy_start = 0; // MaxEnergyStart
|
2017-12-16 14:51:45 +00:00
|
|
|
// Settings.energy_kWhtotal = 0;
|
|
|
|
RtcSettings.energy_kWhtotal = 0;
|
2019-08-25 13:58:45 +01:00
|
|
|
// memset((char*)&Settings.energy_usage, 0x00, sizeof(Settings.energy_usage));
|
|
|
|
memset((char*)&RtcSettings.energy_usage, 0x00, sizeof(RtcSettings.energy_usage));
|
2019-07-08 15:50:23 +01:00
|
|
|
Settings.param[P_OVER_TEMP] = ENERGY_OVERTEMP;
|
2017-05-08 12:21:45 +01:00
|
|
|
|
2019-05-27 10:56:14 +01:00
|
|
|
// IRRemote
|
|
|
|
Settings.param[P_IR_UNKNOW_THRESHOLD] = IR_RCV_MIN_UNKNOWN_SIZE;
|
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// RF Bridge
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
|
2017-10-18 17:22:34 +01:00
|
|
|
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
|
2017-09-02 13:37:02 +01:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Domoticz
|
|
|
|
Settings.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.domoticz_relay_idx[i] = 0;
|
|
|
|
// Settings.domoticz_key_idx[i] = 0;
|
|
|
|
// Settings.domoticz_switch_idx[i] = 0;
|
|
|
|
// }
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 0; i < MAX_DOMOTICZ_SNS_IDX; i++) {
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.domoticz_sensor_idx[i] = 0;
|
|
|
|
// }
|
2017-10-23 11:18:15 +01:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Sensor
|
|
|
|
Settings.flag.temperature_conversion = TEMP_CONVERSION;
|
2018-11-04 15:55:12 +00:00
|
|
|
Settings.flag.pressure_conversion = PRESSURE_CONVERSION;
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.flag2.pressure_resolution = PRESSURE_RESOLUTION;
|
|
|
|
Settings.flag2.humidity_resolution = HUMIDITY_RESOLUTION;
|
|
|
|
Settings.flag2.temperature_resolution = TEMP_RESOLUTION;
|
2017-10-26 15:33:33 +01:00
|
|
|
// Settings.altitude = 0;
|
2017-11-11 11:33:30 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Rules
|
2018-11-04 15:55:12 +00:00
|
|
|
// Settings.rule_enabled = 0;
|
|
|
|
// Settings.rule_once = 0;
|
2019-06-30 15:44:36 +01:00
|
|
|
// for (uint32_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
|
2018-11-27 00:16:47 +00:00
|
|
|
Settings.flag2.calc_resolution = CALC_RESOLUTION;
|
2017-03-12 17:36:33 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Home Assistant
|
|
|
|
Settings.flag.hass_discovery = HOME_ASSISTANT_DISCOVERY_ENABLE;
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Knx
|
|
|
|
// Settings.flag.knx_enabled = 0;
|
|
|
|
// Settings.flag.knx_enable_enhancement = 0;
|
2017-03-12 17:36:33 +00:00
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Light
|
|
|
|
Settings.flag.pwm_control = 1;
|
|
|
|
//Settings.flag.ws_clock_reverse = 0;
|
|
|
|
//Settings.flag.light_signal = 0;
|
|
|
|
//Settings.flag.not_power_linked = 0;
|
|
|
|
//Settings.flag.decimal_text = 0;
|
|
|
|
Settings.pwm_frequency = PWM_FREQ;
|
|
|
|
Settings.pwm_range = PWM_RANGE;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_PWMS; i++) {
|
2017-10-26 15:33:33 +01:00
|
|
|
Settings.light_color[i] = 255;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.pwm_value[i] = 0;
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
2019-04-25 17:50:04 +01:00
|
|
|
Settings.light_correction = 1;
|
2017-10-26 15:33:33 +01:00
|
|
|
Settings.light_dimmer = 10;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.light_fade = 0;
|
2017-10-26 15:33:33 +01:00
|
|
|
Settings.light_speed = 1;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.light_scheme = 0;
|
2017-10-26 15:33:33 +01:00
|
|
|
Settings.light_width = 1;
|
2018-06-02 15:59:09 +01:00
|
|
|
// Settings.light_wakeup = 0;
|
|
|
|
Settings.light_pixels = WS2812_LEDS;
|
|
|
|
// Settings.light_rotation = 0;
|
|
|
|
SettingsDefaultSet_5_8_1(); // Clock color
|
2017-02-21 17:14:33 +00:00
|
|
|
|
2019-08-25 22:10:19 +01:00
|
|
|
Settings.param[P_TUYA_DIMMER_MAX] = TUYA_DIMMER_MAX;
|
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
// Display
|
|
|
|
SettingsDefaultSet_5_10_1(); // Display settings
|
|
|
|
|
|
|
|
// Time
|
2018-11-01 12:00:05 +00:00
|
|
|
if (((APP_TIMEZONE > -14) && (APP_TIMEZONE < 15)) || (99 == APP_TIMEZONE)) {
|
|
|
|
Settings.timezone = APP_TIMEZONE;
|
|
|
|
Settings.timezone_minutes = 0;
|
|
|
|
} else {
|
|
|
|
Settings.timezone = APP_TIMEZONE / 60;
|
|
|
|
Settings.timezone_minutes = abs(APP_TIMEZONE % 60);
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
strlcpy(Settings.ntp_server[0], NTP_SERVER1, sizeof(Settings.ntp_server[0]));
|
|
|
|
strlcpy(Settings.ntp_server[1], NTP_SERVER2, sizeof(Settings.ntp_server[1]));
|
|
|
|
strlcpy(Settings.ntp_server[2], NTP_SERVER3, sizeof(Settings.ntp_server[2]));
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t j = 0; j < 3; j++) {
|
|
|
|
for (uint32_t i = 0; i < strlen(Settings.ntp_server[j]); i++) {
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.ntp_server[j][i] == ',') {
|
|
|
|
Settings.ntp_server[j][i] = '.';
|
2017-04-25 17:24:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.latitude = (int)((double)LATITUDE * 1000000);
|
|
|
|
Settings.longitude = (int)((double)LONGITUDE * 1000000);
|
|
|
|
SettingsDefaultSet_5_13_1c(); // Time STD/DST settings
|
2018-08-27 11:01:20 +01:00
|
|
|
|
|
|
|
Settings.button_debounce = KEY_DEBOUNCE_TIME;
|
|
|
|
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
|
2018-09-29 15:55:53 +01:00
|
|
|
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t j = 0; j < 5; j++) {
|
2018-09-29 15:55:53 +01:00
|
|
|
Settings.rgbwwTable[j] = 255;
|
|
|
|
}
|
2018-11-06 16:33:51 +00:00
|
|
|
|
2019-03-28 11:06:48 +00:00
|
|
|
Settings.novasds_period = WORKING_PERIOD;
|
|
|
|
|
2019-04-09 12:56:19 +01:00
|
|
|
SettingsDefaultWebColor();
|
|
|
|
|
2019-05-24 11:28:09 +01:00
|
|
|
memset(&Settings.monitors, 0xFF, 20); // Enable all possible monitors, displays and sensors
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-02 15:59:09 +01:00
|
|
|
/********************************************************************************************/
|
2017-02-19 16:49:17 +00:00
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefaultSet_5_8_1(void)
|
2017-10-23 11:18:15 +01:00
|
|
|
{
|
|
|
|
// Settings.flag.ws_clock_reverse = 0;
|
|
|
|
Settings.ws_width[WS_SECOND] = 1;
|
|
|
|
Settings.ws_color[WS_SECOND][WS_RED] = 255;
|
|
|
|
Settings.ws_color[WS_SECOND][WS_GREEN] = 0;
|
|
|
|
Settings.ws_color[WS_SECOND][WS_BLUE] = 255;
|
|
|
|
Settings.ws_width[WS_MINUTE] = 3;
|
|
|
|
Settings.ws_color[WS_MINUTE][WS_RED] = 0;
|
|
|
|
Settings.ws_color[WS_MINUTE][WS_GREEN] = 255;
|
|
|
|
Settings.ws_color[WS_MINUTE][WS_BLUE] = 0;
|
|
|
|
Settings.ws_width[WS_HOUR] = 5;
|
|
|
|
Settings.ws_color[WS_HOUR][WS_RED] = 255;
|
|
|
|
Settings.ws_color[WS_HOUR][WS_GREEN] = 0;
|
|
|
|
Settings.ws_color[WS_HOUR][WS_BLUE] = 0;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefaultSet_5_10_1(void)
|
2018-01-05 11:26:19 +00:00
|
|
|
{
|
|
|
|
Settings.display_model = 0;
|
|
|
|
Settings.display_mode = 1;
|
|
|
|
Settings.display_refresh = 2;
|
|
|
|
Settings.display_rows = 2;
|
|
|
|
Settings.display_cols[0] = 16;
|
|
|
|
Settings.display_cols[1] = 8;
|
2018-08-23 10:49:17 +01:00
|
|
|
Settings.display_dimmer = 1;
|
|
|
|
Settings.display_size = 1;
|
|
|
|
Settings.display_font = 1;
|
|
|
|
Settings.display_rotate = 0;
|
2018-01-05 11:26:19 +00:00
|
|
|
Settings.display_address[0] = MTX_ADDRESS1;
|
|
|
|
Settings.display_address[1] = MTX_ADDRESS2;
|
|
|
|
Settings.display_address[2] = MTX_ADDRESS3;
|
|
|
|
Settings.display_address[3] = MTX_ADDRESS4;
|
|
|
|
Settings.display_address[4] = MTX_ADDRESS5;
|
|
|
|
Settings.display_address[5] = MTX_ADDRESS6;
|
|
|
|
Settings.display_address[6] = MTX_ADDRESS7;
|
|
|
|
Settings.display_address[7] = MTX_ADDRESS8;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsResetStd(void)
|
2018-05-13 18:43:48 +01:00
|
|
|
{
|
2018-05-14 22:22:29 +01:00
|
|
|
Settings.tflag[0].hemis = TIME_STD_HEMISPHERE;
|
|
|
|
Settings.tflag[0].week = TIME_STD_WEEK;
|
|
|
|
Settings.tflag[0].dow = TIME_STD_DAY;
|
|
|
|
Settings.tflag[0].month = TIME_STD_MONTH;
|
|
|
|
Settings.tflag[0].hour = TIME_STD_HOUR;
|
|
|
|
Settings.toffset[0] = TIME_STD_OFFSET;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsResetDst(void)
|
2018-05-14 22:22:29 +01:00
|
|
|
{
|
|
|
|
Settings.tflag[1].hemis = TIME_DST_HEMISPHERE;
|
|
|
|
Settings.tflag[1].week = TIME_DST_WEEK;
|
|
|
|
Settings.tflag[1].dow = TIME_DST_DAY;
|
|
|
|
Settings.tflag[1].month = TIME_DST_MONTH;
|
|
|
|
Settings.tflag[1].hour = TIME_DST_HOUR;
|
|
|
|
Settings.toffset[1] = TIME_DST_OFFSET;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDefaultSet_5_13_1c(void)
|
2018-05-14 22:22:29 +01:00
|
|
|
{
|
|
|
|
SettingsResetStd();
|
|
|
|
SettingsResetDst();
|
2018-05-13 18:43:48 +01:00
|
|
|
}
|
|
|
|
|
2019-04-09 12:56:19 +01:00
|
|
|
void SettingsDefaultWebColor(void)
|
|
|
|
{
|
|
|
|
char scolor[10];
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < COL_LAST; i++) {
|
2019-04-09 12:56:19 +01:00
|
|
|
WebHexCode(i, GetTextIndexed(scolor, sizeof(scolor), i, kWebColors));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-19 16:49:17 +00:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void SettingsDelta(void)
|
2017-02-19 16:49:17 +00:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version != VERSION) { // Fix version dependent changes
|
2018-06-02 15:59:09 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version < 0x05050000) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 17; i++) { Settings.rf_code[i][0] = 0; }
|
2017-10-18 17:22:34 +01:00
|
|
|
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
|
2017-07-30 16:55:37 +01:00
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version < 0x05080000) {
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.light_pixels = WS2812_LEDS;
|
|
|
|
Settings.light_width = 1;
|
|
|
|
Settings.light_color[0] = 255;
|
|
|
|
Settings.light_color[1] = 0;
|
|
|
|
Settings.light_color[2] = 0;
|
|
|
|
Settings.light_dimmer = 10;
|
2019-04-25 17:50:04 +01:00
|
|
|
Settings.light_correction = 1;
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.light_fade = 0;
|
|
|
|
Settings.light_speed = 1;
|
|
|
|
Settings.light_scheme = 0;
|
|
|
|
Settings.light_width = 1;
|
|
|
|
Settings.light_wakeup = 0;
|
2017-09-16 16:34:03 +01:00
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version < 0x0508000A) {
|
2018-06-02 15:59:09 +01:00
|
|
|
Settings.power = 0;
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.altitude = 0;
|
2017-10-10 14:40:02 +01:00
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version < 0x0508000B) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) { // Move GPIO_LEDs
|
2017-10-18 17:22:34 +01:00
|
|
|
if ((Settings.my_gp.io[i] >= 25) && (Settings.my_gp.io[i] <= 32)) { // Was GPIO_LED1
|
|
|
|
Settings.my_gp.io[i] += 23; // Move GPIO_LED1
|
2017-10-12 10:29:40 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.pwm_value[i] = Settings.pulse_timer[4 +i];
|
|
|
|
Settings.pulse_timer[4 +i] = 0;
|
2017-10-12 10:29:40 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
if (Settings.version < 0x0508000D) {
|
|
|
|
Settings.pwm_frequency = PWM_FREQ;
|
|
|
|
Settings.pwm_range = PWM_RANGE;
|
|
|
|
}
|
2017-10-23 11:18:15 +01:00
|
|
|
if (Settings.version < 0x0508000E) {
|
|
|
|
SettingsDefaultSet_5_8_1();
|
|
|
|
}
|
2017-11-11 11:33:30 +00:00
|
|
|
if (Settings.version < 0x05090102) {
|
|
|
|
Settings.flag2.data = Settings.flag.data;
|
|
|
|
Settings.flag2.data &= 0xFFE80000;
|
2018-01-27 16:52:48 +00:00
|
|
|
Settings.flag2.voltage_resolution = Settings.flag.not_power_linked;
|
2017-11-11 11:33:30 +00:00
|
|
|
Settings.flag2.current_resolution = 3;
|
|
|
|
Settings.ina219_mode = 0;
|
|
|
|
}
|
2018-01-05 11:26:19 +00:00
|
|
|
if (Settings.version < 0x050A0009) {
|
|
|
|
SettingsDefaultSet_5_10_1();
|
|
|
|
}
|
2018-01-27 16:52:48 +00:00
|
|
|
if (Settings.version < 0x050B0107) {
|
|
|
|
Settings.flag.not_power_linked = 0;
|
|
|
|
}
|
2018-03-09 17:08:17 +00:00
|
|
|
if (Settings.version < 0x050C0005) {
|
2018-03-10 16:58:54 +00:00
|
|
|
Settings.light_rotation = 0;
|
2019-05-24 14:04:48 +01:00
|
|
|
Settings.energy_power_delta = 0;
|
2018-03-09 17:08:17 +00:00
|
|
|
char fingerprint[60];
|
|
|
|
memcpy(fingerprint, Settings.mqtt_fingerprint, sizeof(fingerprint));
|
|
|
|
char *p = fingerprint;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 20; i++) {
|
2018-03-09 17:08:17 +00:00
|
|
|
Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16);
|
|
|
|
Settings.mqtt_fingerprint[1][i] = Settings.mqtt_fingerprint[0][i];
|
|
|
|
}
|
|
|
|
}
|
2018-03-18 12:47:30 +00:00
|
|
|
if (Settings.version < 0x050C0007) {
|
2019-08-28 11:02:27 +01:00
|
|
|
Settings.baudrate = APP_BAUDRATE / 300;
|
2018-03-18 12:47:30 +00:00
|
|
|
}
|
2018-03-20 13:31:11 +00:00
|
|
|
if (Settings.version < 0x050C0008) {
|
2019-08-28 11:02:27 +01:00
|
|
|
Settings.sbaudrate = SOFT_BAUDRATE / 300;
|
2018-03-20 13:31:11 +00:00
|
|
|
Settings.serial_delimiter = 0xff;
|
|
|
|
}
|
2018-04-05 11:49:43 +01:00
|
|
|
if (Settings.version < 0x050C000A) {
|
|
|
|
Settings.latitude = (int)((double)LATITUDE * 1000000);
|
|
|
|
Settings.longitude = (int)((double)LONGITUDE * 1000000);
|
|
|
|
}
|
2018-04-10 10:45:53 +01:00
|
|
|
if (Settings.version < 0x050C000B) {
|
2018-05-24 13:25:52 +01:00
|
|
|
Settings.rules[0][0] = '\0';
|
2018-04-10 10:45:53 +01:00
|
|
|
}
|
2018-04-18 16:28:45 +01:00
|
|
|
if (Settings.version < 0x050C000D) {
|
|
|
|
memmove(Settings.rules, Settings.rules -256, sizeof(Settings.rules)); // move rules up by 256 bytes
|
|
|
|
memset(&Settings.timer, 0x00, sizeof(Timer) * MAX_TIMERS); // Reset timers as layout has changed from v5.12.0i
|
|
|
|
Settings.knx_GA_registered = 0;
|
|
|
|
Settings.knx_CB_registered = 0;
|
|
|
|
memset(&Settings.knx_physsical_addr, 0x00, 0x800 - 0x6b8); // Reset until 0x800 for future use
|
|
|
|
}
|
2018-04-30 11:07:48 +01:00
|
|
|
if (Settings.version < 0x050C000F) {
|
2018-05-13 18:43:48 +01:00
|
|
|
Settings.energy_kWhtoday /= 1000;
|
|
|
|
Settings.energy_kWhyesterday /= 1000;
|
|
|
|
RtcSettings.energy_kWhtoday /= 1000;
|
|
|
|
}
|
2018-05-14 22:22:29 +01:00
|
|
|
if (Settings.version < 0x050D0103) {
|
|
|
|
SettingsDefaultSet_5_13_1c();
|
2018-04-30 11:07:48 +01:00
|
|
|
}
|
2018-05-24 13:25:52 +01:00
|
|
|
if (Settings.version < 0x050E0002) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 1; i < MAX_RULE_SETS; i++) { Settings.rules[i][0] = '\0'; }
|
2018-11-04 15:55:12 +00:00
|
|
|
Settings.rule_enabled = Settings.flag.mqtt_serial_raw; // Was rules_enabled until 5.14.0b
|
|
|
|
Settings.rule_once = Settings.flag.pressure_conversion; // Was rules_once until 5.14.0b
|
2018-05-24 13:25:52 +01:00
|
|
|
}
|
2018-06-02 15:59:09 +01:00
|
|
|
if (Settings.version < 0x06000000) {
|
|
|
|
Settings.cfg_size = sizeof(SYSCFG);
|
|
|
|
Settings.cfg_crc = GetSettingsCrc();
|
|
|
|
}
|
2018-06-28 13:28:14 +01:00
|
|
|
if (Settings.version < 0x06000002) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
|
2018-06-28 13:28:14 +01:00
|
|
|
if (i < 4) {
|
2019-01-25 16:46:27 +00:00
|
|
|
Settings.switchmode[i] = Settings.interlock[i];
|
2018-06-28 13:28:14 +01:00
|
|
|
} else {
|
|
|
|
Settings.switchmode[i] = SWITCH_MODE;
|
|
|
|
}
|
|
|
|
}
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
2018-06-28 13:28:14 +01:00
|
|
|
if (Settings.my_gp.io[i] >= GPIO_SWT5) { // Move up from GPIO_SWT5 to GPIO_KEY1
|
|
|
|
Settings.my_gp.io[i] += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-03 11:48:56 +01:00
|
|
|
if (Settings.version < 0x06000003) {
|
2018-11-04 15:55:12 +00:00
|
|
|
Settings.flag.mqtt_serial_raw = 0; // Was rules_enabled until 5.14.0b
|
|
|
|
Settings.flag.pressure_conversion = 0; // Was rules_once until 5.14.0b
|
2018-07-03 11:48:56 +01:00
|
|
|
Settings.flag3.data = 0;
|
|
|
|
}
|
2018-07-20 15:12:37 +01:00
|
|
|
if (Settings.version < 0x06010103) {
|
|
|
|
Settings.flag3.timers_enable = 1;
|
|
|
|
}
|
2018-08-27 11:01:20 +01:00
|
|
|
if (Settings.version < 0x0601010C) {
|
|
|
|
Settings.button_debounce = KEY_DEBOUNCE_TIME;
|
|
|
|
Settings.switch_debounce = SWITCH_DEBOUNCE_TIME;
|
|
|
|
}
|
2018-09-29 15:55:53 +01:00
|
|
|
if (Settings.version < 0x0602010A) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t j = 0; j < 5; j++) {
|
2018-09-29 15:55:53 +01:00
|
|
|
Settings.rgbwwTable[j] = 255;
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 12:00:05 +00:00
|
|
|
if (Settings.version < 0x06030002) {
|
|
|
|
Settings.timezone_minutes = 0;
|
|
|
|
}
|
2018-11-06 16:33:51 +00:00
|
|
|
if (Settings.version < 0x06030004) {
|
2019-05-24 11:28:09 +01:00
|
|
|
memset(&Settings.monitors, 0xFF, 20); // Enable all possible monitors, displays and sensors
|
2018-11-06 16:33:51 +00:00
|
|
|
}
|
2018-12-01 17:53:42 +00:00
|
|
|
if (Settings.version < 0x0603000E) {
|
|
|
|
Settings.flag2.calc_resolution = CALC_RESOLUTION;
|
|
|
|
}
|
2018-12-01 16:47:25 +00:00
|
|
|
if (Settings.version < 0x0603000F) {
|
|
|
|
if (Settings.sleep < 50) {
|
2018-12-01 17:53:42 +00:00
|
|
|
Settings.sleep = 50; // Default to 50 for sleep, for now
|
2018-12-01 16:47:25 +00:00
|
|
|
}
|
2018-11-18 15:49:02 +00:00
|
|
|
}
|
2019-01-03 16:30:54 +00:00
|
|
|
if (Settings.version < 0x06040105) {
|
2019-01-14 09:57:01 +00:00
|
|
|
Settings.flag3.mdns_enabled = MDNS_ENABLED;
|
2019-01-03 16:30:54 +00:00
|
|
|
Settings.param[P_MDNS_DELAYED_START] = 0;
|
|
|
|
}
|
2019-01-25 16:46:27 +00:00
|
|
|
if (Settings.version < 0x0604010B) {
|
2019-01-27 10:02:12 +00:00
|
|
|
Settings.interlock[0] = 0xFF; // Legacy support using all relays in one interlock group
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 1; i < MAX_INTERLOCKS; i++) { Settings.interlock[i] = 0; }
|
2019-01-25 16:46:27 +00:00
|
|
|
}
|
2019-01-30 13:34:31 +00:00
|
|
|
if (Settings.version < 0x0604010D) {
|
|
|
|
Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET;
|
|
|
|
}
|
2019-02-11 18:21:49 +00:00
|
|
|
if (Settings.version < 0x06040110) {
|
|
|
|
ModuleDefault(WEMOS);
|
|
|
|
}
|
2019-02-25 10:14:33 +00:00
|
|
|
if (Settings.version < 0x06040113) {
|
2019-02-24 23:48:03 +00:00
|
|
|
Settings.param[P_RGB_REMAP] = RGB_REMAP_RGBW;
|
|
|
|
}
|
2019-03-28 11:06:48 +00:00
|
|
|
if (Settings.version < 0x06050003) {
|
|
|
|
Settings.novasds_period = WORKING_PERIOD;
|
|
|
|
}
|
2019-04-09 12:56:19 +01:00
|
|
|
if (Settings.version < 0x06050006) {
|
|
|
|
SettingsDefaultWebColor();
|
|
|
|
}
|
2019-04-10 13:26:36 +01:00
|
|
|
if (Settings.version < 0x06050007) {
|
|
|
|
Settings.ledmask = APP_LEDMASK;
|
|
|
|
}
|
2019-05-13 14:56:01 +01:00
|
|
|
if (Settings.version < 0x0605000A) {
|
|
|
|
Settings.my_adc0 = ADC0_NONE;
|
|
|
|
}
|
2019-05-27 10:56:14 +01:00
|
|
|
if (Settings.version < 0x0605000D) {
|
|
|
|
Settings.param[P_IR_UNKNOW_THRESHOLD] = IR_RCV_MIN_UNKNOWN_SIZE;
|
|
|
|
}
|
2019-07-08 13:16:33 +01:00
|
|
|
if (Settings.version < 0x06060001) {
|
|
|
|
Settings.param[P_OVER_TEMP] = ENERGY_OVERTEMP;
|
|
|
|
}
|
2019-08-25 13:58:45 +01:00
|
|
|
if (Settings.version < 0x06060007) {
|
|
|
|
memset((char*)&Settings +0xE00, 0x00, sizeof(SYSCFG) -0xE00);
|
2019-08-27 16:01:12 +01:00
|
|
|
}
|
|
|
|
if (Settings.version < 0x06060008) {
|
2019-08-25 22:10:19 +01:00
|
|
|
// Move current tuya dimmer range to the new param.
|
|
|
|
if (Settings.flag3.tuya_dimmer_range_255) {
|
|
|
|
Settings.param[P_TUYA_DIMMER_MAX] = 100;
|
|
|
|
} else {
|
|
|
|
Settings.param[P_TUYA_DIMMER_MAX] = 255;
|
|
|
|
}
|
2019-08-27 16:01:12 +01:00
|
|
|
Settings.param[P_ENERGY_TARIFF1] = ENERGY_TARIFF1_HOUR;
|
|
|
|
Settings.param[P_ENERGY_TARIFF2] = ENERGY_TARIFF2_HOUR;
|
|
|
|
Settings.flag3.energy_weekend = ENERGY_TARIFF_WEEKEND;
|
2019-08-25 13:58:45 +01:00
|
|
|
}
|
2019-08-28 11:02:27 +01:00
|
|
|
if (Settings.version < 0x06060009) {
|
|
|
|
Settings.baudrate = Settings.ex_baudrate * 4;
|
|
|
|
Settings.sbaudrate = Settings.ex_sbaudrate * 4;
|
|
|
|
}
|
2018-05-13 18:43:48 +01:00
|
|
|
|
2019-09-03 11:23:44 +01:00
|
|
|
if (Settings.version < 0x0606000A) {
|
|
|
|
uint8_t tuyaindex = 0;
|
2019-09-05 09:41:08 +01:00
|
|
|
if (Settings.param[P_ex_TUYA_DIMMER_ID] > 0) { // ex SetOption34
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 21; // TUYA_MCU_FUNC_DIMMER - Move Tuya Dimmer Id to Map
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_DIMMER_ID];
|
2019-09-03 11:23:44 +01:00
|
|
|
tuyaindex++;
|
2019-09-05 15:56:02 +01:00
|
|
|
} else if (Settings.flag3.ex_tuya_disable_dimmer == 1) { // ex SetOption65
|
2019-09-05 09:41:08 +01:00
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 11; // TUYA_MCU_FUNC_REL1 - Create FnID for Switches
|
2019-09-03 11:23:44 +01:00
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = 1;
|
|
|
|
tuyaindex++;
|
|
|
|
}
|
2019-09-05 09:41:08 +01:00
|
|
|
if (Settings.param[P_ex_TUYA_RELAYS] > 0) {
|
|
|
|
for (uint8_t i = 0 ; i < Settings.param[P_ex_TUYA_RELAYS]; i++) { // ex SetOption41
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 12 + i; // TUYA_MCU_FUNC_REL2 - Create FnID for Switches
|
2019-09-03 11:23:44 +01:00
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = i + 2;
|
|
|
|
tuyaindex++;
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 09:41:08 +01:00
|
|
|
if (Settings.param[P_ex_TUYA_POWER_ID] > 0) { // ex SetOption46
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 31; // TUYA_MCU_FUNC_POWER - Move Tuya Power Id to Map
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_POWER_ID];
|
2019-09-03 11:23:44 +01:00
|
|
|
tuyaindex++;
|
|
|
|
}
|
2019-09-05 09:41:08 +01:00
|
|
|
if (Settings.param[P_ex_TUYA_VOLTAGE_ID] > 0) { // ex SetOption44
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 33; // TUYA_MCU_FUNC_VOLTAGE - Move Tuya Voltage Id to Map
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_VOLTAGE_ID];
|
2019-09-03 11:23:44 +01:00
|
|
|
tuyaindex++;
|
|
|
|
}
|
2019-09-05 09:41:08 +01:00
|
|
|
if (Settings.param[P_ex_TUYA_CURRENT_ID] > 0) { // ex SetOption45
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].fnid = 32; // TUYA_MCU_FUNC_CURRENT - Move Tuya Current Id to Map
|
|
|
|
Settings.tuya_fnid_map[tuyaindex].dpid = Settings.param[P_ex_TUYA_CURRENT_ID];
|
2019-09-03 11:23:44 +01:00
|
|
|
tuyaindex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
Settings.version = VERSION;
|
|
|
|
SettingsSave(1);
|
2017-02-19 16:49:17 +00:00
|
|
|
}
|
|
|
|
}
|