Browse Source

Prepare configuration for version 2.0

fastled
Xose Pérez 7 years ago
parent
commit
4b0d9e4a21
5 changed files with 292 additions and 0 deletions
  1. +2
    -0
      code/espurna/config/arduino.h
  2. +2
    -0
      code/espurna/config/prototypes.h
  3. +3
    -0
      code/espurna/espurna.ino
  4. +259
    -0
      code/espurna/hardware.ino
  5. +26
    -0
      code/espurna/settings.ino

+ 2
- 0
code/espurna/config/arduino.h View File

@ -32,6 +32,8 @@
//#define SONOFF_SV //#define SONOFF_SV
//#define SONOFF_POW //#define SONOFF_POW
//#define SONOFF_DUAL //#define SONOFF_DUAL
//#define ITEAD_1CH_INCHING
//#define ITEAD_MOTOR
//#define SONOFF_4CH //#define SONOFF_4CH
//#define ESP_RELAY_BOARD //#define ESP_RELAY_BOARD
//#define ECOPLUG //#define ECOPLUG


+ 2
- 0
code/espurna/config/prototypes.h View File

@ -11,6 +11,8 @@ void apiRegister(const char * url, const char * key, apiGetCallbackFunction getF
void mqttRegister(void (*callback)(unsigned int, const char *, const char *)); void mqttRegister(void (*callback)(unsigned int, const char *, const char *));
String mqttSubtopic(char * topic); String mqttSubtopic(char * topic);
template<typename T> bool setSetting(const String& key, T value); template<typename T> bool setSetting(const String& key, T value);
template<typename T> bool setSetting(const String& key, unsigned int index, T value);
template<typename T> String getSetting(const String& key, T defaultValue); template<typename T> String getSetting(const String& key, T defaultValue);
template<typename T> String getSetting(const String& key, unsigned int index, T defaultValue);
template<typename T> void domoticzSend(const char * key, T value); template<typename T> void domoticzSend(const char * key, T value);
template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue); template<typename T> void domoticzSend(const char * key, T nvalue, const char * svalue);

+ 3
- 0
code/espurna/espurna.ino View File

@ -197,6 +197,9 @@ void setup() {
powerMonitorSetup(); powerMonitorSetup();
#endif #endif
// Prepare configuration for version 2.0
hwUpwardsCompatibility();
} }
void loop() { void loop() {


+ 259
- 0
code/espurna/hardware.ino View File

@ -0,0 +1,259 @@
/*
HARDWARE MODULE
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
/*
The goal of this file is to store board configuration values in EEPROM so
the migration to future version 2 will be straigh forward.
*/
#define RELAY_PROVIDER_RELAY 0
#define RELAY_PROVIDER_DUAL 1
#define RELAY_PROVIDER_LIGHT 2
#define LIGHT_PROVIDER_NONE 0
#define LIGHT_PROVIDER_WS2812 1
#define LIGHT_PROVIDER_RGB 2
#define LIGHT_PROVIDER_RGBW 3
#define LIGHT_PROVIDER_MY9192 4
void hwUpwardsCompatibility() {
unsigned int board = getSetting("board", 0).toInt();
if (board > 0) return;
#if NODEMCUV2
setSetting("board", 2);
setSetting("ledGPIO", 1, 2);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if D1_RELAYSHIELD
setSetting("board", 3);
setSetting("ledGPIO", 1, 2);
setSetting("ledLogic", 1, 1);
setSetting("relayGPIO", 1, 5);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF
setSetting("board", 4);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_TH
setSetting("board", 5);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_SV
setSetting("board", 6);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_TOUCH
setSetting("board", 7);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_POW
setSetting("board", 8);
setSetting("ledGPIO", 1, 15);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_DUAL
setSetting("board", 9);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnRelay", 3, 1);
setSetting("relayProvider", RELAY_PROVIDER_DUAL);
#endif
#if ITEAD_1CH_INCHING
setSetting("board", 10);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if SONOFF_4CH
setSetting("board", 11);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnGPIO", 2, 9);
setSetting("btnGPIO", 3, 10);
setSetting("btnGPIO", 4, 14);
setSetting("btnRelay", 1, 2);
setSetting("btnRelay", 2, 3);
setSetting("btnRelay", 3, 4);
setSetting("btnRelay", 4, 0);
setSetting("relayGPIO", 1, 12);
setSetting("relayGPIO", 2, 5);
setSetting("relayGPIO", 3, 4);
setSetting("relayGPIO", 4, 15);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
setSetting("relayLogic", 3, 0);
setSetting("relayLogic", 4, 0);
#endif
#if SLAMPHER
setSetting("board", 12);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if S20
setSetting("board", 13);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if ESP_RELAY_BOARD
setSetting("board", 14);
setSetting("ledGPIO", 1, 16);
setSetting("ledLogic", 1, 0);
setSetting("btnGPIO", 1, 0);
setSetting("btnGPIO", 2, 2);
setSetting("btnRelay", 1, 1);
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 12);
setSetting("relayGPIO", 2, 13);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
#endif
#if ECOPLUG
setSetting("board", 15);
setSetting("ledGPIO", 1, 2);
setSetting("ledLogic", 1, 0);
setSetting("btnGPIO", 1, 13);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 15);
setSetting("relayLogic", 1, 0);
#endif
#if WIFI_RELAY_NC
setSetting("board", 16);
setSetting("btnGPIO", 1, 12);
setSetting("btnGPIO", 2, 13);
setSetting("btnRelay", 1, 1);
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 2);
setSetting("relayGPIO", 2, 14);
setSetting("relayLogic", 1, 1);
setSetting("relayLogic", 2, 1);
#endif
#if WIFI_RELAY_NO
setSetting("board", 17);
setSetting("btnGPIO", 1, 12);
setSetting("btnGPIO", 2, 13);
setSetting("btnRelay", 1, 1);
setSetting("btnRelay", 2, 2);
setSetting("relayGPIO", 1, 2);
setSetting("relayGPIO", 2, 14);
setSetting("relayLogic", 1, 0);
setSetting("relayLogic", 2, 0);
#endif
#if MQTT_RELAY
setSetting("board", 18);
setSetting("ledGPIO", 1, 16);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
#if WIFI_RELAYS_BOARD_KIT
setSetting("board", 19);
setSetting("relayGPIO", 1, 0);
setSetting("relayLogic", 1, 1);
setSetting("relayGPIO", 2, 2);
setSetting("relayLogic", 2, 1);
#endif
#if AI_LIGHT
setSetting("board", 20);
setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
setSetting("lightProvider", LIGHT_PROVIDER_MY9192);
setSetting("myDIGPIO", 13);
setSetting("myDCKIGPIO", 15);
#endif
#if LED_CONTROLLER
setSetting("board", 21);
setSetting("relayProvider", RELAY_PROVIDER_LIGHT);
setSetting("lightProvider", LIGHT_PROVIDER_RGB);
setSetting("ledGPIO", 1, 2);
setSetting("ledLogic", 1, 1);
setSetting("redGPIO", 14);
setSetting("greenGPIO", 5);
setSetting("blueGPIO", 12);
setSetting("whiteGPIO", 13);
setSetting("lightLogic", 1);
#endif
#if ITEAD_MOTOR
setSetting("board", 22);
setSetting("ledGPIO", 1, 13);
setSetting("ledLogic", 1, 1);
setSetting("btnGPIO", 1, 0);
setSetting("btnRelay", 1, 1);
setSetting("relayGPIO", 1, 12);
setSetting("relayLogic", 1, 0);
#endif
saveSettings();
}

+ 26
- 0
code/espurna/settings.ino View File

@ -172,12 +172,22 @@ void settingsLoop() {
embedis.process(); embedis.process();
} }
void moveSetting(const char * from, const char * to) {
String value = getSetting(from);
if (value.length() > 0) setSetting(to, value);
delSetting(from);
}
template<typename T> String getSetting(const String& key, T defaultValue) { template<typename T> String getSetting(const String& key, T defaultValue) {
String value; String value;
if (!Embedis::get(key, value)) value = String(defaultValue); if (!Embedis::get(key, value)) value = String(defaultValue);
return value; return value;
} }
template<typename T> String getSetting(const String& key, unsigned int index, T defaultValue) {
return getSetting(key + String(index), defaultValue);
}
String getSetting(const String& key) { String getSetting(const String& key) {
return getSetting(key, ""); return getSetting(key, "");
} }
@ -186,10 +196,26 @@ template<typename T> bool setSetting(const String& key, T value) {
return Embedis::set(key, String(value)); return Embedis::set(key, String(value));
} }
template<typename T> bool setSetting(const String& key, unsigned int index, T value) {
return setSetting(key + String(index), value);
}
bool delSetting(const String& key) { bool delSetting(const String& key) {
return Embedis::del(key); return Embedis::del(key);
} }
bool delSetting(const String& key, unsigned int index) {
return delSetting(key + String(index));
}
bool hasSetting(const String& key) {
return getSetting(key).length() != 0;
}
bool hasSetting(const String& key, unsigned int index) {
return getSetting(key, index, "").length() != 0;
}
void saveSettings() { void saveSettings() {
DEBUG_MSG_P(PSTR("[SETTINGS] Saving\n")); DEBUG_MSG_P(PSTR("[SETTINGS] Saving\n"));
#if not AUTO_SAVE #if not AUTO_SAVE


Loading…
Cancel
Save