feat: 全量同步 254 个常用的 Arduino 扩展库文件
This commit is contained in:
602
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_PZone.cpp
Normal file
602
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_PZone.cpp
Normal file
@@ -0,0 +1,602 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
#include <MD_MAX72xx.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements MD_PZone class methods
|
||||
*/
|
||||
|
||||
MD_PZone::MD_PZone(void) : _fsmState(END), _scrollDistance(0), _zoneEffect(0), _charSpacing(1),
|
||||
_fontDef(nullptr), _userChars(nullptr), _cBufSize(0), _cBuf(nullptr)
|
||||
#if ENA_SPRITE
|
||||
, _spriteInData(nullptr), _spriteOutData(nullptr)
|
||||
#endif
|
||||
{
|
||||
};
|
||||
|
||||
MD_PZone::~MD_PZone(void)
|
||||
{
|
||||
// release the memory for user defined characters
|
||||
charDef_t *p = _userChars;
|
||||
|
||||
while (p!= nullptr)
|
||||
{
|
||||
charDef_t *pt = p;
|
||||
p = pt->next;
|
||||
delete pt;
|
||||
};
|
||||
|
||||
// release memory for the character buffer
|
||||
delete[] _cBuf;
|
||||
}
|
||||
|
||||
void MD_PZone::begin(MD_MAX72XX *p)
|
||||
{
|
||||
_MX = p;
|
||||
allocateFontBuffer();
|
||||
}
|
||||
|
||||
void MD_PZone::allocateFontBuffer(void)
|
||||
{
|
||||
uint8_t size = _MX->getMaxFontWidth() + getCharSpacing();
|
||||
PRINTS("\nallocateFontBuffer");
|
||||
if (size > _cBufSize)
|
||||
{
|
||||
delete[] _cBuf;
|
||||
_cBufSize = size;
|
||||
PRINT(" new size ", _cBufSize);
|
||||
_cBuf = new uint8_t[_cBufSize];
|
||||
}
|
||||
}
|
||||
|
||||
void MD_PZone::setZoneEffect(boolean b, zoneEffect_t ze)
|
||||
{
|
||||
switch (ze)
|
||||
{
|
||||
case PA_FLIP_LR: _zoneEffect = (b ? ZE_SET(_zoneEffect, ZE_FLIP_LR_MASK) : ZE_RESET(_zoneEffect, ZE_FLIP_LR_MASK)); break;
|
||||
case PA_FLIP_UD: _zoneEffect = (b ? ZE_SET(_zoneEffect, ZE_FLIP_UD_MASK) : ZE_RESET(_zoneEffect, ZE_FLIP_UD_MASK)); break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
boolean MD_PZone::getZoneEffect(zoneEffect_t ze)
|
||||
{
|
||||
switch (ze)
|
||||
{
|
||||
case PA_FLIP_LR: return(ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK)); break;
|
||||
case PA_FLIP_UD: return(ZE_TEST(_zoneEffect, ZE_FLIP_UD_MASK)); break;
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
#if ENA_SPRITE
|
||||
void MD_PZone::setSpriteData(uint8_t *inData, uint8_t inWidth, uint8_t inFrames, uint8_t* outData, uint8_t outWidth, uint8_t outFrames)
|
||||
{
|
||||
_spriteInData = inData;
|
||||
_spriteInWidth = inWidth;
|
||||
_spriteInFrames = inFrames;
|
||||
_spriteOutData = outData;
|
||||
_spriteOutWidth = outWidth;
|
||||
_spriteOutFrames = outFrames;
|
||||
}
|
||||
#endif
|
||||
|
||||
void MD_PZone::setInitialConditions(void)
|
||||
// set the global variables initial conditions for all display effects
|
||||
{
|
||||
PRINTS("\nsetInitialConditions");
|
||||
|
||||
if (_pText == nullptr)
|
||||
return;
|
||||
|
||||
_pCurChar = _pText;
|
||||
_limitOverflow = !calcTextLimits(_pText);
|
||||
}
|
||||
|
||||
void MD_PZone::setInitialEffectConditions(void)
|
||||
// set the initial conditions for loops in the FSM
|
||||
{
|
||||
PRINTS("\nsetInitialFSMConditions");
|
||||
|
||||
_startPos = _nextPos = (_textAlignment == PA_RIGHT ? _limitRight : _limitLeft);
|
||||
_endPos = (_textAlignment == PA_RIGHT ? _limitLeft : _limitRight);
|
||||
_posOffset = (_textAlignment == PA_RIGHT ? 1 : -1);
|
||||
}
|
||||
|
||||
uint16_t MD_PZone::getTextWidth(char *p)
|
||||
// Get the width in columns for the text string passed to the function
|
||||
// This is the sum of all the characters and the space between them.
|
||||
{
|
||||
uint16_t sum = 0;
|
||||
|
||||
PRINT("\ngetTextWidth: ", p);
|
||||
|
||||
while (*p != '\0')
|
||||
{
|
||||
sum += findChar(*p++, _cBufSize, _cBuf);
|
||||
if (*p) sum += _charSpacing; // next character is not nul, so add inter-character spacing
|
||||
}
|
||||
|
||||
PRINT("\ngetTextWidth: W=", sum);
|
||||
|
||||
return(sum);
|
||||
}
|
||||
|
||||
bool MD_PZone::calcTextLimits(char *p)
|
||||
// Work out left and right sides for the text to be displayed,
|
||||
// depending on the text alignment. If the message will not fit
|
||||
// in the current display the return false, otherwise true.
|
||||
{
|
||||
bool b = true;
|
||||
uint16_t displayWidth = ZONE_END_COL(_zoneEnd) - ZONE_START_COL(_zoneStart) + 1;
|
||||
|
||||
_textLen = getTextWidth(p);
|
||||
|
||||
PRINT("\ncalcTextLimits: disp=", displayWidth);
|
||||
PRINT(" text=", _textLen);
|
||||
|
||||
switch (_textAlignment)
|
||||
{
|
||||
case PA_LEFT:
|
||||
_limitLeft = ZONE_END_COL(_zoneEnd);
|
||||
if (_textLen > displayWidth)
|
||||
{
|
||||
_limitRight = ZONE_START_COL(_zoneStart);
|
||||
b = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_limitRight = _limitLeft - _textLen + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PA_RIGHT:
|
||||
_limitRight = ZONE_START_COL(_zoneStart);
|
||||
if (_textLen > displayWidth)
|
||||
{
|
||||
_limitLeft = ZONE_END_COL(_zoneEnd);
|
||||
b = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_limitLeft = _limitRight + _textLen - 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case PA_CENTER:
|
||||
if (_textLen > displayWidth)
|
||||
{
|
||||
_limitLeft = ZONE_END_COL(_zoneEnd);
|
||||
_limitRight = ZONE_START_COL(_zoneStart);
|
||||
b= false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_limitRight = ZONE_START_COL(_zoneStart) + ((displayWidth - _textLen)/2);
|
||||
_limitLeft = _limitRight + _textLen - 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
PRINT(" -> L:", _limitLeft);
|
||||
PRINT(" R:", _limitRight);
|
||||
PRINT(" Oveflow:", !b);
|
||||
|
||||
return (b);
|
||||
}
|
||||
|
||||
bool MD_PZone::addChar(uint8_t code, uint8_t *data)
|
||||
// Add a user defined character to the replacement list
|
||||
{
|
||||
charDef_t *pcd;
|
||||
|
||||
if (code == 0)
|
||||
return(false);
|
||||
|
||||
PRINTX("\naddChar 0x", code);
|
||||
|
||||
// first see if we have the code in our list
|
||||
pcd = _userChars;
|
||||
while (pcd != nullptr)
|
||||
{
|
||||
if (pcd->code == code)
|
||||
{
|
||||
pcd->data = data;
|
||||
PRINTS(" found existing in list");
|
||||
return(true);
|
||||
}
|
||||
pcd = pcd->next;
|
||||
}
|
||||
|
||||
// Now see if we have an empty slot in our list
|
||||
pcd = _userChars;
|
||||
while (pcd != nullptr)
|
||||
{
|
||||
if (pcd->code == 0)
|
||||
{
|
||||
pcd->code = code;
|
||||
pcd->data = data;
|
||||
PRINTS(" found empty slot");
|
||||
return(true);
|
||||
}
|
||||
pcd = pcd->next;
|
||||
}
|
||||
|
||||
// default is to add a new node to the front of the list
|
||||
if ((pcd = new charDef_t) != nullptr)
|
||||
{
|
||||
pcd->code = code;
|
||||
pcd->data = data;
|
||||
pcd->next = _userChars;
|
||||
_userChars = pcd;
|
||||
PRINTS(" added new node");
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTS(" failed allocating new node");
|
||||
}
|
||||
|
||||
return(pcd != nullptr);
|
||||
}
|
||||
|
||||
bool MD_PZone::delChar(uint8_t code)
|
||||
// Delete a user defined character from the replacement list
|
||||
{
|
||||
charDef_t *pcd = _userChars;
|
||||
|
||||
if (code == 0)
|
||||
return(false);
|
||||
|
||||
// Scan down the linked list
|
||||
while (pcd != nullptr)
|
||||
{
|
||||
if (pcd->code == code)
|
||||
{
|
||||
pcd->code = 0;
|
||||
pcd->data = nullptr;
|
||||
break;
|
||||
}
|
||||
pcd = pcd->next;
|
||||
}
|
||||
|
||||
return(pcd != nullptr);
|
||||
}
|
||||
|
||||
uint8_t MD_PZone::findChar(uint8_t code, uint8_t size, uint8_t *cBuf)
|
||||
// Find a character either in user defined list or from font table
|
||||
{
|
||||
charDef_t *pcd = _userChars;
|
||||
uint8_t len;
|
||||
|
||||
PRINTX("\nfindUserChar 0x", code);
|
||||
// check local list first
|
||||
while (pcd != nullptr)
|
||||
{
|
||||
PRINTX(" ", pcd->code);
|
||||
if (pcd->code == code) // found it
|
||||
{
|
||||
PRINTS(" found character");
|
||||
len = min(size, pcd->data[0]);
|
||||
memcpy(cBuf, &pcd->data[1], len);
|
||||
return(len);
|
||||
}
|
||||
pcd = pcd->next;
|
||||
}
|
||||
|
||||
// get it from the standard font
|
||||
PRINTS(" no user char");
|
||||
_MX->setFont(_fontDef); // change to the font for this zone
|
||||
len = _MX->getChar(code, size, cBuf);
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
uint8_t MD_PZone::makeChar(char c, bool addBlank)
|
||||
// Load a character bitmap and add in trailing char spacing blanks
|
||||
{
|
||||
uint8_t len;
|
||||
|
||||
|
||||
// look for the character
|
||||
len = findChar((uint8_t)c, _cBufSize, _cBuf);
|
||||
|
||||
PRINTX("\nmakeChar 0x", c);
|
||||
PRINT(", len=", len);
|
||||
|
||||
// Add in the inter char spacing
|
||||
if (addBlank)
|
||||
{
|
||||
for (uint8_t i = 0; i < _charSpacing; i++)
|
||||
{
|
||||
if (len < _cBufSize)
|
||||
_cBuf[len++] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
void MD_PZone::reverseBuf(uint8_t *p, uint8_t size)
|
||||
// reverse the elements of the specified buffer
|
||||
// useful when we are scrolling right and want to insert the columns in reverse order
|
||||
{
|
||||
for (uint8_t i=0; i<size/2; i++)
|
||||
{
|
||||
uint8_t t;
|
||||
|
||||
t = p[i];
|
||||
p[i] = p[size-1-i];
|
||||
p[size-1-i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void MD_PZone::invertBuf(uint8_t *p, uint8_t size)
|
||||
// invert the elements of the specified buffer
|
||||
// used when the character needs to be inverted when ZE_FLIP_UD
|
||||
{
|
||||
for (uint8_t i=0; i<size; i++)
|
||||
{
|
||||
uint8_t v = p[i];
|
||||
|
||||
v = ((v >> 1) & 0x55) | ((v & 0x55) << 1); // swap odd and even bits
|
||||
v = ((v >> 2) & 0x33) | ((v & 0x33) << 2); // swap consecutive pairs
|
||||
v = ((v >> 4) & 0x0F) | ((v & 0x0F) << 4); // swap nibbles ...
|
||||
|
||||
p[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
void MD_PZone::moveTextPointer(void)
|
||||
// This method works when increment is done AFTER processing the character
|
||||
// The _endOfText flag is set as a look ahead (ie, when the last character
|
||||
// is still valid)
|
||||
// We need to move a pointer forward or back, depending on the way we are
|
||||
// travelling through the text buffer.
|
||||
{
|
||||
PRINTS("\nMovePtr");
|
||||
|
||||
if ((!ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && SFX(PA_SCROLL_RIGHT)) ||
|
||||
(ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && !SFX(PA_SCROLL_RIGHT)))
|
||||
{
|
||||
PRINTS(" --");
|
||||
_endOfText = (_pCurChar == _pText);
|
||||
_pCurChar--;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTS(" ++");
|
||||
_pCurChar++;
|
||||
_endOfText = (*_pCurChar == '\0');
|
||||
}
|
||||
|
||||
PRINT(": endOfText ", _endOfText);
|
||||
}
|
||||
|
||||
uint8_t MD_PZone::getFirstChar(void)
|
||||
// load the first char into the char buffer
|
||||
// return 0 if there are no characters
|
||||
{
|
||||
uint8_t len = 0;
|
||||
|
||||
PRINT("\ngetFirst SFX(RIGHT):", SFX(PA_SCROLL_RIGHT));
|
||||
PRINT(" ZETEST(UD):", ZE_TEST(_zoneEffect, ZE_FLIP_UD_MASK));
|
||||
PRINT(" ZETEST(LR):", ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK));
|
||||
|
||||
// initialise pointers and make sure we have a good string to process
|
||||
_pCurChar = _pText;
|
||||
if ((_pCurChar == nullptr) || (*_pCurChar == '\0'))
|
||||
{
|
||||
_endOfText = true;
|
||||
return(0);
|
||||
}
|
||||
_endOfText = false;
|
||||
if ((!ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && (SFX(PA_SCROLL_RIGHT))) ||
|
||||
(ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && !SFX(PA_SCROLL_RIGHT)))
|
||||
{
|
||||
PRINTS("\nReversed String");
|
||||
_pCurChar += strlen(_pText) - 1;
|
||||
}
|
||||
|
||||
// good string, get the first char into the current buffer
|
||||
len = makeChar(*_pCurChar, *(_pCurChar+1) != '\0');
|
||||
|
||||
if ((!ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && (SFX(PA_SCROLL_RIGHT))) ||
|
||||
(ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && !SFX(PA_SCROLL_RIGHT)))
|
||||
{
|
||||
PRINTS("\nReverse Buffer");
|
||||
reverseBuf(_cBuf, len);
|
||||
}
|
||||
|
||||
if ZE_TEST(_zoneEffect, ZE_FLIP_UD_MASK)
|
||||
{
|
||||
PRINTS("\nInvert buffer");
|
||||
invertBuf(_cBuf, len);
|
||||
}
|
||||
|
||||
moveTextPointer();
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
uint8_t MD_PZone::getNextChar(void)
|
||||
// load the next char into the char buffer
|
||||
// return 0 if there are no characters
|
||||
{
|
||||
uint8_t len = 0;
|
||||
|
||||
PRINT("\ngetNexChar SFX(RIGHT):", SFX(PA_SCROLL_RIGHT));
|
||||
PRINT(" ZETEST(UD):", ZE_TEST(_zoneEffect, ZE_FLIP_UD_MASK));
|
||||
PRINT(" ZETEST(LR):", ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK));
|
||||
|
||||
if (_endOfText)
|
||||
return(0);
|
||||
|
||||
len = makeChar(*_pCurChar, *(_pCurChar + 1) != '\0');
|
||||
|
||||
if ((!ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && (SFX(PA_SCROLL_RIGHT))) ||
|
||||
(ZE_TEST(_zoneEffect, ZE_FLIP_LR_MASK) && !SFX(PA_SCROLL_RIGHT)))
|
||||
{
|
||||
PRINTS("\nReversed Buffer");
|
||||
reverseBuf(_cBuf, len);
|
||||
}
|
||||
|
||||
if ZE_TEST(_zoneEffect, ZE_FLIP_UD_MASK)
|
||||
{
|
||||
PRINTS("\nInvert Buffer");
|
||||
invertBuf(_cBuf, len);
|
||||
}
|
||||
|
||||
moveTextPointer();
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
bool MD_PZone::zoneAnimate(void)
|
||||
{
|
||||
#if TIME_PROFILING
|
||||
static uint32_t cycleStartTime;
|
||||
#endif
|
||||
|
||||
_animationAdvanced = false; // assume this will not happen this time around
|
||||
|
||||
if (_fsmState == END)
|
||||
return(true);
|
||||
|
||||
// work through things that stop us running this at all
|
||||
if (((_fsmState == PAUSE) && (millis() - _lastRunTime < _pauseTime)) ||
|
||||
(millis() - _lastRunTime < _tickTime) ||
|
||||
(_suspend))
|
||||
return(false);
|
||||
|
||||
// save the time now, before we run the animation, so that the animation is part of the
|
||||
// delay between animations giving more accurate frame timing.
|
||||
_lastRunTime = millis();
|
||||
_animationAdvanced = true; // we now know it will happen!
|
||||
|
||||
// any text to display?
|
||||
if (_pText != nullptr)
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case END: // do nothing in this state
|
||||
PRINT_STATE("ANIMATE");
|
||||
break;
|
||||
|
||||
case INITIALISE:
|
||||
PRINT_STATE("ANIMATE");
|
||||
#if TIME_PROFILING
|
||||
cycleStartTime = millis();
|
||||
#endif
|
||||
setInitialConditions();
|
||||
_moveIn = true;
|
||||
// fall through to process the effect, first call will be with INITIALISE
|
||||
|
||||
default: // All state except END are handled by the special effect functions
|
||||
PRINT_STATE("ANIMATE");
|
||||
switch (_moveIn ? _effectIn : _effectOut)
|
||||
{
|
||||
case PA_PRINT: effectPrint(_moveIn); break;
|
||||
case PA_SCROLL_UP: effectVScroll(true, _moveIn); break;
|
||||
case PA_SCROLL_DOWN: effectVScroll(false, _moveIn); break;
|
||||
case PA_SCROLL_LEFT: effectHScroll(true, _moveIn); break;
|
||||
case PA_SCROLL_RIGHT: effectHScroll(false, _moveIn); break;
|
||||
#if ENA_MISC
|
||||
case PA_SLICE: effectSlice(_moveIn); break;
|
||||
case PA_MESH: effectMesh(_moveIn); break;
|
||||
case PA_FADE: effectFade(_moveIn); break;
|
||||
case PA_BLINDS: effectBlinds(_moveIn); break;
|
||||
case PA_DISSOLVE: effectDissolve(_moveIn); break;
|
||||
case PA_RANDOM: effectRandom(_moveIn); break;
|
||||
#endif // ENA_MISC
|
||||
#if ENA_SPRITE
|
||||
case PA_SPRITE:
|
||||
effectSprite(_moveIn, _moveIn ? _effectIn : _effectOut); break;
|
||||
#endif // ENA_SPRITE
|
||||
#if ENA_WIPE
|
||||
case PA_WIPE: effectWipe(false, _moveIn); break;
|
||||
case PA_WIPE_CURSOR: effectWipe(true, _moveIn); break;
|
||||
#endif // ENA_WIPE
|
||||
#if ENA_SCAN
|
||||
case PA_SCAN_HORIZX: effectHScan(_moveIn, true); break;
|
||||
case PA_SCAN_HORIZ: effectHScan(_moveIn, false); break;
|
||||
case PA_SCAN_VERTX: effectVScan(_moveIn, true); break;
|
||||
case PA_SCAN_VERT: effectVScan(_moveIn, false); break;
|
||||
#endif // ENA_SCAN
|
||||
#if ENA_OPNCLS
|
||||
case PA_OPENING: effectOpen(false, _moveIn); break;
|
||||
case PA_OPENING_CURSOR: effectOpen(true, _moveIn); break;
|
||||
case PA_CLOSING: effectClose(false, _moveIn);break;
|
||||
case PA_CLOSING_CURSOR: effectClose(true, _moveIn); break;
|
||||
#endif // ENA_OPNCLS
|
||||
#if ENA_SCR_DIA
|
||||
case PA_SCROLL_UP_LEFT: effectDiag(true, true, _moveIn); break;
|
||||
case PA_SCROLL_UP_RIGHT: effectDiag(true, false, _moveIn); break;
|
||||
case PA_SCROLL_DOWN_LEFT: effectDiag(false, true, _moveIn); break;
|
||||
case PA_SCROLL_DOWN_RIGHT: effectDiag(false, false, _moveIn);break;
|
||||
#endif // ENA_SCR_DIA
|
||||
#if ENA_GROW
|
||||
case PA_GROW_UP: effectGrow(true, _moveIn); break;
|
||||
case PA_GROW_DOWN: effectGrow(false, _moveIn); break;
|
||||
#endif // ENA_GROW
|
||||
default:
|
||||
_fsmState = END;
|
||||
}
|
||||
|
||||
// one way toggle for input to output, reset on initialize
|
||||
_moveIn = _moveIn && !(_fsmState == PAUSE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if TIME_PROFILING
|
||||
Serial.print("\nAnim time: ");
|
||||
Serial.print(millis()-_lastRunTime);
|
||||
if (_fsmState == END)
|
||||
{
|
||||
Serial.print("\nCycle time: ");
|
||||
Serial.print(millis()-cycleStartTime);
|
||||
}
|
||||
#endif
|
||||
|
||||
return(_fsmState == END);
|
||||
}
|
||||
|
||||
#if DEBUG_PAROLA_FSM
|
||||
char *MD_PZone::state2string(fsmState_t s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case INITIALISE: return("INIT");
|
||||
case GET_FIRST_CHAR: return("FIRST");
|
||||
case GET_NEXT_CHAR: return("NEXT");
|
||||
case PUT_CHAR: return("PUT");
|
||||
case PUT_FILLER: return("FILLER");
|
||||
case PAUSE: return("PAUSE");
|
||||
case END: return("END");
|
||||
}
|
||||
return("???");
|
||||
};
|
||||
#endif
|
||||
140
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_Parola.cpp
Normal file
140
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_Parola.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
#include <MD_MAX72xx.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements core MD_Parola class methods
|
||||
*/
|
||||
|
||||
MD_Parola::MD_Parola(uint8_t dataPin, uint8_t clkPin, uint8_t csPin, uint8_t numDevices):
|
||||
_D(dataPin, clkPin, csPin, numDevices), _numModules(numDevices)
|
||||
{
|
||||
}
|
||||
|
||||
MD_Parola::MD_Parola(uint8_t csPin, uint8_t numDevices):
|
||||
_D(csPin, numDevices), _numModules(numDevices)
|
||||
{
|
||||
}
|
||||
|
||||
void MD_Parola::begin(uint8_t numZones)
|
||||
{
|
||||
_D.begin();
|
||||
|
||||
// Check boundaries for the number of zones
|
||||
if (numZones == 0) numZones = 1;
|
||||
if (numZones > MAX_ZONES) numZones = MAX_ZONES;
|
||||
_numZones = numZones;
|
||||
|
||||
// Create the zone objects array
|
||||
//_Z = new MD_PZone[_numZones]; // for dynamic array
|
||||
|
||||
for (uint8_t i = 0; i < _numZones; i++)
|
||||
_Z[i].begin(&_D);
|
||||
|
||||
// for one zone automatically make it all modules, user will override if not intended
|
||||
if (_numZones == 1)
|
||||
setZone(0, 0, _numModules - 1);
|
||||
|
||||
// initialise zone-independent options
|
||||
setSpeed(10);
|
||||
setPause(10*getSpeed());
|
||||
setCharSpacing(1);
|
||||
setScrollSpacing(0);
|
||||
setTextAlignment(PA_LEFT);
|
||||
setTextEffect(PA_PRINT, PA_NO_EFFECT);
|
||||
setTextBuffer(nullptr);
|
||||
setInvert(false);
|
||||
setIntensity(MAX_INTENSITY/2);
|
||||
|
||||
// Now set the default viewing parameters for this library
|
||||
_D.setFont(nullptr);
|
||||
}
|
||||
|
||||
MD_Parola::~MD_Parola(void)
|
||||
{
|
||||
// release the zone array (dynamically alocated)
|
||||
//delete [] _Z;
|
||||
}
|
||||
|
||||
bool MD_Parola::setZone(uint8_t z, uint8_t moduleStart, uint8_t moduleEnd)
|
||||
{
|
||||
if ((moduleStart <= moduleEnd) && (moduleEnd < _numModules) && (z < _numZones))
|
||||
{
|
||||
_Z[z].setZone(moduleStart, moduleEnd);
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
void MD_Parola::displayZoneText(uint8_t z, char *pText, textPosition_t align, uint16_t speed, uint16_t pause, textEffect_t effectIn, textEffect_t effectOut)
|
||||
{
|
||||
setTextBuffer(z, pText);
|
||||
setTextAlignment(z, align);
|
||||
setSpeed(z, speed);
|
||||
setPause(z, pause);
|
||||
setTextEffect(z, effectIn, effectOut);
|
||||
|
||||
displayReset(z);
|
||||
}
|
||||
|
||||
bool MD_Parola::displayAnimate(void)
|
||||
{
|
||||
bool b = false;
|
||||
|
||||
// suspend the display while we animate a frame
|
||||
_D.update(MD_MAX72XX::OFF);
|
||||
|
||||
for (uint8_t i = 0; i < _numZones; i++)
|
||||
b |= _Z[i].zoneAnimate();
|
||||
|
||||
// re-enable and update the display
|
||||
_D.update(MD_MAX72XX::ON);
|
||||
|
||||
return(b);
|
||||
}
|
||||
|
||||
size_t MD_Parola::write(const char *str)
|
||||
{
|
||||
displayText((char *)str, getTextAlignment(), 0, 0, PA_PRINT, PA_NO_EFFECT);
|
||||
while (displayAnimate())
|
||||
/* do nothing */;
|
||||
|
||||
return(strlen(str));
|
||||
}
|
||||
|
||||
size_t MD_Parola::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
char *psz = (char *)malloc(sizeof(char) * (size + 1));
|
||||
|
||||
if (psz == nullptr) return(0);
|
||||
|
||||
memcpy(psz, buffer, size);
|
||||
psz[size] = '\0';
|
||||
write(psz);
|
||||
free(psz);
|
||||
|
||||
return(size);
|
||||
}
|
||||
1876
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_Parola.h
Normal file
1876
arduino-libs/arduino-cli/libraries/MD_Parola/src/MD_Parola.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements blinds effect
|
||||
*/
|
||||
|
||||
const uint8_t BLINDS_SIZE = 4; ///< The width of the blinds in pixels
|
||||
|
||||
void MD_PZone::effectBlinds(bool bIn)
|
||||
// Transfer between messages with blinds effects
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE: // bIn = true
|
||||
case PAUSE: // bIn = false
|
||||
PRINT_STATE("IO BLIND");
|
||||
_nextPos = 0;
|
||||
_fsmState = GET_FIRST_CHAR;
|
||||
// fall through
|
||||
|
||||
case GET_FIRST_CHAR: // blinds closing
|
||||
PRINT_STATE("IO BLIND");
|
||||
|
||||
_nextPos++;
|
||||
for (int16_t i=ZONE_START_COL(_zoneStart); i<=ZONE_END_COL(_zoneEnd); i++)
|
||||
{
|
||||
if (i % BLINDS_SIZE < _nextPos)
|
||||
_MX->setColumn(i, LIGHT_BAR);
|
||||
}
|
||||
|
||||
if (_nextPos == BLINDS_SIZE)
|
||||
{
|
||||
_nextPos = BLINDS_SIZE;
|
||||
_fsmState = GET_NEXT_CHAR;
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_NEXT_CHAR: // blinds opening
|
||||
PRINT_STATE("IO BLIND");
|
||||
zoneClear();
|
||||
if (bIn) commonPrint(); // only do this when putting the message up
|
||||
|
||||
_nextPos--;
|
||||
for (int16_t i=ZONE_START_COL(_zoneStart); i<=ZONE_END_COL(_zoneEnd); i++)
|
||||
{
|
||||
if (i % BLINDS_SIZE < _nextPos)
|
||||
_MX->setColumn(i, LIGHT_BAR);
|
||||
}
|
||||
|
||||
if (_nextPos == 0)
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("IO BLIND");
|
||||
zoneClear();
|
||||
if (bIn) commonPrint();
|
||||
_fsmState = (bIn ? PAUSE : END);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("IO BLIND");
|
||||
_fsmState = (bIn ? PAUSE : END);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements closing effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectClose(bool bLightBar, bool bIn)
|
||||
// Dissolve the current message in/out
|
||||
{
|
||||
if (bIn)
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
PRINT_STATE("I CLOSE");
|
||||
_nextPos = 0;
|
||||
zoneClear();
|
||||
if (bLightBar)
|
||||
{
|
||||
_MX->setColumn(_limitLeft, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight,LIGHT_BAR);
|
||||
}
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("I CLOSE");
|
||||
FSMPRINT(" - offset ", _nextPos);
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
{
|
||||
const int16_t halfWidth = (_limitLeft - _limitRight)/2;
|
||||
|
||||
if (_nextPos > halfWidth)
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int16_t i = _limitRight + _nextPos + 1; i < _limitLeft - _nextPos; i++)
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
|
||||
_nextPos++;
|
||||
if (bLightBar && (_nextPos <= halfWidth))
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, LIGHT_BAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I CLOSE");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
PRINT_STATE("O CLOSE");
|
||||
FSMPRINT(" - limits R:", _limitRight);
|
||||
FSMPRINT(" L:", _limitLeft);
|
||||
_nextPos = (_limitLeft-_limitRight)/2;
|
||||
FSMPRINT(" O:", _nextPos);
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
if (bLightBar)
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, LIGHT_BAR);
|
||||
}
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O CLOSE");
|
||||
FSMPRINT(" - offset ", _nextPos);
|
||||
if (_nextPos < 0)
|
||||
{
|
||||
_fsmState = END;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, EMPTY_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, EMPTY_BAR);
|
||||
|
||||
_nextPos--;
|
||||
if (bLightBar && (_nextPos >= 0))
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, LIGHT_BAR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O CLOSE");
|
||||
_fsmState = END;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements diagonal scroll effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectDiag(bool bUp, bool bLeft, bool bIn)
|
||||
// Scroll the display diagonally up or down, left or right, depending on the selected effect
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I DIAG");
|
||||
_nextPos = 0; // the position in the animation
|
||||
_MX->control(_zoneStart, _zoneEnd, MD_MAX72XX::WRAPAROUND, MD_MAX72XX::OFF);
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I DIAG");
|
||||
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
|
||||
for (uint8_t i = _nextPos; i < 7; i++)
|
||||
{
|
||||
// scroll the whole display so that the message appears to be animated
|
||||
// Note: Directions are reversed because we start with the message in the
|
||||
// middle position thru commonPrint() and to see it animated move DOWN we
|
||||
// need to scroll it UP, and vice versa.
|
||||
_MX->transform(_zoneStart, _zoneEnd, bUp ? MD_MAX72XX::TSD : MD_MAX72XX::TSU);
|
||||
_MX->transform(_zoneStart, _zoneEnd, bLeft ? MD_MAX72XX::TSR : MD_MAX72XX::TSL);
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == 7) _fsmState = PAUSE;
|
||||
|
||||
_nextPos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I DIAG");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O DIAG");
|
||||
_nextPos = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O DIAG");
|
||||
|
||||
_MX->transform(_zoneStart, _zoneEnd, bUp ? MD_MAX72XX::TSU : MD_MAX72XX::TSD);
|
||||
_MX->transform(_zoneStart, _zoneEnd, bLeft ? MD_MAX72XX::TSL : MD_MAX72XX::TSR);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == 7) _fsmState = END;
|
||||
|
||||
_nextPos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O DIAG");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements dissolve effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectDissolve(bool bIn)
|
||||
// Dissolve the current message in/out
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE: // bIn = true
|
||||
case PAUSE: // bIn = false
|
||||
case GET_FIRST_CHAR: // first stage dissolve
|
||||
PRINT_STATE("IO DISS");
|
||||
for (int16_t i=ZONE_START_COL(_zoneStart); i<=ZONE_END_COL(_zoneEnd); i++)
|
||||
{
|
||||
uint8_t col = DATA_BAR(_MX->getColumn(i));
|
||||
|
||||
col |= (i&1 ? 0x55 : 0xaa); // checkerboard pattern
|
||||
_MX->setColumn(i, DATA_BAR(col));
|
||||
}
|
||||
_fsmState = GET_NEXT_CHAR;
|
||||
break;
|
||||
|
||||
case GET_NEXT_CHAR: // second stage dissolve
|
||||
PRINT_STATE("IO DISS");
|
||||
zoneClear();
|
||||
if (bIn) commonPrint();
|
||||
for (int16_t i=ZONE_START_COL(_zoneStart); i<=ZONE_END_COL(_zoneEnd); i++)
|
||||
{
|
||||
uint8_t col = DATA_BAR(_MX->getColumn(i));
|
||||
|
||||
col |= (i&1 ? 0xaa : 0x55); // alternate checkerboard pattern
|
||||
_MX->setColumn(i, DATA_BAR(col));
|
||||
}
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("IO DISS");
|
||||
zoneClear();
|
||||
if (bIn) commonPrint();
|
||||
_fsmState = (bIn ? PAUSE : END);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("IO DISS");
|
||||
_fsmState = (bIn ? PAUSE : END);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2016 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements FADE effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectFade(bool bIn)
|
||||
// Fade the display in and out.
|
||||
// If the overall intensity is changed while the animation is running, the
|
||||
// intensity at the start of the animation will be restored at the end, overriding
|
||||
// any user code changes.
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I FADE");
|
||||
_nextPos = 0;
|
||||
_endPos = getIntensity();
|
||||
|
||||
zoneClear();
|
||||
|
||||
_fsmState = GET_FIRST_CHAR;
|
||||
break;
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
FSMPRINT(" I:", _nextPos);
|
||||
FSMPRINT("/", _endPos);
|
||||
|
||||
setIntensity(_nextPos++);
|
||||
commonPrint();
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I FADE");
|
||||
FSMPRINT(" I:", _nextPos);
|
||||
FSMPRINT("/", _endPos);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos > _endPos)
|
||||
_fsmState = PAUSE;
|
||||
else
|
||||
setIntensity(_nextPos++);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I FADE");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O FADE");
|
||||
_nextPos = _endPos = getIntensity();
|
||||
|
||||
FSMPRINT(" I:", _nextPos);
|
||||
FSMPRINT("/", _endPos);
|
||||
|
||||
setIntensity(_nextPos);
|
||||
commonPrint();
|
||||
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O FADE");
|
||||
|
||||
FSMPRINT(" I:", _nextPos);
|
||||
FSMPRINT("/", _endPos);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos < 0)
|
||||
{
|
||||
setIntensity(_endPos); // set to original conditions
|
||||
zoneClear(); // display nothing - we are currently at 0
|
||||
_fsmState = END;
|
||||
}
|
||||
else
|
||||
setIntensity(_nextPos--);
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O FADE");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements grow effects
|
||||
*/
|
||||
|
||||
void MD_PZone::effectGrow(bool bUp, bool bIn)
|
||||
// Scan the message over with a new one
|
||||
// Print up the whole message and then remove the parts we
|
||||
// don't need in order to do the animation.
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I GROW");
|
||||
setInitialEffectConditions();
|
||||
_nextPos = (bUp ? 0xff : 1); // this is the bit mask
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I GROW");
|
||||
|
||||
commonPrint();
|
||||
// check if we have finished
|
||||
if (_nextPos == (bUp ? 0 : 0xff)) // all bits covered
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT("Keep bits ", _nextPos);
|
||||
for (int16_t i = _startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
uint8_t c = DATA_BAR(_MX->getColumn(i)) & (bUp ? ~_nextPos : _nextPos);
|
||||
|
||||
_MX->setColumn(i, DATA_BAR(c));
|
||||
}
|
||||
|
||||
// for the next time around
|
||||
if (bUp)
|
||||
_nextPos >>= 1;
|
||||
else
|
||||
_nextPos = (_nextPos << 1) | 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I GROW");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O GROW");
|
||||
setInitialEffectConditions();
|
||||
_nextPos = (bUp ? 1 : 0xff); // this is the bit mask
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O GROW");
|
||||
commonPrint();
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT(" Keep bits ", _nextPos);
|
||||
for (int16_t i=_startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
uint8_t c = DATA_BAR(_MX->getColumn(i)) & (bUp ? ~_nextPos : _nextPos);
|
||||
|
||||
_MX->setColumn(i, DATA_BAR(c));
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == (bUp ? 0xff : 0x0)) // all bits covered
|
||||
_fsmState = END;
|
||||
|
||||
// for the next time around
|
||||
if (bUp)
|
||||
_nextPos = (_nextPos << 1) | 1;
|
||||
else
|
||||
_nextPos >>= 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O GROW");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements horizontal scrolling effect
|
||||
*/
|
||||
|
||||
#define START_POSITION (bLeft) ? ZONE_START_COL(_zoneStart) : ZONE_END_COL(_zoneEnd) ///< Start position depends on the scrolling direction
|
||||
|
||||
void MD_PZone::effectHScroll(bool bLeft, bool bIn)
|
||||
{
|
||||
if (bIn)
|
||||
{
|
||||
switch(_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
case GET_FIRST_CHAR: // Load the first character from the font table
|
||||
PRINT_STATE("I HSCROLL");
|
||||
|
||||
if ((_charCols = getFirstChar()) == 0)
|
||||
{
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
_countCols = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case GET_NEXT_CHAR: // Load the next character from the font table
|
||||
PRINT_STATE("I HSCROLL");
|
||||
|
||||
// Have we reached the end of the characters string?
|
||||
_charCols = getNextChar();
|
||||
FSMPRINT("\ncharCols ", _charCols);
|
||||
if (_charCols == 0)
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
|
||||
_countCols = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
FSMPRINTS(", fall thru");
|
||||
// !! fall through to next state to start displaying
|
||||
|
||||
case PUT_CHAR: // display the next part of the character
|
||||
PRINT_STATE("I HSCROLL");
|
||||
|
||||
_MX->transform(_zoneStart, _zoneEnd, bLeft ? MD_MAX72XX::TSL : MD_MAX72XX::TSR);
|
||||
_MX->setColumn(START_POSITION, DATA_BAR(_cBuf[_countCols++]));
|
||||
FSMPRINTS(", scroll");
|
||||
|
||||
// end of this buffer - we may need to get another one
|
||||
if (_countCols == _charCols)
|
||||
{
|
||||
if (!_endOfText)
|
||||
_fsmState = GET_NEXT_CHAR;
|
||||
else
|
||||
{
|
||||
// work out the number of filler columns
|
||||
_countCols = (bLeft ? _limitLeft-_textLen-ZONE_START_COL(_zoneStart) + 1 : ZONE_END_COL(_zoneEnd)-_limitLeft);
|
||||
FSMPRINT(", filler count ", _countCols);
|
||||
_fsmState = (_countCols <= 0) ? PAUSE : PUT_FILLER;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PUT_FILLER: // keep sending out blank columns until aligned
|
||||
PRINT_STATE("I HSCROLL");
|
||||
|
||||
_MX->transform(_zoneStart, _zoneEnd, bLeft ? MD_MAX72XX::TSL : MD_MAX72XX::TSR);
|
||||
_MX->setColumn(START_POSITION, EMPTY_BAR);
|
||||
FSMPRINTS(", fill");
|
||||
|
||||
if (--_countCols == 0)
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch(_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
PRINT_STATE("O HSCROLL");
|
||||
_fsmState = PUT_FILLER;
|
||||
FSMPRINTS(" falling thru");
|
||||
// fall through
|
||||
|
||||
case PUT_FILLER:
|
||||
PRINT_STATE("O HSCROLL");
|
||||
_MX->transform(_zoneStart, _zoneEnd, bLeft ? MD_MAX72XX::TSL : MD_MAX72XX::TSR);
|
||||
_MX->setColumn(START_POSITION, EMPTY_BAR);
|
||||
|
||||
// check if enough scrolled off to say that new message should start
|
||||
// how we count depends on the direction for scrolling
|
||||
{
|
||||
uint16_t spaceCount = 0;
|
||||
uint16_t maxCount = (_zoneEnd - _zoneStart + 1) * COL_SIZE;
|
||||
|
||||
if ((_scrollDistance != 0) && (maxCount > _scrollDistance)) maxCount = _scrollDistance;
|
||||
|
||||
if (bLeft)
|
||||
{
|
||||
for (int16_t i = ZONE_START_COL(_zoneStart);
|
||||
(i <= ZONE_END_COL(_zoneEnd)) && (_MX->getColumn(i) == EMPTY_BAR);
|
||||
i++, spaceCount++);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int16_t i = ZONE_END_COL(_zoneEnd);
|
||||
(i >= ZONE_START_COL(_zoneStart)) && (_MX->getColumn(i) == EMPTY_BAR);
|
||||
i--, spaceCount++);
|
||||
}
|
||||
|
||||
if (maxCount <= spaceCount) _fsmState = END; // enough of a space between messages, end this FSM
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements mesh effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectMesh(bool bIn)
|
||||
// Text enters with alternating up/down columns
|
||||
{
|
||||
bool bUp = true;
|
||||
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I MESH");
|
||||
_nextPos = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I MESH");
|
||||
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
|
||||
for (uint8_t c = ZONE_START_COL(_zoneStart); c <= ZONE_END_COL(_zoneEnd); c++)
|
||||
{
|
||||
// scroll the whole display so that the message appears to be animated
|
||||
// Note: Directions are reversed because we start with the message in the
|
||||
// middle position thru commonPrint() and to see it animated move DOWN we
|
||||
// need to scroll it UP, and vice versa.
|
||||
uint8_t col = _MX->getColumn(c);
|
||||
|
||||
col = (bUp ? col >> (COL_SIZE-1-_nextPos) : col << (COL_SIZE-1-_nextPos));
|
||||
_MX->setColumn(c, col);
|
||||
bUp = !bUp;
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
_nextPos++;
|
||||
if (_nextPos == COL_SIZE) _fsmState = PAUSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I MESH");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O MESH");
|
||||
_nextPos = 1;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O MESH");
|
||||
|
||||
for (uint8_t c = ZONE_START_COL(_zoneStart); c <= ZONE_END_COL(_zoneEnd); c++)
|
||||
{
|
||||
uint8_t col = _MX->getColumn(c);
|
||||
|
||||
col = (bUp ? col << _nextPos : col >> _nextPos);
|
||||
_MX->setColumn(c, col);
|
||||
bUp = !bUp;
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
_nextPos++;
|
||||
if (_nextPos == COL_SIZE) _fsmState = END;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O MESH");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements opening effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectOpen(bool bLightBar, bool bIn)
|
||||
// Open the current message in/out
|
||||
{
|
||||
if (bIn)
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
PRINT_STATE("I OPEN");
|
||||
FSMPRINT(" - limits R:", _limitRight);
|
||||
FSMPRINT(" L:", _limitLeft);
|
||||
_nextPos = 1 + (_limitLeft - _limitRight)/2;
|
||||
FSMPRINT(" O:", _nextPos);
|
||||
if (bLightBar)
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, LIGHT_BAR);
|
||||
}
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("I OPEN");
|
||||
FSMPRINT(" - offset ", _nextPos);
|
||||
if (_nextPos < 0)
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
commonPrint();
|
||||
for (int16_t i=0; i<_nextPos; i++)
|
||||
{
|
||||
_MX->setColumn(_limitRight + i, EMPTY_BAR);
|
||||
_MX->setColumn(_limitLeft - i, EMPTY_BAR);
|
||||
}
|
||||
|
||||
_nextPos--;
|
||||
if (bLightBar && (_nextPos >= 0))
|
||||
{
|
||||
_MX->setColumn(_limitRight + _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I OPEN");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
PRINT_STATE("O OPEN");
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
_nextPos = 0;
|
||||
if (bLightBar)
|
||||
{
|
||||
_MX->setColumn(_limitLeft, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight,LIGHT_BAR);
|
||||
}
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through
|
||||
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O OPEN");
|
||||
FSMPRINT(" - offset ", _nextPos);
|
||||
if (_nextPos > (_limitLeft - _limitRight)/2)
|
||||
{
|
||||
_fsmState = END;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, EMPTY_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos, EMPTY_BAR);
|
||||
_nextPos++;
|
||||
if (bLightBar && (_nextPos <= (_limitLeft-_limitRight)/2))
|
||||
{
|
||||
_MX->setColumn(_limitLeft - _nextPos, LIGHT_BAR);
|
||||
_MX->setColumn(_limitRight + _nextPos,LIGHT_BAR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O OPEN");
|
||||
_fsmState = END;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements static print effect
|
||||
*/
|
||||
|
||||
void MD_PZone::commonPrint(void)
|
||||
{
|
||||
int16_t nextPos;
|
||||
|
||||
PRINTS("\ncommonPrint");
|
||||
zoneClear();
|
||||
nextPos = _limitLeft;
|
||||
_charCols = getFirstChar();
|
||||
_countCols = 0;
|
||||
|
||||
while (nextPos >= _limitRight)
|
||||
{
|
||||
if (_countCols == _charCols)
|
||||
{
|
||||
_charCols = getNextChar();
|
||||
_countCols = 0;
|
||||
}
|
||||
|
||||
// now put something on the display
|
||||
_MX->setColumn(nextPos--, DATA_BAR(_cBuf[_countCols++]));
|
||||
}
|
||||
}
|
||||
|
||||
void MD_PZone::effectPrint(bool bIn)
|
||||
// Just print the message in the justification selected
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
commonPrint();
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
else //exiting
|
||||
{
|
||||
zoneClear();
|
||||
_fsmState = END;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements random effect
|
||||
*/
|
||||
|
||||
#define RAND_CYCLE 11 // random effect repeats every RANDOM_CYCLE columns
|
||||
|
||||
void MD_PZone::effectRandom(bool bIn)
|
||||
// Text enters as random dots
|
||||
{
|
||||
static uint8_t pix[RAND_CYCLE]; // pixel data (one byte per column) to mask the display
|
||||
uint8_t c, r; // the row and column coordinates being considered
|
||||
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE: // Entry bIn == true
|
||||
case PAUSE: // Exit bIn == false
|
||||
PRINT_STATE("IO RAND");
|
||||
for (uint8_t i = 0; i < RAND_CYCLE; i++)
|
||||
pix[i] = 0;
|
||||
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("IO RAND");
|
||||
if (bIn) FSMPRINTS(" in"); else FSMPRINTS(" out");
|
||||
|
||||
// Work out and set the next random pixel in the column mask.
|
||||
// Use a loop counter to make sure we just don't loop forever.
|
||||
_nextPos = 0;
|
||||
do
|
||||
{
|
||||
c = random(RAND_CYCLE);
|
||||
r = random(ROW_SIZE);
|
||||
_nextPos++;
|
||||
} while (pix[c] & (1 << r) && _nextPos < 5000);
|
||||
|
||||
// FSMPRINT("\n [r,c]=", r); FSMPRINT(",", c); FSMPRINT(" counter ", _nextPos);
|
||||
|
||||
pix[c] |= (1 << r); // set the r,c location in the mask
|
||||
|
||||
// set up a new display
|
||||
commonPrint();
|
||||
|
||||
// now mask each column by the pixel mask - this repeats every RAND_CYCLE columns, but the
|
||||
// characters don't occupy every pixel so the effect looks 'random' across the whole display.
|
||||
_nextPos = 0;
|
||||
for (uint8_t c = ZONE_START_COL(_zoneStart); c <= ZONE_END_COL(_zoneEnd); c++)
|
||||
{
|
||||
uint8_t col = _MX->getColumn(c);
|
||||
|
||||
col &= (bIn ? pix[_nextPos] : ~pix[_nextPos]); // set or reset the bit (depends on bIn)
|
||||
_MX->setColumn(c, col);
|
||||
|
||||
_nextPos++;
|
||||
if (_nextPos == RAND_CYCLE)
|
||||
_nextPos = 0;
|
||||
}
|
||||
|
||||
// check if we have finished. This is when all the columns have pixels all on (0xff)
|
||||
{
|
||||
bool bEnd = true;
|
||||
|
||||
for (uint8_t i = 0; bEnd && i < COL_SIZE; i++)
|
||||
bEnd = (pix[i] == 0xff);
|
||||
|
||||
if (bEnd) _fsmState = (bIn ? PAUSE : END);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("IO RAND");
|
||||
_fsmState = (bIn ? PAUSE : END);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements scan effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectHScan(bool bIn, bool bBlank)
|
||||
// Scan the message end to end.
|
||||
// if bBlank is true, a blank column scans the text. If false, a non-blank scans the text.
|
||||
// Print up the whole message and then remove the parts we
|
||||
// don't need in order to do the animation.
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I SCANH");
|
||||
setInitialEffectConditions();
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I SCANH");
|
||||
|
||||
commonPrint();
|
||||
// check if we have finished
|
||||
if (_nextPos == _endPos)
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT("Scan col ", _nextPos);
|
||||
for (int16_t i=_startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
if ((!bBlank && (i != _nextPos)) || (bBlank && (i == _nextPos)))
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
}
|
||||
|
||||
_nextPos += _posOffset; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I SCANH");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O SCANH");
|
||||
setInitialEffectConditions();
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O SCANH");
|
||||
commonPrint();
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT(" Scan col ", _nextPos);
|
||||
for (int16_t i=_startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
if ((!bBlank && (i != _nextPos)) || (bBlank && (i == _nextPos)))
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos < _endPos) _fsmState = END;
|
||||
|
||||
_nextPos += _posOffset; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O SCANH");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MD_PZone::effectVScan(bool bIn, bool bBlank)
|
||||
// Scan the message over with a new one
|
||||
// if bBlank is true, a blank column scans the text. If false, a non-blank scans the text.
|
||||
// Print up the whole message and then remove the parts we
|
||||
// don't need in order to do the animation.
|
||||
{
|
||||
uint8_t maskCol = 0;
|
||||
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I SCANV");
|
||||
setInitialEffectConditions();
|
||||
_nextPos = 0; // this is the bit number
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I SCANV");
|
||||
commonPrint();
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == 8) // bits numbered 0 to 7
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT("Keep bit ", _nextPos);
|
||||
maskCol = (1 << _nextPos);
|
||||
for (int16_t i=_startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
uint8_t c = DATA_BAR(_MX->getColumn(i) & (bBlank ? ~maskCol : maskCol));
|
||||
|
||||
_MX->setColumn(i, DATA_BAR(c));
|
||||
}
|
||||
|
||||
_nextPos++; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I SCANV");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O SCANV");
|
||||
setInitialEffectConditions();
|
||||
_nextPos = 7; // the bit number
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O SCANV");
|
||||
|
||||
commonPrint();
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT(" Keep bit ", _nextPos);
|
||||
if (_nextPos >= 0)
|
||||
maskCol = 1 << _nextPos;
|
||||
for (int16_t i=_startPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
{
|
||||
uint8_t c = DATA_BAR(_MX->getColumn(i) & (bBlank ? ~maskCol : maskCol));
|
||||
|
||||
_MX->setColumn(i, DATA_BAR(c));
|
||||
}
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos < 0)
|
||||
_fsmState = END;
|
||||
|
||||
_nextPos--; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O SCANV");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements slice effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectSlice(bool bIn)
|
||||
{
|
||||
if (bIn)
|
||||
{
|
||||
switch(_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
case GET_FIRST_CHAR:
|
||||
PRINT_STATE("I SLICE");
|
||||
|
||||
if ((_charCols = getFirstChar()) == 0)
|
||||
{
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
zoneClear();
|
||||
_countCols = 0;
|
||||
_nextPos = ZONE_START_COL(_zoneStart);
|
||||
_endPos = _limitLeft;
|
||||
|
||||
FSMPRINT(" - Start ", _nextPos);
|
||||
FSMPRINT(", End ", _endPos);
|
||||
|
||||
_fsmState = PUT_CHAR;
|
||||
break;
|
||||
|
||||
case GET_NEXT_CHAR: // Load the next character from the font table
|
||||
PRINT_STATE("I SLICE");
|
||||
// have we reached the end of the characters string?
|
||||
if ((_charCols = getNextChar()) == 0)
|
||||
{
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
_countCols = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
// !! fall through to next state to start displaying
|
||||
|
||||
case PUT_CHAR: // display the next part of the character
|
||||
PRINT_STATE("I SLICE");
|
||||
FSMPRINT(" - Next ", _endPos);
|
||||
FSMPRINT(", anim ", _nextPos);
|
||||
|
||||
// if the text is too long for the zone, stop when we are at the last column of the zone
|
||||
if (_nextPos == _endPos)
|
||||
{
|
||||
_MX->setColumn(_nextPos, DATA_BAR(_cBuf[_countCols]));
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_cBuf[_countCols] == 0) // empty column ?
|
||||
{
|
||||
_nextPos = _endPos; // pretend we just animated it!
|
||||
}
|
||||
else // something to animate
|
||||
{
|
||||
// clear the column and animate the next one
|
||||
if (_nextPos != _endPos) _MX->setColumn(_nextPos, EMPTY_BAR);
|
||||
_nextPos++;
|
||||
_MX->setColumn(_nextPos, DATA_BAR(_cBuf[_countCols]));
|
||||
}
|
||||
|
||||
// set up for the next time
|
||||
if (_nextPos == _endPos)
|
||||
{
|
||||
_nextPos = ZONE_START_COL(_zoneStart);
|
||||
_countCols++;
|
||||
_endPos--;
|
||||
}
|
||||
if (_countCols == _charCols) _fsmState = GET_NEXT_CHAR;
|
||||
break;
|
||||
|
||||
default:
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch(_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
PRINT_STATE("O SLICE");
|
||||
_nextPos = _endPos = _limitLeft;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O SLICE");
|
||||
FSMPRINT(" - Next ", _endPos);
|
||||
FSMPRINT(", anim ", _nextPos);
|
||||
|
||||
while(_MX->getColumn(_nextPos) == EMPTY_BAR && _endPos >= _limitRight)
|
||||
_nextPos = _endPos--; // pretend we just animated it!
|
||||
|
||||
if (_endPos+1 < _limitRight)
|
||||
_fsmState = END; //reached the end
|
||||
else
|
||||
{
|
||||
// Move the column over to the left and blank out previous position
|
||||
if (_nextPos < ZONE_END_COL(_zoneEnd))
|
||||
_MX->setColumn(_nextPos+1, _MX->getColumn(_nextPos));
|
||||
_MX->setColumn(_nextPos, EMPTY_BAR);
|
||||
_nextPos++;
|
||||
|
||||
// set up for the next time
|
||||
if (_nextPos == ZONE_END_COL(_zoneEnd)+1)
|
||||
_nextPos = _endPos--;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
_fsmState = END;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2018 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements various sprite effects
|
||||
*/
|
||||
|
||||
#if ENA_SPRITE
|
||||
|
||||
void MD_PZone::effectSprite(bool bIn, uint8_t id)
|
||||
// Animated Pacman sprite leads or eats up the message.
|
||||
// Print up the whole message and then remove the parts we
|
||||
// don't need in order to do the animation.
|
||||
{
|
||||
if (bIn) // incoming - sprite moves left to right in the zone
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I SPRITE");
|
||||
setInitialEffectConditions();
|
||||
if (_startPos < _endPos)
|
||||
{
|
||||
int16_t t = _startPos;
|
||||
_startPos = _endPos;
|
||||
_endPos = t;
|
||||
}
|
||||
if (_spriteInData == nullptr)
|
||||
{
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
_posOffset = 0; // current animation frame for the sprite
|
||||
_nextPos = ZONE_END_COL(_zoneEnd) + 1;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I SPRITE");
|
||||
|
||||
commonPrint();
|
||||
|
||||
// move reference column and draw new graphic
|
||||
_nextPos--;
|
||||
for (uint8_t i = 0; i < _spriteInWidth; i++)
|
||||
{
|
||||
if ((_nextPos + i) <= ZONE_END_COL(_zoneEnd) && (_nextPos + i) >= ZONE_START_COL(_zoneStart))
|
||||
_MX->setColumn(_nextPos + i, DATA_BAR(pgm_read_byte(_spriteInData + (_posOffset * _spriteInWidth) + i)));
|
||||
}
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
// this is the part to the right of the sprite
|
||||
for (int16_t i = _nextPos - 1; i >= _endPos; i--)
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
|
||||
// advance the animation frame
|
||||
_posOffset++;
|
||||
if (_posOffset >= _spriteInFrames)
|
||||
_posOffset = 0;
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == ZONE_START_COL(_zoneStart) - _spriteInWidth - 1)
|
||||
_fsmState = PAUSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I SPRITE");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting - sprite moves left to right in the zone
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O SPRITE");
|
||||
setInitialEffectConditions();
|
||||
if (_startPos < _endPos)
|
||||
{
|
||||
int16_t t = _startPos;
|
||||
_startPos = _endPos;
|
||||
_endPos = t;
|
||||
}
|
||||
if (_spriteOutData == nullptr)
|
||||
{
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
_nextPos = ZONE_START_COL(_zoneStart) - 1;
|
||||
_posOffset = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O SPRITE");
|
||||
commonPrint();
|
||||
|
||||
// move reference column and draw new graphic
|
||||
_nextPos++;
|
||||
for (uint8_t i = 0; i < _spriteOutWidth; i++)
|
||||
{
|
||||
if ((_nextPos - i) <= ZONE_END_COL(_zoneEnd) && (_nextPos - i) >= ZONE_START_COL(_zoneStart))
|
||||
_MX->setColumn(_nextPos - i, DATA_BAR(pgm_read_byte(_spriteOutData + (_posOffset * _spriteOutWidth) + i)));
|
||||
}
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
// this is the part to the right of the sprite
|
||||
for (int16_t i = _nextPos - _spriteOutWidth; i >= _endPos; i--)
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
|
||||
// advance the animation frame
|
||||
_posOffset++;
|
||||
if (_posOffset >= _spriteOutFrames)
|
||||
_posOffset = 0;
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == ZONE_END_COL(_zoneEnd) + _spriteOutWidth + 1)
|
||||
_fsmState = END;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O SPRITE");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements vertical scroll effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectVScroll(bool bUp, bool bIn)
|
||||
// Scroll the display horizontally up of down, depending on the selected effect
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I VSCROLL");
|
||||
_nextPos = 0;
|
||||
_MX->control(_zoneStart, _zoneEnd, MD_MAX72XX::WRAPAROUND, MD_MAX72XX::OFF);
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I VSCROLL");
|
||||
|
||||
zoneClear();
|
||||
commonPrint();
|
||||
|
||||
for (uint8_t i = _nextPos; i < 7; i++)
|
||||
// scroll the whole display so that the message appears to be animated
|
||||
// Note: Directions are reversed because we start with the message in the
|
||||
// middle position thru commonPrint() and to see it animated move DOWN we
|
||||
// need to scroll it UP, and vice versa.
|
||||
_MX->transform(_zoneStart, _zoneEnd, bUp ? MD_MAX72XX::TSD : MD_MAX72XX::TSU);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == 7) _fsmState = PAUSE;
|
||||
|
||||
_nextPos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I VSCROLL");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O VSCROLL");
|
||||
_nextPos = 0;
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O VSCROLL");
|
||||
|
||||
_MX->transform(_zoneStart, _zoneEnd, bUp ? MD_MAX72XX::TSU : MD_MAX72XX::TSD);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == 7) _fsmState = END;
|
||||
|
||||
_nextPos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O VSCROLL");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
MD_Parola - Library for modular scrolling text and Effects
|
||||
|
||||
See header file for comments
|
||||
|
||||
Copyright (C) 2013 Marco Colli. All rights reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_Parola_lib.h>
|
||||
/**
|
||||
* \file
|
||||
* \brief Implements wipe effect
|
||||
*/
|
||||
|
||||
void MD_PZone::effectWipe(bool bLightBar, bool bIn)
|
||||
// Wipe the message over with a new one
|
||||
// Print up the whole message and then remove the parts we
|
||||
// don't need in order to do the animation.
|
||||
{
|
||||
if (bIn) // incoming
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case INITIALISE:
|
||||
PRINT_STATE("I WIPE");
|
||||
setInitialEffectConditions();
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
case PAUSE:
|
||||
PRINT_STATE("I WIPE");
|
||||
if (_fsmState == PAUSE)
|
||||
_fsmState = PUT_CHAR;
|
||||
|
||||
commonPrint();
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT(" - Clear ", _nextPos);
|
||||
FSMPRINT(" to ", _endPos);
|
||||
FSMPRINT(" step ", _posOffset);
|
||||
for (int16_t i=_nextPos; i != _endPos+_posOffset; i += _posOffset)
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
|
||||
if (bLightBar && (_nextPos != _endPos+_posOffset)) _MX->setColumn(_nextPos, LIGHT_BAR);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == _endPos+_posOffset) _fsmState = PAUSE;
|
||||
|
||||
_nextPos += _posOffset; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("I WIPE");
|
||||
_fsmState = PAUSE;
|
||||
}
|
||||
}
|
||||
else // exiting
|
||||
{
|
||||
switch (_fsmState)
|
||||
{
|
||||
case PAUSE:
|
||||
case INITIALISE:
|
||||
PRINT_STATE("O WIPE");
|
||||
setInitialEffectConditions();
|
||||
_fsmState = PUT_CHAR;
|
||||
// fall through to next state
|
||||
|
||||
case GET_FIRST_CHAR:
|
||||
case GET_NEXT_CHAR:
|
||||
case PUT_CHAR:
|
||||
PRINT_STATE("O WIPE");
|
||||
commonPrint();
|
||||
|
||||
// blank out the part of the display we don't need
|
||||
FSMPRINT(" - Clear ", _nextPos);
|
||||
FSMPRINT(" to ", _endPos);
|
||||
FSMPRINT(" step ", _posOffset);
|
||||
for (int16_t i = _startPos; i != _nextPos + _posOffset; i += _posOffset)
|
||||
_MX->setColumn(i, EMPTY_BAR);
|
||||
|
||||
if (bLightBar && (_nextPos != _endPos+_posOffset)) _MX->setColumn(_nextPos, LIGHT_BAR);
|
||||
|
||||
// check if we have finished
|
||||
if (_nextPos == _endPos + _posOffset) _fsmState = END;
|
||||
|
||||
_nextPos += _posOffset; // for the next time around
|
||||
break;
|
||||
|
||||
default:
|
||||
PRINT_STATE("O WIPE");
|
||||
_fsmState = END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
#ifndef MD_PAROLALIB_H
|
||||
#define MD_PAROLALIB_H
|
||||
/**
|
||||
* \file
|
||||
* \brief Contains internal library definitions
|
||||
*/
|
||||
|
||||
#define DEBUG_PAROLA 0 ///< Set to 1 to enable General debug output
|
||||
#define DEBUG_PAROLA_FSM 0 ///< Set to 1 to enable Finite State Machine debug output
|
||||
#define TIME_PROFILING 0 ///< Set to 1 to enable Time Profile debug output
|
||||
|
||||
#if DEBUG_PAROLA
|
||||
#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); } ///< (GENERAL) Print a string followed by a value (decimal)
|
||||
#define PRINTX(s, v) { Serial.print(F(s)); Serial.print(v, HEX); } ///< (GENERAL) Print a string followed by a value (hex)
|
||||
#define PRINTS(s) Serial.print(F(s)) ///< (GENERAL) Print a string
|
||||
#else
|
||||
#define PRINT(s, v) ///< (GENERAL) Print a string followed by a value (decimal)
|
||||
#define PRINTX(s, v) ///< (GENERAL) Print a string followed by a value (hex)
|
||||
#define PRINTS(s) ///< (GENERAL) Print a string
|
||||
#endif
|
||||
|
||||
#if DEBUG_PAROLA_FSM
|
||||
#define FSMPRINT(s, v) { Serial.print(F(s)); Serial.print(v); } ///< (FSM) Print a string followed by a value (decimal)
|
||||
#define FSMPRINTX(s, v) { Serial.print(F(s)); Serial.print(v, HEX); } ///< (FSM) Print a string followed by a value (hex)
|
||||
#define FSMPRINTS(s) Serial.print(F(s)) ///< (FSM) Print a string
|
||||
#define PRINT_STATE(f) { Serial.print(F("\n")); Serial.print(F(f)); Serial.print(F(" fsm ")); Serial.print(state2string(_fsmState)); } ///< (FSM) Print the current FSM state information
|
||||
#else
|
||||
#define FSMPRINT(s, v) ///< (FSM) Print a string followed by a value (decimal)
|
||||
#define FSMPRINTX(s, v) ///< (FSM) Print a string followed by a value (hex)
|
||||
#define FSMPRINTS(s) ///< (FSM) Print a string
|
||||
#define PRINT_STATE(f) ///< (FSM) Print the current FSM state information
|
||||
#endif
|
||||
|
||||
// General macros and defines
|
||||
#define LIGHT_BAR (_inverted ? 0 : 0xFF) ///< Turn display column to all LEDs on
|
||||
#define EMPTY_BAR (_inverted ? 0xFF : 0) ///< Turn display column to all LEDs off
|
||||
#define DATA_BAR(d) (_inverted ? ~d : d) ///< Turn display column to specified data
|
||||
|
||||
// Zone effects masks
|
||||
#define ZE_SET(b, mask) ((b & ~mask) | mask) ///< clear the bit then put it back in
|
||||
#define ZE_RESET(b, mask) (b & ~mask) ///< clear the bit
|
||||
#define ZE_TEST(b, mask) ((b & mask) != 0) ///< mask off the bit
|
||||
|
||||
#define ZE_FLIP_UD_MASK 0x01 ///< mask bit 0
|
||||
#define ZE_FLIP_LR_MASK 0x02 ///< mask bit 1
|
||||
|
||||
#define SFX(s) ((_moveIn && _effectIn == (s)) || (!_moveIn && _effectOut == (s))) ///< Effect is selected if it is the effect for the current motion
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user