Skip to content

Commit

Permalink
Make LedControl pins option and instance property match existing APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Oct 3, 2012
1 parent a64a4ba commit efbb511
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
8 changes: 5 additions & 3 deletions docs/led-matrix.md
Expand Up @@ -28,9 +28,11 @@ board.on("ready", function() {
];

lc = new five.LedControl({
data: 2,
clock: 3,
cs: 4,
pins: {
data: 2,
clock: 3,
cs: 4
},
devices: 1,
isMatrix: true
});
Expand Down
8 changes: 5 additions & 3 deletions eg/led-matrix.js
Expand Up @@ -19,9 +19,11 @@ board.on("ready", function() {
];

lc = new five.LedControl({
data: 2,
clock: 3,
cs: 4,
pins: {
data: 2,
clock: 3,
cs: 4
},
devices: 1,
isMatrix: true
});
Expand Down
59 changes: 27 additions & 32 deletions lib/ledcontrol.js
Expand Up @@ -39,21 +39,40 @@ var priv = new WeakMap();
function LedControl( opts ) {
var i, j;

// TODO:
// Ask rmurphey why no opts = Board.options( opts );
//
opts = Board.options( opts );

this.board = Board.mount( opts );
this.firmata = this.board.firmata;

this.pins = {
data: opts.pins.data,
clock: opts.pins.clock,
cs: opts.pins.cs
};

this.status = [];

for ( i = 0; i < 64; i++ ) {
this.status[ i ] = 0x00;
}


[ "data", "clock", "cs" ].forEach(function( pin ) {
this.firmata.pinMode( this.pins[ pin ], this.firmata.MODES.OUTPUT );
}, this);

this.board.digitalWrite( this.pins.cs, this.firmata.HIGH );

for ( j = 0; j < opts.devices; j++ ) {
this.send( j, LedControl.OP.DISPLAYTEST, 0 );
this.setScanLimit( j, 7 );
this.send( j, LedControl.OP.DECODEMODE, 0 );
this.clear( j );
this.shutdown( j , true );
}

priv.set( this, {
devices: opts.devices,
pins: {
data: opts.data,
clock: opts.clock,
cs: opts.cs
},
isMatrix: !!opts.isMatrix
});

Expand All @@ -64,36 +83,12 @@ function LedControl( opts ) {
}
},

pins: {
get: function() {
return priv.get( this ).pins;
}
},

isMatrix : {
get: function() {
return priv.get( this ).isMatrix;
}
}
});

[ "data", "clock", "cs" ].forEach(function( pin ) {
this.firmata.pinMode( this.pins[ pin ], this.firmata.MODES.OUTPUT );
}, this);

this.board.digitalWrite( this.pins.cs, this.firmata.HIGH );

for ( i = 0; i < 64; i++ ) {
this.status[ i ] = 0x00;
}

for ( j = 0; j < opts.devices; j++ ) {
this.send( j, LedControl.OP.DISPLAYTEST, 0 );
this.setScanLimit( j, 7 );
this.send( j, LedControl.OP.DECODEMODE, 0 );
this.clear( j );
this.shutdown( j , true );
}
}


Expand Down

0 comments on commit efbb511

Please sign in to comment.