mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 10:19:59 +00:00
Added LPS22HB (RAK-1902) sensor support (#1802)
This commit is contained in:
parent
1e1509fbf5
commit
6b614a2d6a
@ -90,4 +90,5 @@ lib_deps =
|
||||
adafruit/Adafruit MCP9808 Library@^2.0.0
|
||||
adafruit/Adafruit INA260 Library@^1.5.0
|
||||
adafruit/Adafruit INA219@^1.2.0
|
||||
adafruit/Adafruit SHTC3 Library@^1.0.0
|
||||
adafruit/Adafruit SHTC3 Library@^1.0.0
|
||||
adafruit/Adafruit LPS2X@^2.0.4
|
@ -111,6 +111,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define QMC6310_ADDR 0x1C
|
||||
#define QMI8658_ADDR 0x6B
|
||||
#define SHTC3_ADDR 0x70
|
||||
#define LPS22HB_ADDR 0x5C
|
||||
#define LPS22HB_ADDR_ALT 0x5D
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Security
|
||||
|
@ -203,6 +203,10 @@ void scanI2Cdevice(void)
|
||||
DEBUG_MSG("SHTC3 sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr;
|
||||
}
|
||||
if (addr == LPS22HB_ADDR || addr == LPS22HB_ADDR_ALT) {
|
||||
DEBUG_MSG("LPS22HB sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_LPS22] = addr;
|
||||
}
|
||||
} else if (err == 4) {
|
||||
DEBUG_MSG("Unknow error at address 0x%x\n", addr);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "Sensor/INA260Sensor.h"
|
||||
#include "Sensor/INA219Sensor.h"
|
||||
#include "Sensor/SHTC3Sensor.h"
|
||||
#include "Sensor/LPS22HBSensor.h"
|
||||
|
||||
BMP280Sensor bmp280Sensor;
|
||||
BME280Sensor bme280Sensor;
|
||||
@ -26,6 +27,7 @@ MCP9808Sensor mcp9808Sensor;
|
||||
INA260Sensor ina260Sensor;
|
||||
INA219Sensor ina219Sensor;
|
||||
SHTC3Sensor shtc3Sensor;
|
||||
LPS22HBSensor lps22hbSensor;
|
||||
|
||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||
@ -87,6 +89,9 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
result = ina219Sensor.runOnce();
|
||||
if (shtc3Sensor.hasSensor())
|
||||
result = shtc3Sensor.runOnce();
|
||||
if (lps22hbSensor.hasSensor()) {
|
||||
result = lps22hbSensor.runOnce();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
@ -204,6 +209,10 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies
|
||||
DEBUG_MSG("-----------------------------------------\n");
|
||||
DEBUG_MSG("Environment Telemetry: Read data\n");
|
||||
|
||||
if (lps22hbSensor.hasSensor())
|
||||
lps22hbSensor.getMetrics(&m);
|
||||
if (shtc3Sensor.hasSensor())
|
||||
shtc3Sensor.getMetrics(&m);
|
||||
if (bmp280Sensor.hasSensor())
|
||||
bmp280Sensor.getMetrics(&m);
|
||||
if (bme280Sensor.hasSensor())
|
||||
@ -216,8 +225,6 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies
|
||||
ina219Sensor.getMetrics(&m);
|
||||
if (ina260Sensor.hasSensor())
|
||||
ina260Sensor.getMetrics(&m);
|
||||
if (shtc3Sensor.hasSensor())
|
||||
shtc3Sensor.getMetrics(&m);
|
||||
|
||||
DEBUG_MSG("Telemetry->time: %i\n", m.time);
|
||||
DEBUG_MSG("Telemetry->barometric_pressure: %f\n", m.variant.environment_metrics.barometric_pressure);
|
||||
|
36
src/modules/Telemetry/Sensor/LPS22HBSensor.cpp
Normal file
36
src/modules/Telemetry/Sensor/LPS22HBSensor.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "LPS22HBSensor.h"
|
||||
#include <Adafruit_LPS2X.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
|
||||
LPS22HBSensor::LPS22HBSensor() :
|
||||
TelemetrySensor(TelemetrySensorType_LPS22, "LPS22HB")
|
||||
{
|
||||
}
|
||||
|
||||
int32_t LPS22HBSensor::runOnce() {
|
||||
DEBUG_MSG("Init sensor: %s\n", sensorName);
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType]);
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
void LPS22HBSensor::setup()
|
||||
{
|
||||
lps22hb.setDataRate(LPS22_RATE_10_HZ);
|
||||
}
|
||||
|
||||
bool LPS22HBSensor::getMetrics(Telemetry *measurement) {
|
||||
sensors_event_t temp;
|
||||
sensors_event_t pressure;
|
||||
lps22hb.getEvent(&pressure, &temp);
|
||||
|
||||
measurement->variant.environment_metrics.temperature = temp.temperature;
|
||||
measurement->variant.environment_metrics.barometric_pressure = pressure.pressure;
|
||||
|
||||
return true;
|
||||
}
|
17
src/modules/Telemetry/Sensor/LPS22HBSensor.h
Normal file
17
src/modules/Telemetry/Sensor/LPS22HBSensor.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_LPS2X.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
|
||||
class LPS22HBSensor : virtual public TelemetrySensor {
|
||||
private:
|
||||
Adafruit_LPS22 lps22hb;
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
|
||||
public:
|
||||
LPS22HBSensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(Telemetry *measurement) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user