From 6d01e70592c70be1b862c9cd43bd67f51859f725 Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Sun, 27 Jun 2021 13:21:14 +0200 Subject: [PATCH] Osetreni ovladani oled kdyz neni pouzite onoffoverlay. --- src/OLEDUIPlus.cpp | 149 ++++++++++++++++++++++++++------------------- src/OLEDUIPlus.h | 7 ++- 2 files changed, 89 insertions(+), 67 deletions(-) diff --git a/src/OLEDUIPlus.cpp b/src/OLEDUIPlus.cpp index 475fb32..5e4d644 100644 --- a/src/OLEDUIPlus.cpp +++ b/src/OLEDUIPlus.cpp @@ -24,68 +24,6 @@ static bool _displayon = false; // priznak, ze na OLED je videt zobrazeni (neni static oledon _oledon = nullptr; static oledoff _oledoff = nullptr; -void OLEDUIPlus::goToFrame(uint8_t frame) -{ - - _frameptr++; - _frameptr %= sizeof(_frameseq); - _frameseq[_frameptr] = frame; - transitionToFrame(frame); // aktivujeme spravnou obrazovku -} - -void OLEDUIPlus::goToPrevFrame(void) -{ - - _frameptr--; - _frameptr %= sizeof(_frameseq); - transitionToFrame(_frameseq[_frameptr]); // aktivujeme predchozi obrazovku -} - -void OLEDUIPlus::begin(OLEDDisplay *display, kbdRead rKbd, uint32_t timeout, FrameCallback frames[], size_t framesCount, OverlayCallback overlays[], size_t overlaysCount) -{ - - _kbd = rKbd; - _oled = display; - _frames = frames; - _framesCount = framesCount; - _displayon = true; - setTargetFPS(30); - setFrameAnimation(SLIDE_UP); - setFrames(frames, framesCount); - setOverlays(overlays, overlaysCount); - disableAutoTransition(); - disableAllIndicators(); - init(display); - startAnim(1); - _oledtimeout = timeout; - if (0 != _oledtimeout) - _oledTiming.setOneshot(_oledtimeout); -} - -// Spusteni rozsvecovaci/zhasinaci animace -void OLEDUIPlus::startAnim(int open) -{ - - if (0 != open) { - _anim.closing = false; - _anim.doingLine = true; - _anim.height = _oled->height() / 2; - _anim.lineClosing = false; - _anim.lineWidth = 0; -#if defined(OLED_REAL_OFF) - _oled->displayOn(); -#endif - _displayon = true; - } else { - _anim.closing = true; - _anim.doingLine = false; - _anim.height = 0; - _anim.lineClosing = true; - _anim.lineWidth = _oled->width(); - } - _anim.active = true; -} - void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state) { @@ -178,6 +116,77 @@ void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state) } } +void OLEDUIPlus::goToFrame(uint8_t frame) +{ + + _frameptr++; + _frameptr %= sizeof(_frameseq); + _frameseq[_frameptr] = frame; + transitionToFrame(frame); // aktivujeme spravnou obrazovku +} + +void OLEDUIPlus::goToPrevFrame(void) +{ + + _frameptr--; + _frameptr %= sizeof(_frameseq); + transitionToFrame(_frameseq[_frameptr]); // aktivujeme predchozi obrazovku +} + +void OLEDUIPlus::begin(OLEDDisplay *display, kbdRead rKbd, uint32_t timeout, FrameCallback frames[], size_t framesCount, OverlayCallback overlays[], size_t overlaysCount) +{ + int i; + _kbd = rKbd; + _oled = display; + _frames = frames; + _framesCount = framesCount; + _displayon = true; + setTargetFPS(30); + setFrameAnimation(SLIDE_UP); + setFrames(frames, framesCount); + setOverlays(overlays, overlaysCount); + i = 0; + while (i < overlaysCount) { + if (overlays[i] == onOffOverlay) { + _haveOnOffOverlay = true; + break; + } + i++; + } + disableAutoTransition(); + disableAllIndicators(); + init(display); + if (_haveOnOffOverlay) + startAnim(1); + _oledtimeout = timeout; + if (0 != _oledtimeout) + _oledTiming.setOneshot(_oledtimeout); +} + +// Spusteni rozsvecovaci/zhasinaci animace +void OLEDUIPlus::startAnim(int open) +{ + + if (0 != open) { + _anim.closing = false; + _anim.doingLine = true; + _anim.height = _oled->height() / 2; + _anim.lineClosing = false; + _anim.lineWidth = 0; +#if defined(OLED_REAL_OFF) + _oled->displayOn(); +#endif + _displayon = true; + } else { + _anim.closing = true; + _anim.doingLine = false; + _anim.height = 0; + _anim.lineClosing = true; + _anim.lineWidth = _oled->width(); + } + _anim.active = true; +} + bool OLEDUIPlus::loop(void) { bool result = false; @@ -200,7 +209,18 @@ bool OLEDUIPlus::loop(void) // obsluha zhasinani displeje if (0 != _oledtimeout) { if (_oledTiming.expired()) { - startAnim(0); + if (_haveOnOffOverlay) { + startAnim(0); + } else { + _oled->clear(); + _oled->display(); +#if defined(OLED_REAL_OFF) + _oled->displayOff(); +#endif + if (_oledoff != nullptr) + _oledoff(); + _displayon = false; + } } } } else { @@ -291,7 +311,8 @@ int OLEDUIPlus::extendOn(void) if (false == _displayon) { if (_oledon != nullptr) _oledon(); - startAnim(1); + if (_haveOnOffOverlay) + startAnim(1); retval = 1; // musime rozsvitit displej } } diff --git a/src/OLEDUIPlus.h b/src/OLEDUIPlus.h index 2ef6d49..ece420d 100644 --- a/src/OLEDUIPlus.h +++ b/src/OLEDUIPlus.h @@ -42,6 +42,8 @@ typedef struct { const menuEntry_t *entries; } menu_t; +void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state); + class OLEDUIPlus : public OLEDDisplayUi { public: void goToMainFrame(void); @@ -49,7 +51,7 @@ public: void goToPrevFrame(void); void begin(OLEDDisplay *display, kbdRead rKbd, uint32_t timeout, FrameCallback frames[], size_t framesCount, OverlayCallback overlays[], size_t overlaysCount); void startAnim(int open); - void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state); +// void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state); bool loop(void); void drawMenu(OLEDDisplay *display, const menu_t *menu, int *top, int *selected, int16_t x, int16_t y); int handleKbd(void); @@ -85,10 +87,9 @@ private: FrameCallback* _frames; size_t _framesCount = 0; uint8_t _mainFrame = 0xff; + bool _haveOnOffOverlay = false; // priznak, ze mame startovaci a ukoncovaci animaci }; -void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state); - extern OLEDUIPlus ui; #endif