54 lines
1.5 KiB
Python
Executable File
54 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import asrock_hid as h
|
|
|
|
MODES = {
|
|
"off": 0x00, "static": 0x01, "breath": 0x02, "strobe": 0x03,
|
|
"cycle": 0x04, "random": 0x05, "music": 0x06, "wave": 0x07,
|
|
"spring": 0x08, "stack": 0x09, "cram": 0x0A, "scan": 0x0B,
|
|
"neon": 0x0C, "water": 0x0D, "rainbow": 0x0E, "direct": 0x0F,
|
|
}
|
|
|
|
|
|
def to_hex(data):
|
|
return " ".join("%02x" % b for b in data) if data else "no reply"
|
|
|
|
|
|
def main():
|
|
args = sys.argv[1:]
|
|
if not args:
|
|
sys.exit(
|
|
"usage: asrock-led.py read <zone> | set [all|<zone>] <mode> <r> <g> <b> [speed] | commit"
|
|
)
|
|
fd = h.open_dev()
|
|
try:
|
|
cmd_name = args[0].lower()
|
|
if cmd_name == "read":
|
|
zone = int(args[1], 0)
|
|
state = h.read_zone(fd, zone)
|
|
print(state if state else "no reply")
|
|
elif cmd_name == "set":
|
|
is_all = args[1] == "all"
|
|
zone = 0 if is_all else int(args[1], 0)
|
|
mode = MODES[args[2]] if args[2] in MODES else int(args[2], 0)
|
|
r = int(args[3], 0)
|
|
g = int(args[4], 0)
|
|
b = int(args[5], 0)
|
|
speed = int(args[6], 0) if len(args) > 6 else 0xE0
|
|
reply = h.write_set(fd, zone, mode, r, g, b, speed, 1 if is_all else 0)
|
|
print(to_hex(reply))
|
|
elif cmd_name == "commit":
|
|
print(to_hex(h.commit(fd)))
|
|
else:
|
|
sys.exit(f"unknown command: {cmd_name}")
|
|
finally:
|
|
os_close(fd)
|
|
|
|
|
|
def os_close(fd):
|
|
import os
|
|
os.close(fd)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |