@@ -12,7 +12,7 @@ public sealed class Ontroller : WinUsb, IController
1212 public const ushort VendorId = 0x0E8F ;
1313 public const ushort ProductId = 0x1216 ;
1414
15- private readonly object setLedslockObject = new object ( ) ;
15+ private int _pollCounter = 0 ;
1616 private readonly byte [ ] _mu3LedState = new byte [ 33 ] ;
1717 private readonly int _lever_min , _lever_max ;
1818 private readonly float _lever_absolute_center , _lever_range_center ;
@@ -110,6 +110,14 @@ public bool Poll()
110110
111111 LeverPosition = mu3LeverPos ;
112112
113+ // Increment the poll counter and refresh LEDs every 2 polls
114+ _pollCounter ++ ;
115+ if ( _pollCounter % 2 == 0 )
116+ {
117+ _pollCounter = 0 ;
118+ refreshLeds ( ) ;
119+ }
120+
113121 return true ;
114122 }
115123
@@ -133,20 +141,16 @@ public bool InitLeds()
133141
134142 public bool SetLeds ( int board , byte [ ] ledsColors )
135143 {
136- lock ( setLedslockObject )
144+ if ( board == 1 )
137145 {
138- if ( board == 1 )
139- {
140- SetLedsRange ( 0 , 6 , ledsColors ) ;
141- }
142- else if ( board == 0 )
143- {
144- SetLedColor ( 6 , ledsColors [ 0 ] , ledsColors [ 1 ] , ledsColors [ 2 ] ) ;
145- SetLedColor ( 9 , ledsColors [ 61 * 3 - 3 ] , ledsColors [ 61 * 3 - 2 ] , ledsColors [ 61 * 3 - 1 ] ) ;
146- }
147-
148- return refreshLeds ( ) ;
146+ SetLedsRange ( 0 , 6 , ledsColors ) ;
149147 }
148+ else if ( board == 0 )
149+ {
150+ SetLedColor ( 6 , ledsColors [ 0 ] , ledsColors [ 1 ] , ledsColors [ 2 ] ) ;
151+ SetLedColor ( 9 , ledsColors [ 61 * 3 - 3 ] , ledsColors [ 61 * 3 - 2 ] , ledsColors [ 61 * 3 - 1 ] ) ;
152+ }
153+ return true ;
150154 }
151155
152156 private void SetLedsRange ( int startIndex , int count , byte [ ] ledsColors )
@@ -166,6 +170,8 @@ private void SetLedColor(int index, byte red, byte green, byte blue)
166170
167171 public bool refreshLeds ( )
168172 {
173+ String mu3LedStateString = BitConverter . ToString ( _mu3LedState ) ;
174+ Logger . Debug ( $ "Ontroller: Refreshing leds, _mu3LedState: " + mu3LedStateString ) ;
169175 return WriteOutputData ( _mu3LedState , out _ ) ;
170176 }
171177}
0 commit comments