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:
@ -30,11 +30,23 @@ enum mgos_barometer_type {
|
||||
|
||||
struct mgos_barometer;
|
||||
|
||||
struct mgos_barometer_stats {
|
||||
double last_read_time; // value of mg_time() upon last call to _read()
|
||||
uint32_t read; // calls to _read()
|
||||
uint32_t read_success; // successful _read()
|
||||
uint32_t read_success_cached; // calls to _read() which were cached
|
||||
// Note: read_errors := read - read_success - read_success_cached
|
||||
double read_success_usecs; // time spent in successful uncached _read()
|
||||
};
|
||||
|
||||
struct mgos_barometer *mgos_barometer_create_i2c(struct mgos_i2c *i2c, uint8_t i2caddr, enum mgos_barometer_type type);
|
||||
void mgos_barometer_destroy(struct mgos_barometer **sensor);
|
||||
bool mgos_barometer_has_thermometer(struct mgos_barometer *sensor);
|
||||
bool mgos_barometer_has_barometer(struct mgos_barometer *sensor);
|
||||
|
||||
/* Set cache TTL -- will limit reads and return cached data. Set msecs=0 to turn off */
|
||||
bool mgos_barometer_set_cache_ttl(struct mgos_barometer *sensor, uint16_t msecs);
|
||||
|
||||
/* Read all available sensor data from the IMU */
|
||||
bool mgos_barometer_read(struct mgos_barometer *sensor);
|
||||
|
||||
@ -44,6 +56,12 @@ bool mgos_barometer_get_pressure(struct mgos_barometer *sensor, float *p);
|
||||
/* Return temperature data in units of Celcius */
|
||||
bool mgos_barometer_get_temperature(struct mgos_barometer *sensor, float *t);
|
||||
|
||||
/*
|
||||
* Return statistics on the sensor.
|
||||
*/
|
||||
bool mgos_barometer_get_stats(struct mgos_barometer *sensor, struct mgos_barometer_stats *stats);
|
||||
|
||||
|
||||
/*
|
||||
* Initialization function for MGOS -- currently a noop.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user