Skip to content

Commit

Permalink
Led.RGB: Move internal value writing out of controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed May 27, 2015
1 parent 838bc2b commit ce82124
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/led/rgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ var Controllers = {

this.io.analogWrite(pin, value);
}, this);

Object.assign(state, colors);
}
}
},
Expand Down Expand Up @@ -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);
}
}
},
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
});

Expand Down Expand Up @@ -330,7 +331,7 @@ RGB.prototype.color = function(red, green, blue) {
update[color] = value;
}, this);

this.write(update);
this.writeColor(update);

return this;
};
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ce82124

Please sign in to comment.