Skip to content

Softfusion cleanup #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0799196
Make SPI work
Eirenliel Feb 5, 2025
f5df753
ESP32 spelling fix (#396)
ButterscotchV Feb 27, 2025
3d647f0
(Probably) multiply acceleration by tracker rotation offset
Eirenliel Mar 4, 2025
6f515bd
Remove stome stuff from softfusionsensor
gorbit99 Apr 23, 2025
4b65c66
Missed stuff
gorbit99 Apr 23, 2025
50a2da3
Undo defines changes
gorbit99 Apr 23, 2025
e964032
Undo debug.h changes
gorbit99 Apr 23, 2025
7dc88af
Uses32BitSensorData is unneccessary now
gorbit99 Apr 23, 2025
e737eba
Remove some unnecessary variables
gorbit99 Apr 23, 2025
6ef997a
Cleanup some logging text
gorbit99 Apr 23, 2025
2778185
Formatting
gorbit99 Apr 23, 2025
f3e5519
Split SensorBuilder into a header-source file pair
gorbit99 Apr 24, 2025
3138f58
Fix copyright
gorbit99 Apr 24, 2025
91c72d3
Fix some issues with glove after all the changes
Eirenliel Apr 24, 2025
e08a5bf
Add NO_WIRE definition for SPI devices
Eirenliel Apr 24, 2025
f478dd0
Fix formatting
Eirenliel Apr 24, 2025
341a947
Minor fix
Eirenliel Apr 24, 2025
8efc098
If ICM-45686 not found, ask again nicely
Eirenliel Apr 24, 2025
6742a08
Fix MCP interface not building
gorbit99 Apr 24, 2025
9aa4c6c
Remove uneccessary "default" ctor from SPIImpl
gorbit99 Apr 24, 2025
f68ce4e
Remove buildSensorReal
gorbit99 Apr 24, 2025
c214e38
Invert if statement in sensorbuilder+
gorbit99 Apr 24, 2025
800c34e
Fix formatting
Eirenliel Apr 24, 2025
7d794c7
If ICM-45686 not found, ask again nicely
Eirenliel Apr 24, 2025
23719f0
Fix MCP interface not building
gorbit99 Apr 24, 2025
2ed568f
Fix formatting
Eirenliel Apr 24, 2025
14e5399
Various cleanup
gorbit99 Apr 24, 2025
719fb1e
Merge branch 'spi-support2' of https://github.com/SlimeVR/SlimeVR-Tra…
gorbit99 Apr 24, 2025
0bba70d
Formattign
gorbit99 Apr 24, 2025
9510eaa
Merge branch 'spi-support2' into softfusion-cleanup
gorbit99 Apr 24, 2025
5c57bc1
Merge remote-tracking branch 'origin/main' into softfusion-cleanup
gorbit99 Apr 25, 2025
9f8ace3
Merge remote-tracking branch 'origin/main' into softfusion-cleanup
gorbit99 May 14, 2025
4d96306
Fix detected logic
gorbit99 May 14, 2025
9fb5b10
Remove unnecessary Self using
gorbit99 May 14, 2025
1fe3301
For some reason this fixes memory corruption issues
gorbit99 May 14, 2025
4b126b3
Formatting
gorbit99 May 14, 2025
6410c6e
Merge branch 'main' into softfusion-cleanup
gorbit99 May 17, 2025
81f4fcf
This actually works this time
gorbit99 May 17, 2025
1421d6d
Small cleanup
gorbit99 May 17, 2025
be85413
Merge branch 'main' into softfusion-cleanup
gorbit99 May 26, 2025
42042c1
Merge remote-tracking branch 'origin/main' into softfusion-cleanup
gorbit99 Jun 2, 2025
3975bc2
Remove some unused includes
gorbit99 Jun 2, 2025
1c31f8e
Formatting
gorbit99 Jun 2, 2025
adba3fd
Mag support (Attempt 2) (#458)
gorbit99 Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sensors/SensorBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@

#if USE_RUNTIME_CALIBRATION
#include "sensors/softfusion/runtimecalibration/RuntimeCalibration.h"
#define SFCALIBRATOR SlimeVR::Sensors::RuntimeCalibration::RuntimeCalibrator
#define SFCALIBRATOR RuntimeCalibration::RuntimeCalibrator
#else
#include "sensors/softfusion/SoftfusionCalibration.h"
#define SFCALIBRATOR SlimeVR::Sensor::SoftfusionCalibrator
#define SFCALIBRATOR SoftfusionCalibrator
#endif

#ifdef ESP32
Expand Down
24 changes: 24 additions & 0 deletions src/sensors/SensorToggles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,27 @@ bool SensorToggleState::getToggle(SensorToggles toggle) const {
}
return false;
}

void SensorToggleState::onToggleChange(
std::function<void(SensorToggles, bool)>&& callback
) {
this->callback = callback;
}

void SensorToggleState::emitToggleChange(SensorToggles toggle, bool state) const {
if (callback) {
(*callback)(toggle, state);
}
}

const char* SensorToggleState::toggleToString(SensorToggles toggle) {
switch (toggle) {
case SensorToggles::MagEnabled:
return "MagEnabled";
case SensorToggles::CalibrationEnabled:
return "CalibrationEnabled";
case SensorToggles::TempGradientCalibrationEnabled:
return "TempGradientCalibrationEnabled";
}
return "Unknown";
}
9 changes: 9 additions & 0 deletions src/sensors/SensorToggles.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#pragma once

#include <cstdint>
#include <functional>
#include <optional>

#include "../debug.h"

Expand All @@ -38,7 +40,14 @@ class SensorToggleState {
void setToggle(SensorToggles toggle, bool state);
[[nodiscard]] bool getToggle(SensorToggles toggle) const;

void onToggleChange(std::function<void(SensorToggles, bool)>&& callback);

static const char* toggleToString(SensorToggles toggle);

private:
std::optional<std::function<void(SensorToggles, bool)>> callback;
void emitToggleChange(SensorToggles toggle, bool state) const;

bool magEnabled = !USE_6_AXIS;
bool calibrationEnabled = true;
bool tempGradientCalibrationEnabled = true;
Expand Down
7 changes: 7 additions & 0 deletions src/sensors/bno080sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ void BNO080Sensor::motionSetup() {
configured = true;
m_tpsCounter.reset();
m_dataCounter.reset();

toggles.onToggleChange([&](SensorToggles toggle, bool) {
if (toggle == SensorToggles::MagEnabled) {
// TODO: maybe handle this more gracefully, I'm sure it's possible
motionSetup();
}
});
}

void BNO080Sensor::motionLoop() {
Expand Down
12 changes: 9 additions & 3 deletions src/sensors/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void Sensor::resetTemperatureCalibrationState() {
printTemperatureCalibrationUnsupported();
};

const char* Sensor::getAttachedMagnetometer() const { return nullptr; }

SlimeVR::Configuration::SensorConfigBits Sensor::getSensorConfigData() {
return SlimeVR::Configuration::SensorConfigBits{
.magEnabled = toggles.getToggle(SensorToggles::MagEnabled),
Expand Down Expand Up @@ -157,12 +159,16 @@ void Sensor::markRestCalibrationComplete(bool completed) {
}

void Sensor::setFlag(SensorToggles toggle, bool state) {
assert(isFlagSupported(toggle));
if (!isFlagSupported(toggle)) {
m_Logger.error(
"Toggle %s isn't supported by this sensor!",
SensorToggleState::toggleToString(toggle)
);
return;
}

toggles.setToggle(toggle, state);

configuration.setSensorToggles(sensorId, toggles);
configuration.save();

motionSetup();
}
5 changes: 5 additions & 0 deletions src/sensors/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class Sensor {
virtual void printDebugTemperatureCalibrationState();
virtual void resetTemperatureCalibrationState();
virtual void saveTemperatureCalibration();
// TODO: currently only for softfusionsensor, bmi160 and others should get
// an overload too
virtual const char* getAttachedMagnetometer() const;
// TODO: realistically each sensor should print its own state instead of
// having 15 getters for things only the serial commands use
bool isWorking() { return working; };
bool getHadData() const { return hadData; };
bool isValid() { return m_hwInterface != nullptr; };
Expand Down
30 changes: 9 additions & 21 deletions src/sensors/softfusion/CalibrationBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,31 @@
#include <functional>

#include "configuration/SensorConfig.h"
#include "imuconsts.h"
#include "motionprocessing/types.h"
#include "sensors/SensorFusion.h"

namespace SlimeVR::Sensor {
namespace SlimeVR::Sensors {

template <typename IMU, typename RawSensorT, typename RawVectorT>
template <typename IMU>
class CalibrationBase {
public:
CalibrationBase(
SlimeVR::Sensors::SensorFusion& fusion,
IMU& sensor,
uint8_t sensorId,
SlimeVR::Logging::Logger& logger,
float TempTs,
float AScale,
float GScale,
SensorToggleState& toggles
)
: fusion{fusion}
, sensor{sensor}
, sensorId{sensorId}
, logger{logger}
, TempTs{TempTs}
, AScale{AScale}
, GScale{GScale}
, toggles{toggles} {}

using Consts = IMUConsts<IMU>;
using RawSensorT = typename Consts::RawSensorT;

static constexpr bool HasMotionlessCalib
= requires(IMU& i) { typename IMU::MotionlessCalibrationData; };
static constexpr size_t MotionlessCalibDataSize() {
Expand All @@ -65,15 +63,8 @@ class CalibrationBase {
}
}

using EatSamplesFn = std::function<void(const uint32_t)>;
using ReturnLastFn
= std::function<std::tuple<RawVectorT, RawVectorT, int16_t>(const uint32_t)>;

virtual void startCalibration(
int calibrationType,
const EatSamplesFn& eatSamplesForSeconds,
const ReturnLastFn& eatSamplesReturnLast
){};
virtual void checkStartupCalibration() {}
virtual void startCalibration(int calibrationType){};

virtual bool calibrationMatches(
const SlimeVR::Configuration::SensorConfig& sensorCalibration
Expand Down Expand Up @@ -116,10 +107,7 @@ class CalibrationBase {
IMU& sensor;
uint8_t sensorId;
SlimeVR::Logging::Logger& logger;
float TempTs;
float AScale;
float GScale;
SensorToggleState& toggles;
};

} // namespace SlimeVR::Sensor
} // namespace SlimeVR::Sensors
Loading