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
+5 -4
View File
@@ -10,12 +10,14 @@
#include "MMC5983MASensor.h"
#include "MotionSensor.h"
#include <memory>
extern ScanI2C::DeviceAddress magnetometer_found;
class MagnetometerThread : public concurrency::OSThread
{
private:
MotionSensor *sensor = nullptr;
std::unique_ptr<MotionSensor> sensor;
ScanI2C::FoundDevice device;
bool isInitialised = false;
@@ -69,7 +71,7 @@ class MagnetometerThread : public concurrency::OSThread
switch (device.type) {
#if __has_include(<SparkFun_MMC5983MA_Arduino_Library.h>)
case ScanI2C::DeviceType::MMC5983MA:
sensor = new MMC5983MASensor(device);
sensor.reset(new MMC5983MASensor(device));
break;
#endif
default:
@@ -106,8 +108,7 @@ class MagnetometerThread : public concurrency::OSThread
void clean()
{
isInitialised = false;
delete sensor;
sensor = nullptr;
sensor.reset();
}
};