Class: LEDController

LEDController

new LEDController(identifier)

All the fun begins by creating an instance of this class

Parameters:
Name Type Description
identifier String

The LED identifier - one of the values returned by LEDController.discover. If there is only one LED available, the identifier is optional.

Source:

Members

(static) RATE :Number

Base rate at which the LED will blink

The rate controls how fast the LED will blink. If the base blink event duration is one second, and the rate is 2, then the actual duration of the blink event will be calculated as duration divided by rate, i.e. 1s / 2 => 0.5s. The rate gives you an opportunity to speed up or slow down blink rate without modifying any of your code.

Type:
  • Number
Default Value:
  • 1
Source:

(static) ROOT :String

Root path where LEDController should look for LEDs

Feel free to override if your OS puts LED definitions somewhere else.

Type:
  • String
Default Value:
  • /sys/class/leds/
Source:

(readonly) brightness :Object

The LED's brightness information

Type:
  • Object
Properties:
Name Type Description
min integer

Minimum brightness level allowed

max integer

Maximum brightness level allowed

cur integer

Current brightness level (sync getter)

Source:

(readonly) id :String

The LED's identifier, as given to the constructor

Just a helper for you, dear developer...

Type:
  • String
Source:

(readonly) location :String

The current LED's full filesystem location

Type:
  • String
Source:

(readonly) triggers :Object

The LED's supported triggers and currently enabled trigger

Type:
  • Object
Properties:
Name Type Description
all Array

List of supported triggers (strings)

cur String

Currently selected trigger (sync getter)

Source:

Methods

(static) discover() → {Array}

Discover available LEDs on current system

This sync function may be quite slow depending on the number of files and folders within LEDController.ROOT.

Source:
Returns:

List of LED IDs willing to bend to your will

Type
Array

(static) register(parser, handler)

Make your own blinker!

Parameters:
Name Type Description
parser String

The name of the parser - method of this name will be added to LEDController's prototype

handler LEDController.Parser

The actual parser function

Source:

Blink the LED!

Parameters:
Name Type Description
opts LEDController.Blink

Provide some info about how the LED should blink

done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

morse(input, done) → {this}

Turn regular text into morse code emitted from your LED

This method is implemented using the Parser and attached to LEDController's prototype using LEDController.register.

Parameters:
Name Type Description
input String

The text to be morse-coded

done function

Optional callback called at the end of sequence

Source:
Returns:
Type
this

reset(done) → {this}

Remove any blink events possibly scheduled and turn the LED off

Parameters:
Name Type Description
done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

setBrightness(value, done) → {this}

Set the LED's brightness to desired value

The integer value must be from the supported range (min <= value <= max).

Parameters:
Name Type Description
value Number

The new brightness to be set

done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

toString() → {String}

Override default .toString() function to return proper class name

Source:
Returns:

If not called from a subclass, returns [object LEDController]

Type
String

trigger(value, done) → {this}

Set the LED's trigger

Parameters:
Name Type Description
value String

The trigger to be used, as available in triggers' all property

done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

turnOff(done) → {this}

Stop conjuring photons (Turn the LED off)

Parameters:
Name Type Description
done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

turnOn(done) → {this}

Conjure photons (Turn the LED on)

Parameters:
Name Type Description
done function

Optional callback (if omitted, it will throw on error)

Source:
Returns:
Type
this

valueOf() → {Number}

Override default .valueOf() to return current brightness

This implementation is currently experimental and feedback on its usability is very welcome. It does, however, kind of make sense - a "value" of a LED could only be represented by either its colour or brightness (or a combination thereof). And colour we do not support. Note: this function blocks the proces while reading current brightness.

Source:
Returns:

LED's current brigthness

Type
Number

Type Definitions

A Blink describes a blink event

Type:
  • Object
Properties:
Name Type Description
rate Number

Override default rate of blinking

for Number

For how much percent of Blink.of should the LED be turned on?

of Number

What is the total duration of the blink (on + off time)

Source:

Parser(input) → {Array}

A custom blink parser for you to implement

Parameters:
Name Type Description
input mixed

Whatever you would like to convert into blink events

Source:
See:
Returns:

An array of Blink objects which represent the sequence in which the LED should blink

Type
Array