9d076ea0 |
1 | /* $Id: ledframing.h,v 1.1 2010/07/10 09:28:52 simimeie Exp $ |
2 | * Functions for led "animations" |
3 | */ |
4 | |
5 | #ifndef _LEDFRAMING_H_ |
6 | #define _LEDFRAMING_H_ |
7 | |
8 | #include <avr/io.h> |
9 | |
10 | /* Number of frames to allocate in memory. |
11 | * Note: One frame takes up 7 bytes of memory (or more if the compiler |
12 | * chooses a strange alignment) |
13 | * Must not be >255. */ |
14 | #define MAX_FRAMES 32 |
15 | |
16 | struct frame { |
17 | uint16_t duration; /* in ticks */ |
18 | unsigned char action:2; |
19 | union { |
20 | struct { |
21 | uint8_t re; |
22 | uint8_t gr; |
23 | uint8_t bl; |
24 | } rgb; |
25 | struct { |
26 | uint16_t onticks; |
27 | uint16_t offticks; |
28 | } strobe; |
29 | }; |
30 | }; |
31 | |
32 | /* Values for 'action' */ |
33 | /* Fade from last to this color */ |
34 | #define ACTION_FADE 0 |
35 | /* Strobe (blink) */ |
36 | #define ACTION_STROBE 1 |
37 | /* Maximum valid ACTION */ |
38 | #define MAX_ACTION ACTION_STROBE |
39 | |
40 | /* Initializes internal structures. */ |
41 | void ledframing_init(void); |
42 | |
43 | /* Create a frame from a struct frame. */ |
44 | uint8_t addframe_frame(struct frame fr); |
45 | |
46 | /* Create a frame that fades from the last color to this one. duration is |
47 | * the number of ticks this fading should take. |
48 | * There is an obvious special case: fading with a duration of 0 will just |
49 | * switch to that color. |
50 | * Returns 1 if successful, 0 on error (out of memory) */ |
51 | uint8_t addframe_fade(uint16_t duration, uint8_t red, uint8_t green, uint8_t blue); |
52 | |
53 | /* Create a frame where the LEDs are blinking. The color is not changed, |
54 | * thus stays whatever it was before. onticks and offticks give the number |
55 | * of ticks that the LEDs are on and off (respectively) in each blink |
56 | * interval. |
57 | * This can obviously be used to turn off the LEDs for an interval: |
58 | * onticks = 0, offticks = duration. |
59 | * Returns 1 if successful, 0 on error (out of memory) */ |
60 | uint8_t addframe_strobe(uint16_t duration, uint16_t onticks, uint16_t offticks); |
61 | |
62 | /* Returns the next frame (or NULL if there isn't any left) */ |
63 | struct frame * getnextframe(void); |
64 | |
65 | /* Clears the frame buffer */ |
66 | void resetframes(); |
67 | |
68 | #endif /* _LEDFRAMING_H_ */ |