Skip to content

Instantly share code, notes, and snippets.

@vshymanskyy
Created August 9, 2021 13:44
Show Gist options
  • Save vshymanskyy/46297174b52e4d0bd9cccd46478e0a67 to your computer and use it in GitHub Desktop.
Save vshymanskyy/46297174b52e4d0bd9cccd46478e0a67 to your computer and use it in GitHub Desktop.
Asus AURA RGB control using Python
#!/usr/bin/env python3
#
# Warning: use at your own risk!
#
from smbus2 import SMBus
import sys, time, socket
AURA_REG_DEVICE_NAME = 0x1000
AURA_REG_CONFIG_TABLE = 0x1C00
AURA_REG_COLORS_DIRECT = 0x8000
AURA_REG_COLORS_EFFECT = 0x8010
AURA_REG_DIRECT = 0x8020
AURA_REG_MODE = 0x8021
AURA_REG_APPLY = 0x80A0
AURA_REG_SLOT_INDEX = 0x80F8
AURA_REG_I2C_ADDRESS = 0x80F9
AURA_APPLY_VAL = 0x01
AURA_CONFIG_LED_COUNT = 0x02
AURA_MODES = {
"OFF" : 0, # OFF mode
"STATIC" : 1, # Static color mode
"BREATHING" : 2, # Breathing effect mode
"FLASHING" : 3, # Flashing effect mode
"SPECTRUM_CYCLE" : 4, # Spectrum Cycle mode
"RAINBOW" : 5, # Rainbow effect mode
"SPECTRUM_CYCLE_BREATHING" : 6, # Rainbow Breathing effect mode
"CHASE_FADE" : 7, # Chase with Fade effect mode
"SPECTRUM_CYCLE_CHASE_FADE" : 8, # Chase with Fade, Rainbow effect mode
"CHASE" : 9, # Chase effect mode
"SPECTRUM_CYCLE_CHASE" : 10, # Chase with Rainbow effect mode
"SPECTRUM_CYCLE_WAVE" : 11, # Wave effect mode
"CHASE_RAINBOW_PULSE" : 12, # Chase with Rainbow Pulse effect mode
"RANDOM_FLICKER" : 13, # Random flicker effect mode
}
class Aura:
def __init__(self, bus, addr):
self.bus = bus
self.addr = addr
#
# Bus access helpers
#
def read_reg(self, offset):
self.bus.write_word_data(self.addr, 0, socket.htons(offset))
return self.bus.read_byte_data(self.addr, 0x81)
def write_reg(self, offset, val):
self.bus.write_word_data(self.addr, 0, socket.htons(offset))
return self.bus.write_byte_data(self.addr, 0x01, val)
def write_block(self, offset, data):
self.bus.write_word_data(self.addr, 0, socket.htons(offset))
return self.bus.write_block_data(self.addr, 0x03, data)
#
# Basic operations
#
def read_name(self):
name = b''
for i in range(0, 16):
val = self.read_reg(AURA_REG_DEVICE_NAME+i)
if val == 0:
break
name += bytes([val])
return name.decode("utf-8")
def set_direct(self, direct):
self.write_reg(AURA_REG_DIRECT, int(direct))
def set_direct_colors(self, data):
# TODO: check length
self.write_block(AURA_REG_COLORS_DIRECT, data)
def set_effect_colors(self, data):
# TODO: check length
self.write_block(AURA_REG_COLORS_EFFECT, data)
def apply(self):
self.write_reg(AURA_REG_APPLY, AURA_APPLY_VAL)
#
# Convenience API
#
def set_mode(self, mode):
if mode in AURA_MODES:
self.write_reg(AURA_REG_MODE, AURA_MODES[mode])
self.set_direct(False)
elif mode == "DIRECT":
self.set_direct(True)
self.apply()
def set_static(self, r, g, b):
self.set_effect_colors([int(r), int(b), int(g)] * 5)
self.set_mode("STATIC")
def set_breathing(self, r, g, b):
self.set_effect_colors([int(r), int(b), int(g)] * 5)
self.set_mode("BREATHING")
if __name__ == "__main__":
args = sys.argv
AURA_BUS = 0
AURA_ADDR = [ 0x77 ]
with SMBus(AURA_BUS) as bus:
for addr in AURA_ADDR:
aura = Aura(bus, addr)
name = aura.read_name()
#if name != "DIMM_LED-0103":
# raise Exception(f"Invalid device on address {format(addr, '#02x')}")
if args[1] == "static":
aura.set_static(args[2], args[3], args[4])
elif args[1] == "breathing":
aura.set_breathing(args[2], args[3], args[4])
@vshymanskyy
Copy link
Author

/etc/systemd/system/aura_rgb.service

[Unit]
Description=Aura service
After=suspend.target

[Service]
User=root
Type=oneshot
ExecStart=/usr/bin/python3 /usr/bin/aura_rgb.py static 24 0 60
TimeoutSec=0
StandardOutput=syslog

[Install]
WantedBy=multi-user.target sleep.target

/etc/systemd/system/aura_rgb_suspend.service

[Unit]
Description=Aura service (on suspend)
Before=suspend.target

[Service]
User=root
Type=oneshot
ExecStart=/usr/bin/python3 /usr/bin/aura_rgb.py static 3 0 5
TimeoutSec=0
StandardOutput=syslog

[Install]
WantedBy=suspend.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment