Skip to content

Instantly share code, notes, and snippets.

@SaifAqqad
Created May 20, 2023 17:08
Show Gist options
  • Save SaifAqqad/e1708be3200f78e654906b4027a994f6 to your computer and use it in GitHub Desktop.
Save SaifAqqad/e1708be3200f78e654906b4027a994f6 to your computer and use it in GitHub Desktop.
Asus Aura Sync COM API wrapper
#Requires AutoHotkey v1.1.35+
class AuraSync {
static CLSID := "aura.sdk.1"
__New(){
this.sdk := ComObjCreate(AuraSync.CLSID)
this.isControlled := false
this.devices := []
this.releaseMethod := ObjBindMethod(this, "releaseControl")
OnExit(this.releaseMethod)
; Cache devices
for device in this.sdk.Enumerate(0)
this.devices.Push(new AuraSync.Device(device, this))
if (this.devices.Length() > 0)
this.setAllDevicesColor(this.devices[1].lights[1].getColor(), 1)
}
takeControl(){
if(this.isControlled)
return
this.sdk.SwitchMode()
this.isControlled := true
}
releaseControl(){
if(!this.isControlled)
return
this.sdk.ReleaseControl(0)
this.isControlled := false
}
setAllDevicesColor(color, releaseDelay:= 0){
_r := this.releaseMethod
SetTimer, % _r, Off
for i, device in this.devices {
for i, light in device.lights
light.setColor(color)
device.apply()
}
if (releaseDelay > 0)
SetTimer, % _r, % -releaseDelay
}
isInstalled(){
local auraSdk
try {
auraSdk := ComObjCreate(AuraSync.CLSID)
ObjRelease(auraSdk)
} Catch {
return false
}
return true
}
rgbToBgr(r, g, b){
return (b << 16) | (g << 8) | r
}
hexToBgr(hex){
hex := StrReplace(hex, "#", "")
red := Format("{:d}","0x" SubStr(hex, 1, 2))
green := Format("{:d}","0x" SubStr(hex, 3, 2))
blue := Format("{:d}","0x" SubStr(hex, 5, 2))
return (blue << 16) | (green << 8) | red
}
bgrToRgb(color){
red := color & 0xFF
green := (color >> 8) & 0xFF
blue := (color >> 16) & 0xFF
return [red, green, blue]
}
bgrToHex(color){
red := color & 0xFF
green := (color >> 8) & 0xFF
blue := (color >> 16) & 0xFF
return Format("#{:02X}{:02X}{:02X}", red, green, blue)
}
class Device {
__New(raw, sdk){
this.sdk := sdk
this.raw := raw
this.name := raw.Name
this.type := raw.Type
this.width := raw.Width
this.height := raw.Height
; Cache device's lights
this.lights:= []
for light in raw.Lights
this.lights.Push(new AuraSync.Light(light, sdk))
}
apply(){
if (!this.sdk.isControlled)
this.sdk.takeControl()
this.raw.Apply()
}
}
class Light {
__New(raw, sdk){
this.sdk := sdk
this.raw := raw
this.Name := raw.Name
}
setColor(color){
if (!this.sdk.isControlled)
this.sdk.takeControl()
this.raw.Color := color
}
getColor(){
if(!this.sdk.isControlled)
this.sdk.takeControl()
return this.raw.Color
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment