Merge pull request #8225 from pcdiem/pwm-dimmer-10

Fix remote device group update index and power state, Ignore power bu…
This commit is contained in:
Theo Arends 2020-04-19 08:54:08 +02:00 committed by GitHub
commit 6ec18c3c01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -40,7 +40,7 @@ void (* const PWMDimmerCommand[])(void) PROGMEM = {
#ifdef USE_PWM_DIMMER_REMOTE #ifdef USE_PWM_DIMMER_REMOTE
struct remote_pwm_dimmer { struct remote_pwm_dimmer {
power_t power; bool power_on;
uint8_t bri_power_on; uint8_t bri_power_on;
uint8_t bri_preset_low; uint8_t bri_preset_low;
uint8_t bri_preset_high; uint8_t bri_preset_high;
@ -178,7 +178,7 @@ void PWMDimmerHandleDevGroupItem(void)
uint8_t device_group_index = *(uint8_t *)XdrvMailbox.topic; uint8_t device_group_index = *(uint8_t *)XdrvMailbox.topic;
if (device_group_index > remote_pwm_dimmer_count) return; if (device_group_index > remote_pwm_dimmer_count) return;
bool device_is_local = device_groups[device_group_index].local; bool device_is_local = device_groups[device_group_index].local;
struct remote_pwm_dimmer * remote_pwm_dimmer = &remote_pwm_dimmers[device_group_index]; struct remote_pwm_dimmer * remote_pwm_dimmer = &remote_pwm_dimmers[device_group_index - 1];
#else // USE_PWM_DIMMER_REMOTE #else // USE_PWM_DIMMER_REMOTE
if (*(uint8_t *)XdrvMailbox.topic) return; if (*(uint8_t *)XdrvMailbox.topic) return;
#endif // !USE_PWM_DIMMER_REMOTE #endif // !USE_PWM_DIMMER_REMOTE
@ -190,7 +190,7 @@ void PWMDimmerHandleDevGroupItem(void)
break; break;
case DGR_ITEM_POWER: case DGR_ITEM_POWER:
if (!device_is_local) { if (!device_is_local) {
remote_pwm_dimmer->power = value; remote_pwm_dimmer->power_on = value & 1;
remote_pwm_dimmer->power_button_increases_bri = (remote_pwm_dimmer->bri < 128); remote_pwm_dimmer->power_button_increases_bri = (remote_pwm_dimmer->bri < 128);
} }
break; break;
@ -286,7 +286,7 @@ void PWMDimmerHandleButton(void)
// Initialize some variables. // Initialize some variables.
#ifdef USE_PWM_DIMMER_REMOTE #ifdef USE_PWM_DIMMER_REMOTE
bool power_is_on = (!active_device_is_local ? active_remote_pwm_dimmer->power : power); bool power_is_on = (!active_device_is_local ? active_remote_pwm_dimmer->power_on : power);
bool is_power_button = (button_index == power_button_index); bool is_power_button = (button_index == power_button_index);
#else // USE_PWM_DIMMER_REMOTE #else // USE_PWM_DIMMER_REMOTE
bool power_is_on = power; bool power_is_on = power;
@ -344,8 +344,9 @@ void PWMDimmerHandleButton(void)
// If this is about the power button, ... // If this is about the power button, ...
if (is_power_button) { if (is_power_button) {
// If no other buttons are pressed, ... // If no other buttons are pressed and the up or down button was tapped while holding the
if (buttons_pressed == 1) { // power button before this, ...
if (buttons_pressed == 1 && !tap_count) {
// If the power is on, adjust the brightness. Set the direction based on the current // If the power is on, adjust the brightness. Set the direction based on the current
// direction for the device and then invert the direction when the power button is // direction for the device and then invert the direction when the power button is
@ -628,8 +629,8 @@ void PWMDimmerHandleButton(void)
#ifdef USE_DEVICE_GROUPS #ifdef USE_DEVICE_GROUPS
#ifdef USE_PWM_DIMMER_REMOTE #ifdef USE_PWM_DIMMER_REMOTE
if (!active_device_is_local) { if (!active_device_is_local) {
active_remote_pwm_dimmer->power ^= 1; active_remote_pwm_dimmer->power_on ^= 1;
new_power = active_remote_pwm_dimmer->power; new_power = active_remote_pwm_dimmer->power_on;
} }
else { else {
#endif // USE_PWM_DIMMER_REMOTE #endif // USE_PWM_DIMMER_REMOTE