diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index 3ee5d7d3..cb01f34a 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -25,14 +25,22 @@ namespace GHelper.AnimeMatrix BatteryLevel, } + public class SlashPacket : Packet + { + public SlashPacket(byte[] command, byte reportID = 0x5E) : base(reportID, 128, command) + { + } + } + + public class SlashDevice : Device { - internal class SlashPacket : Packet + protected virtual byte reportID => 0x5E; + + protected virtual SlashPacket CreatePacket(byte[] command) { - public SlashPacket(byte[] command) : base(0x5E, 128, command) - { - } + return new SlashPacket(command, reportID); } public static Dictionary Modes = new Dictionary @@ -90,25 +98,25 @@ namespace GHelper.AnimeMatrix public void WakeUp() { - Set(Packet(Encoding.ASCII.GetBytes("ASUS Tech.Inc.")), "SlashWakeUp"); - Set(Packet(0xC2), "SlashWakeUp"); - Set(Packet(0xD1, 0x01, 0x00, 0x01), "SlashWakeUp"); + Set(CreatePacket(Encoding.ASCII.GetBytes("ASUS Tech.Inc.")), "SlashWakeUp"); + Set(CreatePacket([0xC2]), "SlashWakeUp"); + Set(CreatePacket([0xD1, 0x01, 0x00, 0x01 ]), "SlashWakeUp"); } public void Init() { - Set(Packet(0xD7, 0x00, 0x00, 0x01, 0xAC), "SlashInit"); - Set(Packet(0xD2, 0x02, 0x01, 0x08, 0xAB), "SlashInit"); + Set(CreatePacket([0xD7, 0x00, 0x00, 0x01, 0xAC]), "SlashInit"); + Set(CreatePacket([0xD2, 0x02, 0x01, 0x08, 0xAB]), "SlashInit"); } public void SetEnabled(bool status = true) { - Set(Packet(0xD8, 0x02, 0x00, 0x01, status ? (byte)0x00 : (byte)0x80), $"SlashEnable {status}"); + Set(CreatePacket([0xD8, 0x02, 0x00, 0x01, status ? (byte)0x00 : (byte)0x80]), $"SlashEnable {status}"); } public void Save() { - Set(Packet(0xD4, 0x00, 0x00, 0x01, 0xAB), "SlashSave"); + Set(CreatePacket([0xD4, 0x00, 0x00, 0x01, 0xAB]), "SlashSave"); } public void SetMode(SlashMode mode) @@ -124,8 +132,8 @@ namespace GHelper.AnimeMatrix modeByte = 0x00; } - Set(Packet(0xD2, 0x03, 0x00, 0x0C), "SlashMode"); - Set(Packet(0xD3, 0x04, 0x00, 0x0C, 0x01, modeByte, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13), "SlashMode"); + Set(CreatePacket([0xD2, 0x03, 0x00, 0x0C]), "SlashMode"); + Set(CreatePacket([0xD3, 0x04, 0x00, 0x0C, 0x01, modeByte, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13]), "SlashMode"); } public void SetStatic(int brightness = 0) @@ -179,35 +187,35 @@ namespace GHelper.AnimeMatrix public void SetCustom(byte[] data) { - Set(Packet(0xD2, 0x02, 0x01, 0x08, 0xAC), "Static"); - Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAC, 0xFF, 0xFF, 0x01, 0x05, 0xFF, 0xFF), "StaticSettings"); - Set(Packet(0xD4, 0x00, 0x00, 0x01, 0xAC), "StaticSave"); + Set(CreatePacket([0xD2, 0x02, 0x01, 0x08, 0xAC]), "Static"); + Set(CreatePacket([0xD3, 0x03, 0x01, 0x08, 0xAC, 0xFF, 0xFF, 0x01, 0x05, 0xFF, 0xFF]), "StaticSettings"); + Set(CreatePacket([0xD4, 0x00, 0x00, 0x01, 0xAC]), "StaticSave"); byte[] payload = new byte[] { 0xD3, 0x00, 0x00, 0x07 }; - Set(Packet(payload.Concat(data.Take(7)).ToArray()), "Static Data"); + Set(CreatePacket(payload.Concat(data.Take(7)).ToArray()), "Static Data"); } public void SetOptions(bool status, int brightness = 0, int interval = 0) { byte brightnessByte = (byte)(brightness * 85.333); - Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightnessByte, 0xFF, (byte)interval), "SlashOptions"); + Set(CreatePacket([0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightnessByte, 0xFF, (byte)interval]), "SlashOptions"); } public void SetBatterySaver(bool status) { - Set(Packet(0xD8, 0x01, 0x00, 0x01, status ? (byte)0x80 : (byte)0x00), $"SlashBatterySaver {status}"); + Set(CreatePacket([0xD8, 0x01, 0x00, 0x01, status ? (byte)0x80 : (byte)0x00]), $"SlashBatterySaver {status}"); } public void SetLidMode(bool status) { - Set(Packet(0xD8, 0x00, 0x00, 0x02, 0xA5, status ? (byte)0x80 : (byte)0x00), $"DisableLidClose {status}"); + Set(CreatePacket([0xD8, 0x00, 0x00, 0x02, 0xA5, status ? (byte)0x80 : (byte)0x00]), $"DisableLidClose {status}"); } public void SetSleepActive(bool status) { - Set(Packet(0xD2, 0x02, 0x01, 0x08, 0xA1), "SleepInit"); - Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xA1, 0x00, 0xFF, status ? (byte)0x01 : (byte)0x00, 0x02, 0xFF, 0xFF), $"Sleep {status}"); + Set(CreatePacket([0xD2, 0x02, 0x01, 0x08, 0xA1]), "SleepInit"); + Set(CreatePacket([0xD3, 0x03, 0x01, 0x08, 0xA1, 0x00, 0xFF, status ? (byte)0x01 : (byte)0x00, 0x02, 0xFF, 0xFF]), $"Sleep {status}"); } public void Set(Packet packet, string? log = null) @@ -219,15 +227,11 @@ namespace GHelper.AnimeMatrix public class SlashDeviceAura : SlashDevice { - public SlashDeviceAura(): base(0x19B6) - { - } + protected override byte reportID => 0x5D; - internal new class SlashPacket : Packet + protected override SlashPacket CreatePacket(byte[] command) { - public SlashPacket(byte[] command) : base(0x5D, 128, command) - { - } + return new SlashPacket(command, reportID); } }