Skip to content

fix: plasmactl checks for FIFO before writing - #22

Open
iksaif wants to merge 8 commits into
pimoroni:masterfrom
iksaif:fix/plasma-fifo-safety
Open

fix: plasmactl checks for FIFO before writing#22
iksaif wants to merge 8 commits into
pimoroni:masterfrom
iksaif:fix/plasma-fifo-safety

Conversation

@iksaif

@iksaif iksaif commented Aug 22, 2026

Copy link
Copy Markdown

fix: plasmactl checks for FIFO before writing

Stacked PR 3 of 3 — builds on top of #21.
Review in order: #20#21#22.

plasmactl used open(filename, 'wb') which creates a regular file if /tmp/plasma doesn't exist as a FIFO (e.g. the daemon is down). This prevents the daemon from receiving commands on next start because os.mkfifo silently fails when a regular file already exists.

Changes

  • plasmactl: Check stat.S_ISFIFO before opening — rejects regular files and missing paths with a clear error message
  • daemon: If os.mkfifo fails and a stale non-FIFO file exists, remove it and retry instead of silently ignoring
  • systemd: Add ExecStop to send off command before shutdown so LEDs turn off cleanly
  • Bug fix: Correct needs_update logic so static colour changes actually reach the LEDs and per-pixel overrides don't fire every frame (regression introduced in an earlier version of this PR)

Tests

6 new unit tests covering open_fifo rejects regular files / missing files / accepts real FIFOs, daemon removes stale non-FIFO file, daemon preserves existing FIFO, and daemon creates new FIFO. All pass alongside the existing test suite.

Includes from #20 and #21

All performance optimizations, per-pixel control, named colors, and pattern caching from the stacked PRs below.

iksaif added 2 commits August 25, 2026 14:18
- Skip redundant plasma.show() calls when color/brightness hasn't
  changed (solid colors now only update once instead of every frame)
- Skip pattern re-rendering when the animation row hasn't advanced
- Replace FIFO readline busy-wait (time.time() polling loop) with
  select.select() for proper blocking I/O
- Cache loaded PNG patterns instead of re-parsing on every switch
Clearing the flag inside the set_all() branch meant the buffer was
written but never latched to the hardware, so solid colours never
displayed. Patterns were unaffected because that branch leaves the
flag set.
@iksaif
iksaif force-pushed the fix/plasma-fifo-safety branch from 2d98fe8 to 9a6eb5d Compare August 25, 2026 12:21
iksaif added 4 commits August 25, 2026 14:58
Tests cover:
- FIFO.readline uses select.select for blocking I/O
- Pattern caching avoids re-reading from disk
- needs_update flag ensures show() only fires on state changes
- Static color: show() called once, not every frame
- Color/brightness changes trigger show()
- FPS clamped to minimum 1
Add pipe protocol for external apps to control individual LEDs:
- set <index> <r> <g> <b> / set <index> <color> — set a single pixel
- unset <index> — clear a per-pixel override
- clear — clear all per-pixel overrides
- off — turn all LEDs off
- <color_name> — set all LEDs to a named color

Named colors: off, black, white, red, green, blue, yellow, cyan,
purple, magenta, orange, dim_white. Hex colors (#ff0000) also supported.

plasmactl gains --set, --unset, --clear, --off, --color (alias for --colour).
Tests cover:
- parse_color: named colors, hex colors, integer colors, invalid inputs
- Per-pixel overrides: set, unset, clear, off, out-of-range indices
- plasmactl: NAMED_COLORS, Color function, send writes to FIFO
- Check stat.S_ISFIFO before opening in plasmactl
- Remove stale non-FIFO file before mkfifo in daemon
- Add ExecStop to systemd service to turn LEDs off on shutdown
- Fix needs_update logic for static colors and per-pixel overrides
@iksaif
iksaif force-pushed the fix/plasma-fifo-safety branch from 9a6eb5d to 5554b27 Compare August 25, 2026 13:14
Tests cover:
- plasmactl open_fifo rejects regular files and missing files
- plasmactl open_fifo accepts real FIFOs
- daemon FIFO removes stale non-FIFO file before mkfifo
- daemon FIFO preserves existing FIFO (does not remove)
- daemon FIFO creates new FIFO when no file exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant