diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 43f5d99ad..c86c91d59 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2585,15 +2585,6 @@ void GpioInit(void) XdrvCall(FUNC_PRE_INIT); } -void UpdateLoopLoadAvg(uint32_t loop_activity) -{ - uint32_t loop_delay = Settings.param[P_LOOP_SLEEP_DELAY]; - if (!loop_delay) { loop_delay = 1; } // We cannot devide by 0 - uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second - uint32_t this_cycle_ratio = 100 * loop_activity / loop_delay; - loop_load_avg = loop_load_avg - (loop_load_avg / loops_per_second) + this_cycle_ratio; // Take away one loop average away and add the new one -} - extern "C" { extern struct rst_info resetInfo; } @@ -2799,5 +2790,11 @@ void loop(void) delay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period } } - UpdateLoopLoadAvg(my_activity); + + if (!my_activity) { my_activity++; } // We cannot divide by 0 + uint32_t loop_delay = Settings.param[P_LOOP_SLEEP_DELAY]; + if (!loop_delay) { loop_delay++; } // We cannot divide by 0 + uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second + uint32_t this_cycle_ratio = 100 * my_activity / loop_delay; + loop_load_avg = loop_load_avg - (loop_load_avg / loops_per_second) + this_cycle_ratio; // Take away one loop average away and add the new one }