mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-26 22:33:24 +00:00
Support SHT31 temperature sensor
This commit is contained in:
parent
f6ee6265e6
commit
506bae4a8b
@ -105,4 +105,5 @@ lib_deps =
|
||||
adafruit/Adafruit INA260 Library@^1.5.0
|
||||
adafruit/Adafruit INA219@^1.2.0
|
||||
adafruit/Adafruit SHTC3 Library@^1.0.0
|
||||
adafruit/Adafruit LPS2X@^2.0.4
|
||||
adafruit/Adafruit LPS2X@^2.0.4
|
||||
adafruit/Adafruit SHT31 Library@^2.2.0
|
||||
|
@ -114,6 +114,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define SHTC3_ADDR 0x70
|
||||
#define LPS22HB_ADDR 0x5C
|
||||
#define LPS22HB_ADDR_ALT 0x5D
|
||||
#define SHT31_ADDR 0x44
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Security
|
||||
|
@ -191,6 +191,10 @@ void scanI2Cdevice()
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr;
|
||||
DEBUG_MSG("MCP9808 sensor found\n");
|
||||
}
|
||||
if (addr == SHT31_ADDR) {
|
||||
DEBUG_MSG("SHT31 sensor found\n");
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_SHT31] = addr;
|
||||
}
|
||||
if (addr == SHTC3_ADDR) {
|
||||
DEBUG_MSG("SHTC3 sensor found\n");
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "Sensor/INA219Sensor.h"
|
||||
#include "Sensor/SHTC3Sensor.h"
|
||||
#include "Sensor/LPS22HBSensor.h"
|
||||
#include "Sensor/SHT31Sensor.h"
|
||||
|
||||
BMP280Sensor bmp280Sensor;
|
||||
BME280Sensor bme280Sensor;
|
||||
@ -29,6 +30,7 @@ INA260Sensor ina260Sensor;
|
||||
INA219Sensor ina219Sensor;
|
||||
SHTC3Sensor shtc3Sensor;
|
||||
LPS22HBSensor lps22hbSensor;
|
||||
SHT31Sensor sht31Sensor;
|
||||
|
||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||
@ -93,6 +95,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
if (lps22hbSensor.hasSensor()) {
|
||||
result = lps22hbSensor.runOnce();
|
||||
}
|
||||
if (sht31Sensor.hasSensor())
|
||||
result = sht31Sensor.runOnce();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
@ -211,6 +215,8 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
m.variant.environment_metrics.temperature = 0;
|
||||
m.variant.environment_metrics.voltage = 0;
|
||||
|
||||
if (sht31Sensor.hasSensor())
|
||||
sht31Sensor.getMetrics(&m);
|
||||
if (lps22hbSensor.hasSensor())
|
||||
lps22hbSensor.getMetrics(&m);
|
||||
if (shtc3Sensor.hasSensor())
|
||||
|
31
src/modules/Telemetry/Sensor/SHT31Sensor.cpp
Normal file
31
src/modules/Telemetry/Sensor/SHT31Sensor.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "SHT31Sensor.h"
|
||||
#include <Adafruit_SHT31.h>
|
||||
|
||||
SHT31Sensor::SHT31Sensor() :
|
||||
TelemetrySensor(TelemetrySensorType_SHT31, "SHT31")
|
||||
{
|
||||
}
|
||||
|
||||
int32_t SHT31Sensor::runOnce() {
|
||||
DEBUG_MSG("Init sensor: %s\n", sensorName);
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = sht31.begin();
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
void SHT31Sensor::setup()
|
||||
{
|
||||
// Set up oversampling and filter initialization
|
||||
}
|
||||
|
||||
bool SHT31Sensor::getMetrics(Telemetry *measurement) {
|
||||
measurement->variant.environment_metrics.temperature = sht31.readTemperature();
|
||||
measurement->variant.environment_metrics.relative_humidity = sht31.readHumidity();
|
||||
|
||||
return true;
|
||||
}
|
16
src/modules/Telemetry/Sensor/SHT31Sensor.h
Normal file
16
src/modules/Telemetry/Sensor/SHT31Sensor.h
Normal file
@ -0,0 +1,16 @@
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_SHT31.h>
|
||||
|
||||
class SHT31Sensor : virtual public TelemetrySensor {
|
||||
private:
|
||||
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
|
||||
public:
|
||||
SHT31Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(Telemetry *measurement) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user