Made LEDS not count

This commit is contained in:
adamdunkels 2006-10-09 11:55:02 +00:00
parent 20b05c6d22
commit 022b1ba742

View File

@ -28,39 +28,25 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: leds.c,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $ * @(#)$Id: leds.c,v 1.2 2006/10/09 11:55:02 adamdunkels Exp $
*/ */
#include "dev/leds.h" #include "dev/leds.h"
#include "sys/clock.h" #include "sys/clock.h"
static struct { static unsigned char leds, invert;
char green:4, yellow:4, red:4;
} leds;
static struct {
char green:2, yellow:2, red:2; /* These bit fields should really be
only one bit wide, but that
crashed gcc... */
} invert;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
show_leds(void) show_leds(void)
{ {
leds_arch_set((((leds.green > 0) ^ invert.green) ? LEDS_GREEN : 0) | leds_arch_set(leds);
(((leds.yellow > 0) ^ invert.yellow) ? LEDS_YELLOW : 0) |
(((leds.red > 0) ^ invert.red) ? LEDS_RED : 0));
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
leds_init(void) leds_init(void)
{ {
leds.green = leds.red = leds.yellow = 0;
invert.green = invert.red = invert.yellow = 0;
leds_arch_init(); leds_arch_init();
leds = invert = 0;
show_leds();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -82,30 +68,14 @@ leds_get(void) {
void void
leds_on(unsigned char l) leds_on(unsigned char l)
{ {
if((l & LEDS_GREEN) && leds.green < 15) { leds |= l;
++leds.green;
}
if((l & LEDS_YELLOW) && leds.yellow < 15) {
++leds.yellow;
}
if((l & LEDS_RED) && leds.red < 15) {
++leds.red;
}
show_leds(); show_leds();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
leds_off(unsigned char l) leds_off(unsigned char l)
{ {
if((l & LEDS_GREEN) && leds.green > 0) { leds &= ~l;
--leds.green;
}
if((l & LEDS_YELLOW) && leds.yellow > 0) {
--leds.yellow;
}
if((l & LEDS_RED) && leds.red > 0) {
--leds.red;
}
show_leds(); show_leds();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -117,15 +87,7 @@ leds_toggle(unsigned char leds)
/* invert the ínvert register using the leds parameter */ /* invert the ínvert register using the leds parameter */
void leds_invert(unsigned char l) { void leds_invert(unsigned char l) {
if(l & LEDS_GREEN) { leds = ~leds;
invert.green = 1 - invert.green;
}
if(l & LEDS_YELLOW) {
invert.yellow = 1 - invert.yellow;
}
if(l & LEDS_RED) {
invert.red = 1 - invert.red;
}
show_leds(); show_leds();
} }