-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacteristic_occupation.js
69 lines (60 loc) · 1.81 KB
/
characteristic_occupation.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
/**
* Dependencies
**/
var bleno = require('/usr/local/lib/node_modules/bleno');
var util = require('util');
/**
* Types
**/
var Characteristic = bleno.Characteristic;
var Descriptor = bleno.Descriptor;
/**
* Constructor
**/
var Characteristic_Occupation = function(toilet)
{
Characteristic_Occupation.super_.call(this, {
uuid : '0000000000000000000000000000fff1',
properties: [ 'read', 'notify' ],
value: null,
descriptors: [
new Descriptor({
uuid: '2901',
value: 'Toilet occupied: 0 (no), 1 (yes)'
})
]
});
this._value = new Buffer(1);
this._value.writeUInt8(0,0);
this._updateValueCallback = null;
this.toilet = toilet;
}
util.inherits(Characteristic_Occupation, Characteristic);
Characteristic_Occupation.prototype.notifyOccupation = function(occupation)
{
this._value.writeUInt8((occupation ? 1 : 0), 0);
if (this._updateValueCallback) {
this._updateValueCallback(this._value);
}
}
Characteristic_Occupation.prototype.onReadRequest = function(offset, callback)
{
if (offset) {
console.log('Received READ for \'ATTR_LONG:\'' + offset);
callback(this.RESULT_ATTR_NOT_LONG);
} else {
console.log('CharacteristicOccupation - onReadRequest: value = ' + this._value.toString('hex'));
callback(this.RESULT_SUCCESS, this._value);
}
}
Characteristic_Occupation.prototype.onSubscribe = function(maxValueSize, updateValueCallback)
{
console.log('CharacteristicOccupation - onSubscribe');
this._updateValueCallback = updateValueCallback;
};
Characteristic_Occupation.prototype.onUnsubscribe = function()
{
console.log('CharacteristicOccupation - onUnsubscribe');
this._updateValueCallback = null;
};
module.exports = Characteristic_Occupation;