cziter15/emon_fw

Refactor LineSensor code

cziter15 opened this issue · 2 comments

Currently algorithm that calculates mode / dominant is doing unnecessary things.

Technically, this can be handled as ring buffer of 400 values and then any new added reading will increment it's index in array of ocurrences while removed value should decrement.

Summary:
Have ring buffer with 400 values
Head value should increment its count in ocurrences . Tail should decrement. Dominant value is an index in array where value is max. STD ALGOs should be used like std maximum.

https://github.com/krkind/circularbuffercc/blob/master/circularbuffer.hpp

Recommended solution:
https://gist.github.com/cziter15/01dd76660fa27e22d928c0c69cbaf26c

Prewarm state still should be implemented, but this should be easy to fit into LineSensor class.

Code has been refactored and verified on target device.