From a3ee9e74920db86652ddf125ba542dd2e0f3a8f3 Mon Sep 17 00:00:00 2001 From: wvdv2002 Date: Sun, 11 Nov 2018 16:58:21 +0100 Subject: [PATCH] Cleaned up code and settings --- sonoff/settings.h | 2 +- sonoff/sonoff.h | 2 +- sonoff/sonoff_template.h | 23 ++++----- sonoff/xdrv_18_armtronixDualDimmer.ino | 68 ++------------------------ 4 files changed, 14 insertions(+), 81 deletions(-) diff --git a/sonoff/settings.h b/sonoff/settings.h index fcffe681f..cde1b2283 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -68,7 +68,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t time_append_timezone : 1; // bit 2 (v6.2.1.2) uint32_t gui_hostname_ip : 1; // bit 3 (v6.2.1.20) uint32_t tuya_apply_o20 : 1; // bit 4 (v6.3.0.4) - uint32_t armtronix_apply_o20 : 1; // bit 5 (v????) + uint32_t spare05 : 1; uint32_t spare06 : 1; uint32_t spare07 : 1; uint32_t spare08 : 1; diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index ed23f80f2..1050557c0 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -221,7 +221,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_ARMTRONIX_DIMMER_ID, P_MDNS_DELAYED_START, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) +enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index 412717677..be6b18085 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -133,8 +133,6 @@ enum UserSelectablePins { GPIO_RFRECV, // RF receiver GPIO_TUYA_TX, // Tuya Serial interface GPIO_TUYA_RX, // Tuya Serial interface - GPIO_ARMTRONIX_TX, // ARMTRONIX Serial interface - GPIO_ARMTRONIX_RX, // ARMTRONIX Serial interface GPIO_SENSOR_END }; // Programmer selectable GPIO functionality offset by user selectable GPIOs @@ -192,8 +190,8 @@ const char kSensorNames[] PROGMEM = D_SENSOR_HX711_SCK "|" D_SENSOR_HX711_DAT "|" D_SENSOR_TX20_TX "|" D_SENSOR_RFSEND "|" D_SENSOR_RFRECV "|" - D_SENSOR_TUYA_TX "|" D_SENSOR_TUYA_RX "|" - D_SENSOR_ARMTRONIX_TX "|" D_SENSOR_ARMTRONIX_RX; + D_SENSOR_TUYA_TX "|" D_SENSOR_TUYA_RX; + /********************************************************************************************/ // Supported hardware modules @@ -429,10 +427,6 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_TUYA_TX, // Tuya Serial interface GPIO_TUYA_RX // Tuya Serial interface #endif -#ifdef USE_ARMTRONIX_DIMMERS - GPIO_ARMTRONIX_TX, // Tuya Serial interface - GPIO_ARMTRONIX_RX // Tuya Serial interface -#endif }; const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { @@ -1226,18 +1220,19 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, 0 }, - { "ARMTR Dimmr", // ARMTRONIX Dimmer (ESP8266 w/ separate MCU dimmer) - // https://www.amazon.com/gp/product/B07CTNSZZ8/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 - GPIO_USER, // Virtual Button (controlled by MCU) - GPIO_USER, // GPIO01 MCU serial control + { "ARMTR Dimmer", // ARMTRONIX Dimmer, one or two channel (ESP8266 w/ separate MCU dimmer) + // https://www.tindie.com/products/Armtronix/wifi-ac-dimmer-two-triac-board/ + // https://www.tindie.com/products/Armtronix/wifi-ac-dimmer-esp8266-one-triac-board-alexaecho/ + GPIO_USER, + GPIO_TXD, // GPIO01 MCU serial control GPIO_USER, - GPIO_USER, // GPIO03 MCU serial control + GPIO_RXD, // GPIO03 MCU serial control GPIO_USER, GPIO_USER, 0, 0, 0, 0, 0, 0, // Flash connection GPIO_USER, GPIO_USER, - GPIO_USER, // GPIO14 Green Led + GPIO_USER, GPIO_USER, GPIO_USER, 0 diff --git a/sonoff/xdrv_18_armtronixDualDimmer.ino b/sonoff/xdrv_18_armtronixDualDimmer.ino index 8b4c2ea83..0e440bd7e 100644 --- a/sonoff/xdrv_18_armtronixDualDimmer.ino +++ b/sonoff/xdrv_18_armtronixDualDimmer.ino @@ -23,12 +23,6 @@ #define XDRV_18 18 -#ifndef ARMTRONIX_DIMMER_ID -#define ARMTRONIX_DIMMER_ID 0 -#endif - -#define ARMTRONIX_POWER_ID 1 - #include TasmotaSerial *ArmtronixSerial = nullptr; @@ -45,25 +39,6 @@ int8_t armtronix_knobState[2]; //Dimmer state values. -boolean ArmtronixSetPower() -{ - boolean status = false; - - uint8_t rpower = XdrvMailbox.index; - int16_t source = XdrvMailbox.payload; - - if (source != SRC_SWITCH && ArmtronixSerial) { // ignore to prevent loop from pushing state from faceplate interaction - - snprintf_P(log_data, sizeof(log_data), PSTR("ARM: SetDevicePower.rpower=%d"), rpower); - AddLog(LOG_LEVEL_DEBUG); - //ArmtronixSendBool(ARMTRONIX_POWER_ID, rpower); - - status = true; - } - return status; -} - - void LightSerial2Duty(uint8_t duty1, uint8_t duty2) { if (ArmtronixSerial && !armtronix_ignore_dim) { @@ -76,7 +51,7 @@ void LightSerial2Duty(uint8_t duty1, uint8_t duty2) ArmtronixSerial->print("\nDimmer2:"); ArmtronixSerial->println(duty2); - snprintf_P(log_data, sizeof(log_data), PSTR( "ARM: Send Serial Packet Dim Values=%d,%d (id=%d)"), armtronix_dimState[0],armtronix_dimState[1], Settings.param[P_ARMTRONIX_DIMMER_ID]); + snprintf_P(log_data, sizeof(log_data), PSTR( "ARM: Send Serial Packet Dim Values=%d,%d"), armtronix_dimState[0],armtronix_dimState[1]); AddLog(LOG_LEVEL_DEBUG); } else { @@ -97,28 +72,12 @@ void ArmtronixRequestState(){ } } -void ArmtronixResetWifi() -{ - if (!Settings.flag.button_restrict) { - char scmnd[20]; - snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2); - ExecuteCommand(scmnd, SRC_BUTTON); - } -} - /*********************************************************************************************\ * API Functions \*********************************************************************************************/ boolean ArmtronixModuleSelected() { - if (!(pin[GPIO_ARMTRONIX_RX] < 99) || !(pin[GPIO_ARMTRONIX_TX] < 99)) { // fallback to hardware-serial if not explicitly selected - pin[GPIO_ARMTRONIX_TX] = 1; - pin[GPIO_ARMTRONIX_RX] = 3; - Settings.my_gp.io[1] = GPIO_ARMTRONIX_TX; - Settings.my_gp.io[3] = GPIO_ARMTRONIX_RX; - restart_flag = 2; - } light_type = LT_SERIAL2; return true; } @@ -129,10 +88,7 @@ void ArmtronixInit() armtronix_dimState[1] = -1; armtronix_knobState[0] = -1; armtronix_knobState[1] = -1; - if (!Settings.param[P_ARMTRONIX_DIMMER_ID]) { - Settings.param[P_ARMTRONIX_DIMMER_ID] = ARMTRONIX_DIMMER_ID; - } - ArmtronixSerial = new TasmotaSerial(pin[GPIO_ARMTRONIX_RX], pin[GPIO_ARMTRONIX_TX], 2); + ArmtronixSerial = new TasmotaSerial(pin[GPIO_RXD], pin[GPIO_TXD], 2); if (ArmtronixSerial->begin(115200)) { if (ArmtronixSerial->hardwareSerial()) { ClaimSerial(); } ArmtronixSerial->println("Status"); @@ -171,17 +127,6 @@ void ArmtronixSerialInput() } } -boolean ArmtronixButtonPressed() -{ - if (!XdrvMailbox.index && ((PRESSED == XdrvMailbox.payload) && (NOT_PRESSED == lastbutton[XdrvMailbox.index]))) { - snprintf_P(log_data, sizeof(log_data), PSTR("ARM: Reset GPIO triggered")); - AddLog(LOG_LEVEL_DEBUG); - ArmtronixResetWifi(); - return true; // Reset GPIO served here - } - return false; // Don't serve other buttons -} - void ArmtronixSetWifiLed(){ uint8_t wifi_state = 0x02; switch(WifiState()){ @@ -233,17 +178,10 @@ boolean Xdrv18(byte function) case FUNC_LOOP: if (ArmtronixSerial) { ArmtronixSerialInput(); } break; - case FUNC_SET_DEVICE_POWER: - result = ArmtronixSetPower(); - break; - case FUNC_BUTTON_PRESSED: - result = ArmtronixButtonPressed(); - break; case FUNC_EVERY_SECOND: if(ArmtronixSerial){ - flip = !flip; if (armtronix_wifi_state!=WifiState()) { ArmtronixSetWifiLed(); } - if(flip){ + if(uptime&1){ ArmtronixSerial->println("Status"); } }