From 52eeef95f0f4b4a8421871723322ebeb0ed93295 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 24 Nov 2018 17:43:18 +0100 Subject: [PATCH] Add CPU average load Add CPU average load to state message (#4431) --- sonoff/_changelog.ino | 1 + sonoff/sonoff.ino | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 312c2855d..7e38a6aed 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -6,6 +6,7 @@ * Fix possible strncat buffer overflows * Fix MqttRetry values above 255 seconds (#4424) * Increase webui refresh time delay for Save Settings and local OTA Upload (#4423) + * Add CPU average load to state message (#4431) * * 6.3.0.11 20181120 * Add delays removed in 6.3.0.9 (#4233) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index f461b6de0..8bc6113cb 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2583,14 +2583,13 @@ void GpioInit(void) XdrvCall(FUNC_PRE_INIT); } - -void update_loop_load_avg(uint32_t loop_activity) + +void UpdateLoopLoadAvg(uint32_t loop_activity) { - uint32_t loops_per_second = 1000 / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]; // We need to keep track of this many loops per second + uint32_t loops_per_second = 1000 / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]; // We need to keep track of this many loops per second uint32_t this_cycle_ratio = 100 * loop_activity / (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]; - uint32_t new_load_avg = loop_load_avg-(loop_load_avg/loops_per_second); // Take away one loop average - new_load_avg = new_load_avg + this_cycle_ratio; - loop_load_avg = new_load_avg; + uint32_t new_load_avg = loop_load_avg - (loop_load_avg / loops_per_second); // Take away one loop average + loop_load_avg = new_load_avg + this_cycle_ratio;; } extern "C" { @@ -2799,8 +2798,8 @@ void loop(void) } } if (my_activity < (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]) { - update_loop_load_avg(my_activity); + UpdateLoopLoadAvg(my_activity); } else { - update_loop_load_avg((uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]); // Assume 100% loop cycle ratio + UpdateLoopLoadAvg((uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]); // Assume 100% loop cycle ratio } }