-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreos.js
66 lines (52 loc) · 2.14 KB
/
reos.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
var util = require('util');
var NobleDevice = require('noble-device');
var SERVICE_UUID = 'fff0';
var CONTROL_UUID = 'fff3';
var EFFECT_UUID = 'fff3';
var ReosLed = function(peripheral) {
NobleDevice.call(this, peripheral);
};
ReosLed.SCAN_UUIDS = [SERVICE_UUID];
ReosLed.prototype.RGBtoBuffer = function (rgbString) {
rgbString = rgbString || "000000";
var fromString = rgbString
return Buffer.from(fromString, "hex")
};
ReosLed.is = function(peripheral) {
/* This is a big no no , return correct info */
var localName = peripheral.advertisement.localName;
console.log(localName);
return true;
// return ((localName === undefined) || (localName === 'Cnlight') );
};
NobleDevice.Util.inherits(ReosLed, NobleDevice);
ReosLed.prototype.writeServiceStringCharacteristic = function(uuid, string, callback) {
this.writeStringCharacteristic(SERVICE_UUID, uuid, string, callback);
};
ReosLed.prototype.writeControlCharateristic = function(red, green, blue, brightness, callback) {
var rgbString = red + green + blue;
var brightNess = brightness;
var command = this.RGBtoBuffer(rgbString,brightNess);
this.writeServiceStringCharacteristic(CONTROL_UUID, command, callback);
};
ReosLed.prototype.turnOn = function(callback) {
this.writeServiceStringCharacteristic( CONTROL_UUID, this.RGBtoBuffer("0f0d0300ff2b1bd0a00101000000bbffff") ,callback);
};
ReosLed.prototype.turnOff = function(callback) {
this.writeServiceStringCharacteristic( CONTROL_UUID, this.RGBtoBuffer("0f0a0d000000000005000013ffff") ,callback);
};
ReosLed.prototype.setColorAndBrightness = function(red, green, blue, brightness, callback) {
function convert(integer) {
var str = Number(integer).toString(16);
return str.length == 1 ? "0" + str : str;
};
red = convert(red);
blue = convert(blue);
green = convert(green);
brightness = brightness?convert(brightness):"00";
this.writeControlCharateristic(brightness, red, green, blue, callback);
};
// ReosLed.prototype.setGradualMode = function(on, callback) {
// this.writeServiceStringCharacteristic(EFFECT_UUID, on ? 'TS' : 'TE', callback);
// };
module.exports = ReosLed;