mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-24 03:31:14 +00:00
allow sensors connected to second I2C port (#2891)
This commit is contained in:
@@ -88,7 +88,7 @@ void setupModules()
|
||||
#endif
|
||||
#if HAS_SENSOR
|
||||
new EnvironmentTelemetryModule();
|
||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) {
|
||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I].first > 0) {
|
||||
new AirQualityTelemetryModule();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,7 @@ int32_t BME280Sensor::runOnce()
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = bme280.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||
status = bme280.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
||||
|
||||
bme280.setSampling(Adafruit_BME280::MODE_FORCED,
|
||||
Adafruit_BME280::SAMPLING_X1, // Temp. oversampling
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_BME280.h>
|
||||
|
||||
class BME280Sensor : virtual public TelemetrySensor
|
||||
class BME280Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_BME280 bme280;
|
||||
|
||||
@@ -20,7 +20,7 @@ int32_t BME680Sensor::runOnce()
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
if (!bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire))
|
||||
if (!bme680.begin(nodeTelemetrySensorsMap[sensorType].first, *nodeTelemetrySensorsMap[sensorType].second))
|
||||
checkStatus("begin");
|
||||
|
||||
if (bme680.status == BSEC_OK) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "bme680_iaq_33v_3s_4d/bsec_iaq.h"
|
||||
|
||||
class BME680Sensor : virtual public TelemetrySensor
|
||||
class BME680Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Bsec2 bme680;
|
||||
|
||||
@@ -13,7 +13,8 @@ int32_t BMP280Sensor::runOnce()
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||
bmp280 = Adafruit_BMP280(nodeTelemetrySensorsMap[sensorType].second);
|
||||
status = bmp280.begin(nodeTelemetrySensorsMap[sensorType].first);
|
||||
|
||||
bmp280.setSampling(Adafruit_BMP280::MODE_FORCED,
|
||||
Adafruit_BMP280::SAMPLING_X1, // Temp. oversampling
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
class BMP280Sensor : virtual public TelemetrySensor
|
||||
class BMP280Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_BMP280 bmp280;
|
||||
|
||||
@@ -13,8 +13,8 @@ int32_t INA219Sensor::runOnce()
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
if (!ina219.success()) {
|
||||
ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType]);
|
||||
status = ina219.begin();
|
||||
ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType].first);
|
||||
status = ina219.begin(nodeTelemetrySensorsMap[sensorType].second);
|
||||
} else {
|
||||
status = ina219.success();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "VoltageSensor.h"
|
||||
#include <Adafruit_INA219.h>
|
||||
|
||||
class INA219Sensor : virtual public TelemetrySensor, VoltageSensor
|
||||
class INA219Sensor : public TelemetrySensor, VoltageSensor
|
||||
{
|
||||
private:
|
||||
Adafruit_INA219 ina219;
|
||||
|
||||
@@ -14,7 +14,7 @@ int32_t INA260Sensor::runOnce()
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
status = ina260.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||
status = ina260.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
||||
}
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "VoltageSensor.h"
|
||||
#include <Adafruit_INA260.h>
|
||||
|
||||
class INA260Sensor : virtual public TelemetrySensor, VoltageSensor
|
||||
class INA260Sensor : public TelemetrySensor, VoltageSensor
|
||||
{
|
||||
private:
|
||||
Adafruit_INA260 ina260 = Adafruit_INA260();
|
||||
|
||||
@@ -13,7 +13,7 @@ int32_t LPS22HBSensor::runOnce()
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType]);
|
||||
status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Adafruit_LPS2X.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
|
||||
class LPS22HBSensor : virtual public TelemetrySensor
|
||||
class LPS22HBSensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_LPS22 lps22hb;
|
||||
|
||||
@@ -12,7 +12,7 @@ int32_t MCP9808Sensor::runOnce()
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||
status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_MCP9808.h>
|
||||
|
||||
class MCP9808Sensor : virtual public TelemetrySensor
|
||||
class MCP9808Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_MCP9808 mcp9808;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_SHT31.h>
|
||||
|
||||
class SHT31Sensor : virtual public TelemetrySensor
|
||||
class SHT31Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_SHTC3.h>
|
||||
|
||||
class SHTC3Sensor : virtual public TelemetrySensor
|
||||
class SHTC3Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "NodeDB.h"
|
||||
#include <utility>
|
||||
|
||||
class TwoWire;
|
||||
|
||||
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
extern uint8_t nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1];
|
||||
extern std::pair<uint8_t, TwoWire *> nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1];
|
||||
|
||||
class TelemetrySensor
|
||||
{
|
||||
@@ -16,7 +19,7 @@ class TelemetrySensor
|
||||
}
|
||||
|
||||
const char *sensorName;
|
||||
meshtastic_TelemetrySensorType sensorType;
|
||||
meshtastic_TelemetrySensorType sensorType = meshtastic_TelemetrySensorType_SENSOR_UNSET;
|
||||
unsigned status;
|
||||
bool initialized = false;
|
||||
|
||||
@@ -24,9 +27,9 @@ class TelemetrySensor
|
||||
{
|
||||
if (!status) {
|
||||
LOG_WARN("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName);
|
||||
nodeTelemetrySensorsMap[sensorType] = 0;
|
||||
nodeTelemetrySensorsMap[sensorType].first = 0;
|
||||
} else {
|
||||
LOG_INFO("Opened %s sensor on default i2c bus\n", sensorName);
|
||||
LOG_INFO("Opened %s sensor on i2c bus\n", sensorName);
|
||||
setup();
|
||||
}
|
||||
initialized = true;
|
||||
@@ -35,7 +38,7 @@ class TelemetrySensor
|
||||
virtual void setup();
|
||||
|
||||
public:
|
||||
bool hasSensor() { return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0; }
|
||||
bool hasSensor() { return nodeTelemetrySensorsMap[sensorType].first > 0; }
|
||||
|
||||
virtual int32_t runOnce() = 0;
|
||||
virtual bool isInitialized() { return initialized; }
|
||||
|
||||
Reference in New Issue
Block a user