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::createTetrisAppFactory());
system.registerApp(apps::createGameboyAppFactory()); system.registerApp(apps::createGameboyAppFactory());
start_task_usage_monitor(); // start_task_usage_monitor();
system.run(); system.run();
} }

View File

@@ -18,11 +18,13 @@ namespace apps {
namespace { namespace {
using cardboy::sdk::AppButtonEvent; using cardboy::sdk::AppButtonEvent;
using cardboy::sdk::AppTimeoutEvent;
using cardboy::sdk::AppContext; using cardboy::sdk::AppContext;
using cardboy::sdk::AppTimeoutEvent;
using cardboy::sdk::AppTimerEvent; using cardboy::sdk::AppTimerEvent;
constexpr std::uint32_t kRefreshIntervalMs = 100; constexpr std::uint32_t kRefreshIntervalMs = 100;
constexpr std::uint32_t kSlowRefreshMs = 1000;
constexpr std::uint32_t kFastRefreshMs = 20;
constexpr std::uint32_t kUnlockHoldMs = 1500; constexpr std::uint32_t kUnlockHoldMs = 1500;
using Framebuffer = typename AppContext::Framebuffer; using Framebuffer = typename AppContext::Framebuffer;
@@ -60,12 +62,12 @@ public:
holdProgressMs = 0; holdProgressMs = 0;
dirty = true; dirty = true;
lastNotificationInteractionMs = clock.millis(); lastNotificationInteractionMs = clock.millis();
lastRefreshMs = clock.millis();
refreshNotifications(); refreshNotifications();
const auto snap = captureTime(); const auto snap = captureTime();
renderIfNeeded(snap); renderIfNeeded(snap);
lastSnapshot = snap; lastSnapshot = snap;
if (auto* timer = context.timer()) rescheduleRefreshTimer(kSlowRefreshMs);
refreshTimer = timer->scheduleTimer(kRefreshIntervalMs, true);
} }
void onStop() override { cancelRefreshTimer(); } void onStop() override { cancelRefreshTimer(); }
@@ -74,7 +76,10 @@ public:
event.visit(cardboy::sdk::overload([this](const AppButtonEvent& button) { handleButtonEvent(button); }, event.visit(cardboy::sdk::overload([this](const AppButtonEvent& button) { handleButtonEvent(button); },
[this](const AppTimerEvent& timer) { [this](const AppTimerEvent& timer) {
if (timer.handle == refreshTimer) { if (timer.handle == refreshTimer) {
advanceHoldProgress(); const std::uint32_t now = clock.millis();
const std::uint32_t elapsed = now - lastRefreshMs;
lastRefreshMs = now;
advanceHoldProgress(elapsed);
updateDisplay(); updateDisplay();
} }
}, },
@@ -99,6 +104,7 @@ private:
bool holdActive = false; bool holdActive = false;
std::uint32_t holdProgressMs = 0; std::uint32_t holdProgressMs = 0;
std::uint32_t lastNotificationInteractionMs = 0; std::uint32_t lastNotificationInteractionMs = 0;
std::uint32_t lastRefreshMs = 0;
void cancelRefreshTimer() { void cancelRefreshTimer() {
if (refreshTimer == cardboy::sdk::kInvalidAppTimer) if (refreshTimer == cardboy::sdk::kInvalidAppTimer)
@@ -108,6 +114,12 @@ private:
refreshTimer = cardboy::sdk::kInvalidAppTimer; 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; } static bool comboPressed(const cardboy::sdk::InputState& state) { return state.a && state.select; }
void handleButtonEvent(const cardboy::sdk::AppButtonEvent& button) { void handleButtonEvent(const cardboy::sdk::AppButtonEvent& button) {
@@ -193,10 +205,13 @@ private:
} }
void updateHoldState(bool comboNow) { void updateHoldState(bool comboNow) {
const bool wasActive = holdActive;
if (comboNow) { if (comboNow) {
if (!holdActive) { if (!holdActive) {
holdActive = true; holdActive = true;
dirty = true; holdProgressMs = 0;
lastRefreshMs = clock.millis();
dirty = true;
} }
} else { } else {
if (holdActive || holdProgressMs != 0) { if (holdActive || holdProgressMs != 0) {
@@ -205,11 +220,14 @@ private:
dirty = true; dirty = true;
} }
} }
if (wasActive != holdActive) {
rescheduleRefreshTimer(holdActive ? kFastRefreshMs : kSlowRefreshMs);
}
} }
void advanceHoldProgress() { void advanceHoldProgress(std::uint32_t elapsedMs) {
if (holdActive) { 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) { if (next != holdProgressMs) {
holdProgressMs = next; holdProgressMs = next;
dirty = true; dirty = true;