mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
Support radar sensor RCWL-9620 on i2c
This commit is contained in:
parent
ef9808cdd6
commit
9170fe0580
@ -132,4 +132,5 @@ lib_deps =
|
||||
adafruit/Adafruit MPU6050@^2.2.4
|
||||
adafruit/Adafruit LIS3DH@^1.2.4
|
||||
https://github.com/lewisxhe/SensorLib#27fd0f721e20cd09e1f81383f0ba58a54fe84a17
|
||||
adafruit/Adafruit LSM6DS@^4.7.2
|
||||
adafruit/Adafruit LSM6DS@^4.7.2
|
||||
m5stack/M5Unit-Sonic@^0.0.2
|
||||
|
@ -128,6 +128,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define LPS22HB_ADDR_ALT 0x5D
|
||||
#define SHT31_ADDR 0x44
|
||||
#define PMSA0031_ADDR 0x12
|
||||
#define RCWL9620_ADDR 0x57
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ACCELEROMETER
|
||||
|
@ -41,6 +41,7 @@ class ScanI2C
|
||||
BQ24295,
|
||||
LSM6DS3,
|
||||
TCA9555,
|
||||
RCWL9620,
|
||||
#ifdef HAS_NCP5623
|
||||
NCP5623,
|
||||
#endif
|
||||
|
@ -288,6 +288,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
|
||||
|
||||
SCAN_SIMPLE_CASE(SHT31_ADDR, SHT31, "SHT31 sensor found\n")
|
||||
SCAN_SIMPLE_CASE(SHTC3_ADDR, SHTC3, "SHTC3 sensor found\n")
|
||||
SCAN_SIMPLE_CASE(RCWL9620_ADDR, RCWL9620, "RCWL9620 sensor found\n")
|
||||
|
||||
case LPS22HB_ADDR_ALT:
|
||||
SCAN_SIMPLE_CASE(LPS22HB_ADDR, LPS22HB, "LPS22HB sensor found\n")
|
||||
|
@ -533,6 +533,7 @@ void setup()
|
||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMI8658, meshtastic_TelemetrySensorType_QMI8658)
|
||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMC5883L, meshtastic_TelemetrySensorType_QMC5883L)
|
||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
|
||||
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620)
|
||||
|
||||
i2cScanner.reset();
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "Sensor/BMP280Sensor.h"
|
||||
#include "Sensor/LPS22HBSensor.h"
|
||||
#include "Sensor/MCP9808Sensor.h"
|
||||
#include "Sensor/RCWL9620Sensor.h"
|
||||
#include "Sensor/SHT31Sensor.h"
|
||||
#include "Sensor/SHTC3Sensor.h"
|
||||
|
||||
@ -32,6 +33,7 @@ MCP9808Sensor mcp9808Sensor;
|
||||
SHTC3Sensor shtc3Sensor;
|
||||
LPS22HBSensor lps22hbSensor;
|
||||
SHT31Sensor sht31Sensor;
|
||||
RCWL9620Sensor rcwl9620Sensor;
|
||||
|
||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||
@ -90,6 +92,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
result = ina219Sensor.runOnce();
|
||||
if (ina260Sensor.hasSensor())
|
||||
result = ina260Sensor.runOnce();
|
||||
if (rcwl9620Sensor.hasSensor())
|
||||
result = rcwl9620Sensor.runOnce();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
@ -183,6 +187,9 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
|
||||
String(lastMeasurement.variant.environment_metrics.current, 0) + "mA");
|
||||
if (lastMeasurement.variant.environment_metrics.iaq != 0)
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL), "IAQ: " + String(lastMeasurement.variant.environment_metrics.iaq));
|
||||
if (lastMeasurement.variant.environment_metrics.water_level != 0)
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||
"Water Level: " + String(lastMeasurement.variant.environment_metrics.water_level, 0) + "mm");
|
||||
}
|
||||
|
||||
bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
|
||||
@ -192,10 +199,13 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac
|
||||
const char *sender = getSenderShortName(mp);
|
||||
|
||||
LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, "
|
||||
"temperature=%f, voltage=%f\n",
|
||||
"temperature=%f\n",
|
||||
sender, t->variant.environment_metrics.barometric_pressure, t->variant.environment_metrics.current,
|
||||
t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity,
|
||||
t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage);
|
||||
t->variant.environment_metrics.temperature);
|
||||
LOG_INFO("(Received from %s): voltage=%f, IAQ=%d, water_level=%f\n", sender, t->variant.environment_metrics.voltage,
|
||||
t->variant.environment_metrics.iaq, t->variant.environment_metrics.water_level);
|
||||
|
||||
#endif
|
||||
// release previous packet before occupying a new spot
|
||||
if (lastMeasurementPacket != nullptr)
|
||||
@ -220,6 +230,8 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
m.variant.environment_metrics.relative_humidity = 0;
|
||||
m.variant.environment_metrics.temperature = 0;
|
||||
m.variant.environment_metrics.voltage = 0;
|
||||
m.variant.environment_metrics.iaq = 0;
|
||||
m.variant.environment_metrics.water_level = 0;
|
||||
|
||||
if (sht31Sensor.hasSensor())
|
||||
valid = sht31Sensor.getMetrics(&m);
|
||||
@ -241,13 +253,16 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
valid = ina219Sensor.getMetrics(&m);
|
||||
if (ina260Sensor.hasSensor())
|
||||
valid = ina260Sensor.getMetrics(&m);
|
||||
if (rcwl9620Sensor.hasSensor())
|
||||
valid = rcwl9620Sensor.getMetrics(&m);
|
||||
|
||||
if (valid) {
|
||||
LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, "
|
||||
"voltage=%f\n",
|
||||
LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f\n",
|
||||
m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current,
|
||||
m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity,
|
||||
m.variant.environment_metrics.temperature, m.variant.environment_metrics.voltage);
|
||||
m.variant.environment_metrics.temperature);
|
||||
LOG_INFO("(Sending): voltage=%f, IAQ=%d, water_level=%f\n", m.variant.environment_metrics.voltage,
|
||||
m.variant.environment_metrics.iaq, m.variant.environment_metrics.water_level);
|
||||
|
||||
sensor_read_error_count = 0;
|
||||
|
||||
|
26
src/modules/Telemetry/Sensor/RCWL9620Sensor.cpp
Normal file
26
src/modules/Telemetry/Sensor/RCWL9620Sensor.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "RCWL9620Sensor.h"
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "configuration.h"
|
||||
|
||||
RCWL9620Sensor::RCWL9620Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RCWL9620, "RCWL9620") {}
|
||||
|
||||
int32_t RCWL9620Sensor::runOnce()
|
||||
{
|
||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
status = 1;
|
||||
rcwl9620.begin(nodeTelemetrySensorsMap[sensorType].second, nodeTelemetrySensorsMap[sensorType].first, -1, -1);
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
void RCWL9620Sensor::setup() {}
|
||||
|
||||
bool RCWL9620Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
LOG_DEBUG("RCWL9620Sensor::getMetrics\n");
|
||||
measurement->variant.environment_metrics.water_level = rcwl9620.getDistance();
|
||||
return true;
|
||||
}
|
17
src/modules/Telemetry/Sensor/RCWL9620Sensor.h
Normal file
17
src/modules/Telemetry/Sensor/RCWL9620Sensor.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include <Unit_Sonic.h>
|
||||
|
||||
class RCWL9620Sensor : public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
SONIC_I2C rcwl9620;
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
|
||||
public:
|
||||
RCWL9620Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||
};
|
Loading…
Reference in New Issue
Block a user