2024-04-29 22:10:49 +12:00
|
|
|
#include "configuration.h"
|
|
|
|
|
|
2025-04-28 18:35:13 -05:00
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_LPS2X.h>)
|
2024-04-27 18:05:39 +12:00
|
|
|
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2024-05-03 14:26:57 +02:00
|
|
|
#include "LPS22HBSensor.h"
|
2022-10-15 14:55:57 -05:00
|
|
|
#include "TelemetrySensor.h"
|
|
|
|
|
#include <Adafruit_LPS2X.h>
|
|
|
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
LPS22HBSensor::LPS22HBSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_LPS22, "LPS22HB") {}
|
2022-10-15 14:55:57 -05:00
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
int32_t LPS22HBSensor::runOnce()
|
|
|
|
|
{
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("Init sensor: %s", sensorName);
|
2022-10-15 14:55:57 -05:00
|
|
|
if (!hasSensor()) {
|
|
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
2023-10-15 02:33:45 +02:00
|
|
|
status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
2022-10-15 14:55:57 -05:00
|
|
|
return initI2CSensor();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
void LPS22HBSensor::setup()
|
2022-10-15 14:55:57 -05:00
|
|
|
{
|
|
|
|
|
lps22hb.setDataRate(LPS22_RATE_10_HZ);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
bool LPS22HBSensor::getMetrics(meshtastic_Telemetry *measurement)
|
2023-01-18 14:51:48 -06:00
|
|
|
{
|
2024-08-16 17:15:51 -05:00
|
|
|
measurement->variant.environment_metrics.has_temperature = true;
|
|
|
|
|
measurement->variant.environment_metrics.has_barometric_pressure = true;
|
|
|
|
|
|
2022-10-15 14:55:57 -05:00
|
|
|
sensors_event_t temp;
|
|
|
|
|
sensors_event_t pressure;
|
|
|
|
|
lps22hb.getEvent(&pressure, &temp);
|
|
|
|
|
|
|
|
|
|
measurement->variant.environment_metrics.temperature = temp.temperature;
|
|
|
|
|
measurement->variant.environment_metrics.barometric_pressure = pressure.pressure;
|
|
|
|
|
|
|
|
|
|
return true;
|
2024-04-27 18:05:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|