react-native-nitro-compass 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +381 -163
  2. package/android/src/main/java/com/margelo/nitro/nitrocompass/HybridNitroCompass.kt +654 -133
  3. package/ios/HybridNitroCompass.swift +106 -3
  4. package/lib/commonjs/hook.js +98 -11
  5. package/lib/commonjs/hook.js.map +1 -1
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/multiplex.js +23 -2
  8. package/lib/commonjs/multiplex.js.map +1 -1
  9. package/lib/module/hook.js +99 -12
  10. package/lib/module/hook.js.map +1 -1
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/module/multiplex.js +23 -2
  13. package/lib/module/multiplex.js.map +1 -1
  14. package/lib/typescript/src/hook.d.ts +39 -1
  15. package/lib/typescript/src/hook.d.ts.map +1 -1
  16. package/lib/typescript/src/index.d.ts +2 -2
  17. package/lib/typescript/src/index.d.ts.map +1 -1
  18. package/lib/typescript/src/multiplex.d.ts.map +1 -1
  19. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts +142 -18
  20. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts.map +1 -1
  21. package/nitrogen/generated/android/c++/JCompassSample.hpp +7 -3
  22. package/nitrogen/generated/android/c++/JDebugInfo.hpp +85 -0
  23. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.cpp +17 -0
  24. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.hpp +3 -0
  25. package/nitrogen/generated/android/c++/JSensorKind.hpp +6 -3
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/CompassSample.kt +9 -4
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/DebugInfo.kt +86 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/HybridNitroCompassSpec.kt +12 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/SensorKind.kt +4 -3
  30. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Bridge.hpp +12 -0
  31. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Umbrella.hpp +3 -0
  32. package/nitrogen/generated/ios/c++/HybridNitroCompassSpecSwift.hpp +23 -0
  33. package/nitrogen/generated/ios/swift/CompassSample.swift +7 -2
  34. package/nitrogen/generated/ios/swift/DebugInfo.swift +64 -0
  35. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec.swift +3 -0
  36. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec_cxx.swift +34 -0
  37. package/nitrogen/generated/ios/swift/SensorKind.swift +8 -4
  38. package/nitrogen/generated/shared/c++/CompassSample.hpp +6 -2
  39. package/nitrogen/generated/shared/c++/DebugInfo.hpp +111 -0
  40. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.cpp +3 -0
  41. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.hpp +6 -0
  42. package/nitrogen/generated/shared/c++/SensorKind.hpp +10 -6
  43. package/package.json +2 -2
  44. package/src/hook.ts +146 -12
  45. package/src/index.ts +2 -0
  46. package/src/multiplex.ts +23 -2
  47. package/src/specs/NitroCompass.nitro.ts +147 -18
@@ -1,4 +1,4 @@
1
- import type { AccuracyQuality, CompassSample, SensorDiagnostics } from './specs/NitroCompass.nitro';
1
+ import type { AccuracyQuality, CompassSample, PermissionStatus, SensorDiagnostics } from './specs/NitroCompass.nitro';
2
2
  export interface UseCompassOptions {
3
3
  /**
4
4
  * Minimum change between samples in degrees. Pass `0` for "every
@@ -47,6 +47,44 @@ export interface UseCompassResult {
47
47
  hasCompass: boolean;
48
48
  /** Which sensor backs the readings on this device. */
49
49
  diagnostics: SensorDiagnostics | undefined;
50
+ /**
51
+ * Latest platform permission status. Always `'granted'` on Android.
52
+ * On iOS may transition from `'unknown'` → `'granted'`/`'denied'`
53
+ * after `requestPermission()` resolves.
54
+ */
55
+ permission: PermissionStatus;
56
+ /**
57
+ * Synchronous read of the most recent emitted sample (with declination
58
+ * already applied), or `undefined` if not started yet or no sample
59
+ * has arrived. Useful inside event handlers without re-rendering.
60
+ */
61
+ getCurrentHeading: () => CompassSample | undefined;
62
+ /**
63
+ * Force a best-effort sensor recalibration. On Android this re-registers
64
+ * the sensor listeners (often nudges the magnetometer driver to
65
+ * re-evaluate calibration); on iOS it dismisses the heading-calibration
66
+ * overlay and stop/restarts heading updates.
67
+ */
68
+ recalibrate: () => void;
69
+ /**
70
+ * Set the user's geographic location for a tighter interference gate.
71
+ * Android uses the WMM2025 model bundled in `GeomagneticField` to
72
+ * derive the expected field strength at the location; iOS is a no-op
73
+ * because `CLLocationManager` already uses GPS-derived location
74
+ * internally for all field-related reasoning. Pass `NaN` or
75
+ * out-of-range values to revert to the generic 20–70 µT band.
76
+ */
77
+ setLocation: (latitude: number, longitude: number) => void;
78
+ /**
79
+ * Request the platform permission required to deliver headings.
80
+ * Android resolves immediately with `'granted'`. On iOS this prompts
81
+ * the system "Allow location" dialog if the status is `'unknown'`,
82
+ * resolving once the user makes a choice; subsequent calls resolve
83
+ * immediately with the cached status (iOS does not re-prompt). The
84
+ * hook's `permission` field updates automatically when the promise
85
+ * resolves.
86
+ */
87
+ requestPermission: () => Promise<PermissionStatus>;
50
88
  }
51
89
  /**
52
90
  * Ergonomic React wrapper for the NitroCompass surface. Handles
@@ -1 +1 @@
1
- {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../../src/hook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,4BAA4B,CAAA;AAQnC,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,iBAAiB,CAAC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H,UAAU,EAAE,gBAAgB,CAAA;IAC5B;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,aAAa,GAAG,SAAS,CAAA;IAClD;;;;;OAKG;IACH,WAAW,EAAE,MAAM,IAAI,CAAA;IACvB;;;;;;;OAOG;IACH,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC1D;;;;;;;;OAQG;IACH,iBAAiB,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,CAAA;CACnD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CA0JlB"}
@@ -1,6 +1,6 @@
1
- import type { AccuracyQuality, CompassSample, NitroCompass as NitroCompassSpec, PermissionStatus, SensorDiagnostics, SensorKind } from './specs/NitroCompass.nitro';
1
+ import type { AccuracyQuality, CompassSample, DebugInfo, NitroCompass as NitroCompassSpec, PermissionStatus, SensorDiagnostics, SensorKind } from './specs/NitroCompass.nitro';
2
2
  export { NitroCompass } from './native';
3
- export type { AccuracyQuality, CompassSample, PermissionStatus, SensorDiagnostics, SensorKind, };
3
+ export type { AccuracyQuality, CompassSample, DebugInfo, PermissionStatus, SensorDiagnostics, SensorKind, };
4
4
  export type { NitroCompassSpec as NitroCompassHybridObject };
5
5
  export { addCalibrationListener, addHeadingListener, addInterferenceListener, } from './multiplex';
6
6
  export { useCompass } from './hook';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,YAAY,IAAI,gBAAgB,EAChC,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,YAAY,EACV,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,CAAA;AACD,YAAY,EAAE,gBAAgB,IAAI,wBAAwB,EAAE,CAAA;AAE5D,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,IAAI,gBAAgB,EAChC,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC,YAAY,EACV,eAAe,EACf,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,CAAA;AACD,YAAY,EAAE,gBAAgB,IAAI,wBAAwB,EAAE,CAAA;AAE5D,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"multiplex.d.ts","sourceRoot":"","sources":["../../../src/multiplex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,MAAM,4BAA4B,CAAA;AAGnC,KAAK,eAAe,GAAG,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;AACtD,KAAK,mBAAmB,GAAG,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAA;AAC7D,KAAK,oBAAoB,GAAG,CAAC,oBAAoB,EAAE,OAAO,KAAK,IAAI,CAAA;AAyCnE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,eAAe,GAAG,MAAM,IAAI,CAYlE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,mBAAmB,GACtB,MAAM,IAAI,CASZ;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,oBAAoB,GACvB,MAAM,IAAI,CASZ"}
1
+ {"version":3,"file":"multiplex.d.ts","sourceRoot":"","sources":["../../../src/multiplex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,MAAM,4BAA4B,CAAA;AAGnC,KAAK,eAAe,GAAG,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAA;AACtD,KAAK,mBAAmB,GAAG,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI,CAAA;AAC7D,KAAK,oBAAoB,GAAG,CAAC,oBAAoB,EAAE,OAAO,KAAK,IAAI,CAAA;AAyCnE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,eAAe,GAAG,MAAM,IAAI,CAYlE;AASD;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,mBAAmB,GACtB,MAAM,IAAI,CAmBZ;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,oBAAoB,GACvB,MAAM,IAAI,CAaZ"}
@@ -1,7 +1,7 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
2
  /**
3
3
  * One compass heading sample, delivered to the JS callback registered with
4
- * `start()`. Both fields are in degrees.
4
+ * `start()`. Angular fields are in degrees; field strength is in microtesla.
5
5
  *
6
6
  * - `heading`: heading clockwise from north, in `[0, 360)`. Magnetic by
7
7
  * default; if you call `setDeclination(deg)` the offset is applied
@@ -9,41 +9,122 @@ import type { HybridObject } from 'react-native-nitro-modules';
9
9
  * `getCurrentHeading()`).
10
10
  * - `accuracy`: estimated heading uncertainty in degrees, or `-1` when the
11
11
  * platform has not yet reported a usable accuracy. Smaller is better.
12
- * On Android this is read from `event.values[4]` of the rotation-vector
13
- * sensor when available, otherwise mapped from `SensorManager.SENSOR_STATUS_*`.
14
- * On iOS this is `CLHeading.headingAccuracy`.
12
+ * On Android, mapped from the magnetometer's `SENSOR_STATUS_*` accuracy
13
+ * bucket (the figure-8 calibration signal). On iOS this is
14
+ * `CLHeading.headingAccuracy`.
15
+ * - `fieldStrengthMicroTesla`: magnitude of the local magnetic field in
16
+ * microteslas (µT), or `-1` when no reading is available yet. Earth's
17
+ * field is normally 25–65 µT; values well outside this band signal
18
+ * external interference (laptops, monitors, magnets, metal). Useful
19
+ * for rendering a "strength" meter à la consumer compass apps.
15
20
  */
16
21
  export interface CompassSample {
17
22
  heading: number;
18
23
  accuracy: number;
24
+ fieldStrengthMicroTesla: number;
19
25
  }
20
26
  /**
21
- * Coarse calibration bucket reported via `setOnCalibrationNeeded`. Buckets
22
- * are derived from numeric heading accuracy on both platforms (same
23
- * thresholds), so values agree across iOS and Android:
27
+ * Coarse calibration bucket reported via `setOnCalibrationNeeded`. The
28
+ * bucket is derived from a numeric heading-accuracy estimate on both
29
+ * platforms, but the thresholds differ because the underlying scales
30
+ * disagree:
24
31
  *
25
- * `<5°` `high`, `<15°` `medium`, `<30°` `low`, otherwise `unreliable`.
32
+ * - **Android** direct mapping from `SensorManager.SENSOR_STATUS_*`:
33
+ * `HIGH` → `high`, `MEDIUM` → `medium`, `LOW` → `low`,
34
+ * `UNRELIABLE`/`NO_CONTACT` → `unreliable`. The numeric `accuracy`
35
+ * field on `CompassSample` is a synthetic upper bound (`<5°`,
36
+ * `<15°`, `<30°`, `-1`).
37
+ * - **iOS** — bucketed from `CLHeading.headingAccuracy` (degrees) with
38
+ * relaxed thresholds because Apple's stack rarely reports under 5°
39
+ * even on a perfectly-calibrated compass:
40
+ * `<20°` → `high`, `<35°` → `medium`, `<55°` → `low`, otherwise
41
+ * `unreliable`. `unreliable` is also reported when iOS asks to
42
+ * display its built-in calibration UI (we suppress the system UI so
43
+ * you can render your own banner).
26
44
  *
27
- * On iOS `unreliable` is also reported when the system asks to display
28
- * its built-in calibration UI (we suppress it).
45
+ * The buckets are intended for UX ("show calibrate prompt") exact
46
+ * cross-platform parity isn't possible because the platforms emit
47
+ * different underlying signals.
29
48
  */
30
49
  export type AccuracyQuality = 'high' | 'medium' | 'low' | 'unreliable';
31
50
  /**
32
51
  * Identifies which underlying sensor / framework is producing headings.
33
52
  *
34
- * - `rotationVector` — Android `Sensor.TYPE_ROTATION_VECTOR` (gyro + accel
35
- * + magnetometer fused). Best quality.
36
- * - `geomagneticRotationVector` Android
37
- * `Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR` (accel + magnetometer only).
38
- * Used as fallback on gyroless / budget devices; lower update rate and
39
- * more susceptible to magnetic interference.
53
+ * - `magnetometer` — Android raw `TYPE_MAGNETIC_FIELD` + `TYPE_ACCELEROMETER`
54
+ * computed via `SensorManager.getRotationMatrix()` + `getOrientation()`.
55
+ * Stateless: snaps back instantly when external interference (magnets,
56
+ * electronics) is removed, instead of waiting for OS-level fusion to
57
+ * re-converge.
40
58
  * - `coreLocation` — iOS `CLLocationManager` heading. Apple's stack
41
59
  * handles fusion natively.
60
+ * - `rotationVector` / `geomagneticRotationVector` — legacy values kept
61
+ * in the union for source compatibility; no longer returned by current
62
+ * builds.
42
63
  */
43
- export type SensorKind = 'rotationVector' | 'geomagneticRotationVector' | 'coreLocation';
64
+ export type SensorKind = 'magnetometer' | 'coreLocation' | 'rotationVector' | 'geomagneticRotationVector';
44
65
  export interface SensorDiagnostics {
45
66
  sensor: SensorKind;
46
67
  }
68
+ /**
69
+ * Live introspection of the native compass pipeline. Use for
70
+ * diagnosing user-reported issues (heading wrong, banner stuck,
71
+ * compass frozen) — none of these fields are needed for normal
72
+ * operation.
73
+ *
74
+ * Numeric fields use `-1` (or `NaN` for `fusedYawDeg`) as a
75
+ * "not-applicable / not-yet-available" sentinel; consumers should
76
+ * treat those as missing rather than literal values. Most fields
77
+ * are Android-only — iOS uses `CLLocationManager` and doesn't expose
78
+ * the underlying state, so the iOS implementation reports a minimal
79
+ * subset (`lastFieldMicroTesla`, `interferenceActive`).
80
+ */
81
+ export interface DebugInfo {
82
+ /**
83
+ * Whether the library currently considers external interference to
84
+ * be active. Driven by field-magnitude band checks AND (Android,
85
+ * uncalibrated mag only) recent OS hard-iron-bias jumps.
86
+ */
87
+ interferenceActive: boolean;
88
+ /**
89
+ * Milliseconds since the most recent OS hard-iron bias jump on
90
+ * Android's uncalibrated magnetometer. `-1` if never seen.
91
+ * iOS / fallback path: always `-1`.
92
+ */
93
+ msSinceLastBiasJump: number;
94
+ /**
95
+ * The expected magnetic field magnitude (µT) at the user's
96
+ * location, derived from `setLocation()`. Used to tighten the
97
+ * interference band. `-1` if `setLocation()` hasn't been called
98
+ * with valid coordinates.
99
+ */
100
+ expectedFieldMicroTesla: number;
101
+ /**
102
+ * Most recent measured field magnitude (µT) — same value surfaced
103
+ * on `CompassSample.fieldStrengthMicroTesla`. `-1` if no reading.
104
+ */
105
+ lastFieldMicroTesla: number;
106
+ /**
107
+ * Current value of the gyro-corrected fused yaw (deg, [0, 360)).
108
+ * `NaN` before any sample has been processed, or on iOS where
109
+ * gyro fusion is handled inside CLLocationManager.
110
+ */
111
+ fusedYawDeg: number;
112
+ /**
113
+ * Latest yaw rate (deg/s) derived from game-rotation-vector
114
+ * deltas. Used to drive the adaptive input low-pass filter.
115
+ * `0` if game-RV is unavailable / hasn't fired yet.
116
+ */
117
+ lastYawRateDegPerS: number;
118
+ /** Whether `TYPE_GAME_ROTATION_VECTOR` is currently producing events. Always `false` on iOS. */
119
+ hasGameRotationVector: boolean;
120
+ /**
121
+ * Whether Android is sourcing magnetometer data from
122
+ * `TYPE_MAGNETIC_FIELD_UNCALIBRATED` (preferred — bias-jump
123
+ * detection works) vs. the `TYPE_MAGNETIC_FIELD` fallback. Always
124
+ * `false` on iOS.
125
+ */
126
+ usingUncalibratedMag: boolean;
127
+ }
47
128
  /**
48
129
  * Platform permission state required to deliver headings.
49
130
  *
@@ -117,9 +198,16 @@ export interface NitroCompass extends HybridObject<{
117
198
  * (equivalent to `hasCompass() === false`). Safe to call before `start()`.
118
199
  */
119
200
  getDiagnostics(): SensorDiagnostics | undefined;
201
+ /**
202
+ * Snapshot of the internal compass pipeline. Only intended for
203
+ * diagnosing user-reported issues — see {@link DebugInfo} for
204
+ * field-by-field semantics. Cheap to call (no allocations beyond
205
+ * the returned object); poll at any rate the host UI prefers.
206
+ */
207
+ getDebugInfo(): DebugInfo;
120
208
  /**
121
209
  * Whether the device has the hardware required for a compass reading.
122
- * Android: a rotation-vector sensor (fused or geomagnetic) is present.
210
+ * Android: both a magnetometer and an accelerometer are present.
123
211
  * iOS: `CLLocationManager.headingAvailable()`.
124
212
  */
125
213
  hasCompass(): boolean;
@@ -136,6 +224,24 @@ export interface NitroCompass extends HybridObject<{
136
224
  * model like `geomagnetism` keyed on the user's lat/lon.
137
225
  */
138
226
  setDeclination(degrees: number): void;
227
+ /**
228
+ * Set the user's geographic location for a tighter interference
229
+ * gate. With a valid location, the library replaces the generic
230
+ * 20–70 µT "Earth field band" with `expectedField ± 15 µT`, where
231
+ * `expectedField` comes from the WMM2025 model shipped on Android
232
+ * (`GeomagneticField`). This catches weak interference the generic
233
+ * band misses — especially at high/low latitudes where Earth's
234
+ * field is naturally near or above 60 µT.
235
+ *
236
+ * Pass `NaN` for either coordinate, or values outside the valid
237
+ * range (`|lat| > 90`, `|lon| > 180`), to revert to the generic
238
+ * band. Survives across `start`/`stop`.
239
+ *
240
+ * **No-op on iOS.** `CLLocationManager` uses GPS-derived location
241
+ * internally for all field-related reasoning; layering our own
242
+ * lookup on top would be redundant.
243
+ */
244
+ setLocation(latitude: number, longitude: number): void;
139
245
  /**
140
246
  * Register a callback fired when the calibration bucket transitions.
141
247
  * Replaces any previously registered callback. Pass a no-op to mute.
@@ -173,6 +279,24 @@ export interface NitroCompass extends HybridObject<{
173
279
  * `start()`; takes effect immediately.
174
280
  */
175
281
  setPauseOnBackground(enabled: boolean): void;
282
+ /**
283
+ * Force a best-effort sensor recalibration. Resets internal smoothing
284
+ * and quality-bucket state, then re-registers the underlying sensor
285
+ * listeners. On many Android OEMs the re-registration nudges the
286
+ * magnetometer driver to re-evaluate soft/hard-iron calibration, which
287
+ * unsticks an `UNRELIABLE` bucket that's lingering after a strong
288
+ * magnetic excursion (e.g. another phone placed on top, then removed).
289
+ *
290
+ * On iOS this dismisses the system heading-calibration overlay and
291
+ * stops/restarts heading updates. Apple's stack handles the
292
+ * underlying calibration internally.
293
+ *
294
+ * Idempotent — safe to call when not started, in which case it's a
295
+ * no-op. Calibration recovery still requires the user to move the
296
+ * device through varying orientations; this method just clears the
297
+ * library's cached state so progress is reflected promptly.
298
+ */
299
+ recalibrate(): void;
176
300
  /**
177
301
  * Read the current platform permission state synchronously.
178
302
  * On Android this is always `'granted'` (sensors require no permission);
@@ -1 +1 @@
1
- {"version":3,"file":"NitroCompass.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/NitroCompass.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,YAAY,CAAA;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,UAAU,GAClB,gBAAgB,GAChB,2BAA2B,GAC3B,cAAc,CAAA;AAElB,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,UAAU,CAAA;CACnB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,gBAAgB,GAA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,iBAAiB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAC/C"}
@@ -35,9 +35,12 @@ namespace margelo::nitro::nitrocompass {
35
35
  double heading = this->getFieldValue(fieldHeading);
36
36
  static const auto fieldAccuracy = clazz->getField<double>("accuracy");
37
37
  double accuracy = this->getFieldValue(fieldAccuracy);
38
+ static const auto fieldFieldStrengthMicroTesla = clazz->getField<double>("fieldStrengthMicroTesla");
39
+ double fieldStrengthMicroTesla = this->getFieldValue(fieldFieldStrengthMicroTesla);
38
40
  return CompassSample(
39
41
  heading,
40
- accuracy
42
+ accuracy,
43
+ fieldStrengthMicroTesla
41
44
  );
42
45
  }
43
46
 
@@ -47,13 +50,14 @@ namespace margelo::nitro::nitrocompass {
47
50
  */
48
51
  [[maybe_unused]]
49
52
  static jni::local_ref<JCompassSample::javaobject> fromCpp(const CompassSample& value) {
50
- using JSignature = JCompassSample(double, double);
53
+ using JSignature = JCompassSample(double, double, double);
51
54
  static const auto clazz = javaClassStatic();
52
55
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
53
56
  return create(
54
57
  clazz,
55
58
  value.heading,
56
- value.accuracy
59
+ value.accuracy,
60
+ value.fieldStrengthMicroTesla
57
61
  );
58
62
  }
59
63
  };
@@ -0,0 +1,85 @@
1
+ ///
2
+ /// JDebugInfo.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "DebugInfo.hpp"
12
+
13
+
14
+
15
+ namespace margelo::nitro::nitrocompass {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "DebugInfo" and the the Kotlin data class "DebugInfo".
21
+ */
22
+ struct JDebugInfo final: public jni::JavaClass<JDebugInfo> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/nitrocompass/DebugInfo;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct DebugInfo by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ DebugInfo toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldInterferenceActive = clazz->getField<jboolean>("interferenceActive");
35
+ jboolean interferenceActive = this->getFieldValue(fieldInterferenceActive);
36
+ static const auto fieldMsSinceLastBiasJump = clazz->getField<double>("msSinceLastBiasJump");
37
+ double msSinceLastBiasJump = this->getFieldValue(fieldMsSinceLastBiasJump);
38
+ static const auto fieldExpectedFieldMicroTesla = clazz->getField<double>("expectedFieldMicroTesla");
39
+ double expectedFieldMicroTesla = this->getFieldValue(fieldExpectedFieldMicroTesla);
40
+ static const auto fieldLastFieldMicroTesla = clazz->getField<double>("lastFieldMicroTesla");
41
+ double lastFieldMicroTesla = this->getFieldValue(fieldLastFieldMicroTesla);
42
+ static const auto fieldFusedYawDeg = clazz->getField<double>("fusedYawDeg");
43
+ double fusedYawDeg = this->getFieldValue(fieldFusedYawDeg);
44
+ static const auto fieldLastYawRateDegPerS = clazz->getField<double>("lastYawRateDegPerS");
45
+ double lastYawRateDegPerS = this->getFieldValue(fieldLastYawRateDegPerS);
46
+ static const auto fieldHasGameRotationVector = clazz->getField<jboolean>("hasGameRotationVector");
47
+ jboolean hasGameRotationVector = this->getFieldValue(fieldHasGameRotationVector);
48
+ static const auto fieldUsingUncalibratedMag = clazz->getField<jboolean>("usingUncalibratedMag");
49
+ jboolean usingUncalibratedMag = this->getFieldValue(fieldUsingUncalibratedMag);
50
+ return DebugInfo(
51
+ static_cast<bool>(interferenceActive),
52
+ msSinceLastBiasJump,
53
+ expectedFieldMicroTesla,
54
+ lastFieldMicroTesla,
55
+ fusedYawDeg,
56
+ lastYawRateDegPerS,
57
+ static_cast<bool>(hasGameRotationVector),
58
+ static_cast<bool>(usingUncalibratedMag)
59
+ );
60
+ }
61
+
62
+ public:
63
+ /**
64
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
65
+ */
66
+ [[maybe_unused]]
67
+ static jni::local_ref<JDebugInfo::javaobject> fromCpp(const DebugInfo& value) {
68
+ using JSignature = JDebugInfo(jboolean, double, double, double, double, double, jboolean, jboolean);
69
+ static const auto clazz = javaClassStatic();
70
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
71
+ return create(
72
+ clazz,
73
+ value.interferenceActive,
74
+ value.msSinceLastBiasJump,
75
+ value.expectedFieldMicroTesla,
76
+ value.lastFieldMicroTesla,
77
+ value.fusedYawDeg,
78
+ value.lastYawRateDegPerS,
79
+ value.hasGameRotationVector,
80
+ value.usingUncalibratedMag
81
+ );
82
+ }
83
+ };
84
+
85
+ } // namespace margelo::nitro::nitrocompass
@@ -11,6 +11,8 @@
11
11
  namespace margelo::nitro::nitrocompass { struct SensorDiagnostics; }
12
12
  // Forward declaration of `SensorKind` to properly resolve imports.
13
13
  namespace margelo::nitro::nitrocompass { enum class SensorKind; }
14
+ // Forward declaration of `DebugInfo` to properly resolve imports.
15
+ namespace margelo::nitro::nitrocompass { struct DebugInfo; }
14
16
  // Forward declaration of `CompassSample` to properly resolve imports.
15
17
  namespace margelo::nitro::nitrocompass { struct CompassSample; }
16
18
  // Forward declaration of `PermissionStatus` to properly resolve imports.
@@ -23,6 +25,8 @@ namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
23
25
  #include "JSensorDiagnostics.hpp"
24
26
  #include "SensorKind.hpp"
25
27
  #include "JSensorKind.hpp"
28
+ #include "DebugInfo.hpp"
29
+ #include "JDebugInfo.hpp"
26
30
  #include "CompassSample.hpp"
27
31
  #include "JCompassSample.hpp"
28
32
  #include "PermissionStatus.hpp"
@@ -96,6 +100,11 @@ namespace margelo::nitro::nitrocompass {
96
100
  auto __result = method(_javaPart);
97
101
  return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
98
102
  }
103
+ DebugInfo JHybridNitroCompassSpec::getDebugInfo() {
104
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JDebugInfo>()>("getDebugInfo");
105
+ auto __result = method(_javaPart);
106
+ return __result->toCpp();
107
+ }
99
108
  bool JHybridNitroCompassSpec::hasCompass() {
100
109
  static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("hasCompass");
101
110
  auto __result = method(_javaPart);
@@ -110,6 +119,10 @@ namespace margelo::nitro::nitrocompass {
110
119
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* degrees */)>("setDeclination");
111
120
  method(_javaPart, degrees);
112
121
  }
122
+ void JHybridNitroCompassSpec::setLocation(double latitude, double longitude) {
123
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* latitude */, double /* longitude */)>("setLocation");
124
+ method(_javaPart, latitude, longitude);
125
+ }
113
126
  void JHybridNitroCompassSpec::setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) {
114
127
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AccuracyQuality::javaobject> /* onChange */)>("setOnCalibrationNeeded_cxx");
115
128
  method(_javaPart, JFunc_void_AccuracyQuality_cxx::fromCpp(onChange));
@@ -122,6 +135,10 @@ namespace margelo::nitro::nitrocompass {
122
135
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* enabled */)>("setPauseOnBackground");
123
136
  method(_javaPart, enabled);
124
137
  }
138
+ void JHybridNitroCompassSpec::recalibrate() {
139
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("recalibrate");
140
+ method(_javaPart);
141
+ }
125
142
  PermissionStatus JHybridNitroCompassSpec::getPermissionStatus() {
126
143
  static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPermissionStatus>()>("getPermissionStatus");
127
144
  auto __result = method(_javaPart);
@@ -60,12 +60,15 @@ namespace margelo::nitro::nitrocompass {
60
60
  void setFilter(double degrees) override;
61
61
  void setSmoothing(double alpha) override;
62
62
  std::optional<SensorDiagnostics> getDiagnostics() override;
63
+ DebugInfo getDebugInfo() override;
63
64
  bool hasCompass() override;
64
65
  std::optional<CompassSample> getCurrentHeading() override;
65
66
  void setDeclination(double degrees) override;
67
+ void setLocation(double latitude, double longitude) override;
66
68
  void setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) override;
67
69
  void setOnInterferenceDetected(const std::function<void(bool /* interferenceDetected */)>& onChange) override;
68
70
  void setPauseOnBackground(bool enabled) override;
71
+ void recalibrate() override;
69
72
  PermissionStatus getPermissionStatus() override;
70
73
  std::shared_ptr<Promise<PermissionStatus>> requestPermission() override;
71
74
 
@@ -42,15 +42,18 @@ namespace margelo::nitro::nitrocompass {
42
42
  static jni::alias_ref<JSensorKind> fromCpp(SensorKind value) {
43
43
  static const auto clazz = javaClassStatic();
44
44
  switch (value) {
45
+ case SensorKind::MAGNETOMETER:
46
+ static const auto fieldMAGNETOMETER = clazz->getStaticField<JSensorKind>("MAGNETOMETER");
47
+ return clazz->getStaticFieldValue(fieldMAGNETOMETER);
48
+ case SensorKind::CORELOCATION:
49
+ static const auto fieldCORELOCATION = clazz->getStaticField<JSensorKind>("CORELOCATION");
50
+ return clazz->getStaticFieldValue(fieldCORELOCATION);
45
51
  case SensorKind::ROTATIONVECTOR:
46
52
  static const auto fieldROTATIONVECTOR = clazz->getStaticField<JSensorKind>("ROTATIONVECTOR");
47
53
  return clazz->getStaticFieldValue(fieldROTATIONVECTOR);
48
54
  case SensorKind::GEOMAGNETICROTATIONVECTOR:
49
55
  static const auto fieldGEOMAGNETICROTATIONVECTOR = clazz->getStaticField<JSensorKind>("GEOMAGNETICROTATIONVECTOR");
50
56
  return clazz->getStaticFieldValue(fieldGEOMAGNETICROTATIONVECTOR);
51
- case SensorKind::CORELOCATION:
52
- static const auto fieldCORELOCATION = clazz->getStaticField<JSensorKind>("CORELOCATION");
53
- return clazz->getStaticFieldValue(fieldCORELOCATION);
54
57
  default:
55
58
  std::string stringValue = std::to_string(static_cast<int>(value));
56
59
  throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
@@ -23,7 +23,10 @@ data class CompassSample(
23
23
  val heading: Double,
24
24
  @DoNotStrip
25
25
  @Keep
26
- val accuracy: Double
26
+ val accuracy: Double,
27
+ @DoNotStrip
28
+ @Keep
29
+ val fieldStrengthMicroTesla: Double
27
30
  ) {
28
31
  /* primary constructor */
29
32
 
@@ -32,12 +35,14 @@ data class CompassSample(
32
35
  if (other !is CompassSample) return false
33
36
  return Objects.deepEquals(this.heading, other.heading)
34
37
  && Objects.deepEquals(this.accuracy, other.accuracy)
38
+ && Objects.deepEquals(this.fieldStrengthMicroTesla, other.fieldStrengthMicroTesla)
35
39
  }
36
40
 
37
41
  override fun hashCode(): Int {
38
42
  return arrayOf(
39
43
  heading,
40
- accuracy
44
+ accuracy,
45
+ fieldStrengthMicroTesla
41
46
  ).contentDeepHashCode()
42
47
  }
43
48
 
@@ -49,8 +54,8 @@ data class CompassSample(
49
54
  @Keep
50
55
  @Suppress("unused")
51
56
  @JvmStatic
52
- private fun fromCpp(heading: Double, accuracy: Double): CompassSample {
53
- return CompassSample(heading, accuracy)
57
+ private fun fromCpp(heading: Double, accuracy: Double, fieldStrengthMicroTesla: Double): CompassSample {
58
+ return CompassSample(heading, accuracy, fieldStrengthMicroTesla)
54
59
  }
55
60
  }
56
61
  }
@@ -0,0 +1,86 @@
1
+ ///
2
+ /// DebugInfo.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.nitrocompass
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+ import java.util.Objects
13
+
14
+
15
+ /**
16
+ * Represents the JavaScript object/struct "DebugInfo".
17
+ */
18
+ @DoNotStrip
19
+ @Keep
20
+ data class DebugInfo(
21
+ @DoNotStrip
22
+ @Keep
23
+ val interferenceActive: Boolean,
24
+ @DoNotStrip
25
+ @Keep
26
+ val msSinceLastBiasJump: Double,
27
+ @DoNotStrip
28
+ @Keep
29
+ val expectedFieldMicroTesla: Double,
30
+ @DoNotStrip
31
+ @Keep
32
+ val lastFieldMicroTesla: Double,
33
+ @DoNotStrip
34
+ @Keep
35
+ val fusedYawDeg: Double,
36
+ @DoNotStrip
37
+ @Keep
38
+ val lastYawRateDegPerS: Double,
39
+ @DoNotStrip
40
+ @Keep
41
+ val hasGameRotationVector: Boolean,
42
+ @DoNotStrip
43
+ @Keep
44
+ val usingUncalibratedMag: Boolean
45
+ ) {
46
+ /* primary constructor */
47
+
48
+ override fun equals(other: Any?): Boolean {
49
+ if (this === other) return true
50
+ if (other !is DebugInfo) return false
51
+ return Objects.deepEquals(this.interferenceActive, other.interferenceActive)
52
+ && Objects.deepEquals(this.msSinceLastBiasJump, other.msSinceLastBiasJump)
53
+ && Objects.deepEquals(this.expectedFieldMicroTesla, other.expectedFieldMicroTesla)
54
+ && Objects.deepEquals(this.lastFieldMicroTesla, other.lastFieldMicroTesla)
55
+ && Objects.deepEquals(this.fusedYawDeg, other.fusedYawDeg)
56
+ && Objects.deepEquals(this.lastYawRateDegPerS, other.lastYawRateDegPerS)
57
+ && Objects.deepEquals(this.hasGameRotationVector, other.hasGameRotationVector)
58
+ && Objects.deepEquals(this.usingUncalibratedMag, other.usingUncalibratedMag)
59
+ }
60
+
61
+ override fun hashCode(): Int {
62
+ return arrayOf(
63
+ interferenceActive,
64
+ msSinceLastBiasJump,
65
+ expectedFieldMicroTesla,
66
+ lastFieldMicroTesla,
67
+ fusedYawDeg,
68
+ lastYawRateDegPerS,
69
+ hasGameRotationVector,
70
+ usingUncalibratedMag
71
+ ).contentDeepHashCode()
72
+ }
73
+
74
+ companion object {
75
+ /**
76
+ * Constructor called from C++
77
+ */
78
+ @DoNotStrip
79
+ @Keep
80
+ @Suppress("unused")
81
+ @JvmStatic
82
+ private fun fromCpp(interferenceActive: Boolean, msSinceLastBiasJump: Double, expectedFieldMicroTesla: Double, lastFieldMicroTesla: Double, fusedYawDeg: Double, lastYawRateDegPerS: Double, hasGameRotationVector: Boolean, usingUncalibratedMag: Boolean): DebugInfo {
83
+ return DebugInfo(interferenceActive, msSinceLastBiasJump, expectedFieldMicroTesla, lastFieldMicroTesla, fusedYawDeg, lastYawRateDegPerS, hasGameRotationVector, usingUncalibratedMag)
84
+ }
85
+ }
86
+ }