Skip to content

Commit

Permalink
Merge pull request #1005 from ericandrewlewis/docs-1
Browse files Browse the repository at this point in the history
LED controller documentation
  • Loading branch information
rwaldron committed Jan 10, 2016
2 parents db809ac + b45a8d4 commit 37c03fb
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions lib/led/ledcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ var ledCharacters = require("./led-chars");
var priv = new Map(),
Controllers;

/**
* Create an LED control.
* @mixes Board.Component
* @param {Object} opts An options hash.
* @param {String} [opts.controller] The controller to use. Either default ("MAX 7219") or "HT16K33".
* @param {Boolean} [opts.colon] Whether the device has a built in colon.
* @param {Number} [opts.devices] The number of connected LED devices.
* @param {Array} [opts.addresses] I2C addresses.
* @param {*} opts.pins The digital pin numbers that connect to
* data, clock, and cs connections on the controller device.
* Only for use with the default controller.
* Accepts either an object ({data, clock, cs})
* or an array ([data, clock, cs]).
* @param {*} [opts.dims] Dimensions of the LED screen.
* Only for use with the HT16K33 controller.
* @param {Boolean} [opts.isBicolor] Whether the LED screen is bicolor.
* Only for use with the HT16K33 controller.
*/
function LedControl(opts) {

Board.Component.call(
Expand Down Expand Up @@ -163,12 +181,23 @@ function LedControl(opts) {
controller.initialize.call(this, opts);
}

/**
* Iterate over the index of each connected device and invoke a callback function
* for each.
* @param {Function} callbackfn The function to callback for each device index.
*/
LedControl.prototype.each = function(callbackfn) {
for (var i = 0; i < this.devices; i++) {
callbackfn.call(this, i);
}
};

/**
* Turn the LED device(s) on.
* @param {Number} addr The index of the device to turn on.
* If undefined, all devices are turned on.
* @return {LEDControl} Returns this to allow for chaining.
*/
LedControl.prototype.on = function(addr) {
if (typeof addr === "undefined") {
this.each(function(device) {
Expand All @@ -180,6 +209,12 @@ LedControl.prototype.on = function(addr) {
return this;
};

/**
* Turn the LED device(s) off.
* @param {Number} addr The index of the device to turn off.
* If undefined, all devices are turned off.
* @return {LEDControl} Returns this to allow for chaining.
*/
LedControl.prototype.off = function(addr) {
if (typeof addr === "undefined") {
this.each(function(device) {
Expand Down Expand Up @@ -660,10 +695,10 @@ Controllers = {
},

/*
* doSend
* @param {Number} addr Address of Led device
* @param {Number} opcode Operation code
* @param {Number} data Data
* Send data to the LED controller.
* @param {Number} addr Index of the device to address.
* @param {Number} opcode Operation code.
* @param {Number} data Data.
*/
send: function(addr, opcode, data) {
if (arguments.length !== 3) {
Expand Down

0 comments on commit 37c03fb

Please sign in to comment.