From 1f2e69272f5072fb6e4a9bc7c9a007b09100697f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:39:26 +0200 Subject: [PATCH] Fix shutter reset savedata Fix shutter reset savedata (#15895) --- tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index 9c3080c3c..8cdea103a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -55,7 +55,6 @@ int32_t current_stop_way = 0; int32_t next_possible_stop_position = 0; int32_t current_real_position = 0; int32_t current_pwm_velocity = 0; -int8_t savedata_original = 0; const uint8_t MAX_MODES = 7; enum Shutterposition_mode {SHT_UNDEF, SHT_TIME, SHT_TIME_UP_DOWN, SHT_TIME_GARAGE, SHT_COUNTER, SHT_PWM_VALUE, SHT_PWM_TIME,}; @@ -536,8 +535,9 @@ void ShutterPowerOff(uint8_t i) #endif break; } - Settings->save_data = savedata_original; - TasmotaGlobal.save_data_counter = Settings->save_data; + if (Settings->save_data) { + TasmotaGlobal.save_data_counter = Settings->save_data; + } delay(MOTOR_STOP_TIME); } @@ -649,11 +649,6 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) ShutterAllowPreStartProcedure(i); Shutter[i].time = Shutter[i].last_reported_time = 0; - // avoid file system writes during move to minimize missing steps - savedata_original = Settings->save_data; - Settings->save_data = 0; // will be restored after movement - - TasmotaGlobal.save_data_counter = Settings->save_data; ShutterGlobal.skip_relay_change = 0; TasmotaGlobal.rules_flag.shutter_moved = 0; ShutterGlobal.start_reported = 0; @@ -665,6 +660,12 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: VenetianDelay: %d, Pos: %d, Dir: %d, Delta: %d, Dur: %d, StartP: %d, TgtP: %d"), Shutter[i].venetian_delay, Shutter[i].tilt_real_pos,direction,(Shutter[i].tilt_config[1]-Shutter[i].tilt_config[0]), Shutter[i].tilt_config[2],Shutter[i].tilt_start_pos,Shutter[i].tilt_target_pos); } + + // avoid file system writes during move to minimize missing steps + if (Settings->save_data) { + uint32_t move_duration = (direction > 0) ? Shutter[i].open_time : Shutter[i].close_time; + TasmotaGlobal.save_data_counter = Settings->save_data + (move_duration / 10) +1; + } } //AddLog(LOG_LEVEL_DEBUG, PSTR("SHT: Start shtr%d from %d to %d in dir: %d"), i, Shutter[i].start_position, Shutter[i].target_position, direction); Shutter[i].direction = direction; // Last action. This causes RTC to start.