Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
#24 added possibility to choose between GPIO14 Switch "Schalter (abso…
Browse files Browse the repository at this point in the history
…lut)" and "Schalter (toggle)"
  • Loading branch information
jp112sdl committed Nov 16, 2017
1 parent 2aefd44 commit 7b65a33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
10 changes: 7 additions & 3 deletions SonoffHMLOX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ enum TransmitStates_e {
enum GPIO14Modes_e {
GPIO14Mode_OFF,
GPIO14Mode_KEY,
GPIO14Mode_SWITCH
GPIO14Mode_SWITCH_ABSOLUT,
GPIO14Mode_SWITCH_TOGGLE
};

struct globalconfig_t {
Expand Down Expand Up @@ -390,14 +391,17 @@ void loop() {

CurrentSwitchGPIO14State = digitalRead(SwitchGPIOPin14);
//GPIO14 als Schalter
if (GlobalConfig.GPIO14Mode == GPIO14Mode_SWITCH) {
if (GlobalConfig.GPIO14Mode == GPIO14Mode_SWITCH_ABSOLUT || GlobalConfig.GPIO14Mode == GPIO14Mode_SWITCH_TOGGLE) {
if (CurrentSwitchGPIO14State != LastSwitchGPIOPin14State) {
DEBUG("GPIO14 neuer Status = " + String(CurrentSwitchGPIO14State), "loop()", _slInformational);
LastSwitchGPIOPin14State = CurrentSwitchGPIO14State;
if (GlobalConfig.GPIO14asSender) {
if (GlobalConfig.BackendType == BackendType_HomeMatic) setStateCUxD(HomeMaticConfig.ChannelNameSender + ".SET_STATE", (!CurrentSwitchGPIO14State ? "true" : "false"));
} else {
switchRelay(!CurrentSwitchGPIO14State, TRANSMITSTATE); //HIGH = off, LOW = on
if (GlobalConfig.GPIO14Mode == GPIO14Mode_SWITCH_ABSOLUT)
switchRelay(!CurrentSwitchGPIO14State, TRANSMITSTATE); //HIGH = off, LOW = on
if (GlobalConfig.GPIO14Mode == GPIO14Mode_SWITCH_TOGGLE)
toggleRelay(TRANSMITSTATE);
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions Web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const char HTTP_CALIB_INPUT[] PROGMEM = "<div><table><tr><td>Last (W):</td><td a
const char HTTP_DOCALIB_BUTTON[] PROGMEM = "<div><button name='doCalibrate' value='1' type='submit'>Kalibrieren</button></div>";
const char HTTP_UNDOCALIB_BUTTON[] PROGMEM = "<div><button name='undoCalibrate' value='1' type='submit'>Kalib. Reset</button></div>";
const char HTTP_CONF[] PROGMEM = "<div><label>{st}:</label></div><div><input type='text' id='ccuip' name='ccuip' pattern='((^|\\.)((25[0-5])|(2[0-4]\\d)|(1\\d\\d)|([1-9]?\\d))){4}$' maxlength=16 placeholder='{st}' value='{ccuip}'></div><div><label>Ger&auml;tename:</label></div><div><input type='text' id='devicename' name='devicename' pattern='[A-Za-z0-9_ -]+' placeholder='Ger&auml;tename' value='{dn}'></div><div><label for='rstate' class='lcb' title='Stellt den Schaltzustand nach einer Stromunterbrechung wiederher'><input class 'cb' id='rstate' type='checkbox' name='rstate' {rs} value=1> {remanenz}</label></div>";
const char HTTP_CONF_ADD_SWITCH[] PROGMEM = "<div id='div_gpio14mode'><label for='gpio14mode'>GPIO14 Mode</label><span class='ckb cob'><select id='gpio14mode' name='gpio14mode'><option {gpio14mode_off} value='0'>nicht verwendet</option><option {gpio14mode_key} value='1'>Taster</option><option {gpio14mode_switch} value='2'>Schalter</option></select></span></div><div><label class='lcb' for='gpio14assender'><input id='gpio14assender' class='cb' type='checkbox' name='gpio14assender' {gpio14assender} value=1> GPIO14 nur Sender</label></div><div><label class='lcb' for='leddisabled'><input id='leddisabled' class='cb' type='checkbox' name='leddisabled' {le} value=1> LED deaktiviert</label></div>";
const char HTTP_CONF_ADD_SWITCH[] PROGMEM = "<div id='div_gpio14mode'><label for='gpio14mode'>GPIO14 Mode</label><span class='ckb cob'><select id='gpio14mode' name='gpio14mode'><option {gpio14mode_off} value='0'>nicht verwendet</option><option {gpio14mode_key} value='1'>Taster</option><option {gpio14mode_switch_abs} value='2'>Schalter (absolut)</option><option {gpio14mode_switch_tog} value='3'>Schalter (toggle)</option></select></span></div><div><label class='lcb' for='gpio14assender'><input id='gpio14assender' class='cb' type='checkbox' name='gpio14assender' {gpio14assender} value=1> GPIO14 nur Sender</label></div><div><label class='lcb' for='leddisabled'><input id='leddisabled' class='cb' type='checkbox' name='leddisabled' {le} value=1> LED deaktiviert</label></div>";
const char HTTP_CONF_POW_MEASURE_INTERVAL[] PROGMEM = "<div></div><div><label>Messintervall</label></div><div><input type='text' id='measureinterval' name='measureinterval' placeholder='Messintervall' pattern='[0-9]{2,3}' value='{mi}'></div>";
const char HTTP_CONF_LOX[] PROGMEM = "<div><label>UDP Port:</label></div><div><input type='text' id='lox_udpport' pattern='[0-9]{1,5}' maxlength='5' name='lox_udpport' placeholder='UDP Port' value='{udp}'></div>";
const char HTTP_CONF_HM_POW[] PROGMEM = "<div><label>Variable f&uuml;r Leistungswert:</label></div><div><input type='text' id='hmpowvar' name='hmpowvar' placeholder='Variablenname' value='{hmpowvar}' pattern='[A-Za-z0-9_ -]+'></div>";
Expand Down Expand Up @@ -221,6 +221,7 @@ void configHtml() {
if (WebServer.args() > 0) {
GlobalConfig.restoreOldRelayState = false;
GlobalConfig.LEDDisabled = false;
GlobalConfig.GPIO14asSender = false;
for (int i = 0; i < WebServer.args(); i++) {
if (WebServer.argName(i) == "btnSave")
sc = (WebServer.arg(i).toInt() == 1);
Expand Down Expand Up @@ -278,22 +279,32 @@ void configHtml() {
case GPIO14Mode_OFF:
page.replace("{gpio14mode_off}", "selected");
page.replace("{gpio14mode_key}", "");
page.replace("{gpio14mode_switch}", "");
page.replace("{gpio14mode_switch_abs}", "");
page.replace("{gpio14mode_switch_tog}", "");
break;
case GPIO14Mode_KEY:
page.replace("{gpio14mode_off}", "");
page.replace("{gpio14mode_key}", "selected");
page.replace("{gpio14mode_switch}", "");
page.replace("{gpio14mode_switch_abs}", "");
page.replace("{gpio14mode_switch_tog}", "");
break;
case GPIO14Mode_SWITCH:
case GPIO14Mode_SWITCH_ABSOLUT:
page.replace("{gpio14mode_off}", "");
page.replace("{gpio14mode_key}", "");
page.replace("{gpio14mode_switch}", "selected");
page.replace("{gpio14mode_switch_abs}", "selected");
page.replace("{gpio14mode_switch_tog}", "");
break;
case GPIO14Mode_SWITCH_TOGGLE:
page.replace("{gpio14mode_off}", "");
page.replace("{gpio14mode_key}", "");
page.replace("{gpio14mode_switch_abs}", "");
page.replace("{gpio14mode_switch_tog}", "selected");
break;
default:
page.replace("{gpio14mode_off}", "selected");
page.replace("{gpio14mode_key}", "");
page.replace("{gpio14mode_switch}", "");
page.replace("{gpio14mode_switch_abs}", "");
page.replace("{gpio14mode_switch_tog}", "");
break;
}
page.replace("{gpio14assender}", ((GlobalConfig.GPIO14asSender) ? "checked" : ""));
Expand Down
13 changes: 8 additions & 5 deletions WifiManager.ino
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,23 @@ bool doWifiConnect() {
String gpio14 = "";
switch (GlobalConfig.GPIO14Mode) {
case GPIO14Mode_OFF:
gpio14 = F("<option selected value='0'>nicht verwendet</option><option value='1'>Taster</option><option value='2'>Schalter</option>");
gpio14 = F("<option selected value='0'>nicht verwendet</option><option value='1'>Taster</option><option value='2'>Schalter (absolut)</option><option value='3'>Schalter (toggle)</option>");
break;
case GPIO14Mode_KEY:
gpio14 = F("<option value='0'>nicht verwendet</option><option selected value='1'>Taster</option><option value='2'>Schalter</option>");
gpio14 = F("<option value='0'>nicht verwendet</option><option selected value='1'>Taster</option><option value='2'>Schalter (absolut)</option><option value='3'>Schalter (toggle)</option>");
break;
case GPIO14Mode_SWITCH_ABSOLUT:
gpio14 = F("<option value='0'>nicht verwendet</option><option value='1'>Taster</option><option selected value='2'>Schalter (absolut)</option><option value='3'>Schalter (toggle)</option>");
break;
case GPIO14Mode_SWITCH:
gpio14 = F("<option value='0'>nicht verwendet</option><option value='1'>Taster</option><option selected value='2'>Schalter</option>");
case GPIO14Mode_SWITCH_TOGGLE:
gpio14 = F("<option value='0'>nicht verwendet</option><option value='1'>Taster</option><option value='2'>Schalter (absolut)</option><option selected value='3'>Schalter (toggle)</option>");
break;
default:
gpio14 = F("<option selected value='0'>nicht verwendet</option><option value='1'>Taster</option><option value='2'>Schalter</option>");
break;
}
WiFiManagerParameter custom_gpio14mode("gpio14mode_switch", "GPIO14 Mode", "", 8, 2, gpio14.c_str());

char*chrGPIO14asSender = "0";
if (GlobalConfig.GPIO14asSender) chrGPIO14asSender = "1" ;
WiFiManagerParameter custom_gpio14assender("custom_gpio14assender_switch", "GPIO14 nur Sender: ", chrGPIO14asSender, 8, 1);
Expand Down

0 comments on commit 7b65a33

Please sign in to comment.