Files
firmware/src/modules/Telemetry/Sensor/SHT31Sensor.cpp

36 lines
1001 B
C++
Raw Normal View History

#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "SHT31Sensor.h"
2023-01-18 08:56:47 -06:00
#include "../mesh/generated/meshtastic/telemetry.pb.h"
2022-12-28 15:30:23 +01:00
#include "TelemetrySensor.h"
#include <Adafruit_SHT31.h>
SHT31Sensor::SHT31Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_SHT31, "SHT31") {}
2022-12-28 15:30:23 +01:00
int32_t SHT31Sensor::runOnce()
{
LOG_INFO("Init sensor: %s\n", sensorName);
2022-12-28 15:30:23 +01:00
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
2024-03-11 18:51:14 +01:00
sht31 = Adafruit_SHT31(nodeTelemetrySensorsMap[sensorType].second);
2024-03-11 13:51:26 +01:00
status = sht31.begin(nodeTelemetrySensorsMap[sensorType].first);
2022-12-28 15:30:23 +01:00
return initI2CSensor();
}
void SHT31Sensor::setup()
2022-12-28 15:30:23 +01:00
{
// Set up oversampling and filter initialization
}
bool SHT31Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
2022-12-28 15:30:23 +01:00
measurement->variant.environment_metrics.temperature = sht31.readTemperature();
measurement->variant.environment_metrics.relative_humidity = sht31.readHumidity();
return true;
}
#endif