-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacteristic.js
53 lines (38 loc) · 1.31 KB
/
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
var util = require('util');
var fs = require('fs');
function conv(num) {
let b = new ArrayBuffer(4);
new DataView(b).setUint32(0, num);
return Array.from(new Uint8Array(b));
}
var bleno = require('bleno');
var BlenoCharacteristic = bleno.Characteristic;
var EchoCharacteristic = function() {
EchoCharacteristic.super_.call(this, {
uuid: 'ec0e',
properties: ['read', 'notify'],
value: null
});
this._value = new Buffer(0);
this._updateValueCallback = null;
};
util.inherits(EchoCharacteristic, BlenoCharacteristic);
EchoCharacteristic.prototype.onReadRequest = function(offset, callback) {
console.log('EchoCharacteristic - onReadRequest: value = ' + this._value.toString('hex'));
let counterValue = parseInt(
(
fs.readFileSync("/home/pi/curb-wheel/ram/counter.txt")
).toString()
);
console.log("value: " + counterValue)
callback(this.RESULT_SUCCESS, conv(counterValue));
};
EchoCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback) {
console.log('EchoCharacteristic - onSubscribe');
this._updateValueCallback = updateValueCallback;
};
EchoCharacteristic.prototype.onUnsubscribe = function() {
console.log('EchoCharacteristic - onUnsubscribe');
this._updateValueCallback = null;
};
module.exports = EchoCharacteristic;