-
Notifications
You must be signed in to change notification settings - Fork 0
/
current-speed-characteristic.js
72 lines (56 loc) · 1.61 KB
/
current-speed-characteristic.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
66
67
68
69
70
71
72
var util = require('util');
var os = require('os');
var exec = require('child_process').exec;
var bleno = require('bleno');
var Descriptor = bleno.Descriptor;
var Characteristic = bleno.Characteristic;
var CurrentSpeedCharacteristic = function() {
CurrentSpeedCharacteristic.super_.call(this, {
uuid: 'FFC3',
properties: ['read', 'notify'],
descriptors: [
new Descriptor({
uuid: '2901',
value: 'Current Speed'
}),
new Descriptor({
uuid: '2904',
value: new Buffer([0x04, 0x01, 0x27, 0xAD, 0x01, 0x00, 0x00 ]) // maybe 12 0xC unsigned 8 bit
})
]
});
this._updateValueCallback = null;
onNotify = function(){
console.log('notify');
}
};
util.inherits(CurrentSpeedCharacteristic, Characteristic);
var val = 0;
var incr = 1;
function updateVal(){
if (val === 15){
incr = -1;
}
if (val === 0 ){
incr = 1;
}
val += incr;
console.log(val);
}
setInterval(updateVal, 1000);
CurrentSpeedCharacteristic.prototype.onReadRequest = function(offset, callback) {
callback(this.RESULT_SUCCESS, new Buffer([val]));
};
CurrentSpeedCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback){
console.log('CurrentSpeedCharacteristic - onSubscribe');
this._updateValueCallback = updateValueCallback;
setInterval(function(){
//updateVal();
updateValueCallback(new Buffer([val]));
},1000);
};
CurrentSpeedCharacteristic.prototype.onUnsubscribe = function() {
console.log('CurrentSpeedCharacteristic - onUnsubscribe');
this._updateValueCallback = null;
};
module.exports = CurrentSpeedCharacteristic;