From 44cfb84a5ff31cd304f9d8511d527845672befa5 Mon Sep 17 00:00:00 2001 From: Fernando Crespo Date: Fri, 30 Jan 2026 16:59:42 -0300 Subject: [PATCH] Add installation script, default state file, and update README for Acer RGB control --- .gitignore | 3 +- Makefile | 6 ++++ README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ acer-rgb | 18 ++++++++++++ acer-rgbd.cpp | 4 +++ state.default | 3 ++ 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100755 acer-rgb create mode 100644 state.default diff --git a/.gitignore b/.gitignore index cca3c53..1aebf5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ rgb -acer-rgb-cli \ No newline at end of file +acer-rgb-cli +acer-rgbd \ No newline at end of file diff --git a/Makefile b/Makefile index 4d399fd..4dd5ea8 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,12 @@ install: acer-rgbd acer-rgb sudo install -Dm755 acer-rgb.sh /usr/local/bin/acer-rgb sudo install -Dm644 acer-rgbd.service /etc/systemd/system/acer-rgbd.service sudo install -Dm644 acer-rgbd.socket /etc/systemd/system/acer-rgbd.socket + # install default state only if it doesn't already exist + @if [ ! -f /var/lib/acer-rgbd/state.txt ]; then \ + sudo install -Dm644 state.default /var/lib/acer-rgbd/state.txt; \ + else \ + echo "/var/lib/acer-rgbd/state.txt already exists — leaving it in place"; \ + fi sudo systemctl daemon-reload sudo systemctl enable --now acer-rgbd.service diff --git a/README.md b/README.md new file mode 100644 index 0000000..e82cfe8 --- /dev/null +++ b/README.md @@ -0,0 +1,80 @@ +# acer-lighting + +Small tools to control Acer laptop RGB zones and a daemon that persists/apply states. + +## Build + +- Build the daemon only: + +```sh +make acer-rgbd +``` + +- Build the CLI (used for manual commands and test targets): + +```sh +make acer-rgb-cli +``` + +Or build everything with: + +```sh +make build +``` + +## Install + +Install the daemon, helper script and systemd units: + +```sh +sudo make install +``` + +The `install` target will: +- Copy `acer-rgbd` to `/usr/local/bin/acer-rgbd` and `acer-rgb` to `/usr/local/bin/acer-rgb`. +- Install systemd unit and socket under `/etc/systemd/system/` and enable/start the service. +- Create `/var/lib/acer-rgbd/state.txt` with an initial "all green" state so the daemon applies green on first start. + +If you need to undo the install: + +```sh +sudo make uninstall +``` + +## Usage + +- Send commands to the daemon using the `acer-rgb` helper (it talks to the daemon socket): + +```sh +acer-rgb SET dev=keyboard hidraw=/dev/hidraw2 effect=static bright=100 r=0 g=255 b=0 zone=all +acer-rgb GET +``` + +- You can also use the CLI binary for direct HID control (for testing): + +```sh +sudo ./acer-rgb-cli /dev/hidraw2 keyboard static --brightness 100 --rgb 0 255 0 --zone all +``` + +## State file + +The daemon persists three lines (keyboard, lid, button) in `/var/lib/acer-rgbd/state.txt`. Editing that file (as root) changes the values the daemon will reapply on start. + +## Logs & troubleshooting + +View the daemon logs with: + +```sh +journalctl -u acer-rgbd.service -f +``` + +If you modify the state file and want the daemon to reapply immediately, restart it: + +```sh +sudo systemctl restart acer-rgbd.service +``` + +## Notes + +- The installer writes an initial all-green state (keyboard/lid/button) to `/var/lib/acer-rgbd/state.txt` so newly installed systems show green LEDs by default. +- Running the daemon requires root privileges (or appropriate udev rules) to access the HID device. diff --git a/acer-rgb b/acer-rgb new file mode 100755 index 0000000..1349945 --- /dev/null +++ b/acer-rgb @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +SOCK="/run/acer-rgbd.sock" + +if [[ $# -lt 1 ]]; then + echo "Usage:" + echo " acer-rgb GET" + echo " acer-rgb SET hidraw=/dev/hidraw2 dev=keyboard effect=static bright=80 r=255 g=0 b=0 zone=all" + exit 2 +fi + +cmd="$*" +if command -v socat >/dev/null 2>&1; then + printf "%s\n" "$cmd" | socat - UNIX-CONNECT:"$SOCK" +else + printf "%s\n" "$cmd" | nc -U "$SOCK" +fi diff --git a/acer-rgbd.cpp b/acer-rgbd.cpp index 92c35af..9221d0d 100644 --- a/acer-rgbd.cpp +++ b/acer-rgbd.cpp @@ -342,6 +342,10 @@ static bool load_and_apply_all(std::array& states) { if (hid_write_feature(newState, hwerr)) { states[idx] = newState; any = true; + } else { + // couldn't apply to hardware now (device may not exist yet), keep desired state + std::println("[WARN] failed to apply to hw for dev {}: {}", device_to_str(newState.device), hwerr); + states[idx] = newState; } } diff --git a/state.default b/state.default new file mode 100644 index 0000000..be4aa7a --- /dev/null +++ b/state.default @@ -0,0 +1,3 @@ +SET dev=keyboard hidraw=/dev/hidraw2 effect=static bright=100 r=0 g=255 b=0 zone=all +SET dev=lid hidraw=/dev/hidraw2 effect=static bright=100 r=0 g=255 b=0 +SET dev=button hidraw=/dev/hidraw2 effect=static bright=100 r=0 g=255 b=0