iobroker.wifilight
Advanced tools
Comparing version 0.0.1 to 0.0.3
@@ -17,2 +17,3 @@ "use strict"; | ||
vmax: 255, | ||
responseLen: 11, | ||
on: [0xCC, 0x23, 0x33], | ||
@@ -48,2 +49,3 @@ off: [0xCC, 0x24, 0x33], | ||
responseLen: 14, | ||
on: [0x71, 0x23, 0x0f/*, 0xa3*/], | ||
@@ -73,1 +75,2 @@ off: [0x71, 0x24, 0x0f/*, 0xa4*/], | ||
}; | ||
{ | ||
"common": { | ||
"name": "wifilight", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"title": "WiFi Light", | ||
@@ -6,0 +6,0 @@ "desc": { |
{ | ||
"name": "iobroker.wifilight", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"description": "WiFi Light Adapter", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -43,3 +43,3 @@ "use strict"; | ||
ready: function () { | ||
adapter.log.debug = console.log; | ||
//adapter.log.debug = console.log; | ||
devices.init(adapter, function(err) { | ||
@@ -90,3 +90,3 @@ main(); | ||
//var transitionTime = getState(dcs(deviceName, 'tans')) || 3; | ||
var transitionTime = device.get(channel, usedStateNames.transition.n) || 3; | ||
var transitionTime = device.get(channel, usedStateNames.transition.n).val || 3; | ||
device.clearQueue(); | ||
@@ -185,4 +185,7 @@ switch (stateName) { | ||
this.dev = new devices.CDevice(config.ip, ''); | ||
this.setOnline(false); | ||
this.locked = 0; | ||
this.queue = []; | ||
this.dataBuffer = new Uint8Array(200); | ||
this.dataBuffer.pos = 0; | ||
this.states = { red: this.get('r'), green: this.get('g'), blue: this.get('b') }; | ||
@@ -205,3 +208,3 @@ | ||
if (this.USE_SOCKET_ONCE) { | ||
wifi[self.id] = self; | ||
wifi[this.dev.getFullId()] = self; | ||
cb(); | ||
@@ -250,6 +253,6 @@ return; | ||
self.client.connect(self.config.port, self.config.ip, function() { | ||
wifi[self.id] = self; | ||
wifi[self.dev.getFullId()] = self; | ||
self.setOnline(true); | ||
self.updateTimer(); | ||
cb(); | ||
if (cb) cb(); | ||
}); | ||
@@ -598,8 +601,9 @@ }; | ||
var co = this.getRGBStates(channel); | ||
var hsv = colorsys.rgb2Hsv(co)[0]; | ||
var hsv = rgb2hsv(co); | ||
hsv.v = Math.max (Math.min(bri, 100), 0); | ||
co = colorsys.hsv2Rgb(hsv); | ||
co = hsv2rgb(hsv); | ||
this.fade(channel, co, transitionTime); | ||
}; | ||
wifiLight.prototype.onData = function (data) { | ||
@@ -612,7 +616,31 @@ | ||
for (var i=0; i<data.length; i+=11) | ||
var self = this; | ||
var newPos = this.dataBuffer.pos + data.length; | ||
if (newPos > this.dataBuffer.length) { | ||
var b = new Uint8Array(newPos + 200); | ||
for (var i=0; i<this.dataBuffer.pos; i++) { | ||
b [i] = this.dataBuffer[i]; | ||
} | ||
//this.dataBuffer.forEach(function (v, i) { | ||
// b [i] = v; | ||
//}); | ||
b.pos = this.dataBuffer.pos; | ||
this.dataBuffer = b; | ||
} | ||
this.dataBuffer.set(data, this.dataBuffer.pos); | ||
this.dataBuffer.pos += data.length; | ||
//if (this.dataBuffer.pos < this.cmds.responsLen) { | ||
// return null; | ||
//} | ||
while (this.dataBuffer.pos >= this.cmds.responseLen) | ||
{ | ||
var buf = data.slice(i, i + 11); | ||
this.states = this.cmds.decodeResponse(buf); | ||
//var result = this.cmds.decodeResponse(data); | ||
var buf = this.dataBuffer.subarray(0, this.cmds.responseLen); | ||
var states = this.cmds.decodeResponse(buf); | ||
this.dataBuffer.copyWithin(0, this.cmds.responseLen, this.dataBuffer.pos); | ||
this.dataBuffer.pos -= this.cmds.responseLen; | ||
if (!states) break; | ||
this.states = states; | ||
adapter.log.debug('onData: raw:' + JSON.stringify(buf)); | ||
@@ -634,2 +662,48 @@ adapter.log.debug('onData: ' + JSON.stringify(this.states)); | ||
//wifiLight.prototype.xonData = function (data) { | ||
// | ||
// var self = this; | ||
// function set(n, val) { | ||
// if (val != undefined) self.dev.set(n, val); | ||
// } | ||
// | ||
// var self = this; | ||
// | ||
// this.dataBuffer.concat(data.buffer); | ||
// data.forEach(function(val) { | ||
// self.dataBuffer.push(val); | ||
// }); | ||
// //this.dataBuffer.splice(this.dataBuffer.length, 0, data); | ||
// | ||
// if (this.dataBuffer.length < this.cmds.responsLen) { | ||
// return null; | ||
// } | ||
// | ||
// //var len = this.cmds.responsLen ? this.cmds.responsLen : data.length; | ||
// while (this.dataBuffer.length >= this.cmds.responseLen) | ||
// //for (var i=0; i<data.length; i+=len) | ||
// { | ||
// var buf = this.dataBuffer.splice(0, this.cmds.responseLen); | ||
// //var buf = data.slice(i, i + len); | ||
// var states = this.cmds.decodeResponse(buf); | ||
// if (!states) break; | ||
// this.states = states; | ||
// //var result = this.cmds.decodeResponse(data); | ||
// adapter.log.debug('onData: raw:' + JSON.stringify(buf)); | ||
// adapter.log.debug('onData: ' + JSON.stringify(this.states)); | ||
// if (this.states) { | ||
// set(usedStateNames.status.n, this.states.power); | ||
// set(usedStateNames.red.n, this.states.red); | ||
// set(usedStateNames.green.n, this.states.green); | ||
// set(usedStateNames.blue.n, this.states.blue); | ||
// set(usedStateNames.progNo.n, this.states.progNo); | ||
// set(usedStateNames.progOn.n, this.states.progOn); | ||
// set(usedStateNames.speed.n, this.states.speed); | ||
// devices.update(); | ||
// } | ||
// } | ||
// return this.states; | ||
//}; | ||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
@@ -636,0 +710,0 @@ |
78334
1778