Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions oled.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var Oled = function(board, five, opts) {
this.MICROVIEW = opts.microview || false;
this.SLAVEPIN = opts.slavePin || 12;
this.RESETPIN = opts.resetPin || 4;
this.MUXADDRESS = opts.muxAddress || 0;
this.MUXCHANNEL = opts.muxChannel || 0;

// create command buffers
this.DISPLAY_OFF = 0xAE;
Expand Down Expand Up @@ -71,7 +73,7 @@ var Oled = function(board, five, opts) {
'64x48': {
'multiplex': 0x2F,
'compins': 0x12,
'coloffset': (this.MICROVIEW) ? 32 : 0
'coloffset': 32
}
};

Expand Down Expand Up @@ -176,8 +178,15 @@ Oled.prototype._transfer = function(type, val) {
}

if (this.PROTOCOL === 'I2C') {
if (this.MUXADDRESS) {
this.board.io.i2cWrite(this.MUXADDRESS, [0xE0, this.MUXCHANNEL]);
}
// send control and actual val
this.board.io.i2cWrite(this.ADDRESS, [control, val]);

if (this.MUX) {
this.board.io.i2cWrite(this.MUXADDRESS, [0xE0, this.MUXCHANNEL]);
}
} else {
// send val via SPI, no control byte
this._writeSPI(val, type);
Expand Down Expand Up @@ -232,6 +241,10 @@ Oled.prototype._waitUntilReady = function(callback) {
var done,
oled = this;

if (this.MUXADDRESS) {
this.board.io.i2cWrite(this.ADDRESS, [0xE1, this.MUXCHANNEL]);
}

function tick(callback) {
oled._readI2C(function(byte) {
// read the busy byte in the response
Expand All @@ -240,14 +253,17 @@ Oled.prototype._waitUntilReady = function(callback) {
// if not busy, it's ready for callback
callback();
} else {
console.log('I\'m busy!');
setTimeout(tick, 0);
setTimeout(function() {
tick(callback);
}, 0);
}
});
};

if (this.PROTOCOL === 'I2C') {
setTimeout(tick(callback), 0);
setTimeout(function() {
tick(callback);
}, 0);
} else {
callback();
}
Expand Down Expand Up @@ -593,7 +609,7 @@ Oled.prototype.drawLine = function(x0, y0, x1, y1, color, sync) {
// Draw an outlined rectangle
Oled.prototype.drawRect = function(x, y, w, h, color, sync){
var immed = (typeof sync === 'undefined') ? true : sync;
//top
//top
this.drawLine(x, y, x + w, y,color,false);

//left
Expand Down
21 changes: 11 additions & 10 deletions tests/demoTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ board.on('ready', function() {
// I2C va USB
// var opts = {
// width: 128,
// height: 64,
// height: 64,
// address: 0x3D
// };

// SPI via USB
// var opts = {
// width: 128,
// height: 64,
// height: 64,
// slavePin: 12
// };

// SPI Microview via USB
var opts = {
width: 64,
height: 48,
microview: true
height: 48,
address: 0x3C
// microview: true
};

var oled = new Oled(board, five, opts);
Expand All @@ -44,7 +45,7 @@ function test(oled) {
// clear first just in case
oled.update();

// make it prettier
// make it prettier
oled.dimDisplay(true);


Expand All @@ -70,7 +71,7 @@ function test(oled) {
oled.buffer = bitmapbuf;
oled.update();
});

}
},
{
Expand Down Expand Up @@ -106,7 +107,7 @@ function test(oled) {
// create concenctric rectangle outlines
oled.clearDisplay();

//calc how many squares we can fit on the screen
//calc how many squares we can fit on the screen
var padding = 2;
var square_count = ((oled.WIDTH / 2 ) / (padding * 2) ) - 1;

Expand All @@ -128,13 +129,13 @@ function test(oled) {

var x = oled.WIDTH / 2;
var y = oled.HEIGHT / 2;
var radius = oled.HEIGHT - 1
var radius = oled.HEIGHT - 1

//calc how many circles we can fit on the screen
//calc how many circles we can fit on the screen
var circle_count = radius / 3;

for(var i = 0; i < circle_count; i++){
var r = radius - (i * 3);
var r = radius - (i * 3);
oled.drawCircle(x, y, r, 1, false);
}
oled.update();
Expand Down