simultaneous wifi traffic animation

This commit is contained in:
rljonesau 2018-12-02 05:51:53 +11:00
parent e2b207625e
commit d947a4708c
2 changed files with 45 additions and 34 deletions

View file

@ -20,13 +20,12 @@
#define MINI_BATTLABEL #define MINI_BATTLABEL
#define DEMO_AP_MODE //#define DEMO_AP_MODE
CScreenHeader::CScreenHeader(C128x64_OLED& disp, CScreenManager& mgr) : CScreen(disp, mgr) CScreenHeader::CScreenHeader(C128x64_OLED& disp, CScreenManager& mgr) : CScreen(disp, mgr)
{ {
_animateState = 0; _animationHold[0] = _animationHold[1] = 0;
_animationHold = 0; _needAnimationClear[0] = _needAnimationClear[1] = false;
_needAnimationClear = false;
} }
void void
@ -35,7 +34,7 @@ CScreenHeader::show()
_display.clearDisplay(); _display.clearDisplay();
// standard header items // standard header items
//Bluetooth // Bluetooth
if(getBluetoothClient().isConnected()) if(getBluetoothClient().isConnected())
showBTicon(); showBTicon();
// WiFi // WiFi
@ -48,16 +47,19 @@ CScreenHeader::show()
showTime(_display); showTime(_display);
} }
// Animate IN/OUT arrows against the WiFi icon, according to actual web server traffic // Animate IN/OUT arrows against the WiFi icon, according to actual web server traffic:
// an IN arrow is drawn if incoming data has been detected // an IN (down) arrow is drawn if incoming data has been detected.
// an OUT arrow is drawn if outgoing data has been sent // an OUT (up) arrow is drawn if outgoing data has been sent.
// //
// Each arrow is drawn standalone, with a clear interval for a clean flash on the display // Each arrow is drawn for one animation interval with a minimum of one clear interval
// creating a clean flash on the display.
// Both arrows may appear in the same interval.
// The following is a typical sequence, relative to animation ticks, note the gap // The following is a typical sequence, relative to animation ticks, note the gap
// always appears in the animation interval between any arrow shown // that always appears in the animation interval between either arrow shown:
// //
// | | | | | | | | | | | | | | | | | | // | | | | | | | | | | | | | | | | |
// ________^^^^^^____vvvvv_______________vvvvv__________^^^^^_____vvvvv_____________________ // _________^^^^^________________________________________^^^^^_________________________
// ______________vvvvv_____vvvvv_______________vvvvv_____vvvvv_____vvvvv_______________
bool bool
CScreenHeader::animate() CScreenHeader::animate()
@ -68,36 +70,46 @@ CScreenHeader::animate()
#ifdef DEMO_AP_MODE #ifdef DEMO_AP_MODE
xPos += 4; xPos += 4;
#endif #endif
int yPos = H_WIFI_ICON - H_WIFIIN_ICON + 1; int yPos = 0;
// animation hold ensures our arrow indications always have a clear
// period between them, otherwise they just visibly mush together // OUT arrow animation
if(_animationHold) //
_animationHold--; // animation hold ensures our arrow indications are always erased in the next
// as we control (moderate) the delivery, check for any data we have sent first // period, otherwise they just mush together
// An over enthusiastic client would otherwise block the out arrow animation! if(_animationHold[0]) _animationHold[0]--;
if(!_animationHold && hasWebServerSpoken(true)) { if(!_animationHold[0] && hasWebServerSpoken(true)) {
// we have emitted data to the web client, show an OUT arrow // we have emitted data to the web client, show an OUT arrow
// _display.drawBitmap(xPos, yPos, wifiOutIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE); _display.drawBitmap(xPos, yPos, wifiOutIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE);
_display.drawBitmap(xPos, 0, wifiOutIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE); _needAnimationClear[0] = true; // clear arrow upon next iteration
_needAnimationClear = true; // clear arrow upon next iteration _animationHold[0] = 2; // prevent anotehr arrow appearing before previous arrow has been scrubbed
_animationHold = 2; // prevent anotehr arrow appearing before previous arrow has been scrubbed
retval = true; retval = true;
} }
else if(!_animationHold && hasWebClientSpoken(true)) { else if(_needAnimationClear[0]) { // an arrow was drawn in the prior iteration, now erase it
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
retval = true;
_needAnimationClear[0] = false;
}
// IN arrow animation
//
// animation hold ensures our arrow indications are always erased in the next
// period, otherwise they just mush together
yPos = H_WIFI_ICON - H_WIFIIN_ICON + 1;
if(_animationHold[1]) _animationHold[1]--;
if(!_animationHold[1] && hasWebClientSpoken(true)) {
// we have receievd data from the web client, show an IN arrow // we have receievd data from the web client, show an IN arrow
_display.drawBitmap(xPos, yPos, wifiInIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE); _display.drawBitmap(xPos, yPos, wifiInIcon, W_WIFIIN_ICON, H_WIFIIN_ICON, WHITE);
_needAnimationClear = true; // clear arrow upon next iteration _needAnimationClear[1] = true; // clear arrow upon next iteration
_animationHold = 2; // prevent another arrow appearing before previous arrow has been scrubbed _animationHold[1] = 2; // prevent another arrow appearing before previous arrow has been scrubbed
retval = true; retval = true;
} }
else if(_needAnimationClear) { // an arrow was drawn in the prior iteration, now erase it else if(_needAnimationClear[1]) { // an arrow was drawn in the prior iteration, now erase it
_display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK); _display.fillRect(xPos, yPos, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
_display.fillRect(xPos, 0, W_WIFIIN_ICON, H_WIFIIN_ICON, BLACK);
retval = true; retval = true;
_needAnimationClear = false; _needAnimationClear[1] = false;
} }
} }
return retval; // true if we have updated the display contents return retval; // true if we need to update the physical display
} }
void void

View file

@ -29,9 +29,8 @@
class CScreenHeader : public CScreen { class CScreenHeader : public CScreen {
int _animateState; int _animationHold[2]; // [0] out, [1] in
int _animationHold; bool _needAnimationClear[2];
bool _needAnimationClear;
protected: protected:
void showBTicon(); void showBTicon();
void showWifiIcon(); void showWifiIcon();