@@ -104,33 +104,24 @@ public void HandleHidData(byte[] data, PIEDevice sourceDevice, int error)
104104 if ( sourceDevice != Device )
105105 return ;
106106 State . SaveButtonData ( ) ;
107- byte [ ] rdata = null ;
108- while ( 0 == sourceDevice . ReadData ( ref rdata ) ) //do this so don't ever miss any data
109- {
110- #if false
111- String output = "Callback: " + sourceDevice . Pid + ", ID: " + Device . ToString ( ) + ", data=" ;
112- for ( int i = 0 ; i < sourceDevice . ReadLength ; i ++ )
113- output = output + rdata [ i ] . ToString ( ) + " " ;
114- Console . WriteLine ( output ) ;
115- #endif
116- State . DirectionPercent = Percentage ( rdata [ 1 ] , FullReversed , Neutral , FullForward ) ;
117-
118- State . ThrottlePercent = Percentage ( rdata [ 2 ] , ThrottleIdle , FullThrottle ) ;
119-
120- State . DynamicBrakePercent = Percentage ( rdata [ 2 ] , ThrottleIdle , DynamicBrakeSetup , DynamicBrake ) ;
121- State . TrainBrakePercent = Percentage ( rdata [ 3 ] , AutoBrakeRelease , FullAutoBrake ) ;
122- State . EngineBrakePercent = Percentage ( rdata [ 4 ] , IndependentBrakeRelease , IndependentBrakeFull ) ;
123- float a = .01f * State . EngineBrakePercent ;
124- float calOff = ( 1 - a ) * BailOffDisengagedRelease + a * BailOffDisengagedFull ;
125- float calOn = ( 1 - a ) * BailOffEngagedRelease + a * BailOffEngagedFull ;
126- State . BailOff = Percentage ( rdata [ 5 ] , calOff , calOn ) > 50 ;
127- if ( State . TrainBrakePercent >= 100 )
128- State . Emergency = Percentage ( rdata [ 3 ] , FullAutoBrake , EmergencyBrake ) > 50 ;
129-
130- State . Wipers = ( int ) ( .01 * Percentage ( rdata [ 6 ] , Rotary1Position1 , Rotary1Position2 , Rotary1Position3 ) + 2.5 ) ;
131- State . Lights = ( int ) ( .01 * Percentage ( rdata [ 7 ] , Rotary2Position1 , Rotary2Position2 , Rotary2Position3 ) + 2.5 ) ;
132- State . AddButtonData ( rdata ) ;
133- }
107+
108+ State . DirectionPercent = Percentage ( data [ 1 ] , FullReversed , Neutral , FullForward ) ;
109+
110+ State . ThrottlePercent = Percentage ( data [ 2 ] , ThrottleIdle , FullThrottle ) ;
111+
112+ State . DynamicBrakePercent = Percentage ( data [ 2 ] , ThrottleIdle , DynamicBrakeSetup , DynamicBrake ) ;
113+ State . TrainBrakePercent = Percentage ( data [ 3 ] , AutoBrakeRelease , FullAutoBrake ) ;
114+ State . EngineBrakePercent = Percentage ( data [ 4 ] , IndependentBrakeRelease , IndependentBrakeFull ) ;
115+ float a = .01f * State . EngineBrakePercent ;
116+ float calOff = ( 1 - a ) * BailOffDisengagedRelease + a * BailOffDisengagedFull ;
117+ float calOn = ( 1 - a ) * BailOffEngagedRelease + a * BailOffEngagedFull ;
118+ State . BailOff = Percentage ( data [ 5 ] , calOff , calOn ) > 50 ;
119+ if ( State . TrainBrakePercent >= 100 )
120+ State . Emergency = Percentage ( data [ 3 ] , FullAutoBrake , EmergencyBrake ) > 50 ;
121+
122+ State . Wipers = ( int ) ( .01 * Percentage ( data [ 6 ] , Rotary1Position1 , Rotary1Position2 , Rotary1Position3 ) + 2.5 ) ;
123+ State . Lights = ( int ) ( .01 * Percentage ( data [ 7 ] , Rotary2Position1 , Rotary2Position2 , Rotary2Position3 ) + 2.5 ) ;
124+ State . AddButtonData ( data ) ;
134125
135126 if ( State . IsPressed ( 4 , 0x30 ) )
136127 State . Emergency = true ;
0 commit comments