pull/3678/head
Thomas Göttgens 2024-04-21 16:35:41 +02:00
rodzic a957065fe8
commit a231cd2ad0
2 zmienionych plików z 12 dodań i 11 usunięć

Wyświetl plik

@ -11,7 +11,8 @@ int32_t RCWL9620Sensor::runOnce()
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
status = begin(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second);
status = 1;
begin(nodeTelemetrySensorsMap[sensorType].second, nodeTelemetrySensorsMap[sensorType].first);
return initI2CSensor();
}
@ -24,16 +25,14 @@ bool RCWL9620Sensor::getMetrics(meshtastic_Telemetry *measurement)
return true;
}
bool RCWL9620Sensor::begin(uint8_t addr, TwoWire *wire)
void RCWL9620Sensor::begin(TwoWire *wire, uint8_t addr, uint8_t sda, uint8_t scl, uint32_t speed)
{
_wire = wire;
_addr = addr;
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(_addr, _wire);
if (!i2c_dev->begin())
return false;
return true;
_sda = sda;
_scl = scl;
_speed = speed;
_wire->begin();
}
float RCWL9620Sensor::getDistance()

Wyświetl plik

@ -1,17 +1,19 @@
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include <Adafruit_I2CDevice.h>
#include <Wire.h>
class RCWL9620Sensor : public TelemetrySensor
{
private:
uint8_t _addr;
TwoWire *_wire;
uint8_t _scl;
uint8_t _sda;
uint8_t _speed;
protected:
virtual void setup() override;
bool begin(uint8_t addr = 0x57, TwoWire *wire = &Wire);
Adafruit_I2CDevice *i2c_dev = NULL;
void begin(TwoWire *wire = &Wire, uint8_t addr = 0x57, uint8_t sda = -1, uint8_t scl = -1, uint32_t speed = 200000L);
float getDistance();
public: