Add Rotary features

Add On/Off functionality to rotary dial (#8263)
This commit is contained in:
Theo Arends 2020-07-12 18:53:57 +02:00
parent 763c8b637e
commit 96d37ec535
2 changed files with 11 additions and 9 deletions

View File

@ -303,7 +303,7 @@ void ButtonHandler(void)
} }
} }
#ifdef ROTARY_V1 #ifdef ROTARY_V1
if (!((0 == button_index) && RotaryButtonPressed())) { if (!RotaryButtonPressed(button_index)) {
#endif #endif
if (!Settings.flag3.mqtt_buttons && single_press && SendKey(KEY_BUTTON, button_index + Button.press_counter[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set if (!Settings.flag3.mqtt_buttons && single_press && SendKey(KEY_BUTTON, button_index + Button.press_counter[button_index], POWER_TOGGLE)) { // Execute Toggle command via MQTT if ButtonTopic is set
// Success // Success

View File

@ -91,13 +91,6 @@ struct ROTARY {
void update_rotary(void) ICACHE_RAM_ATTR; void update_rotary(void) ICACHE_RAM_ATTR;
void update_rotary(void) { void update_rotary(void) {
if (Rotary.busy) { return; } if (Rotary.busy) { return; }
bool powered_on = (power);
#ifdef USE_LIGHT
if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control
powered_on = (LightPowerIRAM());
}
#endif // USE_LIGHT
if (!powered_on) { return; }
#ifdef ROTARY_OPTION1 #ifdef ROTARY_OPTION1
// https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h // https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h
@ -212,8 +205,10 @@ void update_rotary(void) {
#endif // ROTARY_OPTION3 #endif // ROTARY_OPTION3
} }
bool RotaryButtonPressed(void) { //bool RotaryButtonPressed(void) {
bool RotaryButtonPressed(uint32_t button_index) {
if (!Rotary.present) { return false; } if (!Rotary.present) { return false; }
if (0 != button_index) { return false; }
bool powered_on = (power); bool powered_on = (power);
#ifdef USE_LIGHT #ifdef USE_LIGHT
@ -254,6 +249,13 @@ void RotaryHandler(void) {
Rotary.timeout--; Rotary.timeout--;
if (!Rotary.timeout) { if (!Rotary.timeout) {
Rotary.direction = 0; Rotary.direction = 0;
#ifdef USE_LIGHT
if (!Settings.flag4.rotary_uses_rules) { // SetOption98 - Use rules instead of light control
LightState(0);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_CMND_DIMMER));
XdrvRulesProcess();
}
#endif // USE_LIGHT
} }
} }
if (Rotary.last_position == Rotary.position) { return; } if (Rotary.last_position == Rotary.position) { return; }