From ce8212430e9dcfe923beb4fe3835697f86d22706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Tue, 26 May 2015 23:09:00 -0400 Subject: [PATCH] Led.RGB: Move internal value writing out of controllers --- lib/led/rgb.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/led/rgb.js b/lib/led/rgb.js index ae205e015..53c0f1c09 100644 --- a/lib/led/rgb.js +++ b/lib/led/rgb.js @@ -38,8 +38,6 @@ var Controllers = { this.io.analogWrite(pin, value); }, this); - - Object.assign(state, colors); } } }, @@ -102,8 +100,6 @@ var Controllers = { this.io.i2cWrite(this.address, [this.COMMANDS.LED0_ON_L + 4 * pin, on, on >> 8, off, off >> 8]); }, this); - - Object.assign(state, colors); } } }, @@ -134,12 +130,8 @@ var Controllers = { write: { writable: true, value: function(colors) { - var state = priv.get(this); - this.board.io.i2cWrite(this.address, [this.COMMANDS.GO_TO_RGB_COLOR_NOW, colors.red, colors.green, colors.blue]); - - Object.assign(state, colors); } } } @@ -233,6 +225,15 @@ var RGB = function(opts) { return (current[color] = state[color], current); }, {}); } + }, + writeColor: { + value: function(colors) { + var state = priv.get(this); + + this.write(colors); + + Object.assign(state, colors); + } } }); @@ -330,7 +331,7 @@ RGB.prototype.color = function(red, green, blue) { update[color] = value; }, this); - this.write(update); + this.writeColor(update); return this; }; @@ -344,7 +345,7 @@ RGB.prototype.on = function() { colors = state.prev || { red: 255, green: 255, blue: 255 }; delete state.prev; - this.write(colors); + this.writeColor(colors); } return this; @@ -359,7 +360,7 @@ RGB.prototype.off = function() { return (current[color] = state[color], current); }.bind(this), {}); - this.write({ red: 0, green: 0, blue: 0 }); + this.writeColor({ red: 0, green: 0, blue: 0 }); } return this;