mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 10:19:59 +00:00
WIP
This commit is contained in:
parent
8ab2e91df6
commit
c0d8602e7c
@ -151,13 +151,10 @@ lib_deps =
|
|||||||
ClosedCube OPT3001@^1.1.2
|
ClosedCube OPT3001@^1.1.2
|
||||||
emotibit/EmotiBit MLX90632@^1.0.8
|
emotibit/EmotiBit MLX90632@^1.0.8
|
||||||
dfrobot/DFRobot_RTU@^1.0.3
|
dfrobot/DFRobot_RTU@^1.0.3
|
||||||
|
|
||||||
|
|
||||||
https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.7.2502
|
https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.7.2502
|
||||||
boschsensortec/BME68x Sensor Library@^1.1.40407
|
boschsensortec/BME68x Sensor Library@^1.1.40407
|
||||||
https://github.com/KodinLanewave/INA3221@^1.0.0
|
https://github.com/KodinLanewave/INA3221@^1.0.0
|
||||||
lewisxhe/SensorLib@^0.2.0
|
lewisxhe/SensorLib@^0.2.0
|
||||||
mprograms/QMC5883LCompass@^1.2.0
|
mprograms/QMC5883LCompass@^1.2.0
|
||||||
|
|
||||||
|
|
||||||
https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee
|
https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee
|
||||||
|
https://github.com/meshtastic/i2c-sensor#8e97122268960593c8c279df1a84a29970136a8f
|
@ -52,7 +52,8 @@ class ScanI2C
|
|||||||
AHT10,
|
AHT10,
|
||||||
BMX160,
|
BMX160,
|
||||||
DFROBOT_LARK,
|
DFROBOT_LARK,
|
||||||
NAU7802
|
NAU7802,
|
||||||
|
CUSTOM_SENSOR,
|
||||||
} DeviceType;
|
} DeviceType;
|
||||||
|
|
||||||
// typedef uint8_t DeviceAddress;
|
// typedef uint8_t DeviceAddress;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "linux/LinuxHardwareI2C.h"
|
#include "linux/LinuxHardwareI2C.h"
|
||||||
#endif
|
#endif
|
||||||
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
|
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
|
||||||
|
#include "I2CDefinitions.h"
|
||||||
#include "main.h" // atecc
|
#include "main.h" // atecc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -377,6 +378,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
SCAN_SIMPLE_CASE(OPT3001_ADDR, OPT3001, "OPT3001 light sensor found\n");
|
SCAN_SIMPLE_CASE(OPT3001_ADDR, OPT3001, "OPT3001 light sensor found\n");
|
||||||
SCAN_SIMPLE_CASE(MLX90632_ADDR, MLX90632, "MLX90632 IR temp sensor found\n");
|
SCAN_SIMPLE_CASE(MLX90632_ADDR, MLX90632, "MLX90632 IR temp sensor found\n");
|
||||||
SCAN_SIMPLE_CASE(NAU7802_ADDR, NAU7802, "NAU7802 based scale found\n");
|
SCAN_SIMPLE_CASE(NAU7802_ADDR, NAU7802, "NAU7802 based scale found\n");
|
||||||
|
SCAN_SIMPLE_CASE(MT_I2C_ADDRESS, CUSTOM_SENSOR, "Meshtastic custom I2C 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);
|
||||||
|
@ -569,6 +569,7 @@ void setup()
|
|||||||
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)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::DFROBOT_LARK, meshtastic_TelemetrySensorType_DFROBOT_LARK)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::DFROBOT_LARK, meshtastic_TelemetrySensorType_DFROBOT_LARK)
|
||||||
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::CUSTOM_SENSOR, meshtastic_TelemetrySensorType_CUSTOM_SENSOR)
|
||||||
|
|
||||||
i2cScanner.reset();
|
i2cScanner.reset();
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "Sensor/BMP085Sensor.h"
|
#include "Sensor/BMP085Sensor.h"
|
||||||
#include "Sensor/BMP280Sensor.h"
|
#include "Sensor/BMP280Sensor.h"
|
||||||
#include "Sensor/BMP3XXSensor.h"
|
#include "Sensor/BMP3XXSensor.h"
|
||||||
|
#include "Sensor/CustomI2CSensor.h"
|
||||||
#include "Sensor/DFRobotLarkSensor.h"
|
#include "Sensor/DFRobotLarkSensor.h"
|
||||||
#include "Sensor/LPS22HBSensor.h"
|
#include "Sensor/LPS22HBSensor.h"
|
||||||
#include "Sensor/MCP9808Sensor.h"
|
#include "Sensor/MCP9808Sensor.h"
|
||||||
@ -56,6 +57,7 @@ MLX90632Sensor mlx90632Sensor;
|
|||||||
DFRobotLarkSensor dfRobotLarkSensor;
|
DFRobotLarkSensor dfRobotLarkSensor;
|
||||||
NAU7802Sensor nau7802Sensor;
|
NAU7802Sensor nau7802Sensor;
|
||||||
BMP3XXSensor bmp3xxSensor;
|
BMP3XXSensor bmp3xxSensor;
|
||||||
|
CustomI2CSensor customI2CSensor;
|
||||||
#ifdef T1000X_SENSOR_EN
|
#ifdef T1000X_SENSOR_EN
|
||||||
T1000xSensor t1000xSensor;
|
T1000xSensor t1000xSensor;
|
||||||
#endif
|
#endif
|
||||||
@ -143,6 +145,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
result = mlx90632Sensor.runOnce();
|
result = mlx90632Sensor.runOnce();
|
||||||
if (nau7802Sensor.hasSensor())
|
if (nau7802Sensor.hasSensor())
|
||||||
result = nau7802Sensor.runOnce();
|
result = nau7802Sensor.runOnce();
|
||||||
|
if (customI2CSensor.hasSensor())
|
||||||
|
result = customI2CSensor.runOnce();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -397,6 +401,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
|
|||||||
m->variant.environment_metrics.relative_humidity = m_ahtx.variant.environment_metrics.relative_humidity;
|
m->variant.environment_metrics.relative_humidity = m_ahtx.variant.environment_metrics.relative_humidity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (customI2CSensor.hasSensor()) {
|
||||||
|
valid = valid && customI2CSensor.getMetrics(m);
|
||||||
|
hasSensor = true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return valid && hasSensor;
|
return valid && hasSensor;
|
||||||
|
107
src/modules/Telemetry/Sensor/CustomI2CSensor.cpp
Normal file
107
src/modules/Telemetry/Sensor/CustomI2CSensor.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
|
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "CustomI2CSensor.h"
|
||||||
|
#include "I2CClient.h"
|
||||||
|
#include "I2CDefinitions.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
|
||||||
|
CustomI2CSensor::CustomI2CSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_CUSTOM_SENSOR, "CUSTOM") {}
|
||||||
|
|
||||||
|
int32_t CustomI2CSensor::runOnce()
|
||||||
|
{
|
||||||
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
|
if (!hasSensor()) {
|
||||||
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
|
} else {
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return initI2CSensor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomI2CSensor::setup()
|
||||||
|
{
|
||||||
|
// populates lastMetricsRecieved when data is received
|
||||||
|
Wire.requestFrom(MT_I2C_ADDRESS, meshtastic_EnvironmentMetrics_size);
|
||||||
|
Wire.onReceive(onReceiveMetrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CustomI2CSensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||||
|
{
|
||||||
|
// Wire.requestFrom(MT_I2C_ADDRESS, meshtastic_EnvironmentMetrics_size);
|
||||||
|
// auto length = Wire.available();
|
||||||
|
// LOG_DEBUG("CustomI2CSensor::getMetrics=%d\n", length);
|
||||||
|
// uint8_t buffer[meshtastic_EnvironmentMetrics_size];
|
||||||
|
// Wire.readBytes(buffer, length);
|
||||||
|
// meshtastic_EnvironmentMetrics metrics = meshtastic_EnvironmentMetrics_init_zero;
|
||||||
|
// proto_decode(buffer, meshtastic_EnvironmentMetrics_size, meshtastic_EnvironmentMetrics_fields, &metrics);
|
||||||
|
|
||||||
|
measurement->which_variant = meshtastic_Telemetry_environment_metrics_tag;
|
||||||
|
if (lastMetricsRecieved.has_temperature) {
|
||||||
|
measurement->variant.environment_metrics.has_temperature = true;
|
||||||
|
measurement->variant.environment_metrics.temperature = lastMetricsRecieved.temperature;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_relative_humidity) {
|
||||||
|
measurement->variant.environment_metrics.has_relative_humidity = true;
|
||||||
|
measurement->variant.environment_metrics.relative_humidity = lastMetricsRecieved.relative_humidity;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_barometric_pressure) {
|
||||||
|
measurement->variant.environment_metrics.has_barometric_pressure = true;
|
||||||
|
measurement->variant.environment_metrics.barometric_pressure = lastMetricsRecieved.barometric_pressure;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_gas_resistance) {
|
||||||
|
measurement->variant.environment_metrics.has_gas_resistance = true;
|
||||||
|
measurement->variant.environment_metrics.gas_resistance = lastMetricsRecieved.gas_resistance;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_iaq) {
|
||||||
|
measurement->variant.environment_metrics.has_iaq = true;
|
||||||
|
measurement->variant.environment_metrics.iaq = lastMetricsRecieved.iaq;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_voltage) {
|
||||||
|
measurement->variant.environment_metrics.has_voltage = true;
|
||||||
|
measurement->variant.environment_metrics.voltage = lastMetricsRecieved.voltage;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_current) {
|
||||||
|
measurement->variant.environment_metrics.has_current = true;
|
||||||
|
measurement->variant.environment_metrics.current = lastMetricsRecieved.current;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_distance) {
|
||||||
|
measurement->variant.environment_metrics.has_distance = true;
|
||||||
|
measurement->variant.environment_metrics.distance = lastMetricsRecieved.distance;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_lux) {
|
||||||
|
measurement->variant.environment_metrics.has_lux = true;
|
||||||
|
measurement->variant.environment_metrics.lux = lastMetricsRecieved.lux;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_white_lux) {
|
||||||
|
measurement->variant.environment_metrics.has_white_lux = true;
|
||||||
|
measurement->variant.environment_metrics.white_lux = lastMetricsRecieved.white_lux;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_ir_lux) {
|
||||||
|
measurement->variant.environment_metrics.has_ir_lux = true;
|
||||||
|
measurement->variant.environment_metrics.ir_lux = lastMetricsRecieved.ir_lux;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_uv_lux) {
|
||||||
|
measurement->variant.environment_metrics.has_uv_lux = true;
|
||||||
|
measurement->variant.environment_metrics.uv_lux = lastMetricsRecieved.uv_lux;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_wind_direction) {
|
||||||
|
measurement->variant.environment_metrics.has_wind_direction = true;
|
||||||
|
measurement->variant.environment_metrics.wind_direction = lastMetricsRecieved.wind_direction;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_wind_speed) {
|
||||||
|
measurement->variant.environment_metrics.has_wind_speed = true;
|
||||||
|
measurement->variant.environment_metrics.wind_speed = lastMetricsRecieved.wind_speed;
|
||||||
|
}
|
||||||
|
if (lastMetricsRecieved.has_wind_lull) {
|
||||||
|
measurement->variant.environment_metrics.has_wind_lull = true;
|
||||||
|
measurement->variant.environment_metrics.wind_lull = lastMetricsRecieved.wind_lull;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
19
src/modules/Telemetry/Sensor/CustomI2CSensor.h
Normal file
19
src/modules/Telemetry/Sensor/CustomI2CSensor.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
|
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
|
||||||
|
class CustomI2CSensor : public TelemetrySensor
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
virtual void setup() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CustomI2CSensor();
|
||||||
|
virtual int32_t runOnce() override;
|
||||||
|
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user