mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-26 22:33:24 +00:00
Initial upload
This commit is contained in:
parent
c02bbad9f3
commit
fc1e60ac58
7
.vscode/extensions.json
vendored
7
.vscode/extensions.json
vendored
@ -2,8 +2,9 @@
|
|||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"ms-vscode.cpptools",
|
"platformio.platformio-ide"
|
||||||
"platformio.platformio-ide",
|
|
||||||
"trunk.io"
|
|
||||||
],
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ lib_deps =
|
|||||||
adafruit/Adafruit BMP280 Library@^2.6.8
|
adafruit/Adafruit BMP280 Library@^2.6.8
|
||||||
adafruit/Adafruit BMP085 Library@^1.2.4
|
adafruit/Adafruit BMP085 Library@^1.2.4
|
||||||
adafruit/Adafruit BME280 Library@^2.2.2
|
adafruit/Adafruit BME280 Library@^2.2.2
|
||||||
|
adafruit/Adafruit BMP3XX Library@^2.1.5
|
||||||
adafruit/Adafruit MCP9808 Library@^2.0.0
|
adafruit/Adafruit MCP9808 Library@^2.0.0
|
||||||
adafruit/Adafruit INA260 Library@^1.5.0
|
adafruit/Adafruit INA260 Library@^1.5.0
|
||||||
adafruit/Adafruit INA219@^1.2.0
|
adafruit/Adafruit INA219@^1.2.0
|
||||||
|
@ -24,6 +24,7 @@ class ScanI2C
|
|||||||
BME_280,
|
BME_280,
|
||||||
BMP_280,
|
BMP_280,
|
||||||
BMP_085,
|
BMP_085,
|
||||||
|
BMP_3XX,
|
||||||
INA260,
|
INA260,
|
||||||
INA219,
|
INA219,
|
||||||
INA3221,
|
INA3221,
|
||||||
|
@ -266,9 +266,20 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
LOG_INFO("BMP-085 or BMP-180 sensor found at address 0x%x\n", (uint8_t)addr.address);
|
LOG_INFO("BMP-085 or BMP-180 sensor found at address 0x%x\n", (uint8_t)addr.address);
|
||||||
type = BMP_085;
|
type = BMP_085;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); // GET_ID
|
||||||
|
switch(registerValue) {
|
||||||
|
case 0x50: // BMP-388 should be 0x50
|
||||||
|
LOG_INFO("BMP-388 sensor found at address 0x%x\n", (uint8_t)addr.address);
|
||||||
|
type = BMP_3XX;
|
||||||
|
break;
|
||||||
|
case 0x58: // BMP-280 should be 0x58
|
||||||
default:
|
default:
|
||||||
LOG_INFO("BMP-280 sensor found at address 0x%x\n", (uint8_t)addr.address);
|
LOG_INFO("BMP-280 sensor found at address 0x%x\n", (uint8_t)addr.address);
|
||||||
type = BMP_280;
|
type = BMP_280;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifndef HAS_NCP5623
|
#ifndef HAS_NCP5623
|
||||||
|
@ -562,6 +562,7 @@ void setup()
|
|||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BME_680, meshtastic_TelemetrySensorType_BME680)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BME_680, meshtastic_TelemetrySensorType_BME680)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BME_280, meshtastic_TelemetrySensorType_BME280)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BME_280, meshtastic_TelemetrySensorType_BME280)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BMP_280, meshtastic_TelemetrySensorType_BMP280)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BMP_280, meshtastic_TelemetrySensorType_BMP280)
|
||||||
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BMP_3XX, meshtastic_TelemetrySensorType_BMP3XX)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BMP_085, meshtastic_TelemetrySensorType_BMP085)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::BMP_085, meshtastic_TelemetrySensorType_BMP085)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::INA260, meshtastic_TelemetrySensorType_INA260)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::INA260, meshtastic_TelemetrySensorType_INA260)
|
||||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::INA219, meshtastic_TelemetrySensorType_INA219)
|
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::INA219, meshtastic_TelemetrySensorType_INA219)
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "Sensor/BME680Sensor.h"
|
#include "Sensor/BME680Sensor.h"
|
||||||
#include "Sensor/BMP085Sensor.h"
|
#include "Sensor/BMP085Sensor.h"
|
||||||
#include "Sensor/BMP280Sensor.h"
|
#include "Sensor/BMP280Sensor.h"
|
||||||
|
#include "Sensor/BMP3XXSensor.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"
|
||||||
@ -40,6 +41,7 @@
|
|||||||
BMP085Sensor bmp085Sensor;
|
BMP085Sensor bmp085Sensor;
|
||||||
BMP280Sensor bmp280Sensor;
|
BMP280Sensor bmp280Sensor;
|
||||||
BME280Sensor bme280Sensor;
|
BME280Sensor bme280Sensor;
|
||||||
|
BMP3XXSensor bmp3xxSensor;
|
||||||
BME680Sensor bme680Sensor;
|
BME680Sensor bme680Sensor;
|
||||||
MCP9808Sensor mcp9808Sensor;
|
MCP9808Sensor mcp9808Sensor;
|
||||||
SHTC3Sensor shtc3Sensor;
|
SHTC3Sensor shtc3Sensor;
|
||||||
@ -107,6 +109,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
result = bmp280Sensor.runOnce();
|
result = bmp280Sensor.runOnce();
|
||||||
if (bme280Sensor.hasSensor())
|
if (bme280Sensor.hasSensor())
|
||||||
result = bme280Sensor.runOnce();
|
result = bme280Sensor.runOnce();
|
||||||
|
if (bmp3xxSensor.hasSensor())
|
||||||
|
result = bmp3xxSensor.runOnce();
|
||||||
if (bme680Sensor.hasSensor())
|
if (bme680Sensor.hasSensor())
|
||||||
result = bme680Sensor.runOnce();
|
result = bme680Sensor.runOnce();
|
||||||
if (mcp9808Sensor.hasSensor())
|
if (mcp9808Sensor.hasSensor())
|
||||||
@ -327,6 +331,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
|
|||||||
valid = valid && bme280Sensor.getMetrics(m);
|
valid = valid && bme280Sensor.getMetrics(m);
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
}
|
}
|
||||||
|
if (bmp3xxSensor.hasSensor()) {
|
||||||
|
valid = valid && bmp3xxSensor.getMetrics(m);
|
||||||
|
hasSensor = true;
|
||||||
|
}
|
||||||
if (bme680Sensor.hasSensor()) {
|
if (bme680Sensor.hasSensor()) {
|
||||||
valid = valid && bme680Sensor.getMetrics(m);
|
valid = valid && bme680Sensor.getMetrics(m);
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
@ -372,15 +380,21 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
|
|||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
}
|
}
|
||||||
if (aht10Sensor.hasSensor()) {
|
if (aht10Sensor.hasSensor()) {
|
||||||
if (!bmp280Sensor.hasSensor()) {
|
if (!bmp280Sensor.hasSensor() && !bmp3xxSensor.hasSensor()) {
|
||||||
valid = valid && aht10Sensor.getMetrics(m);
|
valid = valid && aht10Sensor.getMetrics(m);
|
||||||
hasSensor = true;
|
hasSensor = true;
|
||||||
} else {
|
} else if (bmp280Sensor.hasSensor()) {
|
||||||
// prefer bmp280 temp if both sensors are present, fetch only humidity
|
// prefer bmp280 temp if both sensors are present, fetch only humidity
|
||||||
meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero;
|
meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero;
|
||||||
LOG_INFO("AHTX0+BMP280 module detected: using temp from BMP280 and humy from AHTX0\n");
|
LOG_INFO("AHTX0+BMP280 module detected: using temp from BMP280 and humy from AHTX0\n");
|
||||||
aht10Sensor.getMetrics(&m_ahtx);
|
aht10Sensor.getMetrics(&m_ahtx);
|
||||||
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;
|
||||||
|
} else {
|
||||||
|
// prefer bmp3xx temp if both sensors are present, fetch only humidity
|
||||||
|
meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero;
|
||||||
|
LOG_INFO("AHTX0+BMP3XX module detected: using temp from BMP3XX and humy from AHTX0\n");
|
||||||
|
aht10Sensor.getMetrics(&m_ahtx);
|
||||||
|
m->variant.environment_metrics.relative_humidity = m_ahtx.variant.environment_metrics.relative_humidity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,6 +522,11 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule
|
|||||||
if (result != AdminMessageHandleResult::NOT_HANDLED)
|
if (result != AdminMessageHandleResult::NOT_HANDLED)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (bmp3xxSensor.hasSensor()) {
|
||||||
|
result = bmp3xxSensor.handleAdminMessage(mp, request, response);
|
||||||
|
if (result != AdminMessageHandleResult::NOT_HANDLED)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
if (bme680Sensor.hasSensor()) {
|
if (bme680Sensor.hasSensor()) {
|
||||||
result = bme680Sensor.handleAdminMessage(mp, request, response);
|
result = bme680Sensor.handleAdminMessage(mp, request, response);
|
||||||
if (result != AdminMessageHandleResult::NOT_HANDLED)
|
if (result != AdminMessageHandleResult::NOT_HANDLED)
|
||||||
|
58
src/modules/Telemetry/Sensor/BMP3XXSensor.cpp
Normal file
58
src/modules/Telemetry/Sensor/BMP3XXSensor.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
|
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "BMP3XXSensor.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include <Adafruit_BMP3XX.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
BMP3XXSensor::BMP3XXSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_BMP3XX, "BMP3XX"){}
|
||||||
|
|
||||||
|
int32_t BMP3XXSensor::runOnce()
|
||||||
|
{
|
||||||
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
|
if (!hasSensor())
|
||||||
|
{
|
||||||
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = bmp3xx.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
|
||||||
|
|
||||||
|
// set up oversampling and filter initialization
|
||||||
|
bmp3xx.setTemperatureOversampling(BMP3_OVERSAMPLING_4X);
|
||||||
|
bmp3xx.setPressureOversampling(BMP3_OVERSAMPLING_8X);
|
||||||
|
bmp3xx.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
|
||||||
|
bmp3xx.setOutputDataRate(BMP3_ODR_25_HZ);
|
||||||
|
|
||||||
|
// take a couple of initial readings to settle the sensor filters
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
bmp3xx.performReading();
|
||||||
|
}
|
||||||
|
return initI2CSensor();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BMP3XXSensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||||
|
{
|
||||||
|
if ((int)measurement->which_variant == meshtastic_Telemetry_environment_metrics_tag)
|
||||||
|
{
|
||||||
|
bmp3xx.performReading();
|
||||||
|
measurement->variant.environment_metrics.temperature = bmp3xx.readTemperature();
|
||||||
|
measurement->variant.environment_metrics.barometric_pressure = bmp3xx.readPressure() / 100.0F;
|
||||||
|
LOG_DEBUG("BMP3XXSensor::getMetrics id: %i temp: %.1f press %.1f\n", measurement->which_variant, measurement->variant.environment_metrics.temperature, measurement->variant.environment_metrics.barometric_pressure);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_DEBUG("BMP3XXSensor::getMetrics id: %i\n", measurement->which_variant);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float BMP3XXSensor::getAltitudeAMSL()
|
||||||
|
{
|
||||||
|
return bmp3xx.readAltitude(SEAL_LEVEL_HPA);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
31
src/modules/Telemetry/Sensor/BMP3XXSensor.h
Normal file
31
src/modules/Telemetry/Sensor/BMP3XXSensor.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
|
|
||||||
|
#ifndef _BMP3XX_SENSOR_H
|
||||||
|
#define _BMP3XX_SENSOR_H
|
||||||
|
|
||||||
|
#define SEAL_LEVEL_HPA 1013.2f
|
||||||
|
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include <Adafruit_BMP3XX.h>
|
||||||
|
|
||||||
|
class BMP3XXSensor : public TelemetrySensor
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Adafruit_BMP3XX bmp3xx;
|
||||||
|
float pressureHPa = 0.0f;
|
||||||
|
float temperatureCelcius = 0.0f;
|
||||||
|
float altitudeAmslMetres = 0.0f;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BMP3XXSensor();
|
||||||
|
virtual int32_t runOnce() override;
|
||||||
|
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||||
|
virtual float getAltitudeAMSL();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user