SFBQLED.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #ifndef SFBQLED_H
00031 #define SFBQLED_H
00032
00033 #include "SFBTypes.h"
00034 #include "SFBConstants.h"
00035
00039 enum SFBQLEDWhenIdleModes {
00040 QLED_IDLE_OFF,
00041 QLED_IDLE_ON,
00042 QLED_IDLE_REFLEX
00043 };
00044
00144 class SFBQLED {
00145 enum {
00146 QLED_BODY_RGB_RED_PIN,
00147 QLED_BODY_RGB_GREEN_PIN,
00148 QLED_BODY_RGB_BLUE_PIN,
00149 QLED_NORTH_LED_PIN,
00150 QLED_SOUTH_LED_PIN,
00151 QLED_EAST_LED_PIN,
00152 QLED_WEST_LED_PIN,
00153 QLED_NORTH_SIDE_LED_PIN,
00154 QLED_SOUTH_SIDE_LED_PIN,
00155 QLED_EAST_SIDE_LED_PIN,
00156 QLED_WEST_SIDE_LED_PIN,
00157 QLED_COUNT,
00158
00159 FLAG = 0xff,
00160 MAX_TICKS=0x7f,
00161 MS_PER_TICK_BITS = 4,
00162 MS_PER_TICK = 1<<MS_PER_TICK_BITS
00163 };
00164 struct qentry {
00165 u8 onOffTime;
00166 u8 next;
00167 };
00168
00169 qentry * queue;
00170 u16 idleOurs;
00171 u16 idleOn;
00172 u8 oldest[QLED_COUNT];
00173 u8 newest[QLED_COUNT];
00174 u8 freeList;
00175 u8 freeCount;
00176 u8 alarm;
00177 u8 slots;
00178
00179 u32 indexFromSFBPin(u32 sfbPin) ;
00180 u8 sfbPinFromIndex(u32 index) ;
00181 u32 allocEntryIndex() ;
00182 void freeEntryIndex(u32 index) ;
00183 void initEmpty() ;
00184 void initLists() ;
00185 void initQueue() ;
00186 void tick(u32 when) ;
00187
00188 bool isEmpty(u32 idx) { return oldest[idx]==newest[idx]; }
00189
00190 void addOp(u32 sfbPin, bool on, u32 ms);
00191
00192 u32 next(u32 index) { ++index; if (index >= slots) index = 0; return index; }
00193 bool pop(u32 qled) ;
00194
00195 void makeIdle(u32 qled) ;
00196
00197 static void alarmHandler(u32 when, void * arg) ;
00198
00199 public:
00200 SFBQLED() ;
00201
00207 u32 available() { return freeCount; }
00208
00215 u32 size() { return slots; }
00216
00221 void begin() ;
00222
00237 void begin(u16 * buffer, u32 size) ;
00238
00249 void end() ;
00250
00258 void forget(u32 sfbPin) ;
00259
00272 void whenIdle(u32 sfbPin, u32 mode) ;
00273
00285 u32 time(u32 sfbPin) ;
00286
00304 void on(u32 sfbPin, u32 ms) ;
00305
00316 void off(u32 sfbPin, u32 ms) ;
00317
00331 void set(u32 sfbPin, u32 ms, bool turnOn) ;
00332
00333 #ifdef TEST_SFBQLED
00334 void assertOK() ;
00335 u32 getAlarm() { return alarm; }
00336 void doTick(u32 w) { tick(w); }
00337 #endif
00338
00339 };
00340
00341 extern SFBQLED QLED;
00342
00343 #endif