-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
40 lines (32 loc) · 1.15 KB
/
test.js
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
var compass = require("./index.js");
// sample offset & scale data that do nothing, generated myself, be sure
// to grab your own using the `node calibrate` function, because
// the magnetic field distortion is different in each place on the Earth
var offset = {
x: 0,
y: 0,
z: 0,
};
var scale = {
x: 1,
y: 1,
z: 1,
};
var precision = 2;
compass.setOffsetMatrix(offset.x, offset.y, offset.z);
compass.setScaleMatrix(scale.x, scale.y, scale.z);
//apply the local declination angle correction
//values for Tarnowskie Gory, Poland: 5 degrees, 1 minute
//taken from: http://magnetic-declination.com/
//formula: declinationAngle = (degrees + (minutes / 60.0)) / (180 / PI);
var declinationAngle = (5.0 + 1.0 / 60.0) / (180 / Math.PI);
compass.setDeclinationAngle(declinationAngle);
console.log("Declination angle correction: " + declinationAngle);
console.log("Scale matrix: " + JSON.stringify(scale));
console.log("Offset matrix: " + JSON.stringify(offset));
console.log("Precision (digits after comma): " + precision);
if (compass.initialize()) {
setInterval(function () {
console.log("Azimuth: " + compass.readAzimuth().toFixed(precision));
}, 500);
}