Files
roro9stack/src/services/power_service.h
T
twislaandClaude Opus 5.5 e8a654a15f Notes: plain text notes on the SD card, with an editor that saves by itself (#19)
The Notes App lists the files of /notes by their first line, newest first:
n starts a note, Enter opens it, r renames its file, d deletes it after
asking, s sorts by name. A new note's file is named after its first line.

The editor wraps at spaces, 38 columns by 8 rows; Fn+arrows move through
the wrapped text, Ctrl+A and Ctrl+E go to the ends of the line. There is no
save key: the note is written five seconds after the last key, on Back, on
leaving the App, when the screen turns off and before the device powers
off. A save writes a temporary file and puts it in the note's place; a save
cut short is put back, or offered, the next time.

A note is up to 16 KB, held in one buffer reserved when it's opened: the
file is read straight into it and typing never makes it grow. A failed
allocation aborts on this device, and with IRC connected the largest free
block is about 31 KB: a first version that copied the note once on loading
restarted the device when a full note was opened with IRC connected.
Editing files of any size is #47.

The Storage App's text viewer gets `e`, which edits a text file up to 16 KB
with the same editor unless the file is read-only.

439 host tests. Checked on the device: docs/milestones/F1.md.

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

44 lines
1.3 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;
private:
void applyScreen(ScreenState state);
void powerOff();
const Settings& settings_;
PowerPolicy policy_;
PowerButton button_{2000};
ScreenState applied_ = ScreenState::On;
int appliedBrightness_ = -1;
};
} // namespace roro