mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 02:02:23 +00:00
* 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>
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "configuration.h"
|
|
#if !MESHTASTIC_EXCLUDE_I2C
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include <Wire.h>
|
|
|
|
#include "ScanI2C.h"
|
|
|
|
#include "../concurrency/Lock.h"
|
|
|
|
class ScanI2CTwoWire : public ScanI2C
|
|
{
|
|
public:
|
|
void scanPort(ScanI2C::I2CPort) override;
|
|
|
|
void scanPort(ScanI2C::I2CPort, uint8_t *, uint8_t) override;
|
|
|
|
ScanI2C::FoundDevice find(ScanI2C::DeviceType) const override;
|
|
|
|
bool exists(ScanI2C::DeviceType) const override;
|
|
|
|
size_t countDevices() const override;
|
|
|
|
static TwoWire *fetchI2CBus(ScanI2C::DeviceAddress);
|
|
|
|
protected:
|
|
FoundDevice firstOfOrNONE(size_t, DeviceType[]) const override;
|
|
|
|
private:
|
|
typedef struct RegisterLocation {
|
|
DeviceAddress i2cAddress;
|
|
RegisterAddress registerAddress;
|
|
|
|
RegisterLocation(DeviceAddress deviceAddress, RegisterAddress registerAddress)
|
|
: i2cAddress(deviceAddress), registerAddress(registerAddress)
|
|
{
|
|
}
|
|
|
|
} RegisterLocation;
|
|
|
|
typedef uint8_t ResponseWidth;
|
|
|
|
std::map<ScanI2C::DeviceAddress, ScanI2C::DeviceType> foundDevices;
|
|
|
|
// note: prone to overwriting if multiple devices of a type are added at different addresses (rare?)
|
|
std::map<ScanI2C::DeviceType, ScanI2C::DeviceAddress> deviceAddresses;
|
|
|
|
concurrency::Lock lock;
|
|
|
|
uint16_t getRegisterValue(const RegisterLocation &, ResponseWidth, bool) const;
|
|
|
|
DeviceType probeOLED(ScanI2C::DeviceAddress) const;
|
|
|
|
static void logFoundDevice(const char *device, uint8_t address);
|
|
};
|
|
#endif |