peacock README.md
7.2 kB 172 lines
Markdown
at main

peacock #

A glanceable RGB system monitor. peacock maps live CPU / GPU / NET / DISK activity onto a Neo-Tokyo neon palette on your ARGB fans, so at a single glance you read what kind of load the box is under (color) and how much (how many LEDs, how bright, how fast it pulses).

Built for the Airgoo AG-DRGB08 controller (USB 2486:3f08) driven directly over USB HID. No OpenRGB, no SignalRGB, no runtime beyond a static Rust binary.

At a glance #

You see It means
Color which subsystem (hue per metric)
How many LEDs magnitude of that subsystem's load
Brightness intensity (dim -> white-hot as it saturates)
Pulse speed event rate (frantic vs calm)

Four hues, interleaved across all three fans (each LED belongs to one metric by led_index % 4, so every fan shows all four colors):

Metric Color (base -> hot)
CPU magenta -> crimson
GPU cyan -> white-cyan
NET neon green -> acid
DISK amber -> molten

Unlit LEDs rest on a deep indigo idle floor so the case reads "off but alive." Past a metric's saturate_at threshold its lane shifts to the hot color and its pulse bottoms out into a fast alarm blink.

Build #

cargo build --release
# binary: target/release/peacock

Only dependency: libc. Needs a Linux box with /proc and (for the GPU lane) nvidia-smi on PATH; GPU falls back to idle if absent.

Device access #

The fans are daisy-chained on controller channel A4. The board is /dev/hidraw*. Grant access with a udev rule (one-time):

echo 'SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2486", ATTRS{idProduct}=="3f08", MODE="0666"' \
  | sudo tee /etc/udev/rules.d/99-airgoo-rgb.rules
sudo udevadm control --reload-rules && sudo udevadm trigger

The node auto-detects by VID:PID; override with --dev /dev/hidrawN.

Run #

./target/release/peacock live          # the system monitor (default mode)
./target/release/peacock metrics       # print sampled values only (headless check)
./target/release/peacock demo          # static representative load
./target/release/peacock test-hue      # light each metric lane in turn
./target/release/peacock test-sweep    # walk one LED along the chain
./target/release/peacock green         # hold solid green on the strip
PEACOCK_EQ_DEVICE=plughw:1,0 \
  ./target/release/peacock eq          # live audio equalizer (spectrum across the strip)
./target/release/peacock eq-demo       # synthetic tone sweep (no audio needed)

live samples every 250 ms and renders ~30 fps. It runs a keepalive thread that must stay alive the whole time: this board reverts to a dark onboard pattern ~500 ms after the last HID write, so the process must hold the device.

Equalizer mode #

eq taps an ALSA device and maps a 24-band log-spaced spectrum across the LED chain: bass lights the amber end (LED 0), treble the violet end (LED 23), each band's brightness tracking its energy with smoothing + a slow peak-hold. Set the device with PEACOCK_EQ_DEVICE (default default; e.g. a Jabra mic is plughw:1,0). eq-demo needs no audio: it sweeps a synthetic tone through the bands so the mapping can be checked (and runs identically headless).

Config #

peacock.toml (repo has a documented default). Resolved from --config PATH, else $XDG_CONFIG_HOME/peacock.toml, else ~/.config/peacock.toml, else ./peacock.toml, else built-in defaults.

Per-metric tunables (all optional):

Key Meaning
hue / sat the color (HSV); hue 0-360
hot_hue hue used once the metric saturates (overload color)
base_brightness 0..1 dimmer (also scales with load)
min_pulse_ms fastest breath (high event rate)
max_pulse_ms slowest breath (idle)
lane_len max LEDs this metric may light (magnitude ceiling)
saturate_at load fraction where hot-shift + alarm pulse start

A [global] section sets defaults; a [cpu]/[gpu]/[net]/[disk] section overrides.

Run as a service #

systemctl --user start peacock.service     # live monitor, restarts on failure
systemctl --user enable peacock.service    # start at boot (needs loginctl enable-linger)
journalctl --user -u peacock.service -f     # logs
systemctl --user stop peacock.service       # release the device

The equalizer runs as its own unit. Both units hold the one controller, so only one should be active at a time:

systemctl --user stop  peacock.service      # release the controller
systemctl --user start peacock-eq.service   # audio equalizer
# switch back: stop peacock-eq, start peacock

peacock-eq.service sets PEACOCK_EQ_DEVICE=default. On this machine's PipeWire that maps to the microphone, not a monitor of system playback (verified: sink .monitor sources were not ALSA-capturable here), so out of the box the equalizer reacts to mic sound. To visualize system playback, point the device at something that carries it. Test any candidate first:

arecord -q -D DEV -f S16_LE -r 48000 /dev/stdout | aplay -  # hear what DEV captures

Then set it via a drop-in: systemctl --user edit peacock-eq.service with [Service] / Environment=PEACOCK_EQ_DEVICE=DEV. On other setups a monitor source like pipewire or <sink>.monitor works directly.

Architecture #

src/device.rs   DRGB-V4 HID writer + keepalive (the whole reason OpenRGB fails here)
src/palette.rs  Neo-Tokyo hues, HSV, per-metric tunables
src/render.rs   activity+rate -> 24-LED frames (unit-tested)
src/spectrum.rs audio band-energy -> 24 spectrum lanes (unit-tested) + ALSA capture
src/metrics.rs  CPU/NET/DISK from /proc (EMA smoothing)
src/gpu.rs      GPU util via nvidia-smi
src/config.rs   tiny TOML reader (no deps)
src/main.rs     modes + live loop

Why not OpenRGB #

The AG-DRGB08 is OpenRGB-branded but its driver is broken for this board: the CLI drops per-zone writes (zones come up with 0 LEDs, and the board ignores any frame where a channel carries zero data), and the keepalive thread dies the instant a one-shot CLI call exits, so the board reverts to dark. peacock drives the HID protocol directly with a persistent keepalive and correct all-channel padding.

Tests #

cargo test --release   # render model (lane map, monotonicity, hot-shift, idle floor)
                       # + spectrum model (bass/treble band separation, silence, amplitude)

Status #

System monitor: complete, runs as a systemd user service. Audio-equalizer mode: built (band-energy spectrum, synthetic + live ALSA tap); DSP verified headless, LED pipeline + systemd unit verified on the real controller, and the live capture path confirmed end-to-end via PipeWire (arecord -D default streams). Note: on this PipeWire setup ALSA default captures the mic, not system playback; tap a real playback monitor source (or use eq-demo) for music-reactive visuals. Tuning lo_hz/hi_hz/smoothing is best done by eye in-session.