Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debounce cleanups #365

Merged
merged 3 commits into from
Feb 4, 2021
Merged

Debounce cleanups #365

merged 3 commits into from
Feb 4, 2021

Conversation

mairas
Copy link
Collaborator

@mairas mairas commented Jan 25, 2021

I did a bit of reworking on the networking logic and removed the "reboot on wifi disconnect" from the Networking class and made it a consumer of SystemState in SensESPApp. For this, I required Debounce to only trigger the reset if the state had been stable for 3 minutes.

First, I noticed that due to the Debounce template implementation, it was impossibly to instantiate Debounce. I did a quick benchmark to verify the claim in Issue #287 that "if you put the entire implementation in the header file (esp. the configuration stuff) the compiler will generate a TON of redundant code." (The issue sounded a bit peculiar because basically all of STL is, well, templates.)

I have a random SensESP test program that takes some changing AnalogInput, applies hysteresis and rounding and then Debounces the boolean and integer values. Compiled with the original implementation, the RAM footprint was 51.0 KB and flash footprint 1015.4 KB. I then refactored the code into a standard headers-only template class. The RAM footprint remained at 51.0 KB while the flash footprint dropped to 1011.0 KB. So, that is the first major change in this PR.

The second change relates to the Debouncing logic. I am debouncing the system state which gets regular WifiDisconnected updates (the same value all over again). The original logic reset the timer for every update, even if they repeated the same value. That didn't quite make sense to me - it would be impossible to debounce any polled values with this logic. I shuffled the code a bit around but the only change in the end was that repeated values are considered stable instead of resetting the timer every time.

I need Debounce<SystemStatus> for the wifi disconnection watchdog
and it wasn't possibly to instantiate with this setup.

I made a quick test with PlatformIO's inspection tool. I had a random
test program which used DebounceBool and DebounceInt of some
input. The RAM use was 51.0 KB and Flash use was 1015.4 KB. After
changing the transform to header-only templates, RAM use remained
the same but flash use dropped to 1011.0 KB.
@mairas mairas mentioned this pull request Jan 25, 2021
Copy link
Collaborator

@ba58smith ba58smith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@mairas mairas force-pushed the debounce_cleanups branch from 69dd8e9 to 780da88 Compare January 25, 2021 14:21
@mairas
Copy link
Collaborator Author

mairas commented Jan 25, 2021

Since this PR includes a change in the behavior logic, if @joelkoz has any doubt, it'd be great if you could test it before merging so that you're not left in the dark (pun absolutely intended!).

@mairas mairas merged commit fc70c83 into SignalK:master Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants