Skip to content

Commit

Permalink
Obtain magnetometer events from DeviceMotion rather than raw startMag…
Browse files Browse the repository at this point in the history
…netometerUpdates(). This also makes the magnetometer onCancel() method now correct. Added set 'showsDeviceMovementDisplay' to true for magnetometer.
  • Loading branch information
Zabadam committed Jun 3, 2024
1 parent ecc5714 commit 1e2248d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class FPPMagnetometerStreamHandlerPlus: NSObject, MotionStreamHandler {
eventSink sink: @escaping FlutterEventSink
) -> FlutterError? {
_initMotionManager()
_motionManager.startMagnetometerUpdates(to: OperationQueue()) { data, error in
_motionManager.showsDeviceMovementDisplay = true
_motionManager.startDeviceMotionUpdates(
using: CMAttitudeReferenceFrame.xArbitraryCorrectedZVertical, to: OperationQueue()
) { data, error in
if _isCleanUp {
return
}
Expand All @@ -204,7 +207,7 @@ class FPPMagnetometerStreamHandlerPlus: NSObject, MotionStreamHandler {
))
return
}
let magneticField = data!.magneticField
let magneticField = data!.magneticField.field
sendTriplet(x: magneticField.x, y: magneticField.y, z: magneticField.z, sink: sink)
}
return nil
Expand Down

0 comments on commit 1e2248d

Please sign in to comment.