UNPKG

1.01 kBJavaScriptView Raw
1var events = require('events');
2var util = require('util');
3
4var descriptors = require('./descriptors.json');
5
6function Descriptor(peripheral, uuid, handle) {
7 this._peripheral = peripheral;
8 this.uuid = uuid;
9 this.handle = handle;
10 this.name = null;
11 this.type = null;
12 this.value;
13
14 var descriptor = descriptors[uuid];
15 if (descriptor) {
16 this.name = descriptor.name;
17 this.type = descriptor.type;
18 }
19}
20
21util.inherits(Descriptor, events.EventEmitter);
22
23Descriptor.isStandardDescriptor = function(uuid) {
24 return (descriptors[uuid] ? true : false);
25}
26
27Descriptor.prototype.toString = function() {
28 return JSON.stringify({
29 uuid: this.uuid,
30 name: this.name,
31 type: this.type,
32 value : this.value,
33 });
34};
35
36Descriptor.prototype.read = function(callback) {
37 this._peripheral._controller.readDescriptor(this, callback);
38};
39
40Descriptor.prototype.write = function(data, callback) {
41this._peripheral._controller.writeDescriptor(this, data, callback);
42};
43
44module.exports = Descriptor;