diff --git a/__pycache__/daemon_client.cpython-312.pyc b/__pycache__/daemon_client.cpython-312.pyc index 9cd5b01..acd6856 100644 Binary files a/__pycache__/daemon_client.cpython-312.pyc and b/__pycache__/daemon_client.cpython-312.pyc differ diff --git a/acer-rgbd.cpp b/acer-rgbd.cpp index 9221d0d..9c0ee0c 100644 --- a/acer-rgbd.cpp +++ b/acer-rgbd.cpp @@ -48,6 +48,8 @@ static constexpr const char* SOCK_PATH = "/run/acer-rgbd.sock"; static constexpr const char* STATE_DIR = "/var/lib/acer-rgbd"; static constexpr const char* STATE_PATH = "/var/lib/acer-rgbd/state.txt"; +static std::string g_hidraw_path; + struct Settings { std::string hidraw = "/dev/hidraw2"; uint8_t device = KEYBOARD_RGB_ID; @@ -84,6 +86,23 @@ static std::optional read_file(const std::string& path) { return out; } +// Scan /sys/class/hidraw for the ENE keyboard controller by looking for +// HID usage page 0xFF5A (bytes 06 5A FF) at the start of the report descriptor. +// This survives kernel updates that renumber hidraw devices. +static std::string find_ene_hidraw() { + for (int i = 0; i < 16; i++) { + std::string desc_path = "/sys/class/hidraw/hidraw" + std::to_string(i) + "/device/report_descriptor"; + auto desc = read_file(desc_path); + if (!desc || desc->size() < 3) continue; + if ((uint8_t)(*desc)[0] == 0x06 && + (uint8_t)(*desc)[1] == 0x5A && + (uint8_t)(*desc)[2] == 0xFF) { + return "/dev/hidraw" + std::to_string(i); + } + } + return ""; +} + static std::vector split_ws(std::string_view s) { std::vector v; size_t i = 0; @@ -159,7 +178,7 @@ static std::optional parse_zone(const std::string& s) { } static bool hid_write_feature(const Settings& cfg, std::string& err) { - int fd = ::open(cfg.hidraw.c_str(), O_RDWR | O_NONBLOCK); + int fd = ::open(g_hidraw_path.c_str(), O_RDWR | O_NONBLOCK); if (fd < 0) { err = "open hidraw failed"; return false; } std::vector bytes = { @@ -287,7 +306,7 @@ static std::string serialize_one(const Settings& s) { return std::format( "SET dev={} hidraw={} effect={} bright={} speed={} dir={} r={} g={} b={} zone={}\n", device_to_str(s.device), - s.hidraw, + g_hidraw_path, effect_to_str(s.effect), (int)s.brightness, (int)s.speed, @@ -394,6 +413,13 @@ int main() { ensure_dirs(); + g_hidraw_path = find_ene_hidraw(); + if (g_hidraw_path.empty()) { + std::println("[ERR] ENE RGB controller not found in /dev/hidraw*"); + return 1; + } + std::println("ENE RGB controller: {}", g_hidraw_path); + // 3 estados: keyboard/lid/button std::array states; diff --git a/daemon_client.py b/daemon_client.py index 59429a5..c515bd5 100644 --- a/daemon_client.py +++ b/daemon_client.py @@ -36,7 +36,7 @@ class RGBState: def to_command(self) -> str: return ( - f"SET dev={self.device} hidraw={self.hidraw} " + f"SET dev={self.device} " f"effect={self.effect} bright={self.brightness} " f"speed={self.speed} dir={self.direction} " f"r={self.r} g={self.g} b={self.b} zone={self.zone}"