SFBQLED.h

Go to the documentation of this file.
00001 /*                                             -*- mode:C++; fill-column:100 -*-
00002   SFBQLED.h - Queuing system to blink the built-in LEDs without blocking
00003   Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00018   USA
00019 
00020   $Id$
00021 */
00022 
00030 #ifndef SFBQLED_H
00031 #define SFBQLED_H
00032 
00033 #include "SFBTypes.h"     /* For u8 */
00034 #include "SFBConstants.h" /* For FACE_COUNT */
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,       // Min granularity is 16ms, max single event len=2032ms
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;                // If bit clear, return qled to reflex when idle
00171   u16 idleOn;                  // if idleOurs, ledSet(idleOn) when idle
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 /* SFBQLED_H */

Generated on Fri Apr 22 06:54:12 2011 for SFB by doxygen 1.5.9