Osetreni ovladani oled kdyz neni pouzite onoffoverlay.
This commit is contained in:
parent
19b1d3069e
commit
6d01e70592
@ -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()) {
|
||||
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,6 +311,7 @@ int OLEDUIPlus::extendOn(void)
|
||||
if (false == _displayon) {
|
||||
if (_oledon != nullptr)
|
||||
_oledon();
|
||||
if (_haveOnOffOverlay)
|
||||
startAnim(1);
|
||||
retval = 1; // musime rozsvitit displej
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user