Forked LEDMatrix and added horizontal scrolling

Fork of LEDMatrix by Yihui Xiong

Files at this revision

API Documentation at this revision

Comitter:
Bobty
Date:
Fri Jan 15 09:50:10 2016 +0000
Parent:
3:1e06e89bc0c9
Child:
5:334fc002e200
Commit message:
Added control of scrolling and flashing rates

Changed in this revision

LEDMatrix.cpp Show annotated file Show diff for this revision Revisions of this file
LEDMatrix.h Show annotated file Show diff for this revision Revisions of this file
--- a/LEDMatrix.cpp	Thu Jan 14 16:52:04 2016 +0000
+++ b/LEDMatrix.cpp	Fri Jan 15 09:50:10 2016 +0000
@@ -59,12 +59,14 @@
     _isBusy = false;
     _charSeparation = 1;
     _flashCounter = 0;
-    _flashRate = 8;
+    _flashRate = 50;
     _flashState = false;
+    _scrollCounter = 0;
+    _scrollRate = 7;
 }
 
 void LEDMatrix::begin(uint8_t *_pDisplayBuf, uint16_t width, uint16_t height, uint16_t dispBufWidth, 
-                uint16_t numLines, int charSeparation, int flashRate)
+                uint16_t numLines, int charSeparation, int flashRate, int scrollRate)
 {
     ASSERT(0 == (width % LED_MATRIX_LEDS_HORIZONTALLY));
     ASSERT(0 == (scroll_width % LED_MATRIX_LEDS_HORIZONTALLY));
@@ -76,7 +78,10 @@
     this->dispBufWidth = dispBufWidth;
     this->numLines = numLines;
     this->_charSeparation = charSeparation;
-    this->_flashRate = flashRate;
+    if (flashRate > 0)
+        this->_flashRate = flashRate;
+    if (scrollRate > 0)
+        this->_scrollRate = scrollRate;
     if (numLines > LED_MATRIX_MAX_LINES)
         this->numLines = LED_MATRIX_MAX_LINES;
     for (int i = 0; i < LED_MATRIX_LEDS_VERTICALLY; i++)
@@ -323,6 +328,16 @@
         *ptr++ = 0x00;
 }
 
+void LEDMatrix::setScrollRate(int rate)
+{
+    _scrollRate = rate;
+}
+
+void LEDMatrix::setFlashRate(int rate)
+{
+    _flashRate = rate;
+}
+
 void LEDMatrix::setupScroll(int lineIdx, int scrollWidth, int scrollInc)
 {
     // Interpret param
@@ -370,13 +385,17 @@
     
 void LEDMatrix::serviceEffects()
 {
-    // Scroll / flash logic
-    int rowsInLine = (height / numLines);
-    for (int i = 0; i < numLines; i++)
+    // Scroll logic
+    _scrollCounter++;
+    if (_scrollCounter >= _scrollRate)
     {
-        for (int j = 0; j < rowsInLine; j++)
-            _hScrollPos[i*rowsInLine+j] += _lineScrollInc[i];
-        _lineInvert[i] = _lineAlert[i] ? _flashState : false;
+        _scrollCounter = 0;
+        int rowsInLine = (height / numLines);
+        for (int i = 0; i < numLines; i++)
+        {
+            for (int j = 0; j < rowsInLine; j++)
+                _hScrollPos[i*rowsInLine+j] += _lineScrollInc[i];
+        }
     }
     
     // Update flash state
@@ -385,6 +404,10 @@
     {
         _flashCounter = 0;
         _flashState = !_flashState;
+        for (int i = 0; i < numLines; i++)
+        {
+            _lineInvert[i] = _lineAlert[i] ? _flashState : false;
+        }
     }
 }
     
--- a/LEDMatrix.h	Thu Jan 14 16:52:04 2016 +0000
+++ b/LEDMatrix.h	Fri Jan 15 09:50:10 2016 +0000
@@ -40,7 +40,7 @@
      * @param number        panels' number
      */
     void begin(uint8_t *pDisplayBuf, uint16_t width, uint16_t height, uint16_t scrollWidth, 
-        uint16_t numLines, int charSeparation = 1, int flashRate = 8);
+        uint16_t numLines, int charSeparation = 1, int flashRate = -1, int scrollRate = -1);
 
     /**
      * draw a point - origin is like a graph with 0,0 at the lower-left corner
@@ -92,6 +92,8 @@
     int displayLargeDigit(int curX, int curY, char ch);
     int displayLine(int lineIdx, const char* line);
     
+    void setScrollRate(int rate);
+    void setFlashRate(int rate);
     void setAlert(int lineIdx, bool alertOn);
 
     // Called frequently and regularly to handle effects like scrolling
@@ -117,6 +119,8 @@
     int _flashCounter;
     int _flashRate;
     bool _flashState;
+    int _scrollCounter;
+    int _scrollRate;
 };
 
 #endif