Difference between revisions of "MansOS LEDs"

From DiLab
Jump to: navigation, search
Line 1: Line 1:
{{TocRight}}
__TOC__


mos/hil/leds.h
mos/hil/leds.h

Revision as of 14:59, 15 October 2014

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
}