Browse Source

Rename inching to pulse

fastled
Xose Pérez 8 years ago
parent
commit
e2cb9fcaa0
7 changed files with 61 additions and 57 deletions
  1. +5
    -5
      code/espurna/button.ino
  2. +7
    -7
      code/espurna/config/general.h
  3. +5
    -1
      code/espurna/config/hardware.h
  4. BIN
      code/espurna/data/index.html.gz
  5. +33
    -33
      code/espurna/relay.ino
  6. +4
    -4
      code/espurna/web.ino
  7. +7
    -7
      code/html/index.html

+ 5
- 5
code/espurna/button.ino View File

@ -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


+ 7
- 7
code/espurna/config/general.h View File

@ -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


+ 5
- 1
code/espurna/config/hardware.h View File

@ -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


BIN
code/espurna/data/index.html.gz View File


+ 33
- 33
code/espurna/relay.ino View File

@ -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;
}


+ 4
- 4
code/espurna/web.ino View File

@ -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);


+ 7
- 7
code/html/index.html View File

@ -197,23 +197,23 @@
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="relayInch">Relay inching mode</label>
<label class="pure-u-1 pure-u-md-1-4" for="relayPulseMode">Relay pulse mode</label>
<div class="pure-u-1 pure-u-md-3-4">
<select name="relayInch" class="pure-u-1-2" tabindex="4">
<option value="0">No inching</a>
<select name="relayPulseMode" class="pure-u-1-2" tabindex="4">
<option value="0">Don't pulse</a>
<option value="1">Normally OFF (stays on for a brief interval)</a>
<option value="2">Normally ON (stays off for a brief interval)</a>
</select>
</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">When inching enable the relay will automatically switch back to its normal state after the inching time (below).</div>
<div class="pure-u-1 pure-u-md-3-4 hint">When pulse mode is enabled the relay will automatically switch back to its normal state after the pulse time (below).</div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-md-1-4" for="relayInchTime">Relay inching time</label>
<input name="relayInchTime" class="pure-u-1 pure-u-md-3-4" type="number" min="1" tabindex="5" />
<label class="pure-u-1 pure-u-md-1-4" for="relayPulseTime">Relay pulse time</label>
<input name="relayPulseTime" class="pure-u-1 pure-u-md-3-4" type="number" min="1" tabindex="5" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Inching time in seconds.</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Pulse time in seconds.</div>
</div>
<div class="pure-g module module-fauxmo">


Loading…
Cancel
Save