better lockscreen

This commit is contained in:
2025-10-25 14:28:58 +02:00
parent 278e822600
commit 9b5521fc28
2 changed files with 27 additions and 9 deletions

View File

@@ -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();
}

View File

@@ -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,9 +205,12 @@ private:
}
void updateHoldState(bool comboNow) {
const bool wasActive = holdActive;
if (comboNow) {
if (!holdActive) {
holdActive = true;
holdProgressMs = 0;
lastRefreshMs = clock.millis();
dirty = true;
}
} else {
@@ -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;