react-native-nitro-compass 1.0.9 → 1.2.0
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.
- package/README.md +166 -20
- package/android/src/main/java/com/margelo/nitro/nitrocompass/HybridNitroCompass.kt +718 -105
- package/ios/HybridNitroCompass.swift +119 -6
- package/lib/commonjs/hook.js +102 -11
- package/lib/commonjs/hook.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/multiplex.js +23 -2
- package/lib/commonjs/multiplex.js.map +1 -1
- package/lib/module/hook.js +103 -12
- package/lib/module/hook.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/multiplex.js +23 -2
- package/lib/module/multiplex.js.map +1 -1
- package/lib/typescript/src/hook.d.ts +49 -1
- package/lib/typescript/src/hook.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/multiplex.d.ts.map +1 -1
- package/lib/typescript/src/specs/NitroCompass.nitro.d.ts +158 -18
- package/lib/typescript/src/specs/NitroCompass.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JCompassSample.hpp +7 -3
- package/nitrogen/generated/android/c++/JDebugInfo.hpp +85 -0
- package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.cpp +21 -0
- package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/JSensorKind.hpp +6 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/CompassSample.kt +9 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/DebugInfo.kt +86 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/HybridNitroCompassSpec.kt +16 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/SensorKind.kt +4 -3
- package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Bridge.hpp +12 -0
- package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNitroCompassSpecSwift.hpp +29 -0
- package/nitrogen/generated/ios/swift/CompassSample.swift +7 -2
- package/nitrogen/generated/ios/swift/DebugInfo.swift +64 -0
- package/nitrogen/generated/ios/swift/HybridNitroCompassSpec.swift +4 -0
- package/nitrogen/generated/ios/swift/HybridNitroCompassSpec_cxx.swift +45 -0
- package/nitrogen/generated/ios/swift/SensorKind.swift +8 -4
- package/nitrogen/generated/shared/c++/CompassSample.hpp +6 -2
- package/nitrogen/generated/shared/c++/DebugInfo.hpp +111 -0
- package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.hpp +7 -0
- package/nitrogen/generated/shared/c++/SensorKind.hpp +10 -6
- package/package.json +2 -2
- package/src/hook.ts +161 -12
- package/src/index.ts +2 -0
- package/src/multiplex.ts +23 -2
- package/src/specs/NitroCompass.nitro.ts +164 -18
package/lib/module/multiplex.js
CHANGED
|
@@ -71,6 +71,13 @@ export function addHeadingListener(cb) {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// Module-level no-op kept stable so we can swap it back into the native
|
|
75
|
+
// callback slot when the last listener leaves — releasing references
|
|
76
|
+
// to old dispatcher closures, which matters when the JS module is
|
|
77
|
+
// re-evaluated (Metro Fast Refresh, jest module reset).
|
|
78
|
+
const NOOP_CALIBRATION = _ => {};
|
|
79
|
+
const NOOP_INTERFERENCE = _ => {};
|
|
80
|
+
|
|
74
81
|
/**
|
|
75
82
|
* Subscribe to calibration-bucket transitions. Only fires while a
|
|
76
83
|
* heading subscription is active. Returns the unsubscribe function.
|
|
@@ -82,7 +89,17 @@ export function addCalibrationListener(cb) {
|
|
|
82
89
|
}
|
|
83
90
|
calibrationListeners.add(cb);
|
|
84
91
|
return () => {
|
|
85
|
-
calibrationListeners.delete(cb);
|
|
92
|
+
if (!calibrationListeners.delete(cb)) return;
|
|
93
|
+
if (calibrationListeners.size === 0) {
|
|
94
|
+
// Detach our dispatcher from the native side. Without this, a
|
|
95
|
+
// module reload (Metro Fast Refresh, jest resetModules) leaves
|
|
96
|
+
// the old dispatcher pinned in native memory while a new module
|
|
97
|
+
// load installs a *second* dispatcher pointing at a fresh
|
|
98
|
+
// listener Set — splitting events between the two and silently
|
|
99
|
+
// dropping the now-orphaned listeners.
|
|
100
|
+
NitroCompass.setOnCalibrationNeeded(NOOP_CALIBRATION);
|
|
101
|
+
calibrationRegistered = false;
|
|
102
|
+
}
|
|
86
103
|
};
|
|
87
104
|
}
|
|
88
105
|
|
|
@@ -97,7 +114,11 @@ export function addInterferenceListener(cb) {
|
|
|
97
114
|
}
|
|
98
115
|
interferenceListeners.add(cb);
|
|
99
116
|
return () => {
|
|
100
|
-
interferenceListeners.delete(cb);
|
|
117
|
+
if (!interferenceListeners.delete(cb)) return;
|
|
118
|
+
if (interferenceListeners.size === 0) {
|
|
119
|
+
NitroCompass.setOnInterferenceDetected(NOOP_INTERFERENCE);
|
|
120
|
+
interferenceRegistered = false;
|
|
121
|
+
}
|
|
101
122
|
};
|
|
102
123
|
}
|
|
103
124
|
//# sourceMappingURL=multiplex.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NitroCompass","headingListeners","Set","calibrationListeners","interferenceListeners","calibrationRegistered","interferenceRegistered","DEFAULT_FILTER_DEG","dispatchHeading","sample","cb","Array","from","e","console","error","dispatchCalibration","quality","dispatchInterference","detected","addHeadingListener","wasEmpty","size","add","start","delete","stop","addCalibrationListener","setOnCalibrationNeeded","addInterferenceListener","setOnInterferenceDetected"],"sourceRoot":"../../src","sources":["multiplex.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,SAASA,YAAY,QAAQ,UAAU;AAMvC,MAAMC,gBAAgB,GAAG,IAAIC,GAAG,CA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CAAC;EACxB,IAAIW,QAAQ,EAAE;IACZrB,YAAY,CAACwB,KAAK,CAACjB,kBAAkB,EAAEC,eAAe,CAAC;EACzD;EACA,OAAO,MAAM;IACX,IAAI,CAACP,gBAAgB,CAACwB,MAAM,CAACf,EAAE,CAAC,EAAE;IAClC,IAAIT,gBAAgB,CAACqB,IAAI,KAAK,CAAC,EAAE;MAC/BtB,YAAY,CAAC0B,IAAI,CAAC,CAAC;IACrB;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,
|
|
1
|
+
{"version":3,"names":["NitroCompass","headingListeners","Set","calibrationListeners","interferenceListeners","calibrationRegistered","interferenceRegistered","DEFAULT_FILTER_DEG","dispatchHeading","sample","cb","Array","from","e","console","error","dispatchCalibration","quality","dispatchInterference","detected","addHeadingListener","wasEmpty","size","add","start","delete","stop","NOOP_CALIBRATION","_","NOOP_INTERFERENCE","addCalibrationListener","setOnCalibrationNeeded","addInterferenceListener","setOnInterferenceDetected"],"sourceRoot":"../../src","sources":["multiplex.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,SAASA,YAAY,QAAQ,UAAU;AAMvC,MAAMC,gBAAgB,GAAG,IAAIC,GAAG,CAAkB,CAAC;AACnD,MAAMC,oBAAoB,GAAG,IAAID,GAAG,CAAsB,CAAC;AAC3D,MAAME,qBAAqB,GAAG,IAAIF,GAAG,CAAuB,CAAC;AAE7D,IAAIG,qBAAqB,GAAG,KAAK;AACjC,IAAIC,sBAAsB,GAAG,KAAK;AAElC,MAAMC,kBAAkB,GAAG,CAAC;AAE5B,SAASC,eAAeA,CAACC,MAAqB,EAAE;EAC9C,KAAK,MAAMC,EAAE,IAAIC,KAAK,CAACC,IAAI,CAACX,gBAAgB,CAAC,EAAE;IAC7C,IAAI;MACFS,EAAE,CAACD,MAAM,CAAC;IACZ,CAAC,CAAC,OAAOI,CAAC,EAAE;MACVC,OAAO,CAACC,KAAK,CA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AACA,OAAO,SAASE,sBAAsBA,CACpCpB,EAAuB,EACX;EACZ,IAAI,CAACL,qBAAqB,EAAE;IAC1BL,YAAY,CAAC+B,sBAAsB,CAACf,mBAAmB,CAAC;IACxDX,qBAAqB,GAAG,IAAI;EAC9B;EACAF,oBAAoB,CAACoB,GAAG,CAACb,EAAE,CAAC;EAC5B,OAAO,MAAM;IACX,IAAI,CAACP,oBAAoB,CAACsB,MAAM,CAACf,EAAE,CAAC,EAAE;IACtC,IAAIP,oBAAoB,CAACmB,IAAI,KAAK,CAAC,EAAE;MACnC;MACA;MACA;MACA;MACA;MACA;MACAtB,YAAY,CAAC+B,sBAAsB,CAACJ,gBAAgB,CAAC;MACrDtB,qBAAqB,GAAG,KAAK;IAC/B;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAAS2B,uBAAuBA,CACrCtB,EAAwB,EACZ;EACZ,IAAI,CAACJ,sBAAsB,EAAE;IAC3BN,YAAY,CAACiC,yBAAyB,CAACf,oBAAoB,CAAC;IAC5DZ,sBAAsB,GAAG,IAAI;EAC/B;EACAF,qBAAqB,CAACmB,GAAG,CAACb,EAAE,CAAC;EAC7B,OAAO,MAAM;IACX,IAAI,CAACN,qBAAqB,CAACqB,MAAM,CAACf,EAAE,CAAC,EAAE;IACvC,IAAIN,qBAAqB,CAACkB,IAAI,KAAK,CAAC,EAAE;MACpCtB,YAAY,CAACiC,yBAAyB,CAACJ,iBAAiB,CAAC;MACzDvB,sBAAsB,GAAG,KAAK;IAChC;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -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
|
|
@@ -7,6 +7,16 @@ export interface UseCompassOptions {
|
|
|
7
7
|
* the library — last-write-wins.
|
|
8
8
|
*/
|
|
9
9
|
filterDegrees?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Low-pass smoothing factor (EMA α) applied to heading samples.
|
|
12
|
+
* Range `(0, 1]`. Default `0.2` ≈ 100ms time constant at typical
|
|
13
|
+
* Android sample rates. `1.0` disables smoothing. Smaller values
|
|
14
|
+
* smooth more (kills jitter, adds a touch of latency).
|
|
15
|
+
*
|
|
16
|
+
* No-op on iOS — CLLocationManager filters internally.
|
|
17
|
+
* Shared global state — last-write-wins.
|
|
18
|
+
*/
|
|
19
|
+
smoothingAlpha?: number;
|
|
10
20
|
/**
|
|
11
21
|
* Magnetic-to-true offset in signed degrees. Default `0` (magnetic).
|
|
12
22
|
* Pull from a model like `geomagnetism` keyed on the user's lat/lon.
|
|
@@ -37,6 +47,44 @@ export interface UseCompassResult {
|
|
|
37
47
|
hasCompass: boolean;
|
|
38
48
|
/** Which sensor backs the readings on this device. */
|
|
39
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>;
|
|
40
88
|
}
|
|
41
89
|
/**
|
|
42
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;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,OAAO,EAAE,aAAa,GAAG,IAAI,CAAA;IAC7B,o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;;;;;;;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;
|
|
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()`.
|
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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`.
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
28
|
-
*
|
|
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
|
-
* - `
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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 = '
|
|
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
|
*
|
|
@@ -95,15 +176,38 @@ export interface NitroCompass extends HybridObject<{
|
|
|
95
176
|
* effect until `start()` is called.
|
|
96
177
|
*/
|
|
97
178
|
setFilter(degrees: number): void;
|
|
179
|
+
/**
|
|
180
|
+
* Set the low-pass smoothing factor (EMA α) applied to heading samples
|
|
181
|
+
* before delivery. Range `(0, 1]`. Default `0.2` ≈ 100ms time constant
|
|
182
|
+
* at Android's typical 50 Hz sample rate.
|
|
183
|
+
*
|
|
184
|
+
* - `1.0` disables smoothing (every sample passes through unfiltered).
|
|
185
|
+
* - Smaller values smooth more — eliminates rotation-vector jitter at
|
|
186
|
+
* the cost of a small amount of latency.
|
|
187
|
+
*
|
|
188
|
+
* Implemented as a circular EMA on `(sin θ, cos θ)` so the 359°→0°
|
|
189
|
+
* wraparound doesn't bias the average. Survives `start`/`stop`.
|
|
190
|
+
*
|
|
191
|
+
* **No-op on iOS.** `CLLocationManager` filters heading internally with
|
|
192
|
+
* Apple's own algorithm; layering EMA on top would only add latency.
|
|
193
|
+
*/
|
|
194
|
+
setSmoothing(alpha: number): void;
|
|
98
195
|
/**
|
|
99
196
|
* Describe which underlying sensor / framework would produce headings on
|
|
100
197
|
* this device. Returns `undefined` if the device has no compass hardware
|
|
101
198
|
* (equivalent to `hasCompass() === false`). Safe to call before `start()`.
|
|
102
199
|
*/
|
|
103
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;
|
|
104
208
|
/**
|
|
105
209
|
* Whether the device has the hardware required for a compass reading.
|
|
106
|
-
* Android: a
|
|
210
|
+
* Android: both a magnetometer and an accelerometer are present.
|
|
107
211
|
* iOS: `CLLocationManager.headingAvailable()`.
|
|
108
212
|
*/
|
|
109
213
|
hasCompass(): boolean;
|
|
@@ -120,6 +224,24 @@ export interface NitroCompass extends HybridObject<{
|
|
|
120
224
|
* model like `geomagnetism` keyed on the user's lat/lon.
|
|
121
225
|
*/
|
|
122
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;
|
|
123
245
|
/**
|
|
124
246
|
* Register a callback fired when the calibration bucket transitions.
|
|
125
247
|
* Replaces any previously registered callback. Pass a no-op to mute.
|
|
@@ -157,6 +279,24 @@ export interface NitroCompass extends HybridObject<{
|
|
|
157
279
|
* `start()`; takes effect immediately.
|
|
158
280
|
*/
|
|
159
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;
|
|
160
300
|
/**
|
|
161
301
|
* Read the current platform permission state synchronously.
|
|
162
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
|
|
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;;;;;;;;;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ieldAccuracy = 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"
|
|
@@ -87,11 +91,20 @@ namespace margelo::nitro::nitrocompass {
|
|
|
87
91
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* degrees */)>("setFilter");
|
|
88
92
|
method(_javaPart, degrees);
|
|
89
93
|
}
|
|
94
|
+
void JHybridNitroCompassSpec::setSmoothing(double alpha) {
|
|
95
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* alpha */)>("setSmoothing");
|
|
96
|
+
method(_javaPart, alpha);
|
|
97
|
+
}
|
|
90
98
|
std::optional<SensorDiagnostics> JHybridNitroCompassSpec::getDiagnostics() {
|
|
91
99
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JSensorDiagnostics>()>("getDiagnostics");
|
|
92
100
|
auto __result = method(_javaPart);
|
|
93
101
|
return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
|
|
94
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
|
+
}
|
|
95
108
|
bool JHybridNitroCompassSpec::hasCompass() {
|
|
96
109
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("hasCompass");
|
|
97
110
|
auto __result = method(_javaPart);
|
|
@@ -106,6 +119,10 @@ namespace margelo::nitro::nitrocompass {
|
|
|
106
119
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* degrees */)>("setDeclination");
|
|
107
120
|
method(_javaPart, degrees);
|
|
108
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
|
+
}
|
|
109
126
|
void JHybridNitroCompassSpec::setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) {
|
|
110
127
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AccuracyQuality::javaobject> /* onChange */)>("setOnCalibrationNeeded_cxx");
|
|
111
128
|
method(_javaPart, JFunc_void_AccuracyQuality_cxx::fromCpp(onChange));
|
|
@@ -118,6 +135,10 @@ namespace margelo::nitro::nitrocompass {
|
|
|
118
135
|
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* enabled */)>("setPauseOnBackground");
|
|
119
136
|
method(_javaPart, enabled);
|
|
120
137
|
}
|
|
138
|
+
void JHybridNitroCompassSpec::recalibrate() {
|
|
139
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("recalibrate");
|
|
140
|
+
method(_javaPart);
|
|
141
|
+
}
|
|
121
142
|
PermissionStatus JHybridNitroCompassSpec::getPermissionStatus() {
|
|
122
143
|
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPermissionStatus>()>("getPermissionStatus");
|
|
123
144
|
auto __result = method(_javaPart);
|
|
@@ -58,13 +58,17 @@ namespace margelo::nitro::nitrocompass {
|
|
|
58
58
|
void stop() override;
|
|
59
59
|
bool isStarted() override;
|
|
60
60
|
void setFilter(double degrees) override;
|
|
61
|
+
void setSmoothing(double alpha) override;
|
|
61
62
|
std::optional<SensorDiagnostics> getDiagnostics() override;
|
|
63
|
+
DebugInfo getDebugInfo() override;
|
|
62
64
|
bool hasCompass() override;
|
|
63
65
|
std::optional<CompassSample> getCurrentHeading() override;
|
|
64
66
|
void setDeclination(double degrees) override;
|
|
67
|
+
void setLocation(double latitude, double longitude) override;
|
|
65
68
|
void setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) override;
|
|
66
69
|
void setOnInterferenceDetected(const std::function<void(bool /* interferenceDetected */)>& onChange) override;
|
|
67
70
|
void setPauseOnBackground(bool enabled) override;
|
|
71
|
+
void recalibrate() override;
|
|
68
72
|
PermissionStatus getPermissionStatus() override;
|
|
69
73
|
std::shared_ptr<Promise<PermissionStatus>> requestPermission() override;
|
|
70
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 + "!");
|