ensure the only operation from main loop() is load
since isr handles incrementing the counter, resulting value is calculated as
offset between the current and the previous reading (always positive)
Optimize isr handler once more by removing gpio -> index conversion at runtime
Drop atomics for now, since we can also make the whole operation atomic
by locking GPIO interrupts while reading and setting the counter value
And we don't have another thread / core to worry about
resolve#2368
- Fixes "undefined reference to `__atomic_fetch_add_4'"
Notably, std::atomic_fetch_add(&counter, 1) would also trigger this.
std::atomic<T>::operator+= does not allow in-place change, since it
returns T instead of T&
- Another work reduction in the isr, treat 'value' as `counter > 0`
instead of relying on the notion that we can sometimes read the value
with very low counter frequency
- Fix duplicated initializations
Always do digitalRead() after ISR
Drop trigger, since we can handle this inside of reading routine
(although, pending some changes to make reading interval per-sensor)
Rework read / write through std::atomic
- magnitudes vector grows by calling copy ctor, ensure filter never gets deleted
- ensure we can't use magnitude member instead of ctor arg
- more magnitude references instead of using index access
- additional checks for isnan, fix report never triggering
- drop event callback. at least for EventSensor, we already have
report with min / max value change triggers
* emon: configure ratios without reboot
* settings: serialize() support
* debug: use vsnprintf from newlib, not from sdk
* settings/experimental: show defaults via `get`
* emon: override base methods, fix defaults
* sensor/emon: expose internal index calculation
- refactor configuration to use the correct index when accessing indexed
sensor methods. store index value on magnitude, refactor loops to
accomodate this new functionality
- rename slot(index) -> description(index), since we use 'slot' as
numeric value
- Update sensor classes to support a generic way to store energy values
- Update sensor conversion code to deal with units and not magnitudes
- Add magnitude<->unit for sensors, generic way of defining used unit. Convert from sensor magnitude unit to the one used for display.
- Reset energy value based on index through external means (MQTT, HTTP)
- Rework energy timestamping, update webui with 'last saved' value
While this solves the energy conversion issues and we are finally seeing the real value, what I don't really like:
- KilowattHour and WattHour are separate enum tags, thus sort-of are different types altogether
- Conversion code in Energy object should probably use some generic 'ratio' calculation? (https://en.cppreference.com/w/cpp/numeric/ratio/ratio)
- We are still using runtime checks to do calculations and depend that sensor outputs only one specific value type.
Consider this a fix for energy display / storage and preliminary work on sensor.ino
Further sensor refactoring... soon.
* Sensors: refactor configuration
- move sensor implementaion to the .ino,
remove dependency undef / define from sensor files
- update test/build/sensor.h from SENSOR_SUPPORT
- allow to change sensor config variables externally
- `#include <...>` for global headers and libraries,
fix relative path for math library
* add missing sns <-> i2c dependency
* ledrelay should return relay_none as default
* rollback to original test header
* include debug header when requested (relative)