Skip to content

Commit

Permalink
Merge pull request #9445 from pcdiem/pwm1
Browse files Browse the repository at this point in the history
Fix PWM Dimmer to properly handle more-to-come finalization
  • Loading branch information
arendst committed Oct 2, 2020
2 parents edd8990 + 184601f commit cc6fb36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions tasmota/support_device_groups.ino
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de

#ifdef DEVICE_GROUPS_DEBUG
switch (item) {
case DGR_ITEM_FLAGS:
case DGR_ITEM_LIGHT_FADE:
case DGR_ITEM_LIGHT_SPEED:
case DGR_ITEM_LIGHT_BRI:
Expand Down
12 changes: 6 additions & 6 deletions tasmota/xdrv_35_pwm_dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void PWMDimmerHandleButton(void)
int32_t bri_offset = 0;
uint8_t power_on_bri = 0;
uint8_t dgr_item = 0;
uint8_t dgr_value;
uint8_t dgr_value = 0;
uint8_t dgr_more_to_come = false;
uint32_t button_index = XdrvMailbox.index;
uint32_t now = millis();
Expand Down Expand Up @@ -475,7 +475,7 @@ void PWMDimmerHandleButton(void)
#endif // USE_PWM_DIMMER_REMOTE
power_button_increases_bri ^= 1;
#ifdef USE_PWM_DIMMER_REMOTE
dgr_item = 255;
dgr_item = DGR_ITEM_FLAGS;
state_updated = true;
#endif // USE_PWM_DIMMER_REMOTE
}
Expand Down Expand Up @@ -510,7 +510,7 @@ void PWMDimmerHandleButton(void)
// If the down button was tapped and held, we changed the fixed color. Send a final
// update.
else if (down_button_tapped) {
dgr_item = 255;
dgr_item = DGR_ITEM_FLAGS;
}
}
}
Expand Down Expand Up @@ -551,15 +551,15 @@ void PWMDimmerHandleButton(void)
// button is pressed. The new brightness will be calculated below.
if (button_hold_time[button_index] >= now) {
bri_offset = (is_down_button ? -1 : 1);
dgr_item = 255;
dgr_item = DGR_ITEM_FLAGS;
state_updated = true;
}

// If the button was held and the hold was not processed by a rule, we changed the
// brightness and sent updates with the more-to-come message type while the button was
// held. Send a final update.
else if (!button_hold_processed[button_index]) {
dgr_item = 255;
dgr_item = DGR_ITEM_FLAGS;
state_updated = true;
}
}
Expand Down Expand Up @@ -666,7 +666,7 @@ void PWMDimmerHandleButton(void)
// update.
if (dgr_item) {
#ifdef USE_DEVICE_GROUPS
if (dgr_item == 255) dgr_item = 0;
AddLog_P2(LOG_LEVEL_ERROR, PSTR("PWMDimmer: sending DGR item %u"), dgr_item);
SendDeviceGroupMessage(power_button_index, (dgr_more_to_come ? DGR_MSGTYP_UPDATE_MORE_TO_COME : DGR_MSGTYP_UPDATE_DIRECT), dgr_item, dgr_value);
#endif // USE_DEVICE_GROUPS
#ifdef USE_PWM_DIMMER_REMOTE
Expand Down

0 comments on commit cc6fb36

Please sign in to comment.