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

@ -12,6 +12,7 @@ bool mgos_barometer_mpl115_create(struct mgos_barometer *dev) {
mpl115_data=calloc(1, sizeof(struct mgos_barometer_mpl115_data));
if (!mpl115_data) return false;
// TODO(pim): fix this -- math is wrong.
mpl115_data->a0=(float)(((uint16_t) data[0] << 8) | data[1]) / 8.0;
mpl115_data->b1=(float)(((uint16_t) data[2] << 8) | data[3]) / 8192.0;
mpl115_data->b2=(float)(((uint16_t) data[4] << 8) | data[5]) / 16384.0;