mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-24 17:32:18 +00:00
Add TSL2591 sensor support (#4014)
This commit is contained in:
parent
9a855c0b6f
commit
6ce2fdc1c8
@ -136,3 +136,4 @@ lib_deps =
|
|||||||
mprograms/QMC5883LCompass@^1.2.0
|
mprograms/QMC5883LCompass@^1.2.0
|
||||||
adafruit/Adafruit VEML7700 Library@^2.1.6
|
adafruit/Adafruit VEML7700 Library@^2.1.6
|
||||||
adafruit/Adafruit SHT4x Library@^1.0.4
|
adafruit/Adafruit SHT4x Library@^1.0.4
|
||||||
|
adafruit/Adafruit TSL2591 Library@^1.4.5
|
@ -131,6 +131,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define AHT10_ADDR 0x38
|
#define AHT10_ADDR 0x38
|
||||||
#define RCWL9620_ADDR 0x57
|
#define RCWL9620_ADDR 0x57
|
||||||
#define VEML7700_ADDR 0x10
|
#define VEML7700_ADDR 0x10
|
||||||
|
#define TSL25911_ADDR 0x29
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// ACCELEROMETER
|
// ACCELEROMETER
|
||||||
|
@ -45,7 +45,8 @@ class ScanI2C
|
|||||||
VEML7700,
|
VEML7700,
|
||||||
RCWL9620,
|
RCWL9620,
|
||||||
NCP5623,
|
NCP5623,
|
||||||
AHT10
|
TSL2591,
|
||||||
|
AHT10,
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
|
|
||||||
// typedef uint8_t DeviceAddress;
|
// typedef uint8_t DeviceAddress;
|
||||||
|
@ -342,6 +342,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
|
|||||||
SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3 accelerometer found at address 0x%x\n", (uint8_t)addr.address);
|
SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3 accelerometer found at address 0x%x\n", (uint8_t)addr.address);
|
||||||
SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n");
|
SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n");
|
||||||
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n");
|
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n");
|
||||||
|
SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591 light sensor found\n");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);
|
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);
|
||||||
|
@ -533,6 +533,7 @@ void setup()
|
|||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700)
|
||||||
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::TSL2591, meshtastic_TelemetrySensorType_TSL25911FN)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::AHT10, meshtastic_TelemetrySensorType_AHT10)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::AHT10, meshtastic_TelemetrySensorType_AHT10)
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "Sensor/SHT31Sensor.h"
|
#include "Sensor/SHT31Sensor.h"
|
||||||
#include "Sensor/SHT4XSensor.h"
|
#include "Sensor/SHT4XSensor.h"
|
||||||
#include "Sensor/SHTC3Sensor.h"
|
#include "Sensor/SHTC3Sensor.h"
|
||||||
|
#include "Sensor/TSL2591Sensor.h"
|
||||||
#include "Sensor/VEML7700Sensor.h"
|
#include "Sensor/VEML7700Sensor.h"
|
||||||
|
|
||||||
BMP085Sensor bmp085Sensor;
|
BMP085Sensor bmp085Sensor;
|
||||||
@ -40,6 +41,7 @@ SHTC3Sensor shtc3Sensor;
|
|||||||
LPS22HBSensor lps22hbSensor;
|
LPS22HBSensor lps22hbSensor;
|
||||||
SHT31Sensor sht31Sensor;
|
SHT31Sensor sht31Sensor;
|
||||||
VEML7700Sensor veml7700Sensor;
|
VEML7700Sensor veml7700Sensor;
|
||||||
|
TSL2591Sensor tsl2591Sensor;
|
||||||
SHT4XSensor sht4xSensor;
|
SHT4XSensor sht4xSensor;
|
||||||
RCWL9620Sensor rcwl9620Sensor;
|
RCWL9620Sensor rcwl9620Sensor;
|
||||||
AHT10Sensor aht10Sensor;
|
AHT10Sensor aht10Sensor;
|
||||||
@ -105,6 +107,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
result = ina260Sensor.runOnce();
|
result = ina260Sensor.runOnce();
|
||||||
if (veml7700Sensor.hasSensor())
|
if (veml7700Sensor.hasSensor())
|
||||||
result = veml7700Sensor.runOnce();
|
result = veml7700Sensor.runOnce();
|
||||||
|
if (tsl2591Sensor.hasSensor())
|
||||||
|
result = tsl2591Sensor.runOnce();
|
||||||
if (rcwl9620Sensor.hasSensor())
|
if (rcwl9620Sensor.hasSensor())
|
||||||
result = rcwl9620Sensor.runOnce();
|
result = rcwl9620Sensor.runOnce();
|
||||||
if (aht10Sensor.hasSensor())
|
if (aht10Sensor.hasSensor())
|
||||||
@ -291,6 +295,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
valid = valid && veml7700Sensor.getMetrics(&m);
|
valid = valid && veml7700Sensor.getMetrics(&m);
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
}
|
}
|
||||||
|
if (tsl2591Sensor.hasSensor()) {
|
||||||
|
valid = valid && tsl2591Sensor.getMetrics(&m);
|
||||||
|
hasSensor = true;
|
||||||
|
}
|
||||||
if (rcwl9620Sensor.hasSensor()) {
|
if (rcwl9620Sensor.hasSensor()) {
|
||||||
valid = valid && rcwl9620Sensor.getMetrics(&m);
|
valid = valid && rcwl9620Sensor.getMetrics(&m);
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
|
38
src/modules/Telemetry/Sensor/TSL2591Sensor.cpp
Normal file
38
src/modules/Telemetry/Sensor/TSL2591Sensor.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "TSL2591Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
#include <Adafruit_TSL2591.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
TSL2591Sensor::TSL2591Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_TSL25911FN, "TSL2591") {}
|
||||||
|
|
||||||
|
int32_t TSL2591Sensor::runOnce()
|
||||||
|
{
|
||||||
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
|
if (!hasSensor()) {
|
||||||
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
|
}
|
||||||
|
status = tsl.begin(nodeTelemetrySensorsMap[sensorType].second);
|
||||||
|
|
||||||
|
return initI2CSensor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TSL2591Sensor::setup()
|
||||||
|
{
|
||||||
|
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
|
||||||
|
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TSL2591Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||||
|
{
|
||||||
|
uint32_t lum = tsl.getFullLuminosity();
|
||||||
|
uint16_t ir, full;
|
||||||
|
ir = lum >> 16;
|
||||||
|
full = lum & 0xFFFF;
|
||||||
|
|
||||||
|
measurement->variant.environment_metrics.lux = tsl.calculateLux(full, ir);
|
||||||
|
LOG_INFO("Lux: %f\n", measurement->variant.environment_metrics.lux);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
17
src/modules/Telemetry/Sensor/TSL2591Sensor.h
Normal file
17
src/modules/Telemetry/Sensor/TSL2591Sensor.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include <Adafruit_TSL2591.h>
|
||||||
|
|
||||||
|
class TSL2591Sensor : public TelemetrySensor
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Adafruit_TSL2591 tsl;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void setup() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TSL2591Sensor();
|
||||||
|
virtual int32_t runOnce() override;
|
||||||
|
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user