Forked LEDMatrix and added horizontal scrolling

Fork of LEDMatrix by Yihui Xiong

Revision:
2:cd2da920cf98
Parent:
1:79cf2e115449
Child:
3:1e06e89bc0c9
--- a/LEDMatrix.h	Mon Jan 11 21:05:53 2016 +0000
+++ b/LEDMatrix.h	Thu Jan 14 12:57:59 2016 +0000
@@ -24,19 +24,25 @@
 
 #include "mbed.h"
 
-class LEDMatrix {
+const int LED_MATRIX_LEDS_HORIZONTALLY = 32;
+const int LED_MATRIX_LEDS_VERTICALLY = 16;
+const int LED_MATRIX_MAX_LINES = 16;
+
+class LEDMatrix 
+{
 public:
+    
     LEDMatrix(PinName pinA, PinName pinB, PinName pinC, PinName pinD, PinName pinOE, PinName pinR1, PinName pinSTB, PinName pinCLK);
     
     /**
      * set the display's display buffer and number, the buffer's size must be not less than 512 * number / 8 bytes
-     * @param displaybuf    display buffer
+     * @param pDisplayBuf    display buffer
      * @param number        panels' number
      */
-    void begin(uint8_t *displaybuf, uint16_t width, uint16_t height);
+    void begin(uint8_t *pDisplayBuf, uint16_t width, uint16_t height, uint16_t scrollWidth, uint16_t numLines, int charSeparation = 1);
 
     /**
-     * draw a point
+     * draw a point - origin is like a graph with 0,0 at the lower-left corner
      * @param x     x
      * @param y     y
      * @param pixel 0: led off, >0: led on
@@ -44,7 +50,7 @@
     void drawPoint(uint16_t x, uint16_t y, uint8_t pixel);
 
     /**
-     * draw a rect
+     * draw a rect - origin is like a graph with 0,0 at the lower-left corner
      * @param (x1, y1)   top-left position
      * @param (x2, y2)   bottom-right position, not included in the rect
      * @param pixel      0: rect off, >0: rect on
@@ -60,35 +66,49 @@
     void drawImage(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t *image);
 
     /**
-     * Set screen buffer to zero
-     */
-    void clear();
-
-    /**
      * turn off 1/16 leds and turn on another 1/16 leds
      */
     void scan();
 
-    void reverse();
+    void invertColour();
 
-    uint8_t isReversed();
+    uint8_t isInvertedColour();
 
     void on();
 
     void off();
     
-    void scrollLeft();
-    void scrollReset();
-    void scrollToPos(int pos);
+    // Passing lineIdx == -1 to the following functions resets all lines
+    // Lines are numbered starting at 0
+    void clear(int lineIdx = -1);
+    void scroll(int lineIdx, bool scrollLeft);
+    void scrollReset(int lineIdx = -1);
+    void scrollToPos(int lineIdx, int pos);
+    void setupScroll(int lineIdx, int scrollWidth, int scrollInc);
 
+    uint8_t reverseBits(uint8_t b);
+    int displayChar(int xPos, int yPos, char ch);
+    int displayLargeDigit(int curX, int curY, char ch);
+    int displayLine(int lineIdx, const char* line);
+
+    // Called frequently and regularly to handle effects like scrolling
+    void serviceEffects();
+    
 private:
+    bool getRowsToWorkOn(int lineIdx, int &startRow, int &numRows);
     DigitalOut a, b, c, d, oe, r1, stb, clk;
-    uint8_t *displaybuf;
+    uint8_t *_pDisplayBuf;
     uint16_t width;
     uint16_t height;
+    uint16_t dispBufWidth;
+    uint16_t numLines;
     uint8_t  mask;
-    uint8_t  state;
-    int _horizontalScrollPos;
+    bool _isEnabled;
+    int _hScrollPos[LED_MATRIX_LEDS_VERTICALLY];
+    int _hScrollWidth[LED_MATRIX_LEDS_VERTICALLY];
+    bool _isBusy;
+    int _charSeparation;
+    int _lineScrollInc[LED_MATRIX_MAX_LINES];
 };
 
 #endif