Benny Andersen / microbitOLED

Dependencies:   microbit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Display.h Source File

Display.h

00001 #include "MicroBit.h"
00002 #include "MicroBitDisplay.h"
00003 
00004 #ifndef microbitOLED_Display
00005 #define microbitOLED_Display
00006 
00007 /**
00008   * Constructs display by parameters to the '5 rows'.
00009   * Takes five 5bit values in range [0,31] and a bool \n 
00010   * value for 'showing left bit column' 
00011   */
00012 struct Ledrows {
00013     union {
00014     struct {
00015     int r0:5;
00016     int r1:5;
00017     int r2:5;
00018     int r3:5;
00019     int r4:5; };
00020     int all; };
00021     Ledrows(uint8_t lr0,uint8_t lr1,uint8_t lr2,uint8_t lr3,uint8_t lr4, bool b15On) 
00022     : r0(lr0),r1(lr1),r2(lr2),r3(lr3),r4(lr4) {
00023         if (b15On) all |= 0x01084210; }
00024     
00025 };
00026 
00027 
00028 /**
00029   * Use Microbit 5x5 led display in various output communications.
00030   * It deals with display in DISPLAY_MODE_BLACK_AND_WHITE mode 
00031   */
00032 class Display { 
00033 
00034     /**
00035       * Representation the 25 leds.
00036       * The physical leds are counted from right bottom and continuing \n 
00037       * from right on each row above. Light in a led corresponds to 1 stick.\n 
00038       * Writting to the display is writting to this buffer AND the display  \n 
00039       * only if a value is changed - this demands clearing the display is \n 
00040       * nullifying this stick prior uDisplay.image.clear();
00041       */
00042     bool stick[25];
00043     MicroBitDisplay & uDisplay;
00044     union { // context dependt trueshowing aliases
00045     uint8_t curLength;
00046     uint8_t rowNr; };
00047     uint32_t showbit;
00048     
00049 public:
00050 
00051     /**
00052       * Display hold a refference to a MicroBitDisplay object. 
00053       * When constructed from MicroBit's  MicroBitDisplay of a not yet initialized \n 
00054       * MicroBit object - that must be done before using the Display instance.\n 
00055       *
00056       * @param uDpl reference to a MicroBitDisplay object.
00057       */
00058     Display(MicroBitDisplay & uDpl);
00059     
00060     /**
00061       * Clears the display and its buffer 
00062       */
00063     void clear();
00064     
00065     /**
00066       * The stick's length is represented by the count of digits being 1.
00067       *
00068       * @param size in range [0,24]
00069       */
00070     void setStick(uint8_t size);
00071     
00072     /**
00073       * Set a single dot.
00074       *
00075       * @param position in [0,24] for showing that single dot.
00076       */
00077     void setFlag(uint8_t position);
00078     
00079     /**
00080       * Puts a bitpattern in a row.
00081       *
00082       * @param rowNr in [0,4] for selected row
00083       * @param rowContent in [0,31] to be shown binary
00084       */
00085     void toRow(uint8_t rowNr, uint8_t rowContent);
00086     
00087     /**
00088       * 25 bits showed in the display as a whole.
00089       *
00090       * @param bits25 contains the 25 bit to be showed
00091       */
00092     void toRows(uint32_t allBits);
00093 
00094     /**
00095       * Vertdecimal shows a single number in [00000,99999].
00096       * The parameters goes from top to bottom, whereas a obvious \n  
00097       * perception is reading the disply number from top bottom. \n   
00098       * Nothing restrict the rows to hold values less teen \n 
00099       * but if some are greather than 31 the value or proberbly \n
00100       * bitwise ored og cleared by other numbers
00101       *
00102       * @param r0 bottom row - row 0 
00103       * @param r1 row 1
00104       * @param r2 row 2
00105       * @param r3 row 3 
00106       * @param r4 top row - row 4
00107       */
00108     void vertDecimal(uint8_t r0,uint8_t r1,uint8_t r2,uint8_t r3,uint8_t r4); 
00109   
00110     /**
00111       * Vertdecimal shows a single number in [00000,99999].
00112       * The parameters goes from top to bottom, whereas a obvious \n  
00113       * perception is reading the disply number from top bottom. \n   
00114       * It os possible to turn on left column on the display
00115       * 
00116       * @param r0 bottom row - row 0 
00117       * @param r1 row 1
00118       * @param r2 row 2
00119       * @param r3 row 3 
00120       * @param r4 top row - row 4
00121       * @param leftDotOn turns left dot on. leftdot is not used to represent a digit in base 10 numbers.
00122       */
00123     void vertDecimal(uint8_t r0,uint8_t r1,uint8_t r2,uint8_t r3,uint8_t r4, bool leftDotOn);
00124 
00125     /**
00126     * Binary Clock with hours and minuts.
00127     * hours in top rows (4 for multiplum of 10, 3 for remainer) \n 
00128     * minuts in bottom rows (1 for multiplum of 10, 0 for remainer)
00129     *
00130     * @param minuts of the day
00131     */
00132     void vertClock(uint16_t minuts); 
00133     
00134     /**
00135     * Binary Clock with hours, minuts an seconds.
00136     * hours in row 4 (top row)\n 
00137     * minuts in rows 3 and 2  (3 for multiplum of 10, 2 for remainer)\n 
00138     * seconds in rows 1 and 0 (1 for multiplum of 10, 0 for remainer)\n 
00139     *
00140     * @param second of the day
00141     */
00142     void vertSecClock(uint32_t minuts); 
00143     
00144 private:
00145     void paintStick(bool(Display::*getState)(uint8_t));
00146     void clearStick();
00147     bool bitplot(uint8_t num);
00148     bool simplePlot(uint8_t num);
00149     bool lessCurLength(uint8_t num);
00150     bool orPoint(uint8_t num);
00151 };    
00152 
00153 
00154 #endif