refactor(io): unique_ptr ownership for motion sensors and I2C keyboard (#11458)

* refactor(io): unique_ptr ownership for motion sensors and I2C keyboard

- AccelerometerThread / MagnetometerThread: the owned MotionSensor
  becomes unique_ptr, removing the manual delete/null bookkeeping in
  clean(). Deletion behavior is unchanged (MotionSensor's destructor is
  virtual).

- KbI2cBase: the TCA keyboard was a reference member bound to an
  anonymous heap allocation - ownership was invisible and nothing could
  ever free it. It becomes unique_ptr with an out-of-line destructor
  (the base type is only forward-declared in the header).

- GeoCoord::pointAtDistance returned shared_ptr with no shared
  ownership anywhere (and no callers); return by value instead.

No behavior change.

* fix(io): make TCA8418KeyboardBase destructor public for unique_ptr ownership

* refactor(gps): delete dead pointAtDistance instead of converting it

Per review: zero callers in this repo or device-ui, and the math was
wrong at both ends (rangeMetersToRadians multiplies meters by 1852,
treating meters as nautical miles). Remove it, its now-unused helper,
and the <memory> include the old shared_ptr signature pulled in.
This commit is contained in:
Ben Meadors
2026-08-14 09:33:39 +00:00
committed by GitHub
parent a661fd8cd4
commit 5e54262fe1
7 changed files with 44 additions and 74 deletions
+15 -14
View File
@@ -21,6 +21,8 @@
#include "LSM6DS3Sensor.h"
#include "MPU6050Sensor.h"
#include "MotionSensor.h"
#include <memory>
#ifdef HAS_QMA6100P
#include "QMA6100PSensor.h"
#endif
@@ -33,7 +35,7 @@ extern ScanI2C::DeviceAddress accelerometer_found;
class AccelerometerThread : public concurrency::OSThread
{
private:
MotionSensor *sensor = nullptr;
std::unique_ptr<MotionSensor> sensor;
bool isInitialised = false;
public:
@@ -93,56 +95,56 @@ class AccelerometerThread : public concurrency::OSThread
switch (device.type) {
#ifdef HAS_BMA423
case ScanI2C::DeviceType::BMA423:
sensor = new BMA423Sensor(device);
sensor.reset(new BMA423Sensor(device));
break;
#endif
#if __has_include(<Adafruit_MPU6050.h>)
case ScanI2C::DeviceType::MPU6050:
sensor = new MPU6050Sensor(device);
sensor.reset(new MPU6050Sensor(device));
break;
#endif
case ScanI2C::DeviceType::BMX160:
sensor = new BMX160Sensor(device);
sensor.reset(new BMX160Sensor(device));
break;
#if __has_include(<Adafruit_LIS3DH.h>)
case ScanI2C::DeviceType::LIS3DH:
case ScanI2C::DeviceType::SC7A20:
sensor = new LIS3DHSensor(device);
sensor.reset(new LIS3DHSensor(device));
break;
#endif
#if __has_include(<Adafruit_LSM6DS3TRC.h>)
case ScanI2C::DeviceType::LSM6DS3:
sensor = new LSM6DS3Sensor(device);
sensor.reset(new LSM6DS3Sensor(device));
break;
#endif
#ifdef HAS_STK8XXX
case ScanI2C::DeviceType::STK8BAXX:
sensor = new STK8XXXSensor(device);
sensor.reset(new STK8XXXSensor(device));
break;
#endif
#if __has_include(<ICM_20948.h>)
case ScanI2C::DeviceType::ICM20948:
sensor = new ICM20948Sensor(device);
sensor.reset(new ICM20948Sensor(device));
break;
#endif
#if __has_include(<ICM42670P.h>)
case ScanI2C::DeviceType::ICM42607P:
sensor = new ICM42607PSensor(device);
sensor.reset(new ICM42607PSensor(device));
break;
#endif
#if __has_include(<DFRobot_BMM150.h>)
case ScanI2C::DeviceType::BMM150:
sensor = new BMM150Sensor(device);
sensor.reset(new BMM150Sensor(device));
break;
#endif
#ifdef HAS_BMI270
case ScanI2C::DeviceType::BMI270:
sensor = new BMI270Sensor(device);
sensor.reset(new BMI270Sensor(device));
break;
#endif
#ifdef HAS_QMA6100P
case ScanI2C::DeviceType::QMA6100P:
sensor = new QMA6100PSensor(device);
sensor.reset(new QMA6100PSensor(device));
break;
#endif
default:
@@ -185,8 +187,7 @@ class AccelerometerThread : public concurrency::OSThread
void clean()
{
isInitialised = false;
delete sensor;
sensor = nullptr;
sensor.reset();
}
};