Commit 6477e0e
committed
Combined: Windows daemon + Activity backport + multi-session fixes
Branches three open PRs into one working stack on a Windows host with the
480x480 Waveshare AMOLED-2.16:
- Base: PR HermannBjorgvin#26 (dilbery's USB CDC transport)
- Plus daemon: cross-platform port + Windows hook-compat
- Plus feature: PR HermannBjorgvin#22 (tobby168's Activity screen / Claude Code hooks)
- Plus 3 fixes: firmware buffers + parse for multi-session payloads
Windows daemon port (vs PR HermannBjorgvin#26)
-------------------------------
daemon/claude_usage_daemon.py:
- find_port() on win32 uses pyserial list_ports filtered by USB VID
(303A Espressif, 10C4 SiLabs, 1A86 WCH, 0403 FTDI). Locale-independent —
works on non-English Windows where caption strings are translated.
- termios import + HUPCL clear gated to sys.platform != "win32".
- write_payload uses ensure_ascii=False so UTF-8 stays raw (em-dashes etc
are 3 bytes instead of 6-byte \uXXXX escapes; smaller payloads, less
pressure on ArduinoJson on the firmware side).
daemon/clawdmeter_hook.py (from PR HermannBjorgvin#22):
- fcntl is Unix-only; replace with msvcrt.locking on win32.
daemon/install_hooks_win.py (new):
- Windows analogue of install-mac.sh's inline-Python hook registration.
Backs up settings.json before writing, idempotent.
Windows host scripts (from PR HermannBjorgvin#23): flash-win.ps1, install-win.ps1,
setup-win.ps1, uninstall-win.ps1, daemon/run-daemon.ps1. Brought along so
this branch is buildable + installable on Windows without cherry-picking.
Activity backport on USB CDC (vs PR HermannBjorgvin#22)
----------------------------------------
firmware/src/data.h: PR HermannBjorgvin#22 ActivityData / SessionData / TodoItem structs.
firmware/src/ui.h: +SCREEN_ACTIVITY enum + ui_update_activity() API.
firmware/src/ui.cpp: PR HermannBjorgvin#22 init_activity_screen / render_activity /
activity_gesture_cb / ui_update_activity grafted onto
PR HermannBjorgvin#26's ui.cpp; cycle order Splash > Usage > Link >
Activity > Usage.
firmware/src/main.cpp: parse_json gets optional ActivityData* out-param;
sessions / todos extracted into the struct;
ui_update_activity() called after each successful parse.
daemon/claude_usage_daemon.py:
- load_activity_sessions() + state_file_mtime() from PR HermannBjorgvin#22.
- Main loop tracks last_state_mtime; payload includes "sessions" whenever
the file changes OR a fresh API poll happens.
Three firmware fixes needed for multi-session payloads
------------------------------------------------------
Real-world payloads with 2 sessions x 5-10 todos each routinely hit
700-1000 bytes — well past anything PR HermannBjorgvin#26's defaults handled.
1. firmware/src/serial_link.cpp: LINE_BUF_SIZE / DATA_BUF_SIZE 192 -> 4096.
192 was tuned for the ~120-byte Usage-only payload; longer lines were
silently dropped at the line-accumulator level.
2. firmware/src/main.cpp: Serial.setRxBufferSize(4096) before Serial.begin.
USB-CDC RX defaults to ~256 bytes; a 798-byte payload arrived as
strlen=317 on the firmware side (truncated at receive). Bumping the
buffer is the actual fix (CFG_TUD_CDC_RX_BUFSIZE redefine is ignored
because Arduino-ESP32 overrides it via CONFIG_TINYUSB_CDC_RX_BUFSIZE).
3. firmware/src/main.cpp: parse_json is two-pass.
- Pass 1 is a Filter()'d deserialization that only extracts the Usage
scalars (s/sr/w/wr/st/ok). A tiny doc, always succeeds.
- Pass 2 is a best-effort full parse for the "sessions" array. If it
fails (oversized, mid-line truncation, unicode oddity) we leave
ActivityData empty but still ACK the payload upstream — Usage stays
intact, Activity falls back to its empty render state.
Tested
------
Waveshare ESP32-S3-Touch-AMOLED-2.16 on Windows 10 (Dutch locale, Realtek
BT 5.1 adapter unused, USB-C only). Two parallel Claude Code sessions on
the same host:
- 11+ todos across two sessions, ~1KB payload, ACK'd reliably.
- Activity screen renders project name, in-progress todo activeForm,
counter coloured by phase, todo list windowed around the in-progress
item. PWR cycles Usage <-> Link <-> Activity.
- state.json updates on every PreToolUse/PostToolUse/UserPromptSubmit/
Stop/SessionStart; daemon picks it up on its 5s tick.1 parent 04a6b68 commit 6477e0e
14 files changed
Lines changed: 1652 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
40 | 63 | | |
41 | 64 | | |
42 | 65 | | |
| |||
130 | 153 | | |
131 | 154 | | |
132 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
133 | 226 | | |
134 | | - | |
135 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
136 | 242 | | |
137 | 243 | | |
138 | 244 | | |
| |||
141 | 247 | | |
142 | 248 | | |
143 | 249 | | |
144 | | - | |
| 250 | + | |
145 | 251 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
150 | 257 | | |
151 | 258 | | |
152 | 259 | | |
| |||
157 | 264 | | |
158 | 265 | | |
159 | 266 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
168 | 276 | | |
169 | 277 | | |
170 | 278 | | |
| |||
236 | 344 | | |
237 | 345 | | |
238 | 346 | | |
239 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
240 | 354 | | |
241 | 355 | | |
242 | 356 | | |
| |||
262 | 376 | | |
263 | 377 | | |
264 | 378 | | |
| 379 | + | |
| 380 | + | |
265 | 381 | | |
266 | 382 | | |
267 | 383 | | |
268 | 384 | | |
269 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
270 | 394 | | |
271 | 395 | | |
272 | 396 | | |
273 | 397 | | |
274 | 398 | | |
275 | | - | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
276 | 420 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
287 | 425 | | |
288 | 426 | | |
289 | 427 | | |
| |||
0 commit comments