Files
roro9stack/src/services/power_service.h
T
twislaandClaude Opus 5.5 de8af6ed92
CI / build (pull_request) Successful in 1m52s
Site / build (pull_request) Successful in 12s
Notes: edit a text file of any size (#47)
The editor held the whole note in memory and stopped at 16 KB. It now keeps
a window of the file around the cursor, and the rest on the card as a list
of pieces (notes::NoteDocument). Memory with a note open is what it was.

Up to 64 KB a save rewrites the file, as before. Above, the five-second
save appends what changed to <note>.edit, and the file is rewritten on
leaving the note, with a progress bar. After a power cut, opening the note
picks the edit up where it was saved; a rewrite cut short is finished or
dropped, never half applied.

Also: Ctrl with Fn+Up/Down go to the start and end of the note; the
consoles' `key` command takes ctrl-, alt- and shift-; the Storage App's
`e` no longer refuses a big file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-07 15:39:45 +02:00

46 lines
1.5 KiB
C++

#pragma once
#include <functional>
#include "power_policy.h"
#include "service.h"
#include "settings.h"
namespace roro {
// Screen dimming/off from user activity and G0 handling. A long G0 press powers off (deep sleep,
// woken by G0); Services stop with it.
class PowerService : public Service {
public:
explicit PowerService(const Settings& settings);
const char* name() const override { return "power"; }
uint32_t tickIntervalMs() const override { return 50; }
void start() override;
void tick(uint32_t nowMs) override;
// Call for every key press before routing it. Returns true if the key must not reach the App.
bool onKey(uint32_t nowMs) { return policy_.activity(nowMs); }
// A Toast is showing until untilMs: light an Off screen (dimmed) so it can be read.
void onNotification(uint32_t nowMs, uint32_t untilMs) { policy_.notify(nowMs, untilMs); }
ScreenState screen() const { return applied_; }
// Run before the device powers off: the last chance to put on the card what's only in memory.
std::function<void()> beforePowerOff;
bool poweringOff() const { return poweringOff_; } // from beforePowerOff on: no time for long work
private:
void applyScreen(ScreenState state);
void powerOff();
const Settings& settings_;
PowerPolicy policy_;
PowerButton button_{2000};
ScreenState applied_ = ScreenState::On;
int appliedBrightness_ = -1;
bool poweringOff_ = false;
};
} // namespace roro