Skip to content

Commit

Permalink
Merge pull request #1 from alexfederlin/alexfederlin-patch-1
Browse files Browse the repository at this point in the history
fixed garbled output with println
  • Loading branch information
craigmw authored Mar 24, 2020
2 parents 915b477 + 869b42b commit 446c4e3
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions lcdi2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,112 @@ let LCD = class LCD {
RW: 0x20 // not used
};

// <<<<<<< alexfederlin-patch-1
var buffer = new Buffer(3); //Required for printlnBuffer.

//LCD() - Initialize LCD object.
// device: I2C bus number; 0 for rev. 1 boards, 1 for rev. 2+ boards.
// address: Address of device (use i2cdetect to determine this)
// cols: columns supported by display (e.g. 16 or 20)
// rows: rows supported by display (e.g. 2 or 4 )
var LCD = function (device, address, cols, rows ) {
//this.i2c = new i2c(address, {
// device : device
// });
this.device = device;
this.address = address;
this.cols = cols;
this.rows = rows;
this.error = null;
this.i2c = i2c.open( device, function( err ) {
if ( err ) {
console.log( 'Unable to open I2C port on device ' + device + ' ERROR: ' + err );
console.log( this );
this.error = err;
return this
};
});
//console.log( 'Opened I2C port on bus ' + device + ' for LCD at address 0x' + address.toString( 16 ) + '.' );
this._sleep(1000);

this.init();

return this;
};

// commands
LCD.CLEARDISPLAY = 0x01;
LCD.RETURNHOME = 0x02;
LCD.ENTRYMODESET = 0x04;
LCD.DISPLAYCONTROL = 0x08;
LCD.CURSORSHIFT = 0x10;
LCD.FUNCTIONSET = 0x20;
LCD.SETCGRAMADDR = 0x40;
LCD.SETDDRAMADDR = 0x80;

//# flags for display entry mode
LCD.ENTRYRIGHT = 0x00;
LCD.ENTRYLEFT = 0x02;
LCD.ENTRYSHIFTINCREMENT = 0x01;
LCD.ENTRYSHIFTDECREMENT = 0x00;

//# flags for display on/off control
LCD.DISPLAYON = 0x04;
LCD.DISPLAYOFF = 0x00;
LCD.CURSORON = 0x02;
LCD.CURSOROFF = 0x00;
LCD.BLINKON = 0x01;
LCD.BLINKOFF = 0x00;

//# flags for display/cursor shift
LCD.DISPLAYMOVE = 0x08;
LCD.CURSORMOVE = 0x00;
LCD.MOVERIGHT = 0x04;
LCD.MOVELEFT = 0x00;

//# flags for function set
LCD._8BITMODE = 0x10;
LCD._4BITMODE = 0x00;
LCD._2LINE = 0x08;
LCD._1LINE = 0x00;
LCD._5x10DOTS = 0x04;
LCD._5x8DOTS = 0x00;

//Line addresses.
LCD.LINEADDRESS = [];
LCD.LINEADDRESS[1] = 0x80;
LCD.LINEADDRESS[2] = 0xC0;
LCD.LINEADDRESS[3] = 0x94;
LCD.LINEADDRESS[4] = 0xD4;

LCD.prototype.init = function (){
this.write4( 0x33, displayPorts.CMD); //initialization
this._sleep(200);
this.write4(0x32, displayPorts.CMD); //initialization
this._sleep(100);
this.write4( 0x06, displayPorts.CMD); //initialization
this._sleep(100);
this.write4( 0x28, displayPorts.CMD); //initialization
this._sleep(100);
this.write4( 0x01, displayPorts.CMD); //initialization
this._sleep(100);


this.write4(LCD.FUNCTIONSET | LCD._4BITMODE | LCD._2LINE | LCD._5x10DOTS, displayPorts.CMD); //4 bit - 2 line 5x7 matrix

this._sleep(10);
this.write( LCD.DISPLAYCONTROL | LCD.DISPLAYON, displayPorts.CMD); //turn cursor off 0x0E to enable cursor
this._sleep(10);
this.write( LCD.ENTRYMODESET | LCD.ENTRYLEFT, displayPorts.CMD); //shift cursor right
this._sleep(10);
this.write( LCD.CLEARDISPLAY, displayPorts.CMD); // LCD clear
this.write( displayPorts.backlight, displayPorts.CHR ); //Turn on backlight.
}

LCD.prototype._sleep = function (milli) {
sleep.usleep(milli * 1000);
};
// =======
this.buffer = new Buffer(3); //Required for printlnBuffer.

// commands
Expand Down Expand Up @@ -117,6 +223,7 @@ let LCD = class LCD {

return this;
};
// >>>>>>> master

_sleep(milli) {
sleep.usleep(milli * 1000);
Expand Down Expand Up @@ -183,11 +290,19 @@ let LCD = class LCD {
return this;
};

// <<<<<<< alexfederlin-patch-1

This comment has been minimized.

Copy link
@SimonGAndrews

SimonGAndrews Apr 28, 2020

see new issue #7. looks like this change has been inserted in the wrong place and causing compile failure. Looks like the variable 'line' is expected to be a parameter in the containing function as per some of the other functions.
Regards, Simon

//Set cursor to correct line.
if ( line > 0 && line <= this.rows ) {
this.write( LCD.LINEADDRESS[line], displayPorts.CMD );
this._sleep(2);
};
// =======
writeBlock(x, c) {
this.write4Block(x, c);
this.write4Block(x << 4, c);
return this;
};
//>>>>>>> master

clear() {
return this.write(this.CLEARDISPLAY, this.displayPorts.CMD);
Expand Down

0 comments on commit 446c4e3

Please sign in to comment.