mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
Refactoring some of the i2c boilerplate (#1498)
* Refactoring some of the i2c boilerplate * Default value * Debug statement
This commit is contained in:
@@ -5,16 +5,37 @@
|
||||
|
||||
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
inline bool hasSensor(TelemetrySensorType sensorType) {
|
||||
return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0;
|
||||
}
|
||||
|
||||
class TelemetrySensor
|
||||
{
|
||||
protected:
|
||||
TelemetrySensor() {}
|
||||
TelemetrySensor(TelemetrySensorType sensorType, const char *sensorName)
|
||||
{
|
||||
this->sensorName = sensorName;
|
||||
this->sensorType = sensorType;
|
||||
this->status = 0;
|
||||
}
|
||||
|
||||
const char *sensorName;
|
||||
TelemetrySensorType sensorType;
|
||||
unsigned status;
|
||||
|
||||
int32_t initI2CSensor() {
|
||||
if (!status) {
|
||||
DEBUG_MSG("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName);
|
||||
nodeTelemetrySensorsMap[sensorType] = 0;
|
||||
} else {
|
||||
DEBUG_MSG("Opened %s sensor on default i2c bus\n", sensorName);
|
||||
setup();
|
||||
}
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
virtual void setup();
|
||||
|
||||
public:
|
||||
bool hasSensor() {
|
||||
return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0;
|
||||
}
|
||||
|
||||
virtual int32_t runOnce() = 0;
|
||||
virtual bool getMeasurement(Telemetry *measurement) = 0;
|
||||
virtual bool getMetrics(Telemetry *measurement) = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user