BlinkState

BlinkState represents two discrete states: visible and hidden. The application only needs to query isVisible() while drawing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "blink/BlinkState.h"

class CursorApp final : public IApplication {
public:
CursorApp(PixelUI& ui, void*)
: ui_(ui), cursorBlink_(ui, 500U) {}

void onEnter(ExitCallback cb) override {
IApplication::onEnter(cb);
cursorBlink_.start();
}

void draw() override {
if (cursorBlink_.isVisible()) {
ui_.getU8G2().drawBox(10, 20, 6, 2);
}
}

bool handleInput(InputEvent event) override {
if (event == InputEvent::BACK) {
requestExit();
return true;
}
return false;
}

void onExit() override {
cursorBlink_.stop();
}

private:
PixelUI& ui_;
BlinkState cursorBlink_;
};

API

  • start() begins blinking in the visible phase; repeated calls do not restart the timer.
  • stop() stops immediately and switches to hidden.
  • stopWhenVisible() waits for the next visible phase before stopping when currently hidden; when already visible, it stops immediately and remains visible.
  • setInterval(ms) changes the toggle interval. While running, it restarts timing from the current time.
  • isVisible() and isRunning() are read-only state queries.
  • interval() returns the normalized effective interval.

The interval is clamped to 1..INT32_MAX milliseconds. This excludes a zero interval and keeps deadline comparison using 32-bit unsigned timestamps unambiguous across wraparound.

Scheduling and lifetime

BlinkState automatically registers with UiDeadlineScheduler during construction. PixelUI marks the UI dirty only when the deadline is reached and visibility actually changes, so no manual update() or continuous drawing is required. Tickless mode can sleep directly until the next toggle.

The object unregisters from the scheduler during destruction. Because it stores a reference to its PixelUI, a BlinkState must not outlive that PixelUI. Making it an App or Widget member is normally the most natural choice.

Use the animation system when coordinates or other values must change continuously. BlinkState only handles discrete show/hide state.

最新文章
网站信息
文章数目 :
1
本站访客数 :
本站总浏览量 :
最后更新时间 :