kopia lustrzana https://github.com/meshtastic/firmware
SHTC3 Sensor (RAK-1901) support (#1800)
rodzic
028b25cfe8
commit
a3e67f8e4b
|
@ -90,4 +90,4 @@ lib_deps =
|
|||
adafruit/Adafruit MCP9808 Library@^2.0.0
|
||||
adafruit/Adafruit INA260 Library@^1.5.0
|
||||
adafruit/Adafruit INA219@^1.2.0
|
||||
|
||||
https://github.com/adafruit/Adafruit_SHTC3@^1.0.0
|
||||
|
|
|
@ -110,6 +110,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define INA_ADDR_ALTERNATE 0x41
|
||||
#define QMC6310_ADDR 0x1C
|
||||
#define QMI8658_ADDR 0x6B
|
||||
#define SHTC3_ADDR 0x70
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Security
|
||||
|
|
|
@ -191,14 +191,18 @@ void scanI2Cdevice(void)
|
|||
nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr;
|
||||
DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
}
|
||||
if(addr == QMC6310_ADDR){
|
||||
if (addr == QMC6310_ADDR) {
|
||||
DEBUG_MSG("QMC6310 3-Axis magnetic sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr;
|
||||
}
|
||||
if(addr == QMI8658_ADDR){
|
||||
if (addr == QMI8658_ADDR) {
|
||||
DEBUG_MSG("QMI8658 6-Axis inertial measurement sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr;
|
||||
}
|
||||
if (addr == SHTC3_ADDR) {
|
||||
DEBUG_MSG("SHTC3 sensor found at address 0x%x\n", (uint8_t)addr);
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr;
|
||||
}
|
||||
} else if (err == 4) {
|
||||
DEBUG_MSG("Unknow error at address 0x%x\n", addr);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "Sensor/MCP9808Sensor.h"
|
||||
#include "Sensor/INA260Sensor.h"
|
||||
#include "Sensor/INA219Sensor.h"
|
||||
#include "Sensor/SHTC3Sensor.h"
|
||||
|
||||
BMP280Sensor bmp280Sensor;
|
||||
BME280Sensor bme280Sensor;
|
||||
|
@ -24,6 +25,7 @@ BME680Sensor bme680Sensor;
|
|||
MCP9808Sensor mcp9808Sensor;
|
||||
INA260Sensor ina260Sensor;
|
||||
INA219Sensor ina219Sensor;
|
||||
SHTC3Sensor shtc3Sensor;
|
||||
|
||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||
|
@ -83,6 +85,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||
result = ina260Sensor.runOnce();
|
||||
if (ina219Sensor.hasSensor())
|
||||
result = ina219Sensor.runOnce();
|
||||
if (shtc3Sensor.hasSensor())
|
||||
result = shtc3Sensor.runOnce();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
|
@ -212,6 +216,8 @@ 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);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "SHTC3Sensor.h"
|
||||
#include <Adafruit_SHTC3.h>
|
||||
|
||||
SHTC3Sensor::SHTC3Sensor() :
|
||||
TelemetrySensor(TelemetrySensorType_SHTC3, "SHTC3")
|
||||
{
|
||||
}
|
||||
|
||||
int32_t SHTC3Sensor::runOnce() {
|
||||
DEBUG_MSG("Init sensor: %s\n", sensorName);
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = shtc3.begin();
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
void SHTC3Sensor::setup()
|
||||
{
|
||||
// Set up oversampling and filter initialization
|
||||
}
|
||||
|
||||
bool SHTC3Sensor::getMetrics(Telemetry *measurement) {
|
||||
sensors_event_t humidity, temp;
|
||||
shtc3.getEvent(&humidity, &temp);
|
||||
|
||||
measurement->variant.environment_metrics.temperature = temp.temperature;
|
||||
measurement->variant.environment_metrics.relative_humidity = humidity.relative_humidity;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Adafruit_SHTC3.h>
|
||||
|
||||
class SHTC3Sensor : virtual public TelemetrySensor {
|
||||
private:
|
||||
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
|
||||
public:
|
||||
SHTC3Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(Telemetry *measurement) override;
|
||||
};
|
Ładowanie…
Reference in New Issue