-
Notifications
You must be signed in to change notification settings - Fork 0
/
BluetoothCharacteristic.js
51 lines (38 loc) · 1.62 KB
/
BluetoothCharacteristic.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
/*jslint node:true,vars:true,bitwise:true,unparam:true */
/*jshint unused:true */
var util = require('util');
var bleno = require('bleno');
var BlenoCharacteristic = bleno.Characteristic;
var BluetoothCharacteristic = function(uuid) {
BluetoothCharacteristic.super_.call(this, {
uuid: uuid,
properties: ['read', /*'write',*/ 'notify'],
value: null
});
this._value = new Buffer("Hello World from Edison!", "utf-8");
console.log("Characterisitic's value: "+this._value);
this._updateValueCallback = null;
};
util.inherits(BluetoothCharacteristic, BlenoCharacteristic);
BluetoothCharacteristic.prototype.onReadRequest = function(offset, callback) {
console.log('BluetoothCharacteristic - onReadRequest: value = ' + this._value.toString("utf-8"));
callback(this.RESULT_SUCCESS, this._value);
};
BluetoothCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
this._value = data;
console.log('BluetoothCharacteristic - onWriteRequest: value = ' + this._value.toString("utf-8"));
if (this._updateValueCallback) {
console.log('BluetoothCharacteristic - onWriteRequest: notifying');
this._updateValueCallback(this._value);
}
callback(this.RESULT_SUCCESS);
};
BluetoothCharacteristic.prototype.onSubscribe = function(maxValueSize, updateValueCallback) {
console.log('BluetoothCharacteristic - onSubscribe');
this._updateValueCallback = updateValueCallback;
};
BluetoothCharacteristic.prototype.onUnsubscribe = function() {
console.log('BluetoothCharacteristic - onUnsubscribe');
this._updateValueCallback = null;
};
module.exports = BluetoothCharacteristic;