mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-18 11:13:29 +00:00
Add bmp-280 support (#1581)
This commit is contained in:
parent
ade32b1827
commit
97684c6c73
@ -81,6 +81,7 @@ lib_deps =
|
|||||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||||
paulstoffregen/OneWire@^2.3.5
|
paulstoffregen/OneWire@^2.3.5
|
||||||
robtillaart/DS18B20@^0.1.11
|
robtillaart/DS18B20@^0.1.11
|
||||||
|
adafruit/Adafruit BMP280 Library@^2.6.3
|
||||||
adafruit/Adafruit BME280 Library@^2.2.2
|
adafruit/Adafruit BME280 Library@^2.2.2
|
||||||
adafruit/Adafruit BME680 Library@^2.0.1
|
adafruit/Adafruit BME680 Library@^2.0.1
|
||||||
adafruit/Adafruit MCP9808 Library@^2.0.0
|
adafruit/Adafruit MCP9808 Library@^2.0.0
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8c6ada3df4a9ea17a89d31b4f814d83a3c503b53
|
Subproject commit 11d94c9b15e9085b0f2516735ad816a3a35d5680
|
@ -124,6 +124,9 @@ void scanI2Cdevice(void)
|
|||||||
} else if (registerValue == 0x60) {
|
} else if (registerValue == 0x60) {
|
||||||
DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr);
|
DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr);
|
||||||
nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr;
|
nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr;
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("BMP-280 sensor found at address 0x%x\n", (uint8_t)addr);
|
||||||
|
nodeTelemetrySensorsMap[TelemetrySensorType_BMP280] = addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) {
|
if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) {
|
||||||
|
@ -93,7 +93,7 @@ uint32_t serialSinceMsec;
|
|||||||
bool axp192_found;
|
bool axp192_found;
|
||||||
|
|
||||||
// Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan
|
// Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan
|
||||||
uint8_t nodeTelemetrySensorsMap[6] = { 0, 0, 0, 0, 0, 0 };
|
uint8_t nodeTelemetrySensorsMap[7] = { 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
Router *router = NULL; // Users of router don't care what sort of subclass implements that API
|
Router *router = NULL; // Users of router don't care what sort of subclass implements that API
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ extern bool axp192_found;
|
|||||||
extern bool isCharging;
|
extern bool isCharging;
|
||||||
extern bool isUSBPowered;
|
extern bool isUSBPowered;
|
||||||
|
|
||||||
extern uint8_t nodeTelemetrySensorsMap[6];
|
extern uint8_t nodeTelemetrySensorsMap[7];
|
||||||
|
|
||||||
// Global Screen singleton.
|
// Global Screen singleton.
|
||||||
extern graphics::Screen *screen;
|
extern graphics::Screen *screen;
|
||||||
|
@ -23,7 +23,9 @@ typedef enum _TelemetrySensorType {
|
|||||||
/* Moderate accuracy current and voltage */
|
/* Moderate accuracy current and voltage */
|
||||||
TelemetrySensorType_INA260 = 4,
|
TelemetrySensorType_INA260 = 4,
|
||||||
/* Moderate accuracy current and voltage */
|
/* Moderate accuracy current and voltage */
|
||||||
TelemetrySensorType_INA219 = 5
|
TelemetrySensorType_INA219 = 5,
|
||||||
|
/* High accuracy temperature and pressure */
|
||||||
|
TelemetrySensorType_BMP280 = 6
|
||||||
} TelemetrySensorType;
|
} TelemetrySensorType;
|
||||||
|
|
||||||
/* Struct definitions */
|
/* Struct definitions */
|
||||||
@ -75,8 +77,8 @@ typedef struct _Telemetry {
|
|||||||
|
|
||||||
/* Helper constants for enums */
|
/* Helper constants for enums */
|
||||||
#define _TelemetrySensorType_MIN TelemetrySensorType_NotSet
|
#define _TelemetrySensorType_MIN TelemetrySensorType_NotSet
|
||||||
#define _TelemetrySensorType_MAX TelemetrySensorType_INA219
|
#define _TelemetrySensorType_MAX TelemetrySensorType_BMP280
|
||||||
#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_INA219+1))
|
#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_BMP280+1))
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -11,12 +11,14 @@
|
|||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
|
#include "Sensor/BMP280Sensor.h"
|
||||||
#include "Sensor/BME280Sensor.h"
|
#include "Sensor/BME280Sensor.h"
|
||||||
#include "Sensor/BME680Sensor.h"
|
#include "Sensor/BME680Sensor.h"
|
||||||
#include "Sensor/MCP9808Sensor.h"
|
#include "Sensor/MCP9808Sensor.h"
|
||||||
#include "Sensor/INA260Sensor.h"
|
#include "Sensor/INA260Sensor.h"
|
||||||
#include "Sensor/INA219Sensor.h"
|
#include "Sensor/INA219Sensor.h"
|
||||||
|
|
||||||
|
BMP280Sensor bmp280Sensor;
|
||||||
BME280Sensor bme280Sensor;
|
BME280Sensor bme280Sensor;
|
||||||
BME680Sensor bme680Sensor;
|
BME680Sensor bme680Sensor;
|
||||||
MCP9808Sensor mcp9808Sensor;
|
MCP9808Sensor mcp9808Sensor;
|
||||||
@ -69,10 +71,12 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
DEBUG_MSG("Environment Telemetry: Initializing\n");
|
DEBUG_MSG("Environment Telemetry: Initializing\n");
|
||||||
// it's possible to have this module enabled, only for displaying values on the screen.
|
// it's possible to have this module enabled, only for displaying values on the screen.
|
||||||
// therefore, we should only enable the sensor loop if measurement is also enabled
|
// therefore, we should only enable the sensor loop if measurement is also enabled
|
||||||
if (bme680Sensor.hasSensor())
|
if (bmp280Sensor.hasSensor())
|
||||||
result = bme680Sensor.runOnce();
|
result = bmp280Sensor.runOnce();
|
||||||
if (bme280Sensor.hasSensor())
|
if (bme280Sensor.hasSensor())
|
||||||
result = bme280Sensor.runOnce();
|
result = bme280Sensor.runOnce();
|
||||||
|
if (bme680Sensor.hasSensor())
|
||||||
|
result = bme680Sensor.runOnce();
|
||||||
if (mcp9808Sensor.hasSensor())
|
if (mcp9808Sensor.hasSensor())
|
||||||
result = mcp9808Sensor.runOnce();
|
result = mcp9808Sensor.runOnce();
|
||||||
if (ina260Sensor.hasSensor())
|
if (ina260Sensor.hasSensor())
|
||||||
@ -196,6 +200,8 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies
|
|||||||
DEBUG_MSG("-----------------------------------------\n");
|
DEBUG_MSG("-----------------------------------------\n");
|
||||||
DEBUG_MSG("Environment Telemetry: Read data\n");
|
DEBUG_MSG("Environment Telemetry: Read data\n");
|
||||||
|
|
||||||
|
if (bmp280Sensor.hasSensor())
|
||||||
|
bmp280Sensor.getMetrics(&m);
|
||||||
if (bme280Sensor.hasSensor())
|
if (bme280Sensor.hasSensor())
|
||||||
bme280Sensor.getMetrics(&m);
|
bme280Sensor.getMetrics(&m);
|
||||||
if (bme680Sensor.hasSensor())
|
if (bme680Sensor.hasSensor())
|
||||||
|
30
src/modules/Telemetry/Sensor/BMP280Sensor.cpp
Normal file
30
src/modules/Telemetry/Sensor/BMP280Sensor.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "../mesh/generated/telemetry.pb.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "BMP280Sensor.h"
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
BMP280Sensor::BMP280Sensor() :
|
||||||
|
TelemetrySensor(TelemetrySensorType_BME280, "BMP280")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BMP280Sensor::runOnce() {
|
||||||
|
DEBUG_MSG("Init sensor: %s\n", sensorName);
|
||||||
|
if (!hasSensor()) {
|
||||||
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
|
}
|
||||||
|
status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||||
|
return initI2CSensor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMP280Sensor::setup() { }
|
||||||
|
|
||||||
|
bool BMP280Sensor::getMetrics(Telemetry *measurement) {
|
||||||
|
DEBUG_MSG("BMP280Sensor::getMetrics\n");
|
||||||
|
measurement->variant.environment_metrics.temperature = bmp280.readTemperature();
|
||||||
|
measurement->variant.environment_metrics.barometric_pressure = bmp280.readPressure() / 100.0F;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
16
src/modules/Telemetry/Sensor/BMP280Sensor.h
Normal file
16
src/modules/Telemetry/Sensor/BMP280Sensor.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "../mesh/generated/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
|
class BMP280Sensor : virtual public TelemetrySensor {
|
||||||
|
private:
|
||||||
|
Adafruit_BMP280 bmp280;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void setup() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BMP280Sensor();
|
||||||
|
virtual int32_t runOnce() override;
|
||||||
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user