Parola for Arduino  1.0
Text effects for Parola modular hardware
MD_Parola_HScroll.cpp
1 /*
2 MD_Parola - Library for modular scrolling text and Effects
3 
4 See header file for comments
5 This file contains implements text scrolling
6 
7 Copyright (C) 2013 Marco Colli. All rights reserved.
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <MD_Parola.h>
25 #include <MD_Parola_lib.h>
26 
27 #define START_POSITION (effectSelect == SCROLL_RIGHT) ? _D.getColumnCount()-1 : 0
28 #define SCROLL_DIRECTION (effectSelect == SCROLL_RIGHT) ? MD_MAX72XX::TSR : MD_MAX72XX::TSL
29 
30 void MD_Parola::effectHScroll(textEffect_t effectSelect, bool bIn)
31 {
32  if (bIn)
33  {
34  switch(_fsmState)
35  {
36  case INITIALISE:
37  case GET_FIRST_CHAR: // Load the first character from the font table
38  PRINT_STATE("I HSCROLL");
39 
40  if ((_charCols = getFirstChar()) == 0)
41  {
42  _fsmState = END;
43  break;
44  }
45  _countCols = 0;
46  _fsmState = PUT_CHAR;
47  break;
48 
49  case GET_NEXT_CHAR: // Load the next character from the font table
50  PRINT_STATE("I HSCROLL");
51 
52  // Have we reached the end of the characters string?
53  _charCols = getNextChar();
54  FSMPRINT("\ncharCols ", _charCols);
55  if (_charCols == 0)
56  {
57  _fsmState = PAUSE;
58  break;
59  }
60 
61  _countCols = 0;
62  _fsmState = PUT_CHAR;
63  FSMPRINTS(", fall thru");
64  // !! fall through to next state to start displaying
65 
66  case PUT_CHAR: // display the next part of the character
67  PRINT_STATE("I HSCROLL");
68 
69  _D.transform(SCROLL_DIRECTION);
70  _D.setColumn(START_POSITION, _cBuf[_countCols++]);
71  FSMPRINTS(", scroll");
72 
73  // end of this buffer - we may need to get another one
74  if (_countCols == _charCols)
75  {
76  if (!_endOfText)
77  _fsmState = GET_NEXT_CHAR;
78  else
79  {
80  // work out the number of filler columns
81  _countCols = (effectSelect == SCROLL_RIGHT ? _D.getColumnCount()-_limitLeft-1 : _limitLeft-_textLen);
82  FSMPRINT(", filler count ", _countCols);
83  _fsmState = (_countCols <= 0) ? PAUSE : PUT_FILLER;
84  }
85  }
86  break;
87 
88  case PUT_FILLER: // keep sending out blank columns until aligned
89  PRINT_STATE("I HSCROLL");
90 
91  _D.transform(SCROLL_DIRECTION);
92  FSMPRINTS(", fill");
93 
94  if (--_countCols == 0)
95  _fsmState = PAUSE;
96  break;
97 
98  default:
99  _fsmState = PAUSE;
100  break;
101  }
102  }
103  else // exiting
104  {
105  bool b;
106 
107  switch(_fsmState)
108  {
109  case PAUSE:
110  PRINT_STATE("O HSCROLL");
111  _fsmState = PUT_FILLER;
112  FSMPRINTS(" falling thru");
113  // fall through
114 
115  case PUT_FILLER:
116  PRINT_STATE("O HSCROLL");
117  _D.transform(SCROLL_DIRECTION);
118 
119  b = true;
120  for (uint16_t i=0; (i<_D.getColumnCount()) && b; i++)
121  b &= (_D.getColumn(i) == 0);
122 
123  if (b) _fsmState = END; // no data is being displayed
124  break;
125 
126  default:
127  _fsmState = END;
128  break;
129  }
130  }
131 }