diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 529dfcfe..1d39a35f 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -77,10 +77,10 @@ void buttonSetup() { _buttons.push_back(new DebounceEvent(BUTTON4_PIN)); #endif - #ifdef ITEAD_1CH_INCHING - pinMode(LED_INCHING, OUTPUT); - byte relayInch = getSetting("relayInch", String(RELAY_INCHING)).toInt(); - digitalWrite(LED_INCHING, relayInch != RELAY_INCHING_NONE); + #ifdef LED_PULSE + pinMode(LED_PULSE, OUTPUT); + byte relayPulseMode = getSetting("relayPulseMode", String(RELAY_PULSE_MODE)).toInt(); + digitalWrite(LED_PULSE, relayPulseMode != RELAY_PULSE_NONE); #endif DEBUG_MSG("[BUTTON] Number of buttons: %d\n", _buttons.size()); @@ -99,7 +99,7 @@ void buttonLoop() { } #ifdef ITEAD_1CH_INCHING if (i == 1) { - relayInchingToggle(); + relayPulseToggle(); continue; } #endif diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index c8d0fdad..7b23d978 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -20,12 +20,12 @@ #define RELAY_SYNC_ONE 2 #define RELAY_SYNC_SAME 3 -#define RELAY_INCHING_NONE 0 -#define RELAY_INCHING_OFF 1 -#define RELAY_INCHING_ON 2 +#define RELAY_PULSE_NONE 0 +#define RELAY_PULSE_OFF 1 +#define RELAY_PULSE_ON 2 -// Inching time in seconds -#define RELAY_INCHING_TIME 1 +// Pulse time in seconds +#define RELAY_PULSE_TIME 1 // 0 means OFF, 1 ON and 2 whatever was before #define RELAY_MODE RELAY_MODE_OFF @@ -33,8 +33,8 @@ // 0 means ANY, 1 zero or one and 2 one and only one #define RELAY_SYNC RELAY_SYNC_ANY -// 0 means no inching, 1 means normally off, 2 normally on -#define RELAY_INCHING RELAY_INCHING_NONE +// 0 means no pulses, 1 means normally off, 2 normally on +#define RELAY_PULSE_MODE RELAY_PULSE_NONE //-------------------------------------------------------------------------------- // LED diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index f5f67cf8..289bfac5 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -158,6 +158,10 @@ #elif defined(ITEAD_1CH_INCHING) + // Note: definitions for this board are based on third party data + // and have not been fully tested yet. If you have the chance to + // test them, please report back. Thank you. + #define MANUFACTURER "ITEAD" #define DEVICE "1CH_INCHING" #define BUTTON1_PIN 0 @@ -165,7 +169,7 @@ #define RELAY1_PIN 12 #define LED1_PIN 13 #define LED1_PIN_INVERSE 0 - #define LED_INCHING 14 + #define LED_PULSE 14 // ----------------------------------------------------------------------------- // Electrodragon boards diff --git a/code/espurna/data/index.html.gz b/code/espurna/data/index.html.gz index 2e18235d..006c0967 100644 Binary files a/code/espurna/data/index.html.gz and b/code/espurna/data/index.html.gz differ diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 9e896cab..cf8eeb29 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -21,7 +21,7 @@ bool recursive = false; #ifdef SONOFF_DUAL unsigned char dualRelayStatus = 0; #endif -Ticker inching; +Ticker pulseTicker; // ----------------------------------------------------------------------------- // RELAY @@ -69,69 +69,69 @@ bool relayStatus(unsigned char id) { #endif } -void relayInchingBack(unsigned char id) { +void relayPulseBack(unsigned char id) { relayToggle(id); - inching.detach(); + pulseTicker.detach(); } -void relayInchingStart(unsigned char id) { +void relayPulseStart(unsigned char id) { - byte relayInch = getSetting("relayInch", RELAY_INCHING).toInt(); - if (relayInch == RELAY_INCHING_NONE) return; + byte relayPulseMode = getSetting("relayPulseMode", RELAY_PULSE_MODE).toInt(); + if (relayPulseMode == RELAY_PULSE_NONE) return; bool status = relayStatus(id); - bool inchingStatus = (relayInch == RELAY_INCHING_ON); - if (inchingStatus == status) { - inching.detach(); + bool pulseStatus = (relayPulseMode == RELAY_PULSE_ON); + if (pulseStatus == status) { + pulseTicker.detach(); return; } - inching.attach( - getSetting("relayInchTime", RELAY_INCHING_TIME).toInt(), - relayInchingBack, + pulseTicker.attach( + getSetting("relayPulseTime", RELAY_PULSE_TIME).toInt(), + relayPulseBack, id ); } -unsigned int relayInching() { - unsigned int relayInch = getSetting("relayInch", RELAY_INCHING).toInt(); - return relayInch; +unsigned int relayPulseMode() { + unsigned int value = getSetting("relayPulseMode", RELAY_PULSE_MODE).toInt(); + return value; } -void relayInching(unsigned int relayInch, bool report) { +void relayPulseMode(unsigned int value, bool report) { - setSetting("relayInch", relayInch); + setSetting("relayPulseMode", value); /* if (report) { String mqttGetter = getSetting("mqttGetter", MQTT_USE_GETTER); char topic[strlen(MQTT_RELAY_TOPIC) + mqttGetter.length() + 10]; - sprintf(topic, "%s/inching%s", MQTT_RELAY_TOPIC, mqttGetter.c_str()); + sprintf(topic, "%s/pulse%s", MQTT_RELAY_TOPIC, mqttGetter.c_str()); char value[2]; - sprintf(value, "%d", relayInch); + sprintf(value, "%d", value); mqttSend(topic, value); } */ char message[20]; - sprintf(message, "{\"relayInch\": %d}", relayInch); + sprintf(message, "{\"relayPulseMode\": %d}", value); wsSend(message); - #ifdef LED_INCHING - digitalWrite(LED_INCHING, relayInch != RELAY_INCHING_NONE); + #ifdef LED_PULSE + digitalWrite(LED_PULSE, relayPulseMode != RELAY_PULSE_NONE); #endif } -void relayInching(unsigned int relayInch) { - relayInching(relayInch, true); +void relayPulseMode(unsigned int value) { + relayPulseMode(value, true); } -void relayInchingToggle() { - unsigned int relayInch = relayInching(); - relayInch = (relayInch == RELAY_INCHING_NONE) ? RELAY_INCHING_OFF : RELAY_INCHING_NONE; - relayInching(relayInch); +void relayPulseToggle() { + unsigned int value = relayPulseMode(); + value = (value == RELAY_PULSE_NONE) ? RELAY_PULSE_OFF : RELAY_PULSE_NONE; + relayPulseMode(value); } bool relayStatus(unsigned char id, bool status, bool report) { @@ -160,7 +160,7 @@ bool relayStatus(unsigned char id, bool status, bool report) { #endif if (!recursive) { - relayInchingStart(id); + relayPulseStart(id); relaySync(id); relaySave(); } @@ -263,7 +263,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo sprintf(buffer, "%s/+%s", MQTT_RELAY_TOPIC, mqttSetter.c_str()); mqttSubscribe(buffer); - sprintf(buffer, "%s/inching%s", MQTT_RELAY_TOPIC, mqttSetter.c_str()); + sprintf(buffer, "%s/pulse%s", MQTT_RELAY_TOPIC, mqttSetter.c_str()); mqttSubscribe(buffer); } @@ -278,9 +278,9 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo // Get value unsigned int value = (char)payload[0] - '0'; - // Inching topic - if (t.indexOf("inching") > 0) { - relayInching(value, !sameSetGet); + // Pulse topic + if (t.indexOf("pulse") > 0) { + relayPulseMode(value, !sameSetGet); return; } diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 151deb7d..bb2df58f 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -237,8 +237,8 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) { #endif #if ITEAD_1CH_INCHING - byte relayInch = getSetting("relayInch", String(RELAY_INCHING)).toInt(); - digitalWrite(LED_INCHING, relayInch != RELAY_INCHING_NONE); + byte relayPulseMode = getSetting("relayPulseMode", String(RELAY_PULSE_MODE)).toInt(); + digitalWrite(LED_PULSE, relayPulseMode != RELAY_PULSE_NONE); #endif // Check if we should reconfigure MQTT connection @@ -291,8 +291,8 @@ void _wsStart(uint32_t client_id) { relay.add(relayStatus(relayID)); } root["relayMode"] = getSetting("relayMode", RELAY_MODE); - root["relayInch"] = getSetting("relayInch", RELAY_INCHING); - root["relayInchTime"] = getSetting("relayInchTime", RELAY_INCHING_TIME); + root["relayPulseMode"] = getSetting("relayPulseMode", RELAY_PULSE_MODE); + root["relayPulseTime"] = getSetting("relayPulseTime", RELAY_PULSE_TIME); if (relayCount() > 1) { root["multirelayVisible"] = 1; root["relaySync"] = getSetting("relaySync", RELAY_SYNC); diff --git a/code/html/index.html b/code/html/index.html index 82ab1ba9..48b1b969 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -197,23 +197,23 @@
- +
- +
 
-
When inching enable the relay will automatically switch back to its normal state after the inching time (below).
+
When pulse mode is enabled the relay will automatically switch back to its normal state after the pulse time (below).
- - + +
 
-
Inching time in seconds.
+
Pulse time in seconds.