-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMagReadings.js
66 lines (53 loc) · 1.61 KB
/
getMagReadings.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
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
var util = require('util');
var async = require('async');
var SensorTag = require('sensortag');
SensorTag.discover(function(sensorTag) {
sensorTag.on('disconnect', function() {
console.log('disconnected!');
process.exit(0);
});
async.series([
function(callback) {
console.log('connect');
sensorTag.connect(callback);
},
function(callback) {
console.log('discoverServicesAndCharacteristics');
sensorTag.discoverServicesAndCharacteristics(callback);
},
function(callback) {
console.log('enableMagnetometer');
sensorTag.enableMagnetometer(callback);
},
function(callback) {
sensorTag.setMagnetometerPeriod(200,callback);
},
function(callback) {
setTimeout(callback, 2000);
},
function(callback) {
console.log('readMagnetometer');
sensorTag.readMagnetometer(function(x, y, z) {
console.log('\tx = %d μT', x.toFixed(1));
console.log('\ty = %d μT', y.toFixed(1));
console.log('\tz = %d μT', z.toFixed(1));
callback();
});
},
function(callback) {
console.log('magnetometerChange');
sensorTag.on('magnetometerChange', function(x, y,z) {
console.log('\tx = %d μT', x.toFixed(1));
console.log('\ty = %d μT', y.toFixed(1));
console.log('\tz = %d μT', z.toFixed(1));
});
sensorTag.notifyMagnetometer(function() {
});
},
function(callback) {
console.log('disableMagnetometer');
sensorTag.disableMagnetometer(callback);
}
]
);
});