Add Read Cache and Stats

- baro.cache_ttl_ms avoids multiple reads
- by default, cache is off (cache_ttl_ms=0)
- stats are updated (similar to how prometheus-sensors does this)
This commit is contained in:
Pim van Pelt
2018-04-21 15:39:57 +02:00
parent 89ec34dc1d
commit 9d9cd1d00a
5 changed files with 57 additions and 1 deletions

View File

@ -32,6 +32,7 @@ typedef bool (*mgos_barometer_mag_read_fn)(struct mgos_barometer *dev);
struct mgos_barometer {
struct mgos_i2c * i2c;
uint8_t i2caddr;
uint16_t cache_ttl_ms;
enum mgos_barometer_type type;
bool has_thermometer;
bool has_barometer;
@ -45,6 +46,8 @@ struct mgos_barometer {
float pressure; // in Pascals
float temperature; // in Celcius
struct mgos_barometer_stats stats;
};
#ifdef __cplusplus