mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-09 12:49:40 +00:00

* First addition of __has_include for sensor support * Add __has_include blocks for sensors * Put BMP and BME back in the right sensors * Make TelemetrySensor::setup() a pure virtual finction * Split environmental_base to environmental_extra, to compile the working sensor libs for Native * Remove hard-coded checks for ARCH_PORTDUINO * Un-clobber bmx160 * Move BusIO to environmental_extra due to Armv7 compile error * Move to forked BusIO for the moment * Enable HAS_SENSOR for Portduino * Move back to Adafruit BusIO after patch
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "configuration.h"
|
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<Adafruit_LPS2X.h>)
|
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
#include "LPS22HBSensor.h"
|
|
#include "TelemetrySensor.h"
|
|
#include <Adafruit_LPS2X.h>
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
LPS22HBSensor::LPS22HBSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_LPS22, "LPS22HB") {}
|
|
|
|
int32_t LPS22HBSensor::runOnce()
|
|
{
|
|
LOG_INFO("Init sensor: %s", sensorName);
|
|
if (!hasSensor()) {
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
}
|
|
status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
|
return initI2CSensor();
|
|
}
|
|
|
|
void LPS22HBSensor::setup()
|
|
{
|
|
lps22hb.setDataRate(LPS22_RATE_10_HZ);
|
|
}
|
|
|
|
bool LPS22HBSensor::getMetrics(meshtastic_Telemetry *measurement)
|
|
{
|
|
measurement->variant.environment_metrics.has_temperature = true;
|
|
measurement->variant.environment_metrics.has_barometric_pressure = true;
|
|
|
|
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;
|
|
}
|
|
|
|
#endif |