11// Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads
22
33using HidSharp ;
4+ using HidSharp . Reports ;
45using System . Text ;
56
67namespace GHelper . USB
78{
89 public static class XGM
910 {
11+ const byte XGM_REPORT_ID = 0x5e ;
1012 const int ASUS_ID = 0x0b05 ;
11- static readonly int [ ] deviceIds = { 0x1970 , 0x1a9a , 0x1C29 } ;
13+ static readonly int [ ] deviceIds = { 0x1970 , 0x1a9a , 0x1C29 , 0x19b6 } ;
1214
1315 public static HidDevice ? GetDevice ( )
1416 {
1517 try
1618 {
19+ var devices = DeviceList . Local . GetHidDevices ( ASUS_ID ) . Where ( device =>
20+ deviceIds . Contains ( device . ProductID ) &&
21+ device . CanOpen ) ;
22+
23+ /*
24+ foreach (var device in devices)
25+ {
26+ var report = device.GetReportDescriptor().TryGetReport(ReportType.Feature, XGM_REPORT_ID, out _);
27+ Logger.WriteLine($"Found XGM Device: PID={device.ProductID}, MaxFeatureReportLength={device.GetMaxFeatureReportLength()}, Report={report}");
28+ }
29+ */
30+
1731 return DeviceList . Local . GetHidDevices ( ASUS_ID ) . FirstOrDefault ( device =>
1832 deviceIds . Contains ( device . ProductID ) &&
1933 device . CanOpen &&
20- device . GetMaxFeatureReportLength ( ) >= 300 ) ;
34+ device . GetReportDescriptor ( ) . TryGetReport ( ReportType . Feature , XGM_REPORT_ID , out _ ) ) ;
2135 }
2236 catch ( Exception ex )
2337 {
@@ -44,7 +58,7 @@ public static void Write(byte[] data)
4458
4559 using ( HidStream hidStream = device . Open ( ) )
4660 {
47- byte [ ] payload = new byte [ 300 ] ;
61+ byte [ ] payload = new byte [ device . GetMaxFeatureReportLength ( ) ] ;
4862 data . CopyTo ( payload , 0 ) ;
4963 hidStream . SetFeature ( payload ) ;
5064 Logger . WriteLine ( $ "XGM-{ device . ProductID } |{ device . GetMaxFeatureReportLength ( ) } :{ BitConverter . ToString ( data ) } ") ;
@@ -71,7 +85,7 @@ public static void Init()
7185
7286 public static void Light ( bool status )
7387 {
74- Write ( [ 0x5e , 0xc5 , status ? ( byte ) 0x50 : ( byte ) 0 ] ) ;
88+ Write ( [ XGM_REPORT_ID , 0xc5 , status ? ( byte ) 0x50 : ( byte ) 0 ] ) ;
7589 }
7690
7791 public static void InitLight ( )
@@ -86,7 +100,7 @@ public static void Reset()
86100 {
87101 Task . Run ( ( ) =>
88102 {
89- if ( IsConnected ( ) ) Write ( [ 0x5e , 0xd1 , 0x02 ] ) ;
103+ if ( IsConnected ( ) ) Write ( [ XGM_REPORT_ID , 0xd1 , 0x02 ] ) ;
90104 } ) ;
91105 }
92106
@@ -98,7 +112,7 @@ public static void SetFan(byte[] curve)
98112 {
99113 if ( AsusACPI . IsInvalidCurve ( curve ) ) return ;
100114 byte [ ] msg = new byte [ 19 ] ;
101- Array . Copy ( new byte [ ] { 0x5e , 0xd1 , 0x01 } , msg , 3 ) ;
115+ Array . Copy ( new byte [ ] { XGM_REPORT_ID , 0xd1 , 0x01 } , msg , 3 ) ;
102116 Array . Copy ( curve , 0 , msg , 3 , curve . Length ) ;
103117 Write ( msg ) ;
104118 }
0 commit comments