react-native-nitro-compass 1.1.0 → 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 +141 -20
- package/android/src/main/java/com/margelo/nitro/nitrocompass/HybridNitroCompass.kt +654 -133
- package/ios/HybridNitroCompass.swift +106 -3
- package/lib/commonjs/hook.js +98 -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 +99 -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 +39 -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 +142 -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 +17 -0
- package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.hpp +3 -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 +12 -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 +23 -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 +3 -0
- package/nitrogen/generated/ios/swift/HybridNitroCompassSpec_cxx.swift +34 -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 +3 -0
- package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.hpp +6 -0
- package/nitrogen/generated/shared/c++/SensorKind.hpp +10 -6
- package/package.json +2 -2
- package/src/hook.ts +146 -12
- package/src/index.ts +2 -0
- package/src/multiplex.ts +23 -2
- package/src/specs/NitroCompass.nitro.ts +147 -18
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/HybridNitroCompassSpec.kt
CHANGED
|
@@ -58,6 +58,10 @@ abstract class HybridNitroCompassSpec: HybridObject() {
|
|
|
58
58
|
@Keep
|
|
59
59
|
abstract fun getDiagnostics(): SensorDiagnostics?
|
|
60
60
|
|
|
61
|
+
@DoNotStrip
|
|
62
|
+
@Keep
|
|
63
|
+
abstract fun getDebugInfo(): DebugInfo
|
|
64
|
+
|
|
61
65
|
@DoNotStrip
|
|
62
66
|
@Keep
|
|
63
67
|
abstract fun hasCompass(): Boolean
|
|
@@ -70,6 +74,10 @@ abstract class HybridNitroCompassSpec: HybridObject() {
|
|
|
70
74
|
@Keep
|
|
71
75
|
abstract fun setDeclination(degrees: Double): Unit
|
|
72
76
|
|
|
77
|
+
@DoNotStrip
|
|
78
|
+
@Keep
|
|
79
|
+
abstract fun setLocation(latitude: Double, longitude: Double): Unit
|
|
80
|
+
|
|
73
81
|
abstract fun setOnCalibrationNeeded(onChange: (quality: AccuracyQuality) -> Unit): Unit
|
|
74
82
|
|
|
75
83
|
@DoNotStrip
|
|
@@ -92,6 +100,10 @@ abstract class HybridNitroCompassSpec: HybridObject() {
|
|
|
92
100
|
@Keep
|
|
93
101
|
abstract fun setPauseOnBackground(enabled: Boolean): Unit
|
|
94
102
|
|
|
103
|
+
@DoNotStrip
|
|
104
|
+
@Keep
|
|
105
|
+
abstract fun recalibrate(): Unit
|
|
106
|
+
|
|
95
107
|
@DoNotStrip
|
|
96
108
|
@Keep
|
|
97
109
|
abstract fun getPermissionStatus(): PermissionStatus
|
|
@@ -16,9 +16,10 @@ import com.facebook.proguard.annotations.DoNotStrip
|
|
|
16
16
|
@DoNotStrip
|
|
17
17
|
@Keep
|
|
18
18
|
enum class SensorKind(@DoNotStrip @Keep val value: Int) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
MAGNETOMETER(0),
|
|
20
|
+
CORELOCATION(1),
|
|
21
|
+
ROTATIONVECTOR(2),
|
|
22
|
+
GEOMAGNETICROTATIONVECTOR(3);
|
|
22
23
|
|
|
23
24
|
companion object
|
|
24
25
|
}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
|
|
13
13
|
// Forward declaration of `CompassSample` to properly resolve imports.
|
|
14
14
|
namespace margelo::nitro::nitrocompass { struct CompassSample; }
|
|
15
|
+
// Forward declaration of `DebugInfo` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::nitrocompass { struct DebugInfo; }
|
|
15
17
|
// Forward declaration of `HybridNitroCompassSpec` to properly resolve imports.
|
|
16
18
|
namespace margelo::nitro::nitrocompass { class HybridNitroCompassSpec; }
|
|
17
19
|
// Forward declaration of `PermissionStatus` to properly resolve imports.
|
|
@@ -28,6 +30,7 @@ namespace NitroCompass { class HybridNitroCompassSpec_cxx; }
|
|
|
28
30
|
// Include C++ defined types
|
|
29
31
|
#include "AccuracyQuality.hpp"
|
|
30
32
|
#include "CompassSample.hpp"
|
|
33
|
+
#include "DebugInfo.hpp"
|
|
31
34
|
#include "HybridNitroCompassSpec.hpp"
|
|
32
35
|
#include "PermissionStatus.hpp"
|
|
33
36
|
#include "SensorDiagnostics.hpp"
|
|
@@ -237,6 +240,15 @@ namespace margelo::nitro::nitrocompass::bridge::swift {
|
|
|
237
240
|
return Result<std::optional<SensorDiagnostics>>::withError(error);
|
|
238
241
|
}
|
|
239
242
|
|
|
243
|
+
// pragma MARK: Result<DebugInfo>
|
|
244
|
+
using Result_DebugInfo_ = Result<DebugInfo>;
|
|
245
|
+
inline Result_DebugInfo_ create_Result_DebugInfo_(const DebugInfo& value) noexcept {
|
|
246
|
+
return Result<DebugInfo>::withValue(value);
|
|
247
|
+
}
|
|
248
|
+
inline Result_DebugInfo_ create_Result_DebugInfo_(const std::exception_ptr& error) noexcept {
|
|
249
|
+
return Result<DebugInfo>::withError(error);
|
|
250
|
+
}
|
|
251
|
+
|
|
240
252
|
// pragma MARK: Result<std::optional<CompassSample>>
|
|
241
253
|
using Result_std__optional_CompassSample__ = Result<std::optional<CompassSample>>;
|
|
242
254
|
inline Result_std__optional_CompassSample__ create_Result_std__optional_CompassSample__(const std::optional<CompassSample>& value) noexcept {
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
|
|
13
13
|
// Forward declaration of `CompassSample` to properly resolve imports.
|
|
14
14
|
namespace margelo::nitro::nitrocompass { struct CompassSample; }
|
|
15
|
+
// Forward declaration of `DebugInfo` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::nitrocompass { struct DebugInfo; }
|
|
15
17
|
// Forward declaration of `HybridNitroCompassSpec` to properly resolve imports.
|
|
16
18
|
namespace margelo::nitro::nitrocompass { class HybridNitroCompassSpec; }
|
|
17
19
|
// Forward declaration of `PermissionStatus` to properly resolve imports.
|
|
@@ -24,6 +26,7 @@ namespace margelo::nitro::nitrocompass { enum class SensorKind; }
|
|
|
24
26
|
// Include C++ defined types
|
|
25
27
|
#include "AccuracyQuality.hpp"
|
|
26
28
|
#include "CompassSample.hpp"
|
|
29
|
+
#include "DebugInfo.hpp"
|
|
27
30
|
#include "HybridNitroCompassSpec.hpp"
|
|
28
31
|
#include "PermissionStatus.hpp"
|
|
29
32
|
#include "SensorDiagnostics.hpp"
|
|
@@ -18,6 +18,8 @@ namespace margelo::nitro::nitrocompass { struct CompassSample; }
|
|
|
18
18
|
namespace margelo::nitro::nitrocompass { struct SensorDiagnostics; }
|
|
19
19
|
// Forward declaration of `SensorKind` to properly resolve imports.
|
|
20
20
|
namespace margelo::nitro::nitrocompass { enum class SensorKind; }
|
|
21
|
+
// Forward declaration of `DebugInfo` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::nitrocompass { struct DebugInfo; }
|
|
21
23
|
// Forward declaration of `AccuracyQuality` to properly resolve imports.
|
|
22
24
|
namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
|
|
23
25
|
// Forward declaration of `PermissionStatus` to properly resolve imports.
|
|
@@ -28,6 +30,7 @@ namespace margelo::nitro::nitrocompass { enum class PermissionStatus; }
|
|
|
28
30
|
#include "SensorDiagnostics.hpp"
|
|
29
31
|
#include <optional>
|
|
30
32
|
#include "SensorKind.hpp"
|
|
33
|
+
#include "DebugInfo.hpp"
|
|
31
34
|
#include "AccuracyQuality.hpp"
|
|
32
35
|
#include "PermissionStatus.hpp"
|
|
33
36
|
#include <NitroModules/Promise.hpp>
|
|
@@ -122,6 +125,14 @@ namespace margelo::nitro::nitrocompass {
|
|
|
122
125
|
auto __value = std::move(__result.value());
|
|
123
126
|
return __value;
|
|
124
127
|
}
|
|
128
|
+
inline DebugInfo getDebugInfo() override {
|
|
129
|
+
auto __result = _swiftPart.getDebugInfo();
|
|
130
|
+
if (__result.hasError()) [[unlikely]] {
|
|
131
|
+
std::rethrow_exception(__result.error());
|
|
132
|
+
}
|
|
133
|
+
auto __value = std::move(__result.value());
|
|
134
|
+
return __value;
|
|
135
|
+
}
|
|
125
136
|
inline bool hasCompass() override {
|
|
126
137
|
auto __result = _swiftPart.hasCompass();
|
|
127
138
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -144,6 +155,12 @@ namespace margelo::nitro::nitrocompass {
|
|
|
144
155
|
std::rethrow_exception(__result.error());
|
|
145
156
|
}
|
|
146
157
|
}
|
|
158
|
+
inline void setLocation(double latitude, double longitude) override {
|
|
159
|
+
auto __result = _swiftPart.setLocation(std::forward<decltype(latitude)>(latitude), std::forward<decltype(longitude)>(longitude));
|
|
160
|
+
if (__result.hasError()) [[unlikely]] {
|
|
161
|
+
std::rethrow_exception(__result.error());
|
|
162
|
+
}
|
|
163
|
+
}
|
|
147
164
|
inline void setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) override {
|
|
148
165
|
auto __result = _swiftPart.setOnCalibrationNeeded(onChange);
|
|
149
166
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -162,6 +179,12 @@ namespace margelo::nitro::nitrocompass {
|
|
|
162
179
|
std::rethrow_exception(__result.error());
|
|
163
180
|
}
|
|
164
181
|
}
|
|
182
|
+
inline void recalibrate() override {
|
|
183
|
+
auto __result = _swiftPart.recalibrate();
|
|
184
|
+
if (__result.hasError()) [[unlikely]] {
|
|
185
|
+
std::rethrow_exception(__result.error());
|
|
186
|
+
}
|
|
187
|
+
}
|
|
165
188
|
inline PermissionStatus getPermissionStatus() override {
|
|
166
189
|
auto __result = _swiftPart.getPermissionStatus();
|
|
167
190
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -18,8 +18,8 @@ public extension CompassSample {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of `CompassSample`.
|
|
20
20
|
*/
|
|
21
|
-
init(heading: Double, accuracy: Double) {
|
|
22
|
-
self.init(heading, accuracy)
|
|
21
|
+
init(heading: Double, accuracy: Double, fieldStrengthMicroTesla: Double) {
|
|
22
|
+
self.init(heading, accuracy, fieldStrengthMicroTesla)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
@inline(__always)
|
|
@@ -31,4 +31,9 @@ public extension CompassSample {
|
|
|
31
31
|
var accuracy: Double {
|
|
32
32
|
return self.__accuracy
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var fieldStrengthMicroTesla: Double {
|
|
37
|
+
return self.__fieldStrengthMicroTesla
|
|
38
|
+
}
|
|
34
39
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// DebugInfo.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents an instance of `DebugInfo`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias DebugInfo = margelo.nitro.nitrocompass.DebugInfo
|
|
14
|
+
|
|
15
|
+
public extension DebugInfo {
|
|
16
|
+
private typealias bridge = margelo.nitro.nitrocompass.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `DebugInfo`.
|
|
20
|
+
*/
|
|
21
|
+
init(interferenceActive: Bool, msSinceLastBiasJump: Double, expectedFieldMicroTesla: Double, lastFieldMicroTesla: Double, fusedYawDeg: Double, lastYawRateDegPerS: Double, hasGameRotationVector: Bool, usingUncalibratedMag: Bool) {
|
|
22
|
+
self.init(interferenceActive, msSinceLastBiasJump, expectedFieldMicroTesla, lastFieldMicroTesla, fusedYawDeg, lastYawRateDegPerS, hasGameRotationVector, usingUncalibratedMag)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@inline(__always)
|
|
26
|
+
var interferenceActive: Bool {
|
|
27
|
+
return self.__interferenceActive
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline(__always)
|
|
31
|
+
var msSinceLastBiasJump: Double {
|
|
32
|
+
return self.__msSinceLastBiasJump
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var expectedFieldMicroTesla: Double {
|
|
37
|
+
return self.__expectedFieldMicroTesla
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline(__always)
|
|
41
|
+
var lastFieldMicroTesla: Double {
|
|
42
|
+
return self.__lastFieldMicroTesla
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@inline(__always)
|
|
46
|
+
var fusedYawDeg: Double {
|
|
47
|
+
return self.__fusedYawDeg
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@inline(__always)
|
|
51
|
+
var lastYawRateDegPerS: Double {
|
|
52
|
+
return self.__lastYawRateDegPerS
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@inline(__always)
|
|
56
|
+
var hasGameRotationVector: Bool {
|
|
57
|
+
return self.__hasGameRotationVector
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@inline(__always)
|
|
61
|
+
var usingUncalibratedMag: Bool {
|
|
62
|
+
return self.__usingUncalibratedMag
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -19,12 +19,15 @@ public protocol HybridNitroCompassSpec_protocol: HybridObject {
|
|
|
19
19
|
func setFilter(degrees: Double) throws -> Void
|
|
20
20
|
func setSmoothing(alpha: Double) throws -> Void
|
|
21
21
|
func getDiagnostics() throws -> SensorDiagnostics?
|
|
22
|
+
func getDebugInfo() throws -> DebugInfo
|
|
22
23
|
func hasCompass() throws -> Bool
|
|
23
24
|
func getCurrentHeading() throws -> CompassSample?
|
|
24
25
|
func setDeclination(degrees: Double) throws -> Void
|
|
26
|
+
func setLocation(latitude: Double, longitude: Double) throws -> Void
|
|
25
27
|
func setOnCalibrationNeeded(onChange: @escaping (_ quality: AccuracyQuality) -> Void) throws -> Void
|
|
26
28
|
func setOnInterferenceDetected(onChange: @escaping (_ interferenceDetected: Bool) -> Void) throws -> Void
|
|
27
29
|
func setPauseOnBackground(enabled: Bool) throws -> Void
|
|
30
|
+
func recalibrate() throws -> Void
|
|
28
31
|
func getPermissionStatus() throws -> PermissionStatus
|
|
29
32
|
func requestPermission() throws -> Promise<PermissionStatus>
|
|
30
33
|
}
|
|
@@ -203,6 +203,18 @@ open class HybridNitroCompassSpec_cxx {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
@inline(__always)
|
|
207
|
+
public final func getDebugInfo() -> bridge.Result_DebugInfo_ {
|
|
208
|
+
do {
|
|
209
|
+
let __result = try self.__implementation.getDebugInfo()
|
|
210
|
+
let __resultCpp = __result
|
|
211
|
+
return bridge.create_Result_DebugInfo_(__resultCpp)
|
|
212
|
+
} catch (let __error) {
|
|
213
|
+
let __exceptionPtr = __error.toCpp()
|
|
214
|
+
return bridge.create_Result_DebugInfo_(__exceptionPtr)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
@inline(__always)
|
|
207
219
|
public final func hasCompass() -> bridge.Result_bool_ {
|
|
208
220
|
do {
|
|
@@ -244,6 +256,17 @@ open class HybridNitroCompassSpec_cxx {
|
|
|
244
256
|
}
|
|
245
257
|
}
|
|
246
258
|
|
|
259
|
+
@inline(__always)
|
|
260
|
+
public final func setLocation(latitude: Double, longitude: Double) -> bridge.Result_void_ {
|
|
261
|
+
do {
|
|
262
|
+
try self.__implementation.setLocation(latitude: latitude, longitude: longitude)
|
|
263
|
+
return bridge.create_Result_void_()
|
|
264
|
+
} catch (let __error) {
|
|
265
|
+
let __exceptionPtr = __error.toCpp()
|
|
266
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
247
270
|
@inline(__always)
|
|
248
271
|
public final func setOnCalibrationNeeded(onChange: bridge.Func_void_AccuracyQuality) -> bridge.Result_void_ {
|
|
249
272
|
do {
|
|
@@ -287,6 +310,17 @@ open class HybridNitroCompassSpec_cxx {
|
|
|
287
310
|
}
|
|
288
311
|
}
|
|
289
312
|
|
|
313
|
+
@inline(__always)
|
|
314
|
+
public final func recalibrate() -> bridge.Result_void_ {
|
|
315
|
+
do {
|
|
316
|
+
try self.__implementation.recalibrate()
|
|
317
|
+
return bridge.create_Result_void_()
|
|
318
|
+
} catch (let __error) {
|
|
319
|
+
let __exceptionPtr = __error.toCpp()
|
|
320
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
290
324
|
@inline(__always)
|
|
291
325
|
public final func getPermissionStatus() -> bridge.Result_PermissionStatus_ {
|
|
292
326
|
do {
|
|
@@ -17,12 +17,14 @@ public extension SensorKind {
|
|
|
17
17
|
*/
|
|
18
18
|
init?(fromString string: String) {
|
|
19
19
|
switch string {
|
|
20
|
+
case "magnetometer":
|
|
21
|
+
self = .magnetometer
|
|
22
|
+
case "coreLocation":
|
|
23
|
+
self = .corelocation
|
|
20
24
|
case "rotationVector":
|
|
21
25
|
self = .rotationvector
|
|
22
26
|
case "geomagneticRotationVector":
|
|
23
27
|
self = .geomagneticrotationvector
|
|
24
|
-
case "coreLocation":
|
|
25
|
-
self = .corelocation
|
|
26
28
|
default:
|
|
27
29
|
return nil
|
|
28
30
|
}
|
|
@@ -33,12 +35,14 @@ public extension SensorKind {
|
|
|
33
35
|
*/
|
|
34
36
|
var stringValue: String {
|
|
35
37
|
switch self {
|
|
38
|
+
case .magnetometer:
|
|
39
|
+
return "magnetometer"
|
|
40
|
+
case .corelocation:
|
|
41
|
+
return "coreLocation"
|
|
36
42
|
case .rotationvector:
|
|
37
43
|
return "rotationVector"
|
|
38
44
|
case .geomagneticrotationvector:
|
|
39
45
|
return "geomagneticRotationVector"
|
|
40
|
-
case .corelocation:
|
|
41
|
-
return "coreLocation"
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
}
|
|
@@ -41,10 +41,11 @@ namespace margelo::nitro::nitrocompass {
|
|
|
41
41
|
public:
|
|
42
42
|
double heading SWIFT_PRIVATE;
|
|
43
43
|
double accuracy SWIFT_PRIVATE;
|
|
44
|
+
double fieldStrengthMicroTesla SWIFT_PRIVATE;
|
|
44
45
|
|
|
45
46
|
public:
|
|
46
47
|
CompassSample() = default;
|
|
47
|
-
explicit CompassSample(double heading, double accuracy): heading(heading), accuracy(accuracy) {}
|
|
48
|
+
explicit CompassSample(double heading, double accuracy, double fieldStrengthMicroTesla): heading(heading), accuracy(accuracy), fieldStrengthMicroTesla(fieldStrengthMicroTesla) {}
|
|
48
49
|
|
|
49
50
|
public:
|
|
50
51
|
friend bool operator==(const CompassSample& lhs, const CompassSample& rhs) = default;
|
|
@@ -61,13 +62,15 @@ namespace margelo::nitro {
|
|
|
61
62
|
jsi::Object obj = arg.asObject(runtime);
|
|
62
63
|
return margelo::nitro::nitrocompass::CompassSample(
|
|
63
64
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "heading"))),
|
|
64
|
-
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))
|
|
65
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy"))),
|
|
66
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fieldStrengthMicroTesla")))
|
|
65
67
|
);
|
|
66
68
|
}
|
|
67
69
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrocompass::CompassSample& arg) {
|
|
68
70
|
jsi::Object obj(runtime);
|
|
69
71
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "heading"), JSIConverter<double>::toJSI(runtime, arg.heading));
|
|
70
72
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "accuracy"), JSIConverter<double>::toJSI(runtime, arg.accuracy));
|
|
73
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "fieldStrengthMicroTesla"), JSIConverter<double>::toJSI(runtime, arg.fieldStrengthMicroTesla));
|
|
71
74
|
return obj;
|
|
72
75
|
}
|
|
73
76
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -80,6 +83,7 @@ namespace margelo::nitro {
|
|
|
80
83
|
}
|
|
81
84
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "heading")))) return false;
|
|
82
85
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))) return false;
|
|
86
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fieldStrengthMicroTesla")))) return false;
|
|
83
87
|
return true;
|
|
84
88
|
}
|
|
85
89
|
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// DebugInfo.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrocompass {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (DebugInfo).
|
|
39
|
+
*/
|
|
40
|
+
struct DebugInfo final {
|
|
41
|
+
public:
|
|
42
|
+
bool interferenceActive SWIFT_PRIVATE;
|
|
43
|
+
double msSinceLastBiasJump SWIFT_PRIVATE;
|
|
44
|
+
double expectedFieldMicroTesla SWIFT_PRIVATE;
|
|
45
|
+
double lastFieldMicroTesla SWIFT_PRIVATE;
|
|
46
|
+
double fusedYawDeg SWIFT_PRIVATE;
|
|
47
|
+
double lastYawRateDegPerS SWIFT_PRIVATE;
|
|
48
|
+
bool hasGameRotationVector SWIFT_PRIVATE;
|
|
49
|
+
bool usingUncalibratedMag SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
DebugInfo() = default;
|
|
53
|
+
explicit DebugInfo(bool interferenceActive, double msSinceLastBiasJump, double expectedFieldMicroTesla, double lastFieldMicroTesla, double fusedYawDeg, double lastYawRateDegPerS, bool hasGameRotationVector, bool usingUncalibratedMag): interferenceActive(interferenceActive), msSinceLastBiasJump(msSinceLastBiasJump), expectedFieldMicroTesla(expectedFieldMicroTesla), lastFieldMicroTesla(lastFieldMicroTesla), fusedYawDeg(fusedYawDeg), lastYawRateDegPerS(lastYawRateDegPerS), hasGameRotationVector(hasGameRotationVector), usingUncalibratedMag(usingUncalibratedMag) {}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
friend bool operator==(const DebugInfo& lhs, const DebugInfo& rhs) = default;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace margelo::nitro::nitrocompass
|
|
60
|
+
|
|
61
|
+
namespace margelo::nitro {
|
|
62
|
+
|
|
63
|
+
// C++ DebugInfo <> JS DebugInfo (object)
|
|
64
|
+
template <>
|
|
65
|
+
struct JSIConverter<margelo::nitro::nitrocompass::DebugInfo> final {
|
|
66
|
+
static inline margelo::nitro::nitrocompass::DebugInfo fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
67
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
68
|
+
return margelo::nitro::nitrocompass::DebugInfo(
|
|
69
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "interferenceActive"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "msSinceLastBiasJump"))),
|
|
71
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "expectedFieldMicroTesla"))),
|
|
72
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastFieldMicroTesla"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fusedYawDeg"))),
|
|
74
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastYawRateDegPerS"))),
|
|
75
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasGameRotationVector"))),
|
|
76
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "usingUncalibratedMag")))
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrocompass::DebugInfo& arg) {
|
|
80
|
+
jsi::Object obj(runtime);
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "interferenceActive"), JSIConverter<bool>::toJSI(runtime, arg.interferenceActive));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "msSinceLastBiasJump"), JSIConverter<double>::toJSI(runtime, arg.msSinceLastBiasJump));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "expectedFieldMicroTesla"), JSIConverter<double>::toJSI(runtime, arg.expectedFieldMicroTesla));
|
|
84
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "lastFieldMicroTesla"), JSIConverter<double>::toJSI(runtime, arg.lastFieldMicroTesla));
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "fusedYawDeg"), JSIConverter<double>::toJSI(runtime, arg.fusedYawDeg));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "lastYawRateDegPerS"), JSIConverter<double>::toJSI(runtime, arg.lastYawRateDegPerS));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "hasGameRotationVector"), JSIConverter<bool>::toJSI(runtime, arg.hasGameRotationVector));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "usingUncalibratedMag"), JSIConverter<bool>::toJSI(runtime, arg.usingUncalibratedMag));
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
92
|
+
if (!value.isObject()) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
jsi::Object obj = value.getObject(runtime);
|
|
96
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "interferenceActive")))) return false;
|
|
100
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "msSinceLastBiasJump")))) return false;
|
|
101
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "expectedFieldMicroTesla")))) return false;
|
|
102
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastFieldMicroTesla")))) return false;
|
|
103
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fusedYawDeg")))) return false;
|
|
104
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "lastYawRateDegPerS")))) return false;
|
|
105
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hasGameRotationVector")))) return false;
|
|
106
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "usingUncalibratedMag")))) return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
} // namespace margelo::nitro
|
|
@@ -20,12 +20,15 @@ namespace margelo::nitro::nitrocompass {
|
|
|
20
20
|
prototype.registerHybridMethod("setFilter", &HybridNitroCompassSpec::setFilter);
|
|
21
21
|
prototype.registerHybridMethod("setSmoothing", &HybridNitroCompassSpec::setSmoothing);
|
|
22
22
|
prototype.registerHybridMethod("getDiagnostics", &HybridNitroCompassSpec::getDiagnostics);
|
|
23
|
+
prototype.registerHybridMethod("getDebugInfo", &HybridNitroCompassSpec::getDebugInfo);
|
|
23
24
|
prototype.registerHybridMethod("hasCompass", &HybridNitroCompassSpec::hasCompass);
|
|
24
25
|
prototype.registerHybridMethod("getCurrentHeading", &HybridNitroCompassSpec::getCurrentHeading);
|
|
25
26
|
prototype.registerHybridMethod("setDeclination", &HybridNitroCompassSpec::setDeclination);
|
|
27
|
+
prototype.registerHybridMethod("setLocation", &HybridNitroCompassSpec::setLocation);
|
|
26
28
|
prototype.registerHybridMethod("setOnCalibrationNeeded", &HybridNitroCompassSpec::setOnCalibrationNeeded);
|
|
27
29
|
prototype.registerHybridMethod("setOnInterferenceDetected", &HybridNitroCompassSpec::setOnInterferenceDetected);
|
|
28
30
|
prototype.registerHybridMethod("setPauseOnBackground", &HybridNitroCompassSpec::setPauseOnBackground);
|
|
31
|
+
prototype.registerHybridMethod("recalibrate", &HybridNitroCompassSpec::recalibrate);
|
|
29
32
|
prototype.registerHybridMethod("getPermissionStatus", &HybridNitroCompassSpec::getPermissionStatus);
|
|
30
33
|
prototype.registerHybridMethod("requestPermission", &HybridNitroCompassSpec::requestPermission);
|
|
31
34
|
});
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
namespace margelo::nitro::nitrocompass { struct CompassSample; }
|
|
18
18
|
// Forward declaration of `SensorDiagnostics` to properly resolve imports.
|
|
19
19
|
namespace margelo::nitro::nitrocompass { struct SensorDiagnostics; }
|
|
20
|
+
// Forward declaration of `DebugInfo` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::nitrocompass { struct DebugInfo; }
|
|
20
22
|
// Forward declaration of `AccuracyQuality` to properly resolve imports.
|
|
21
23
|
namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
|
|
22
24
|
// Forward declaration of `PermissionStatus` to properly resolve imports.
|
|
@@ -26,6 +28,7 @@ namespace margelo::nitro::nitrocompass { enum class PermissionStatus; }
|
|
|
26
28
|
#include <functional>
|
|
27
29
|
#include "SensorDiagnostics.hpp"
|
|
28
30
|
#include <optional>
|
|
31
|
+
#include "DebugInfo.hpp"
|
|
29
32
|
#include "AccuracyQuality.hpp"
|
|
30
33
|
#include "PermissionStatus.hpp"
|
|
31
34
|
#include <NitroModules/Promise.hpp>
|
|
@@ -67,12 +70,15 @@ namespace margelo::nitro::nitrocompass {
|
|
|
67
70
|
virtual void setFilter(double degrees) = 0;
|
|
68
71
|
virtual void setSmoothing(double alpha) = 0;
|
|
69
72
|
virtual std::optional<SensorDiagnostics> getDiagnostics() = 0;
|
|
73
|
+
virtual DebugInfo getDebugInfo() = 0;
|
|
70
74
|
virtual bool hasCompass() = 0;
|
|
71
75
|
virtual std::optional<CompassSample> getCurrentHeading() = 0;
|
|
72
76
|
virtual void setDeclination(double degrees) = 0;
|
|
77
|
+
virtual void setLocation(double latitude, double longitude) = 0;
|
|
73
78
|
virtual void setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) = 0;
|
|
74
79
|
virtual void setOnInterferenceDetected(const std::function<void(bool /* interferenceDetected */)>& onChange) = 0;
|
|
75
80
|
virtual void setPauseOnBackground(bool enabled) = 0;
|
|
81
|
+
virtual void recalibrate() = 0;
|
|
76
82
|
virtual PermissionStatus getPermissionStatus() = 0;
|
|
77
83
|
virtual std::shared_ptr<Promise<PermissionStatus>> requestPermission() = 0;
|
|
78
84
|
|
|
@@ -29,9 +29,10 @@ namespace margelo::nitro::nitrocompass {
|
|
|
29
29
|
* An enum which can be represented as a JavaScript union (SensorKind).
|
|
30
30
|
*/
|
|
31
31
|
enum class SensorKind {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
MAGNETOMETER SWIFT_NAME(magnetometer) = 0,
|
|
33
|
+
CORELOCATION SWIFT_NAME(corelocation) = 1,
|
|
34
|
+
ROTATIONVECTOR SWIFT_NAME(rotationvector) = 2,
|
|
35
|
+
GEOMAGNETICROTATIONVECTOR SWIFT_NAME(geomagneticrotationvector) = 3,
|
|
35
36
|
} CLOSED_ENUM;
|
|
36
37
|
|
|
37
38
|
} // namespace margelo::nitro::nitrocompass
|
|
@@ -44,18 +45,20 @@ namespace margelo::nitro {
|
|
|
44
45
|
static inline margelo::nitro::nitrocompass::SensorKind fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
46
|
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
47
|
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
48
|
+
case hashString("magnetometer"): return margelo::nitro::nitrocompass::SensorKind::MAGNETOMETER;
|
|
49
|
+
case hashString("coreLocation"): return margelo::nitro::nitrocompass::SensorKind::CORELOCATION;
|
|
47
50
|
case hashString("rotationVector"): return margelo::nitro::nitrocompass::SensorKind::ROTATIONVECTOR;
|
|
48
51
|
case hashString("geomagneticRotationVector"): return margelo::nitro::nitrocompass::SensorKind::GEOMAGNETICROTATIONVECTOR;
|
|
49
|
-
case hashString("coreLocation"): return margelo::nitro::nitrocompass::SensorKind::CORELOCATION;
|
|
50
52
|
default: [[unlikely]]
|
|
51
53
|
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum SensorKind - invalid value!");
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrocompass::SensorKind arg) {
|
|
55
57
|
switch (arg) {
|
|
58
|
+
case margelo::nitro::nitrocompass::SensorKind::MAGNETOMETER: return JSIConverter<std::string>::toJSI(runtime, "magnetometer");
|
|
59
|
+
case margelo::nitro::nitrocompass::SensorKind::CORELOCATION: return JSIConverter<std::string>::toJSI(runtime, "coreLocation");
|
|
56
60
|
case margelo::nitro::nitrocompass::SensorKind::ROTATIONVECTOR: return JSIConverter<std::string>::toJSI(runtime, "rotationVector");
|
|
57
61
|
case margelo::nitro::nitrocompass::SensorKind::GEOMAGNETICROTATIONVECTOR: return JSIConverter<std::string>::toJSI(runtime, "geomagneticRotationVector");
|
|
58
|
-
case margelo::nitro::nitrocompass::SensorKind::CORELOCATION: return JSIConverter<std::string>::toJSI(runtime, "coreLocation");
|
|
59
62
|
default: [[unlikely]]
|
|
60
63
|
throw std::invalid_argument("Cannot convert SensorKind to JS - invalid value: "
|
|
61
64
|
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
@@ -67,9 +70,10 @@ namespace margelo::nitro {
|
|
|
67
70
|
}
|
|
68
71
|
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
72
|
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
73
|
+
case hashString("magnetometer"):
|
|
74
|
+
case hashString("coreLocation"):
|
|
70
75
|
case hashString("rotationVector"):
|
|
71
76
|
case hashString("geomagneticRotationVector"):
|
|
72
|
-
case hashString("coreLocation"):
|
|
73
77
|
return true;
|
|
74
78
|
default:
|
|
75
79
|
return false;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-compass",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
7
|
-
"description": "Fast, accurate compass heading for React Native, powered by Nitro Modules. Uses Android
|
|
7
|
+
"description": "Fast, accurate compass heading for React Native, powered by Nitro Modules. Uses raw Android accelerometer + magnetometer fusion (instant interference recovery) and iOS CLHeading.",
|
|
8
8
|
"main": "./lib/commonjs/index.js",
|
|
9
9
|
"module": "./lib/module/index.js",
|
|
10
10
|
"types": "./lib/typescript/src/index.d.ts",
|