From a785d7a6ad2072a07450256425bf4cc7c63b8b25 Mon Sep 17 00:00:00 2001 From: Paul C Diem Date: Sat, 7 Nov 2020 17:37:06 -0600 Subject: [PATCH] Set light_dimmer on DGR bri changes, Use DGR direct for PWM dimmer bri changes --- tasmota/xdrv_04_light.ino | 12 ++++++++---- tasmota/xdrv_35_pwm_dimmer.ino | 20 +++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 323069b9d..db07bec91 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1954,7 +1954,7 @@ void LightAnimate(void) } if (Light.update) { #ifdef USE_DEVICE_GROUPS - if (Light.power) LightSendDeviceGroupStatus(false); + if (Light.power && !Light.devgrp_no_channels_out) LightSendDeviceGroupStatus(false); #endif // USE_DEVICE_GROUPS uint16_t cur_col_10[LST_MAX]; // 10 bits resolution @@ -2315,7 +2315,7 @@ void LightSendDeviceGroupStatus(bool status) static uint8_t last_bri; uint8_t bri = light_state.getBri(); bool send_bri_update = (status || bri != last_bri); - if (Light.subtype > LST_SINGLE && !Light.devgrp_no_channels_out) { + if (Light.subtype > LST_SINGLE) { static uint8_t channels[LST_MAX + 1] = { 0, 0, 0, 0, 0, 0 }; if (status) { light_state.getChannels(channels); @@ -2345,13 +2345,17 @@ void LightHandleDevGroupItem(void) switch (XdrvMailbox.command_code) { case DGR_ITEM_EOL: more_to_come = (XdrvMailbox.index & DGR_FLAG_MORE_TO_COME); - if (restore_power && !more_to_come) { + if (more_to_come) { + TasmotaGlobal.skip_light_fade = true; + } + else if (restore_power) { restore_power = false; Light.power = Light.old_power; } LightAnimate(); + TasmotaGlobal.skip_light_fade = true; if (send_state && !more_to_come) { light_controller.saveSettings(); if (Settings.flag3.hass_tele_on_power) { // SetOption59 - Send tele/%topic%/STATE in addition to stat/%topic%/RESULT @@ -2363,6 +2367,7 @@ void LightHandleDevGroupItem(void) case DGR_ITEM_LIGHT_BRI: if (light_state.getBri() != value) { light_state.setBri(value); + Settings.light_dimmer = light_state.BriToDimmer(value); send_state = true; } break; @@ -2431,7 +2436,6 @@ void LightHandleDevGroupItem(void) light_controller.changeChannels(Light.entry_color); light_controller.changeBri(old_bri); Settings.light_scheme = 0; - Light.devgrp_no_channels_out = false; if (!restore_power && !Light.power) { Light.old_power = Light.power; Light.power = 0xff; diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index 4cb98fe52..ad774c03e 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -91,14 +91,14 @@ void PWMModulePreInit(void) if (TasmotaGlobal.module_changed) { Settings.flag.pwm_control = true; // SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL Settings.bri_power_on = Settings.bri_preset_low = Settings.bri_preset_high = 0; + } - // Previous versions of PWM Dimmer used SetOption32 - Button held for factor times longer as the - // hold time. The hold time is now fixed and SetOption32 is used as normal including to - // determine how long a button is held before a reset command is executed. If SetOption32 is - // still 5, change it to 40 (the default). - if (Settings.param[P_HOLD_TIME] == 5) Settings.param[P_HOLD_TIME] = 40; - } - + // Previous versions of PWM Dimmer used SetOption32 - Button held for factor times longer as the + // hold time. The hold time is now fixed and SetOption32 is used as normal including to + // determine how long a button is held before a reset command is executed. If SetOption32 is + // still 5, change it to 40 (the default). + if (Settings.param[P_HOLD_TIME] == 5) Settings.param[P_HOLD_TIME] = 40; + // Make sure the brightness level settings are sensible. if (!Settings.bri_power_on) Settings.bri_power_on = 128; if (!Settings.bri_preset_low) Settings.bri_preset_low = 10; @@ -482,7 +482,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed) else #endif // USE_PWM_DIMMER_REMOTE bri = light_state.getBri(); - int32_t new_bri = bri + bri_offset * ((dgr_item ? 16 : Settings.light_correction ? 4 : bri / 16 + 1)); + int32_t new_bri = bri + bri_offset * (Settings.light_correction ? 4 : bri / 16 + 1); if (bri_offset > 0) { if (new_bri > 255) new_bri = 255; @@ -492,7 +492,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed) } if (new_bri != bri) { #ifdef USE_DEVICE_GROUPS - SendDeviceGroupMessage(power_button_index, (dgr_more_to_come ? DGR_MSGTYP_UPDATE_MORE_TO_COME : DGR_MSGTYP_UPDATE), DGR_ITEM_LIGHT_BRI, new_bri); + SendDeviceGroupMessage(power_button_index, (dgr_more_to_come ? DGR_MSGTYP_UPDATE_MORE_TO_COME : DGR_MSGTYP_UPDATE_DIRECT), DGR_ITEM_LIGHT_BRI, new_bri); #endif // USE_DEVICE_GROUPS #ifdef USE_PWM_DIMMER_REMOTE if (active_remote_pwm_dimmer) { @@ -506,6 +506,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed) ignore_dgr_sends = true; #endif // USE_DEVICE_GROUPS light_state.setBri(new_bri); + Settings.light_dimmer = light_state.BriToDimmer(new_bri); LightAnimate(); TasmotaGlobal.skip_light_fade = false; #ifdef USE_DEVICE_GROUPS @@ -551,6 +552,7 @@ void PWMDimmerHandleButton(uint32_t button_index, bool pressed) else { #endif // USE_PWM_DIMMER_REMOTE light_state.setBri(power_on_bri); + Settings.light_dimmer = light_state.BriToDimmer(power_on_bri); #ifdef USE_DEVICE_GROUPS Light.devgrp_no_channels_out = true; #endif // USE_DEVICE_GROUPS