Fix immediate issues

Fix immediate issues
This commit is contained in:
Theo Arends 2019-10-25 18:28:35 +02:00
parent 897fa45576
commit 60ac14767c
2 changed files with 9 additions and 6 deletions

View File

@ -1199,6 +1199,7 @@ void SettingsDelta(void)
}
if (Settings.version < 0x06060014) {
// Clear unused parameters for future use
/*
Settings.flag3.ex_tuya_dimmer_range_255 = 0;
Settings.flag3.ex_tuya_dimmer_min_limit = 0;
Settings.param[P_ex_TUYA_RELAYS] = 0;
@ -1208,7 +1209,7 @@ void SettingsDelta(void)
Settings.param[P_ex_TUYA_POWER_ID] = 0;
Settings.ex_baudrate = 0;
Settings.ex_sbaudrate = 0;
*/
Settings.flag3.fast_power_cycle_disable = 0;
Settings.energy_power_delta = Settings.ex_energy_power_delta;
Settings.ex_energy_power_delta = 0;

View File

@ -292,11 +292,13 @@ void EnergyMarginCheck(void)
DEBUG_DRIVER_LOG(PSTR("NRG: Delta %d, Power %d"), delta, min_power);
if ( ((Settings.energy_power_delta < 101) && (((delta * 100) / min_power) > Settings.energy_power_delta)) || // 1..100 = Percentage
((Settings.energy_power_delta > 100) && (delta > (Settings.energy_power_delta -100))) ) { // 101..32000 = Absolute
Energy.power_delta = true;
Energy.power_history[1] = Energy.active_power[0]; // We only want one report so reset history
Energy.power_history[2] = Energy.active_power[0];
if (delta) { // Fix divide by 0 exception (#6741)
if (((Settings.energy_power_delta < 101) && (((delta * 100) / min_power) > Settings.energy_power_delta)) || // 1..100 = Percentage
((Settings.energy_power_delta > 100) && (delta > (Settings.energy_power_delta -100)))) { // 101..32000 = Absolute
Energy.power_delta = true;
Energy.power_history[1] = Energy.active_power[0]; // We only want one report so reset history
Energy.power_history[2] = Energy.active_power[0];
}
}
}
Energy.power_history[0] = Energy.power_history[1]; // Shift in history every second allowing power changes to settle for up to three seconds