ASRock Polychrome system LED indicator: HID driver, daemon, systemd unit, udev rule
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import os
|
||||
import select
|
||||
import time
|
||||
|
||||
DEFAULT_DEV = os.environ.get("ASROCK_HID", "/dev/hidraw0")
|
||||
|
||||
A_OFF = 0x00
|
||||
A_STATIC = 0x01
|
||||
A_BREATH = 0x02
|
||||
A_STROBE = 0x03
|
||||
A_CYCLE = 0x04
|
||||
A_RANDOM = 0x05
|
||||
A_MUSIC = 0x06
|
||||
A_WAVE = 0x07
|
||||
A_SPRING = 0x08
|
||||
A_STACK = 0x09
|
||||
A_CRAM = 0x0A
|
||||
A_SCAN = 0x0B
|
||||
A_NEON = 0x0C
|
||||
A_WATER = 0x0D
|
||||
A_RAINBOW = 0x0E
|
||||
A_DIRECT = 0x0F
|
||||
|
||||
WRITE = 0x10
|
||||
READ = 0x11
|
||||
COMMIT = 0x12
|
||||
|
||||
|
||||
def _cmd(c, zone=0, mode=0, r=0, g=0, b=0, speed=0, ff=0, allzone=0):
|
||||
m = bytearray(64)
|
||||
m[0] = c
|
||||
m[2] = zone
|
||||
m[3] = mode
|
||||
m[4] = r
|
||||
m[5] = g
|
||||
m[6] = b
|
||||
m[7] = speed
|
||||
m[8] = ff
|
||||
m[9] = allzone
|
||||
return m
|
||||
|
||||
|
||||
def open_dev(path=DEFAULT_DEV):
|
||||
return os.open(path, os.O_RDWR)
|
||||
|
||||
|
||||
def xfer(fd, msg):
|
||||
os.write(fd, bytes(msg))
|
||||
time.sleep(0.01)
|
||||
r, _, _ = select.select([fd], [], [], 0.2)
|
||||
if r:
|
||||
return os.read(fd, 256)
|
||||
return None
|
||||
|
||||
|
||||
def write_set(fd, zone, mode, r, g, b, speed, allzone):
|
||||
return xfer(fd, _cmd(WRITE, zone, mode, r, g, b, speed, 0xFF, allzone))
|
||||
|
||||
|
||||
def read_zone(fd, zone):
|
||||
reply = xfer(fd, _cmd(READ, zone=zone))
|
||||
if not reply or len(reply) < 11:
|
||||
return None
|
||||
return {
|
||||
"zone": reply[3],
|
||||
"mode": reply[4],
|
||||
"r": reply[5],
|
||||
"g": reply[6],
|
||||
"b": reply[7],
|
||||
"speed": reply[8],
|
||||
"all": reply[10],
|
||||
}
|
||||
|
||||
|
||||
def commit(fd):
|
||||
return xfer(fd, _cmd(COMMIT))
|
||||
Reference in New Issue
Block a user