mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-10 21:19:07 +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
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
#include "configuration.h"
|
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include(<DFRobot_RainfallSensor.h>)
|
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
#include "DFRobotGravitySensor.h"
|
|
#include "TelemetrySensor.h"
|
|
#include <DFRobot_RainfallSensor.h>
|
|
#include <string>
|
|
|
|
DFRobotGravitySensor::DFRobotGravitySensor() : TelemetrySensor(meshtastic_TelemetrySensorType_DFROBOT_RAIN, "DFROBOT_RAIN") {}
|
|
|
|
int32_t DFRobotGravitySensor::runOnce()
|
|
{
|
|
LOG_INFO("Init sensor: %s", sensorName);
|
|
if (!hasSensor()) {
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
}
|
|
|
|
gravity = DFRobot_RainfallSensor_I2C(nodeTelemetrySensorsMap[sensorType].second);
|
|
status = gravity.begin();
|
|
|
|
return initI2CSensor();
|
|
}
|
|
|
|
void DFRobotGravitySensor::setup()
|
|
{
|
|
LOG_DEBUG("%s VID: %x, PID: %x, Version: %s", sensorName, gravity.vid, gravity.pid, gravity.getFirmwareVersion().c_str());
|
|
}
|
|
|
|
bool DFRobotGravitySensor::getMetrics(meshtastic_Telemetry *measurement)
|
|
{
|
|
measurement->variant.environment_metrics.has_rainfall_1h = true;
|
|
measurement->variant.environment_metrics.has_rainfall_24h = true;
|
|
|
|
measurement->variant.environment_metrics.rainfall_1h = gravity.getRainfall(1);
|
|
measurement->variant.environment_metrics.rainfall_24h = gravity.getRainfall(24);
|
|
|
|
LOG_INFO("Rain 1h: %f mm", measurement->variant.environment_metrics.rainfall_1h);
|
|
LOG_INFO("Rain 24h: %f mm", measurement->variant.environment_metrics.rainfall_24h);
|
|
return true;
|
|
}
|
|
|
|
#endif |