forked from random-labs/react-native-helloworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
218 lines (198 loc) · 7.78 KB
/
App.js
File metadata and controls
218 lines (198 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {NativeEventEmitter, NativeModules} from 'react-native';
// import MessageQueue from 'react-native/Libraries/BatchedBridge/MessageQueue.js';
// const spyFunction = (msg) => {
// console.log(msg);
// };
// MessageQueue.spy(spyFunction);
// module.exports = NativeModules.MotionDnaReactBridge;
import {
Platform,
StyleSheet,
Text,
TextInput,
View,
PermissionsAndroid
} from 'react-native';
motionDNAstring = ""
// function motionDNACallback(err, parameter) {
// motionDNAstring = parameter
// }
async function requestNavisensPermission() {
if(Platform.OS === 'android') {
try {
var granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Fine Location Permission',
'message': 'This location API needs your location'
}
)
var granted1 = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
{
'title': 'Coarse Location Permission',
'message': 'This location API needs your location'
}
)
var granted2 = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
'title': 'Log File Storage Permission',
'message': 'This app needs external storage permissions' +
' to record log files if you enable that feature'
}
)
} catch (err) {
console.warn(err)
}
}
}
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
constructor() {
super();
requestNavisensPermission();
this.state = {
motionDNAstring: "test",
locationStatus: "UNKNOWN",
location_localLocation_x: "x",
location_localLocation_z: "y",
location_localLocation_y: "z",
location_globalLocation_latitude: "lat",
location_globalLocation_longitude: "long",
location_globalLocation_altitude: "alt",
location_localHeading: "heading",
motion_motionType: "nada",
gpsLocation_globalLocation_latitude: "lat",
gpsLocation_globalLocation_longitude: "long",
gpsLocation_globalLocation_altitude: "alt",
navidate: "0",
errorCode: "NO ERROR CODE",
errorString: "NO ERROR STRING"
};
console.log("initialized react app")
this.motionManager = NativeModules.MotionDnaReactBridge
this.motionManager.runMotionDna("<YOUR DEVELOPER KEY>",() => {
this.motionManager.setLocationNavisens();
// this.motionManager.setLocationGPSOnly();
// this.motionManager.setBinaryFileLoggingEnabled(true)
// this.motionManager.setLocalHeadingOffsetInDegrees(90)
this.motionManager.setExternalPositioningState("HIGH_ACCURACY")
this.motionManager.setPowerMode("PERFORMANCE");
this.motionManager.setBackpropagationEnabled(true);
// this.motionManager.setBackpropagationBufferSize(100);
this.motionManager.setCallbackUpdateRateInMs(2000)
//this.motionManager.setNetworkUpdateRateInMs(100)
});
this.motionDnaEmitter = new NativeEventEmitter(this.motionManager);
console.log("set emitter")
this.subscription = this.motionDnaEmitter.addListener(
'MotionDnaEvent',
(motionDna) => {
// console.log("parameter: " + motionDna.location_localHeading);
this.setState({motionDNAstring: motionDna.MotionDnaString,
locationStatus: motionDna.location_locationStatus,
location_localLocation_x: motionDna.location_localLocation_x.toFixed(3),
location_localLocation_y: motionDna.location_localLocation_y.toFixed(3),
location_localLocation_z: motionDna.location_localLocation_z.toFixed(3),
location_globalLocation_latitude: motionDna.location_globalLocation_latitude.toFixed(5),
location_globalLocation_longitude: motionDna.location_globalLocation_longitude.toFixed(5),
location_globalLocation_altitude: motionDna.location_globalLocation_altitude.toFixed(3),
location_localHeading: motionDna.location_localHeading.toFixed(3),
motion_motionType: motionDna.motion_motionType,
gpsLocation_globalLocation_latitude: motionDna.GPSLocation_globalLocation_latitude.toFixed(5),
gpsLocation_globalLocation_longitude: motionDna.GPSLocation_globalLocation_longitude.toFixed(5),
gpsLocation_globalLocation_altitude: motionDna.GPSLocation_globalLocation_altitude.toFixed(3),
navidate: motionDna.timestamp.toString()
});
// console.log(this.state.navidate)
// this.setState({[motionDna.target.id]:motionDna.target.value});
});
this.errorSubscription = this.motionDnaEmitter.addListener('MotionDnaErrorEvent',(error) => {
this.setState({
errorCode: error.errorCode,
errorString: error.errorString
});
});
console.log("done initializing")
// this.motionManager.setMotionDnaCallback((err, parameter) =>
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Test!
</Text>
{/* <TextInput style={styles.instructions}
value={this.state.motionDNAstring}
/> */}
<Text style={styles.instructions}>
{"X: " + this.state.location_localLocation_x + " Y: " + this.state.location_localLocation_y + " Z: " + this.state.location_localLocation_z}
</Text>
<Text style={styles.instructions}>
{"NAVISENS LOCATION"}
</Text>
<Text style={styles.instructions}>
{"Lat: " + this.state.location_globalLocation_latitude + " Long: " + this.state.location_globalLocation_longitude + " Alt: " + this.state.location_globalLocation_altitude}
</Text>
<Text style={styles.instructions}>
{"GPS LOCATION"}
</Text>
<Text style={styles.instructions}>
{"Lat: " + this.state.gpsLocation_globalLocation_latitude + " Long: " + this.state.gpsLocation_globalLocation_longitude + " Alt: " + this.state.gpsLocation_globalLocation_altitude}
</Text>
<Text style={styles.instructions}>
{this.state.location_localHeading}
</Text>
<Text style={styles.instructions}>
{this.state.motion_motionType}
</Text>
<Text style={styles.instructions}>
{this.state.navidate}
</Text>
<Text style={styles.instructions}>
{this.state.errorCode}
</Text>
<Text style={styles.instructions}>
{this.state.errorString}
</Text>
<Text style={styles.instructions}>
{this.state.locationStatus}
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#dd6260',
marginBottom: 5,
},
});