Parola for Arduino  1.0
Text effects for Parola modular hardware
MD_Parola_Slice.cpp
1 /*
2 MD_Parola - Library for modular scrolling text and Effects
3 
4 See header file for comments
5 This file contains implements slice text display
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 void MD_Parola::effectSlice(bool bIn)
28 {
29  static int16_t nextColumn, animColumn;
30 
31  if (bIn)
32  {
33  switch(_fsmState)
34  {
35  case INITIALISE:
36  case GET_FIRST_CHAR:
37  PRINT_STATE("I SLICE");
38 
39  if ((_charCols = getFirstChar()) == 0)
40  {
41  _fsmState = END;
42  break;
43  }
44  displayClear();
45  _countCols = 0;
46  animColumn = 0;
47  nextColumn = _limitLeft;
48 
49  _fsmState = PUT_CHAR;
50  break;
51 
52  case GET_NEXT_CHAR: // Load the next character from the font table
53  PRINT_STATE("I SLICE");
54  // have we reached the end of the characters string?
55  if ((_charCols = getNextChar()) == 0)
56  {
57  _fsmState = PAUSE;
58  break;
59  }
60  _countCols = 0;
61  _fsmState = PUT_CHAR;
62  // !! fall through to next state to start displaying
63 
64  case PUT_CHAR: // display the next part of the character
65  PRINT_STATE("I SLICE");
66  FSMPRINT(" - Next ", nextColumn);
67  FSMPRINT(", anim ", animColumn);
68 
69  if (_cBuf[_countCols] == 0)
70  {
71  animColumn = nextColumn; // pretend we just animated it!
72  }
73  else
74  {
75  // clear the column and animate the next one
76  if (animColumn != nextColumn) _D.setColumn(animColumn, 0);
77  animColumn++;
78  _D.setColumn(animColumn, _cBuf[_countCols]);
79  }
80 
81  // set up for the next time
82  if (animColumn == nextColumn)
83  {
84  animColumn = 0;
85  _countCols++;
86  nextColumn--;
87  }
88  if (_countCols == _charCols) _fsmState = GET_NEXT_CHAR;
89  break;
90 
91  default:
92  _fsmState = PAUSE;
93  }
94  }
95  else // exiting
96  {
97  switch(_fsmState)
98  {
99  case PAUSE:
100  PRINT_STATE("O SLICE");
101  animColumn = nextColumn = _limitLeft;
102  _fsmState = PUT_CHAR;
103  // fall through
104 
105  case GET_FIRST_CHAR:
106  case GET_NEXT_CHAR:
107  case PUT_CHAR:
108  PRINT_STATE("O SLICE");
109  FSMPRINT(" - Next ", nextColumn);
110  FSMPRINT(", anim ", animColumn);
111 
112  if (_D.getColumn(animColumn) == 0)
113  {
114  animColumn = _D.getColumnCount(); // pretend we just animated it!
115  }
116  else
117  {
118  // Move the column over
119  _D.setColumn(animColumn+1, _D.getColumn(animColumn));
120  _D.setColumn(animColumn, 0);
121  animColumn++;
122  }
123 
124  // set up for the next time
125  if (animColumn == _D.getColumnCount()) animColumn = nextColumn--;
126 
127  if (nextColumn < _limitRight) _fsmState = END; //reached the end
128  break;
129 
130  default:
131  _fsmState = END;
132  }
133  }
134 }