mirror of https://github.com/meshcore-dev/MeshCore
6 changed files with 97 additions and 241 deletions
@ -1,39 +0,0 @@ |
|||||
#pragma once |
|
||||
#include <Mesh.h> |
|
||||
#include <Adafruit_AHTX0.h> |
|
||||
|
|
||||
#define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address
|
|
||||
|
|
||||
static Adafruit_AHTX0 AHTX0; |
|
||||
|
|
||||
class AHTX0Sensor { |
|
||||
bool initialized = false; |
|
||||
public: |
|
||||
void begin() { |
|
||||
if (AHTX0.begin(&Wire, 0, TELEM_AHTX_ADDRESS)) { |
|
||||
MESH_DEBUG_PRINTLN("Found AHT10/AHT20 at address: %02X", TELEM_AHTX_ADDRESS); |
|
||||
initialized = true; |
|
||||
} else { |
|
||||
initialized = false; |
|
||||
MESH_DEBUG_PRINTLN("AHT10/AHT20 was not found at I2C address %02X", TELEM_AHTX_ADDRESS); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
bool isInitialized() const { return initialized; }; |
|
||||
|
|
||||
float getRelativeHumidity() const { |
|
||||
if (initialized) { |
|
||||
sensors_event_t humidity, temp; |
|
||||
AHTX0.getEvent(&humidity, &temp); |
|
||||
return humidity.relative_humidity; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
float getTemperature() const { |
|
||||
if (initialized) { |
|
||||
sensors_event_t humidity, temp; |
|
||||
AHTX0.getEvent(&humidity, &temp); |
|
||||
return temp.temperature; |
|
||||
} |
|
||||
} |
|
||||
}; |
|
||||
@ -1,55 +0,0 @@ |
|||||
#pragma once |
|
||||
#include <Mesh.h> |
|
||||
#include <Adafruit_BME280.h> |
|
||||
|
|
||||
#define TELEM_BME280_ADDRESS 0x76 // BME280 environmental sensor I2C address
|
|
||||
#define SEALEVELPRESSURE_HPA (1013.25) // Athmospheric pressure at sea level
|
|
||||
|
|
||||
static Adafruit_BME280 BME280; |
|
||||
|
|
||||
class BME280Sensor { |
|
||||
bool initialized = false; |
|
||||
public: |
|
||||
void begin() { |
|
||||
if (BME280.begin(TELEM_BME280_ADDRESS, &Wire)) { |
|
||||
MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", TELEM_BME280_ADDRESS); |
|
||||
MESH_DEBUG_PRINTLN("BME sensor ID: %02X", BME280.sensorID); |
|
||||
initialized = true; |
|
||||
} else { |
|
||||
initialized = false; |
|
||||
MESH_DEBUG_PRINTLN("BME280 was not found at I2C address %02X", TELEM_BME280_ADDRESS); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
bool isInitialized() const { return initialized; }; |
|
||||
|
|
||||
float getRelativeHumidity() const { |
|
||||
if (initialized) { |
|
||||
return BME280.readHumidity();; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
float getTemperature() const { |
|
||||
if (initialized) { |
|
||||
return BME280.readTemperature();; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
float getBarometricPressure() const { |
|
||||
if (initialized) { |
|
||||
return BME280.readPressure(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
float getAltitude() const { |
|
||||
if (initialized) { |
|
||||
return BME280.readAltitude(SEALEVELPRESSURE_HPA); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void setTemperatureCompensation(float delta) { |
|
||||
if (initialized) { |
|
||||
BME280.setTemperatureCompensation(delta); |
|
||||
} |
|
||||
} |
|
||||
}; |
|
||||
@ -1,33 +1,37 @@ |
|||||
#pragma once |
#pragma once |
||||
|
|
||||
#include <helpers/SensorManager.h> |
#include <helpers/SensorManager.h> |
||||
#include "INA3221Sensor.h" |
#include <Mesh.h> |
||||
#include "INA219Sensor.h" |
#include <Adafruit_INA3221.h> |
||||
#include "AHTX0Sensor.h" |
#include <Adafruit_INA219.h> |
||||
#include "BME280Sensor.h" |
#include <Adafruit_AHTX0.h> |
||||
|
#include <Adafruit_BME280.h> |
||||
|
|
||||
#define NUM_SENSOR_SETTINGS 3 |
#define NUM_SENSOR_SETTINGS 3 |
||||
|
|
||||
#define TELEM_INA3221_SETTING_CH1 "INA3221-1" |
#define TELEM_AHTX_ADDRESS 0x38 // AHT10, AHT20 temperature and humidity sensor I2C address
|
||||
#define TELEM_INA3221_SETTING_CH2 "INA3221-2" |
#define TELEM_BME280_ADDRESS 0x76 // BME280 environmental sensor I2C address
|
||||
#define TELEM_INA3221_SETTING_CH3 "INA3221-3" |
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current sensor I2C address
|
||||
|
#define TELEM_INA219_ADDRESS 0x40 // INA219 single channel current sensor I2C address
|
||||
|
|
||||
class EnvironmentSensorManager : public SensorManager { |
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
|
||||
// INA3221 channels in telemetry
|
#define TELEM_INA3221_NUM_CHANNELS 3 |
||||
const char * INA3221_CHANNEL_NAMES[NUM_SENSOR_SETTINGS] = { TELEM_INA3221_SETTING_CH1, TELEM_INA3221_SETTING_CH2, TELEM_INA3221_SETTING_CH3}; |
|
||||
|
#define TELEM_INA219_SHUNT_VALUE 0.100 // shunt value in ohms (may differ between manufacturers)
|
||||
|
#define TELEM_INA219_MAX_CURRENT 5 |
||||
|
|
||||
|
#define TELEM_BME280_SEALEVELPRESSURE_HPA (1013.25) // Athmospheric pressure at sea level
|
||||
|
|
||||
|
class EnvironmentSensorManager : public SensorManager { |
||||
protected: |
protected: |
||||
int next_available_channel = TELEM_CHANNEL_SELF + 1; |
int next_available_channel = TELEM_CHANNEL_SELF + 1; |
||||
INA3221Sensor INA3221_sensor; |
|
||||
AHTX0Sensor AHTX0_sensor; |
bool INA3221_initialized = false; |
||||
INA219Sensor INA219_sensor; |
bool INA219_initialized = false; |
||||
BME280Sensor BME280_sensor; |
bool BME280_initialized = false; |
||||
|
bool AHTX0_initialized = false; |
||||
public: |
public: |
||||
EnvironmentSensorManager(){}; |
EnvironmentSensorManager(){}; |
||||
bool begin() override; |
bool begin() override; |
||||
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; |
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; |
||||
int getNumSettings() const override; |
|
||||
const char* getSettingName(int i) const override; |
|
||||
const char* getSettingValue(int i) const override; |
|
||||
bool setSettingValue(const char* name, const char* value) override; |
|
||||
}; |
}; |
||||
|
|||||
@ -1,71 +0,0 @@ |
|||||
#pragma once |
|
||||
|
|
||||
#include <Mesh.h> |
|
||||
#include <INA3221.h> |
|
||||
|
|
||||
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current sensor I2C address
|
|
||||
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
|
|
||||
|
|
||||
#define NUM_CHANNELS 3 |
|
||||
|
|
||||
static INA3221 INA_3221(TELEM_INA3221_ADDRESS, &Wire); |
|
||||
|
|
||||
class INA3221Sensor { |
|
||||
bool initialized = false; |
|
||||
|
|
||||
public: |
|
||||
void begin() { |
|
||||
if (INA_3221.begin()) { |
|
||||
MESH_DEBUG_PRINTLN("Found INA3221 at address: %02X", INA_3221.getAddress()); |
|
||||
MESH_DEBUG_PRINTLN("%04X %04X %04X", INA_3221.getDieID(), INA_3221.getManufacturerID(), INA_3221.getConfiguration()); |
|
||||
|
|
||||
for(int i = 0; i < 3; i++) { |
|
||||
INA_3221.setShuntR(i, TELEM_INA3221_SHUNT_VALUE); |
|
||||
} |
|
||||
initialized = true; |
|
||||
} else { |
|
||||
initialized = false; |
|
||||
MESH_DEBUG_PRINTLN("INA3221 was not found at I2C address %02X", TELEM_INA3221_ADDRESS); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
bool isInitialized() const { return initialized; } |
|
||||
|
|
||||
int numChannels() const { return NUM_CHANNELS; } |
|
||||
|
|
||||
float getVoltage(int channel) const { |
|
||||
if (initialized && channel >=0 && channel < NUM_CHANNELS) { |
|
||||
return INA_3221.getBusVoltage(channel); |
|
||||
} |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
float getCurrent(int channel) const { |
|
||||
if (initialized && channel >=0 && channel < NUM_CHANNELS) { |
|
||||
return INA_3221.getCurrent(channel); |
|
||||
} |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
float getPower (int channel) const { |
|
||||
if (initialized && channel >=0 && channel < NUM_CHANNELS) { |
|
||||
return INA_3221.getPower(channel); |
|
||||
} |
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
bool setChannelEnabled(int channel, bool enabled) { |
|
||||
if (initialized && channel >=0 && channel < NUM_CHANNELS) { |
|
||||
INA_3221.enableChannel(channel); |
|
||||
return true; |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
bool getChannelEnabled(int channel) const { |
|
||||
if (initialized && channel >=0 && channel < NUM_CHANNELS) { |
|
||||
return INA_3221.getEnableChannel(channel); |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
}; |
|
||||
Loading…
Reference in new issue