mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 07:07:49 +01:00
better lockscreen
This commit is contained in:
@@ -241,7 +241,7 @@ extern "C" void app_main() {
|
||||
system.registerApp(apps::createTetrisAppFactory());
|
||||
system.registerApp(apps::createGameboyAppFactory());
|
||||
|
||||
start_task_usage_monitor();
|
||||
// start_task_usage_monitor();
|
||||
|
||||
system.run();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@ namespace apps {
|
||||
namespace {
|
||||
|
||||
using cardboy::sdk::AppButtonEvent;
|
||||
using cardboy::sdk::AppTimeoutEvent;
|
||||
using cardboy::sdk::AppContext;
|
||||
using cardboy::sdk::AppTimeoutEvent;
|
||||
using cardboy::sdk::AppTimerEvent;
|
||||
|
||||
constexpr std::uint32_t kRefreshIntervalMs = 100;
|
||||
constexpr std::uint32_t kSlowRefreshMs = 1000;
|
||||
constexpr std::uint32_t kFastRefreshMs = 20;
|
||||
constexpr std::uint32_t kUnlockHoldMs = 1500;
|
||||
|
||||
using Framebuffer = typename AppContext::Framebuffer;
|
||||
@@ -60,12 +62,12 @@ public:
|
||||
holdProgressMs = 0;
|
||||
dirty = true;
|
||||
lastNotificationInteractionMs = clock.millis();
|
||||
lastRefreshMs = clock.millis();
|
||||
refreshNotifications();
|
||||
const auto snap = captureTime();
|
||||
renderIfNeeded(snap);
|
||||
lastSnapshot = snap;
|
||||
if (auto* timer = context.timer())
|
||||
refreshTimer = timer->scheduleTimer(kRefreshIntervalMs, true);
|
||||
rescheduleRefreshTimer(kSlowRefreshMs);
|
||||
}
|
||||
|
||||
void onStop() override { cancelRefreshTimer(); }
|
||||
@@ -74,7 +76,10 @@ public:
|
||||
event.visit(cardboy::sdk::overload([this](const AppButtonEvent& button) { handleButtonEvent(button); },
|
||||
[this](const AppTimerEvent& timer) {
|
||||
if (timer.handle == refreshTimer) {
|
||||
advanceHoldProgress();
|
||||
const std::uint32_t now = clock.millis();
|
||||
const std::uint32_t elapsed = now - lastRefreshMs;
|
||||
lastRefreshMs = now;
|
||||
advanceHoldProgress(elapsed);
|
||||
updateDisplay();
|
||||
}
|
||||
},
|
||||
@@ -99,6 +104,7 @@ private:
|
||||
bool holdActive = false;
|
||||
std::uint32_t holdProgressMs = 0;
|
||||
std::uint32_t lastNotificationInteractionMs = 0;
|
||||
std::uint32_t lastRefreshMs = 0;
|
||||
|
||||
void cancelRefreshTimer() {
|
||||
if (refreshTimer == cardboy::sdk::kInvalidAppTimer)
|
||||
@@ -108,6 +114,12 @@ private:
|
||||
refreshTimer = cardboy::sdk::kInvalidAppTimer;
|
||||
}
|
||||
|
||||
void rescheduleRefreshTimer(std::uint32_t intervalMs) {
|
||||
cancelRefreshTimer();
|
||||
if (auto* timer = context.timer())
|
||||
refreshTimer = timer->scheduleTimer(intervalMs, true);
|
||||
}
|
||||
|
||||
static bool comboPressed(const cardboy::sdk::InputState& state) { return state.a && state.select; }
|
||||
|
||||
void handleButtonEvent(const cardboy::sdk::AppButtonEvent& button) {
|
||||
@@ -193,10 +205,13 @@ private:
|
||||
}
|
||||
|
||||
void updateHoldState(bool comboNow) {
|
||||
const bool wasActive = holdActive;
|
||||
if (comboNow) {
|
||||
if (!holdActive) {
|
||||
holdActive = true;
|
||||
dirty = true;
|
||||
holdActive = true;
|
||||
holdProgressMs = 0;
|
||||
lastRefreshMs = clock.millis();
|
||||
dirty = true;
|
||||
}
|
||||
} else {
|
||||
if (holdActive || holdProgressMs != 0) {
|
||||
@@ -205,11 +220,14 @@ private:
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if (wasActive != holdActive) {
|
||||
rescheduleRefreshTimer(holdActive ? kFastRefreshMs : kSlowRefreshMs);
|
||||
}
|
||||
}
|
||||
|
||||
void advanceHoldProgress() {
|
||||
void advanceHoldProgress(std::uint32_t elapsedMs) {
|
||||
if (holdActive) {
|
||||
const std::uint32_t next = std::min<std::uint32_t>(holdProgressMs + kRefreshIntervalMs, kUnlockHoldMs);
|
||||
const std::uint32_t next = std::min<std::uint32_t>(holdProgressMs + elapsedMs, kUnlockHoldMs);
|
||||
if (next != holdProgressMs) {
|
||||
holdProgressMs = next;
|
||||
dirty = true;
|
||||
|
||||
Reference in New Issue
Block a user