Difference between revisions of "MansOS API"
(→LEDs) |
(→Usage and configuration) |
||
Line 10: | Line 10: | ||
=== Usage and configuration === |
=== Usage and configuration === |
||
LED support is turned ON by default. It can be disabled by adding the following line to the application config file: |
LED support is turned ON by default. It can be disabled by adding the following line to the application [[MansOS_configuration_options || config file]]: |
||
USE_LEDS = n |
USE_LEDS = n |
Revision as of 18:17, 14 November 2011
Contents
LEDs
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
LED function reference
// 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)
LED usage 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 }
Humidity sensor
See Humidity Reference .
Light sensor
mos/hil/light.h
void lightInit(); // init light sensor, do not turn it on - called by kernel automatically, not needed in application void lightOn(); // turn on light sensor void lightOff(); // turn off light sensor uint16_t readLight(); // read light value
uint16_t readVisibleLight(); // read visible light value uint16_t readPARLight(); // read photo-syntetically active radiation value
ADC
mos/hil/adc.h
void adcOn(); void adcOff();
uint16_t adcRead(uint8_t channel); // sets channel, reads value
// alternative faster version: set channel once, read multiple times (usable, if the same channel read many times) void adcSetChannel(uint8_t ch); uint16_t adcReadFast();
uint8_t adcGetChannelCount() // returns ADC channel count provided by the platform
Sleep
mos/hil/sleep.h
mleep(miliseconds)
USART
See mos/hil/usart.h for more details!
uint_t USARTInit(uint8_t id, uint32_t speed, uint8_t conf);
uint_t USARTSendByte(uint8_t id, uint8_t data); uint_t USARTSendString(uint8_t id, uint8_t *data); uint_t USARTSendStringLine(uint8_t id, uint8_t *data); void USARTSendData(uint8_t id, uint8_t *data, uint16_t len);
uint_t USARTEnableTX(uint8_t id); uint_t USARTDisableTX(uint8_t id); uint_t USARTEnableRX(uint8_t id); uint_t USARTDisableRX(uint8_t id);
/** * Set callback function for per-byte data receive. The callback is called * on every received packet * @param id - ID of the UART used (See MCU datasheet to get IDs) * @param cb - callback function: void myCallback(uint8_t byte) */ uint_t USARTSetReceiveHandle(uint8_t id, USARTCallback_t cb);
/** * Set callback for per-packet data receive. Stores the received bytes in * the buffer and the callback is called when either a newline is received * ('\n', binary value 10) or at most len bytes are received. The newline is * also stored in the buffer * Also enables USART RX automatically. * After the callback, buffer is reset and reception restarts. * Warning: Can use only one USART at a time (single buffer, single handler)! * * @param id - ID of the UART used (See MCU datasheet to get IDs) * @param cb - callback function: void myCallback(uint8_t bytes). Here the * bytes parameter contains not the last byte received but * total received byte count (i.e., bytes stored in the buffer)! * @param len - size of the buffer in bytes. Callback is called when len * bytes are received (or when '\n' is received). * When len is zero, no packet size is checked, only on newline * reception the callback is called. */ uint_t USARTSetPacketReceiveHandle(uint8_t id, USARTCallback_t cb, void *buffer, uint16_t len);