Implemented first Hangar-Service
Dependencies: CalibrateMagneto QuaternionMath
Fork of SML2 by
Diff: SensorFusion.cpp
- Revision:
- 20:503cbe360419
- Parent:
- 19:9e9753b87cfe
- Child:
- 21:5a0c9406e119
--- a/SensorFusion.cpp Thu Apr 02 14:13:01 2015 +0000 +++ b/SensorFusion.cpp Thu Apr 09 09:51:51 2015 +0000 @@ -8,6 +8,22 @@ deltat(0.010), // sec beta(1) // correction gain { + // Setup a dummy delegate object which will catch callbacks if another delegate is not set. + // This avoids having to do a comparison every time the callback is to be called. + class dummy : public SensorFusion::Delegate + { + virtual void sensorTick(Vector3 fused, Vector3 accel, Vector3 magneto, Vector3 gyro, Quaternion q) + { + // do nothing + } + } defaultDelegate; + + setDelegate(defaultDelegate); +} + +void SensorFusion::setDelegate(SensorFusion::Delegate &d) +{ + delegate = &d; } bool SensorFusion::start() @@ -69,7 +85,7 @@ Vector3 const fused = eulerAngles(q); - sensorTick(fused, accel_reading, magneto_reading, gyro_degrees, q); + delegate->sensorTick(fused, accel_reading, magneto_reading, gyro_degrees, q); } void SensorFusion::updateFilter(float ax, float ay, float az, float gx, float gy, float gz, float mx, float my, float mz)