X-Git-Url: http://git.rrze.uni-erlangen.de/gitweb/?p=moodlight.git;a=blobdiff_plain;f=ledframing.h;fp=ledframing.h;h=900eea0aa1cab8611d4696da381dc78273db88a9;hp=0000000000000000000000000000000000000000;hb=9d076ea0c15fc4f9c3c8f67415040545be1bf0c6;hpb=c7c49995443544bf5eaf10ec2890923bad939a6f diff --git a/ledframing.h b/ledframing.h new file mode 100644 index 0000000..900eea0 --- /dev/null +++ b/ledframing.h @@ -0,0 +1,68 @@ +/* $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 + +/* 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_ */