-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TI OPT3001 light sensor support (#4015)
* TI OPT3001 light sensor support * Added register interrogation to deconflict with SHT sensors on same address
- Loading branch information
1 parent
2723ae6
commit 97a5abb
Showing
8 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ class ScanI2C | |
RCWL9620, | ||
NCP5623, | ||
TSL2591, | ||
OPT3001, | ||
AHT10, | ||
} DeviceType; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "OPT3001Sensor.h" | ||
#include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
#include "TelemetrySensor.h" | ||
#include "configuration.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 = B1100; | ||
newConfig.ConvertionTime = B0; | ||
newConfig.Latch = B1; | ||
newConfig.ModeOfConversionOperation = B11; | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
#include "TelemetrySensor.h" | ||
#include <ClosedCube_OPT3001.h> | ||
|
||
class OPT3001Sensor : public TelemetrySensor | ||
{ | ||
private: | ||
ClosedCube_OPT3001 opt3001; | ||
|
||
protected: | ||
virtual void setup() override; | ||
|
||
public: | ||
OPT3001Sensor(); | ||
virtual int32_t runOnce() override; | ||
virtual bool getMetrics(meshtastic_Telemetry *measurement) override; | ||
}; |