Difference between revisions of "MansOS LEDs"

From DiLab
Jump to: navigation, search
Line 22: Line 22:
All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/
All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/


<pre>
// Toggle an LED, addressed by color
// Toggle an LED, addressed by color
toggleRedLed()
toggleRedLed()
Line 58: Line 59:
uint8_t getLeds()
uint8_t getLeds()
setLeds(bitmap)
setLeds(bitmap)
</pre>


== Examples ==
== Examples ==
Line 65: Line 67:
Blink the platform's default LED once every second.
Blink the platform's default LED once every second.


<pre>
// Example from apps/demo/Blink
// Example from apps/demo/Blink


while (1) {
while (1) {
// change red LED status
// change red LED status
toggleLed();
toggleLed();
// wait for 1000 milliseconds
// wait for 1000 milliseconds
mdelay(1000);
mdelay(1000);
}
}
</pre>


=== Counter representation on LEDs ===
=== Counter representation on LEDs ===
Line 78: Line 82:
Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.
Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.


<pre>
// Example from apps/demo/CounterToLeds
// Example from apps/demo/CounterToLeds


uint8_t counter;
uint8_t counter;
counter = 1;
counter = 1;
while (1) {
while (1) {
setLeds(counter++);
setLeds(counter++);
msleep(1000); // sleep one second
msleep(1000); // sleep one second
}
}
</pre>

Revision as of 19:46, 14 November 2011

mos/hil/leds.h

MansOS provides API for Light-Emitting Diode (LED) setting and status checking (whether a LED is ON or OFF). LEDs are connected directly to GPIO pins, and each platform must define pin numbers for available LEDs on the hardware platform.

LEDs can be addressed in two different forms: by color or by led number. LEDs are always accessible by number, starting from 0 up to LED_COUNT - 1, where LED_COUNT is a constant specifying LED count on the particular platform. LED addressing by color is optional, platform-dependent. On some platforms, such as TelosB, different colors are available, for example, red, green and blue LED. On some platforms all the LEDs can be of the same color.

Up to 8 LEDs are supported.

Usage and configuration

LED support is turned ON by default. It can be disabled by adding the following line to the application config file:

USE_LEDS = n

Dependencies

There are no dependencies for using LEDs.

Function reference

All platform-independent LED functions are described in mos/hil/leds.h . Implementation can be found under mos/hal/platforms/<platform-name>/

 // Toggle an LED, addressed by color
 toggleRedLed() 
 toggleGreenLed()
 toggleBlueLed()

 // Toggle an LED, addressed by number
 toggleLed(ledNr)

 // Toggle platform's default LED
 toggleLed()

 // Turn ON an LED, addressed by color
 redLedOn()
 greenLedOn()
 blueLedOn()

 // Turn OFF an LED, addressed by color
 redLedOff()
 greenLedOff()
 blueLedOff()

 // Turn ON/OFF an LED, addressed by number
 ledOn(uint8_t ledNr)
 ledOff(uint8_t ledNr)

 // Turn platform's default LED ON/OFF
 ledOn();
 ledOff();

 // Return true, if an LED, addressed by number, is ON; false (zero) otherwise
 bool ledIsOn(ledNr)

 // Get and set all LEDs, addressed by a bitmask
 // for example, if getLeds() returns 5, LEDs #0 and #2 are ON ((2 << 0) + (2 << 2) = 5)
 uint8_t getLeds()
 setLeds(bitmap)

Examples

Blink

Blink the platform's default LED once every second.

// Example from apps/demo/Blink

while (1) {
    // change red LED status
    toggleLed();
    // wait for 1000 milliseconds
     mdelay(1000);
}

Counter representation on LEDs

Represent an incrementing counter on the LEDs. If less than 8 LEDs are supported by the platform, the youngest bits are shown.

// Example from apps/demo/CounterToLeds

uint8_t counter;
counter = 1;
while (1) {
    setLeds(counter++);
    msleep(1000); // sleep one second
}