mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 22:22:05 +00:00

* Fix LED pinout for T-Echo board marked v1.0, date 2021-6-28 * Merge PR #420 * Fixed double and missing Default class. * Use correct format specifier and fixed typo. * Removed duplicate code. * Fix error: #if with no expression * Fix warning: extra tokens at end of #endif directive. * Fix antenna switching logic. Complementary-pin control logic is required on the rp2040-lora board. * Fix deprecated macros. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "configuration.h"
|
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
#include "OPT3001Sensor.h"
|
|
#include "TelemetrySensor.h"
|
|
#include <ClosedCube_OPT3001.h>
|
|
|
|
OPT3001Sensor::OPT3001Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_OPT3001, "OPT3001") {}
|
|
|
|
int32_t OPT3001Sensor::runOnce()
|
|
{
|
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
|
if (!hasSensor()) {
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
}
|
|
auto errorCode = opt3001.begin(nodeTelemetrySensorsMap[sensorType].first);
|
|
status = errorCode == NO_ERROR;
|
|
|
|
return initI2CSensor();
|
|
}
|
|
|
|
void OPT3001Sensor::setup()
|
|
{
|
|
OPT3001_Config newConfig;
|
|
|
|
newConfig.RangeNumber = 0b1100;
|
|
newConfig.ConvertionTime = 0b0;
|
|
newConfig.Latch = 0b1;
|
|
newConfig.ModeOfConversionOperation = 0b11;
|
|
|
|
OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);
|
|
if (errorConfig != NO_ERROR) {
|
|
LOG_ERROR("OPT3001 configuration error #%d", errorConfig);
|
|
}
|
|
}
|
|
|
|
bool OPT3001Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
|
{
|
|
OPT3001 result = opt3001.readResult();
|
|
|
|
measurement->variant.environment_metrics.lux = result.lux;
|
|
LOG_INFO("Lux: %f\n", measurement->variant.environment_metrics.lux);
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif |