Make 2720 Flip lid switching instant and route closed-flip events to the cover

The lid daemon re-derived "observed" from a stale EV_SW mask on every 100 ms
iteration and only read the raw hall lines every 200 ms, so the candidate
oscillated and the 80 ms debounce almost never completed. A controlled hall
transition on the live phone took over 2.2 s to blank and lock the main panel.
The hall reading is now sticky, every EV_SW edge forces an immediate hall
re-read, the loop and debounce are 20 ms, and the daemon writes the lid state,
lock flag, Sxmo state and both backlights synchronously in C before spawning
hooks. A direct xset DPMS off/on stops or resumes Xorg's SPI flushes at once.
bananarchy-lid-state.sh guards the asynchronous hooks by lid state and a
transition generation counter, so a late screenoff cannot re-lock a flip that
was just opened.

bananarchy-lid-gate.sh now gates sxmo_wm.sh display on, the screen-wake
helper, the backlight udev helper, sxmo_state.sh set unlock (dwm calls it
directly) and both input handler copies. While the flip is closed it blocks
the main panel and keypad backlight, forces brightness/kbd/DPMS off against
stray writes, and forwards a WAKE datagram to the cover display. Ring,
notification and call-state hooks publish to the cover, and the cover daemon
gained WAKE, event wakes, immunity to repeated LID CLOSED rebroadcasts and a
bounded retry for a DPMS-deferred draw.

Live verification with controlled hall transitions and uinput switch/key
injection: close blanks and locks in ~45-90 ms (hall-poll fallback
~100-220 ms), open restores brightness, keypad backlight, unlock and DPMS in
~10-130 ms with no stale-hook re-lock. All three external keys and an
incoming call leave brightness=0, kbd_backlight=0 and DPMS=Off while the
cover reports backend=spidev visible=1; opening returns mux=open.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
0f33aa6e9fc70022574b453aaafb9307c4d185431d3be272782c8403dd0fb291 in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms
twelve updated rootfs files byte-for-byte, and the bootfs sync, boot image
check, artifact sync, host tests and rebuild preflight all pass.

This is an intermediate checkpoint: eyes-on cover illumination and the
remaining polarity/CS fixes are still required.
This commit is contained in:
Luxferre committed 2026-11-10 20:23:06 +02:00
1 parent 40a840b49b
commit 2857ef4374
29 files changed
+567 -49

No files matched your search

+42 -10
View File
@@ -1046,6 +1046,18 @@ static int test_value(const char *mode)
return 0;
}
/* A closed flip lights the outer panel only. Status updates (NETWORK,
* BATTERY) refresh an already visible cover but never wake it; real events
* (BUTTON, WAKE, CALL, NOTIFY, SMS) do. */
static void cover_wake(struct state *state, int *redraw)
{
if(strcmp(state->lid, "closed") == 0 && state->enabled && !state->test) {
state->visible = 1;
state->last_input_ms = now_ms();
*redraw = 1;
}
}
static void handle_command(char *buffer, struct state *state,
struct cover_hw *hw, int *redraw)
{
@@ -1058,19 +1070,23 @@ static void handle_command(char *buffer, struct state *state,
upper_string(command);
if(strcmp(command, "LID") == 0) {
char *value = strtok_r(NULL, " \t\r\n", &save);
int new_closed = value && strcasecmp(value, "CLOSED") == 0;
int old_closed = strcmp(state->lid, "closed") == 0;
safe_copy(state->lid, sizeof(state->lid),
value && strcasecmp(value, "CLOSED") == 0 ? "closed" : "open");
/* An open flip is always fully off; a closed flip waits for a button. */
state->visible = 0;
state->last_input_ms = now_ms();
*redraw = 1;
} else if(strcmp(command, "BUTTON") == 0) {
/* Trusted external side-button event from bananarchy-volume-keys. */
if(strcmp(state->lid, "closed") == 0 && state->enabled && !state->test) {
state->visible = 1;
new_closed ? "closed" : "open");
/* The lid daemon rebroadcasts its state every 2 s. Only a real
* transition blanks the cover; a repeating LID CLOSED must not undo a
* WAKE from an incoming call or an external side button. */
if(new_closed != old_closed) {
state->visible = 0;
state->last_input_ms = now_ms();
*redraw = 1;
}
} else if(strcmp(command, "BUTTON") == 0 ||
strcmp(command, "WAKE") == 0) {
/* Trusted external side button, or a main-panel wake request that the
* closed-lid gate forwarded to the cover display. */
cover_wake(state, redraw);
} else if(strcmp(command, "NETWORK") == 0) {
char *rest = save;
while(rest && (*rest == ' ' || *rest == '\t'))
@@ -1085,6 +1101,7 @@ static void handle_command(char *buffer, struct state *state,
rest++;
safe_copy(state->message, sizeof(state->message), rest ? rest : "");
trim(state->message);
cover_wake(state, redraw);
if(state->visible)
*redraw = 1;
} else if(strcmp(command, "CALL") == 0) {
@@ -1092,11 +1109,14 @@ static void handle_command(char *buffer, struct state *state,
if(value) {
safe_copy(state->call, sizeof(state->call), value);
lower_string(state->call);
if(strcmp(state->call, "none") != 0)
cover_wake(state, redraw);
}
} else if(strcmp(command, "SMS") == 0) {
char *value = strtok_r(NULL, " \t\r\n", &save);
if(value)
state->sms = (int)strtol(value, NULL, 10);
cover_wake(state, redraw);
} else if(strcmp(command, "BATTERY") == 0) {
char *value = strtok_r(NULL, " \t\r\n", &save);
if(value)
@@ -1201,6 +1221,7 @@ int main(int argc, char **argv)
struct state state;
struct cover_hw hw;
long long last_draw = 0;
long long pending_until = 0;
int redraw = 1;
if(lock_fd < 0)
return 1;
@@ -1263,13 +1284,24 @@ int main(int argc, char **argv)
set_backlight(&state, cover_is_lit(&state));
snprintf(state.backend, sizeof(state.backend), "%s",
cover_draw(&hw, fb_path, &state));
/* The lid daemon forces DPMS off asynchronously. Retry a pending draw
* for a bounded window so the cover lights even if the first draw ran
* before Xorg stopped flushing the main panel. */
pending_until = strcmp(state.backend, "pending") == 0 ?
now + 3000 : 0;
last_draw = now;
redraw = 0;
}
if(pending_until > now)
timeout_ms = 50;
pfd.fd = server;
pfd.events = POLLIN;
pfd.revents = 0;
if(poll(&pfd, 1, timeout_ms) > 0 && (pfd.revents & POLLIN)) {
if(poll(&pfd, 1, timeout_ms) == 0 && pending_until > now &&
strcmp(state.backend, "pending") == 0) {
redraw = 1;
}
if(pfd.revents & POLLIN) {
nread = recvfrom(server, buffer, sizeof(buffer) - 1, 0,
(struct sockaddr *)&peer, &peer_len);
if(nread > 0) {