mirror of https://github.com/arendst/Tasmota.git
use Switch mode definitions
This commit is contained in:
parent
fa27a0881d
commit
2a8d8f9874
|
@ -231,9 +231,9 @@ void SwitchHandler(uint8_t mode)
|
|||
uint8_t button = Switch.virtual_state[i];
|
||||
uint8_t switchflag = POWER_TOGGLE +1;
|
||||
|
||||
if (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? 0x3F: 0xFF)) {
|
||||
if (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) {
|
||||
Switch.hold_timer[i]--;
|
||||
if ((Switch.hold_timer[i] & 0x3F) == loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) == loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if ((Settings.switchmode[i] == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) {
|
||||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ void SwitchHandler(uint8_t mode)
|
|||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||
}
|
||||
}
|
||||
if (0 == (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? 0x3F: 0xFF))) {
|
||||
if (0 == (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) {
|
||||
switch (Settings.switchmode[i]) {
|
||||
case TOGGLEMULTI:
|
||||
switchflag = POWER_TOGGLE; // Toggle after hold
|
||||
|
@ -329,14 +329,14 @@ void SwitchHandler(uint8_t mode)
|
|||
break;
|
||||
case PUSHHOLDMULTI:
|
||||
if (NOT_PRESSED == button) {
|
||||
if ((Switch.hold_timer[i] & 0x3F) != 0) {
|
||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & 0xc0) == 0x40) ? 0x80 : 0;
|
||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK)) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
||||
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
||||
}
|
||||
} else {
|
||||
if ((Switch.hold_timer[i] & 0x3F) > loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if((Switch.hold_timer[i] & 0xC0) != 0x80) {
|
||||
Switch.hold_timer[i]= 0x40;
|
||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) > loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
||||
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
||||
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
||||
}
|
||||
else{
|
||||
|
@ -348,18 +348,18 @@ void SwitchHandler(uint8_t mode)
|
|||
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
||||
}
|
||||
}
|
||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & 0xC0) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||
break;
|
||||
case PUSHHOLDMULTI_INV:
|
||||
if (PRESSED == button) {
|
||||
if ((Switch.hold_timer[i] & 0x3F) != 0) {
|
||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & 0xc0) == 0x40) ? 0x80 : 0;
|
||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
||||
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
||||
}
|
||||
} else {
|
||||
if ((Switch.hold_timer[i] & 0x3F)> loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if((Switch.hold_timer[i] & 0xC0) != 0x80) {
|
||||
Switch.hold_timer[i]= 0x40;
|
||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK)> loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
||||
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
||||
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
||||
}
|
||||
else{
|
||||
|
@ -371,7 +371,7 @@ void SwitchHandler(uint8_t mode)
|
|||
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
||||
}
|
||||
}
|
||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & 0xC0) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||
break;
|
||||
case PUSHON:
|
||||
if (PRESSED == button) {
|
||||
|
|
|
@ -209,6 +209,12 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to
|
|||
#define KNX_MAX_device_param 31
|
||||
#define MAX_KNXTX_CMNDS 5
|
||||
|
||||
// Switch Mode definietions
|
||||
#define SM_TIMER_MASK 0x3F
|
||||
#define SM_NO_TIMER_MASK 0xFF
|
||||
#define SM_FIRST_PRESS 0x40
|
||||
#define SM_SECOND_PRESS 0x80
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Enumeration
|
||||
\*********************************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue