Osetreni ovladani oled kdyz neni pouzite onoffoverlay.

This commit is contained in:
Pavel Brychta 2021-06-27 13:21:14 +02:00
parent 19b1d3069e
commit 6d01e70592
2 changed files with 89 additions and 67 deletions

View File

@ -24,68 +24,6 @@ static bool _displayon = false; // priznak, ze na OLED je videt zobrazeni (neni
static oledon _oledon = nullptr; static oledon _oledon = nullptr;
static oledoff _oledoff = 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) 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 OLEDUIPlus::loop(void)
{ {
bool result = false; bool result = false;
@ -200,7 +209,18 @@ bool OLEDUIPlus::loop(void)
// obsluha zhasinani displeje // obsluha zhasinani displeje
if (0 != _oledtimeout) { if (0 != _oledtimeout) {
if (_oledTiming.expired()) { 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 { } else {
@ -291,7 +311,8 @@ int OLEDUIPlus::extendOn(void)
if (false == _displayon) { if (false == _displayon) {
if (_oledon != nullptr) if (_oledon != nullptr)
_oledon(); _oledon();
startAnim(1); if (_haveOnOffOverlay)
startAnim(1);
retval = 1; // musime rozsvitit displej retval = 1; // musime rozsvitit displej
} }
} }

View File

@ -42,6 +42,8 @@ typedef struct {
const menuEntry_t *entries; const menuEntry_t *entries;
} menu_t; } menu_t;
void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state);
class OLEDUIPlus : public OLEDDisplayUi { class OLEDUIPlus : public OLEDDisplayUi {
public: public:
void goToMainFrame(void); void goToMainFrame(void);
@ -49,7 +51,7 @@ public:
void goToPrevFrame(void); void goToPrevFrame(void);
void begin(OLEDDisplay *display, kbdRead rKbd, uint32_t timeout, FrameCallback frames[], size_t framesCount, OverlayCallback overlays[], size_t overlaysCount); void begin(OLEDDisplay *display, kbdRead rKbd, uint32_t timeout, FrameCallback frames[], size_t framesCount, OverlayCallback overlays[], size_t overlaysCount);
void startAnim(int open); void startAnim(int open);
void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state); // void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state);
bool loop(void); bool loop(void);
void drawMenu(OLEDDisplay *display, const menu_t *menu, int *top, int *selected, int16_t x, int16_t y); void drawMenu(OLEDDisplay *display, const menu_t *menu, int *top, int *selected, int16_t x, int16_t y);
int handleKbd(void); int handleKbd(void);
@ -85,10 +87,9 @@ private:
FrameCallback* _frames; FrameCallback* _frames;
size_t _framesCount = 0; size_t _framesCount = 0;
uint8_t _mainFrame = 0xff; uint8_t _mainFrame = 0xff;
bool _haveOnOffOverlay = false; // priznak, ze mame startovaci a ukoncovaci animaci
}; };
void onOffOverlay(OLEDDisplay *display, OLEDDisplayUiState *state);
extern OLEDUIPlus ui; extern OLEDUIPlus ui;
#endif #endif