+/* $Id: ledframing.h,v 1.1 2010/07/10 09:28:52 simimeie Exp $
+ * Functions for led "animations"
+ */
+
+#ifndef _LEDFRAMING_H_
+#define _LEDFRAMING_H_
+
+#include <avr/io.h>
+
+/* Number of frames to allocate in memory.
+ * Note: One frame takes up 7 bytes of memory (or more if the compiler
+ * chooses a strange alignment)
+ * Must not be >255. */
+#define MAX_FRAMES 32
+
+struct frame {
+ uint16_t duration; /* in ticks */
+ unsigned char action:2;
+ union {
+ struct {
+ uint8_t re;
+ uint8_t gr;
+ uint8_t bl;
+ } rgb;
+ struct {
+ uint16_t onticks;
+ uint16_t offticks;
+ } strobe;
+ };
+};
+
+/* Values for 'action' */
+/* Fade from last to this color */
+#define ACTION_FADE 0
+/* Strobe (blink) */
+#define ACTION_STROBE 1
+/* Maximum valid ACTION */
+#define MAX_ACTION ACTION_STROBE
+
+/* Initializes internal structures. */
+void ledframing_init(void);
+
+/* Create a frame from a struct frame. */
+uint8_t addframe_frame(struct frame fr);
+
+/* Create a frame that fades from the last color to this one. duration is
+ * the number of ticks this fading should take.
+ * There is an obvious special case: fading with a duration of 0 will just
+ * switch to that color.
+ * Returns 1 if successful, 0 on error (out of memory) */
+uint8_t addframe_fade(uint16_t duration, uint8_t red, uint8_t green, uint8_t blue);
+
+/* Create a frame where the LEDs are blinking. The color is not changed,
+ * thus stays whatever it was before. onticks and offticks give the number
+ * of ticks that the LEDs are on and off (respectively) in each blink
+ * interval.
+ * This can obviously be used to turn off the LEDs for an interval:
+ * onticks = 0, offticks = duration.
+ * Returns 1 if successful, 0 on error (out of memory) */
+uint8_t addframe_strobe(uint16_t duration, uint16_t onticks, uint16_t offticks);
+
+/* Returns the next frame (or NULL if there isn't any left) */
+struct frame * getnextframe(void);
+
+/* Clears the frame buffer */
+void resetframes();
+
+#endif /* _LEDFRAMING_H_ */