Permalink
Browse files

LCD: bgOn/bgOff for applicable devices

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
1 parent 3489091 commit 2d018e09502e5545f3bfcfa90e16bc5d7afce3b4 @rwaldron committed Dec 12, 2016
Showing with 87 additions and 27 deletions.
  1. +30 −8 lib/lcd.js
  2. +57 −19 test/lcd.js
View
@@ -183,6 +183,7 @@ var Controllers = {
blocking: {
var lines = this.REGISTER.DIMENSIONS | this.REGISTER.LINE[2];
// Copied from Grove Studio lib.
+ // https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after
// power rises above 2.7V before sending commands.
@@ -210,11 +211,16 @@ var Controllers = {
}
// Backlight initialization
- this.io.i2cWrite(this.address.rgb, [0, 0]);
- this.io.i2cWrite(this.address.rgb, [1, 0]);
- this.io.i2cWrite(this.address.rgb, [0x08, 0xAA]);
- this.bgColor(opts.color || "white");
+
+
+ this.bgOn();
+
+ if (opts.color) {
+ this.bgColor(opts.color);
+ } else {
+ this.bgColor("black");
+ }
},
},
clear: {
@@ -229,13 +235,29 @@ var Controllers = {
},
bgColor: {
value: function(red, green, blue) {
- var registers = [0x04, 0x03, 0x02];
var rgb = RGB.ToRGB(red, green, blue);
+ var address = this.address.rgb;
- RGB.colors.forEach(function(color, index) {
- this.io.i2cWrite(this.address.rgb, [registers[index], rgb[color]]);
- }, this);
+ this.io.i2cWrite(address, [0x00, 0]);
+ this.io.i2cWrite(address, [0x01, 0]);
+ // TRY THIS IN ONE CALL!
+ this.io.i2cWrite(address, [0x04, rgb.red]);
+ this.io.i2cWrite(address, [0x03, rgb.green]);
+ this.io.i2cWrite(address, [0x02, rgb.blue]);
+
+ return this;
+ }
+ },
+ bgOn: {
+ value: function() {
+ this.io.i2cWrite(this.address.rgb, [this.REGISTER.BACKLIGHT_ON, 0xAA]);
+ return this;
+ }
+ },
+ bgOff: {
+ value: function() {
+ this.io.i2cWrite(this.address.rgb, [this.REGISTER.BACKLIGHT_ON, 0x00]);
return this;
}
},
View
@@ -461,8 +461,42 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.done();
},
+ bgOn: function(test) {
+ test.expect(2);
+
+ var lcd = new LCD({
+ controller: "JHD1313M1",
+ board: this.board
+ });
+
+ this.i2cWrite.reset();
+
+ lcd.bgOn();
+
+ test.equal(this.i2cWrite.callCount, 1);
+ test.deepEqual(this.i2cWrite.lastCall.args, [ 98, [ 0x08, 0xAA ] ]);
+ test.done();
+ },
+
+ bgOff: function(test) {
+ test.expect(2);
+
+ var lcd = new LCD({
+ controller: "JHD1313M1",
+ board: this.board
+ });
+
+ this.i2cWrite.reset();
+
+ lcd.bgOff();
+
+ test.equal(this.i2cWrite.callCount, 1);
+ test.deepEqual(this.i2cWrite.lastCall.args, [ 98, [ 0x08, 0x00 ] ]);
+ test.done();
+ },
+
bgColor: function(test) {
- test.expect(36);
+ test.expect(38);
var lcd = new LCD({
controller: "JHD1313M1",
@@ -477,9 +511,13 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 1);
test.deepEqual(this.ToRGB.firstCall.args, [[0, 0, 0], undefined, undefined]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0, green: 0, blue: 0});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0 ] ]);
+
+
+ test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 0, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 1, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0 ] ]);
this.ToRGB.reset();
this.i2cWrite.reset();
@@ -489,9 +527,9 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 1);
test.deepEqual(this.ToRGB.firstCall.args, [0xff, 0xff, 0xff]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0xFF, green: 0xFF, blue: 0xFF});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0xFF ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0xFF ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0xFF ] ]);
this.ToRGB.reset();
this.i2cWrite.reset();
@@ -501,9 +539,9 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 1);
test.deepEqual(this.ToRGB.firstCall.args, ["ff0000", undefined, undefined]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0xFF, green: 0, blue: 0});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0xFF ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0 ] ]);
this.ToRGB.reset();
this.i2cWrite.reset();
@@ -513,9 +551,9 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 1);
test.deepEqual(this.ToRGB.firstCall.args, ["#ff0000", undefined, undefined]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0xFF, green: 0, blue: 0});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0xFF ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0 ] ]);
this.ToRGB.reset();
this.i2cWrite.reset();
@@ -525,9 +563,9 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 1);
test.deepEqual(this.ToRGB.firstCall.args, [{red: 0, green: 0xFF, blue: 0}, undefined, undefined]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0, green: 0xFF, blue: 0});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0xFF ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0 ] ]);
this.ToRGB.reset();
this.i2cWrite.reset();
@@ -538,9 +576,9 @@ exports["LCD - I2C (JHD1313M1)"] = {
test.equal(this.ToRGB.callCount, 2);
test.deepEqual(this.ToRGB.firstCall.args, ["blue", undefined, undefined]);
test.deepEqual(this.ToRGB.lastCall.returnValue, {red: 0, green: 0, blue: 0xFF});
- test.deepEqual(this.i2cWrite.getCall(0).args, [ 98, [ 4, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(1).args, [ 98, [ 3, 0 ] ]);
- test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 2, 0xFF ] ]);
+ test.deepEqual(this.i2cWrite.getCall(2).args, [ 98, [ 4, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(3).args, [ 98, [ 3, 0 ] ]);
+ test.deepEqual(this.i2cWrite.getCall(4).args, [ 98, [ 2, 0xFF ] ]);
test.done();
},

0 comments on commit 2d018e0

Please sign in to comment.