Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mwittig committed May 10, 2015
1 parent d58cbb1 commit 483780b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var light = new Milight({
zone = 1;

light.sendCommands(commands.rgbw.on(zone), commands.rgbw.brightness(100));
for (var x=0; x<256; x+=5) {
light.sendCommands( commands.rgbw.on(zone), commands.rgbw.hue(x));
for (var x = 0; x < 256; x += 5) {
light.sendCommands(commands.rgbw.on(zone), commands.rgbw.hue(x));
}
light.pause(1000);
light.sendCommands(commands.rgbw.off(zone));
Expand All @@ -22,12 +22,12 @@ light.sendCommands(commands.rgbw.off(zone));
light.pause(1000);
light.sendCommands(commands.rgbw.whiteMode(zone), commands.rgbw.on(zone));
light.pause(1000);
light.sendCommands( commands.rgbw.on(zone), commands.rgbw.hue(255));
light.sendCommands(commands.rgbw.on(zone), commands.rgbw.hue(255));
light.pause(1000);
light.sendCommands( commands.rgbw.on(zone), commands.rgbw.hue(126));
light.sendCommands(commands.rgbw.on(zone), commands.rgbw.hue(126));
light.pause(1000);
light.sendCommands( commands.rgbw.off(zone));
light.close().then(function() {
light.sendCommands(commands.rgbw.off(zone));
light.close().then(function () {
console.log("Finished");
});

14 changes: 7 additions & 7 deletions src/milight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ const
DEFAULT_IP = '255.255.255.255',
DEFAULT_PORT = 8899,
DEFAULT_COMMAND_DELAY = 30,
DEFAULT_COMMAND_REPEAT=3;
DEFAULT_COMMAND_REPEAT = 3;

//
// Local helper functions
//

function buffer2hex(buffer) {
result = [];
for (var i = 0; i < buffer.length ; i++) {
for (var i = 0; i < buffer.length; i++) {
result.push('0x' + buffer[i].toString(16))
}
return result;
Expand Down Expand Up @@ -72,7 +72,7 @@ MilightController.prototype._createSocket = function () {
var socket = dgram.createSocket('udp4');

if (self._broadcastMode) {
socket.bind(function() {
socket.bind(function () {
socket.setBroadcast(true);
self.clientSocket = socket;
debug("Milight: Initializing Socket (broadcast mode) completed");
Expand Down Expand Up @@ -100,7 +100,7 @@ MilightController.prototype._sendThreeByteArray = function (threeByteArray) {
return self._sendRequest = Promise.settle([self._sendRequest]).then(function () {

return new Promise(function (resolve, reject) {
self._createSocket().then(function() {
self._createSocket().then(function () {
self.clientSocket.send(buffer
, 0
, buffer.length
Expand All @@ -112,14 +112,14 @@ MilightController.prototype._sendThreeByteArray = function (threeByteArray) {
return reject(err);
}
else {
debug('Milight: bytesSent=' + bytes +', buffer=[' + buffer2hex(buffer) + ']');
debug('Milight: bytesSent=' + bytes + ', buffer=[' + buffer2hex(buffer) + ']');
return Promise.delay(self._delayBetweenCommands).then(function () {
return resolve();
});
}
}
);
}).catch(function(error) {
}).catch(function (error) {
return reject(error);
})
})
Expand All @@ -142,7 +142,7 @@ MilightController.prototype.sendCommands = function (varArgArray) {

return self._lastRequest = Promise.settle([self._lastRequest]).then(function () {

for (var r=0; r < self._commandRepeat; r++) {
for (var r = 0; r < self._commandRepeat; r++) {
for (var i = 0; i < varArgs.length; i++) {
if (!varArgs[i] instanceof Array) {
return Promise.reject(new Error("Array arguments required"));
Expand Down

0 comments on commit 483780b

Please sign in to comment.