mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 02:32:23 +00:00
rework sensor instantiation to saves memory by removing the static allocation (#8054)
* rework I2C sensor init the goal is to only instantiate sensors that are pressend to save memory. side effacts: - easyer sensor integration (less C&P code) - nodeTelemetrySensorsMap can be removed when all devices are migrated * add missing ifdef * refactor a bunch of more sensors RAM -816 Flash -916 * fix build for t1000 * refactor more sensors RAM -192 Flash -60 * improve error handling Flash -112 * fix build * fix build * fix IndicatorSensor * fix tracker-t1000-e build not sure what magic is used but it works * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/Telemetry/Sensor/DFRobotGravitySensor.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "MeshModule.h"
|
||||
#include "NodeDB.h"
|
||||
#include "detect/ScanI2C.h"
|
||||
#include <utility>
|
||||
|
||||
#if !ARCH_PORTDUINO
|
||||
@@ -42,22 +43,32 @@ class TelemetrySensor
|
||||
initialized = true;
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
virtual void setup() = 0;
|
||||
|
||||
// TODO: check is setup used at all?
|
||||
virtual void setup() {}
|
||||
|
||||
public:
|
||||
virtual ~TelemetrySensor() {}
|
||||
|
||||
virtual AdminMessageHandleResult handleAdminMessage(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *request,
|
||||
meshtastic_AdminMessage *response)
|
||||
{
|
||||
return AdminMessageHandleResult::NOT_HANDLED;
|
||||
}
|
||||
|
||||
// TODO: delete after migration
|
||||
bool hasSensor() { return nodeTelemetrySensorsMap[sensorType].first > 0; }
|
||||
|
||||
virtual int32_t runOnce() = 0;
|
||||
#if WIRE_INTERFACES_COUNT > 1
|
||||
// Set to true if Implementation only works first I2C port (Wire)
|
||||
virtual bool onlyWire1() { return false; }
|
||||
#endif
|
||||
virtual int32_t runOnce() { return INT32_MAX; }
|
||||
virtual bool isInitialized() { return initialized; }
|
||||
virtual bool isRunning() { return status > 0; }
|
||||
|
||||
virtual bool getMetrics(meshtastic_Telemetry *measurement) = 0;
|
||||
virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) { return false; };
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user