2323using Orts . Simulation . RollingStocks ;
2424using ORTS . Common ;
2525using ORTS . Common . Input ;
26- using PIEHidDotNet ;
26+ using RailDriver ;
2727
2828namespace Orts . Viewer3D
2929{
3030 /// <summary>
3131 /// Class to get data from RailDriver and translate it into something useful for UserInput
3232 /// </summary>
33- public class UserInputRailDriver : PIEDataHandler , PIEErrorHandler
33+ public class UserInputRailDriver : IDataHandler , IErrorHandler
3434 {
3535 PIEDevice Device ; // Our RailDriver
3636 byte [ ] WriteBuffer ; // Buffer for sending data to RailDriver
@@ -69,15 +69,15 @@ public UserInputRailDriver(string basePath)
6969 {
7070 try
7171 {
72- PIEDevice [ ] devices = PIEHidDotNet . PIEDevice . EnumeratePIE ( ) ;
72+ PIEDevice [ ] devices = PIEDevice . EnumeratePIE ( ) ;
7373 for ( int i = 0 ; i < devices . Length ; i ++ )
7474 {
7575 if ( devices [ i ] . HidUsagePage == 0xc && devices [ i ] . Pid == 210 )
7676 {
7777 Device = devices [ i ] ;
7878 Device . SetupInterface ( ) ;
7979 Device . SetErrorCallback ( this ) ;
80- Device . SetDataCallback ( this , DataCallbackFilterType . callOnChangedData ) ;
80+ Device . SetDataCallback ( this ) ;
8181 WriteBuffer = new byte [ Device . WriteLength ] ;
8282 State = new RailDriverState ( ) ;
8383 SetLEDs ( 0x40 , 0x40 , 0x40 ) ;
@@ -98,38 +98,29 @@ public UserInputRailDriver(string basePath)
9898 /// </summary>
9999 /// <param name="data"></param>
100100 /// <param name="sourceDevice"></param>
101- public void HandlePIEHidData ( Byte [ ] data , PIEDevice sourceDevice )
101+ public void HandleHidData ( byte [ ] data , PIEDevice sourceDevice , int error )
102102 {
103103 if ( sourceDevice != Device )
104104 return ;
105105 State . SaveButtonData ( ) ;
106- byte [ ] rdata = null ;
107- while ( 0 == sourceDevice . ReadData ( ref rdata ) ) //do this so don't ever miss any data
108- {
109- #if false
110- String output = "Callback: " + sourceDevice . Pid + ", ID: " + Device . ToString ( ) + ", data=" ;
111- for ( int i = 0 ; i < sourceDevice . ReadLength ; i ++ )
112- output = output + rdata [ i ] . ToString ( ) + " " ;
113- Console . WriteLine ( output ) ;
114- #endif
115- State . DirectionPercent = Percentage ( rdata [ 1 ] , FullReversed , Neutral , FullForward ) ;
116-
117- State . ThrottlePercent = Percentage ( rdata [ 2 ] , ThrottleIdle , FullThrottle ) ;
118-
119- State . DynamicBrakePercent = Percentage ( rdata [ 2 ] , ThrottleIdle , DynamicBrakeSetup , DynamicBrake ) ;
120- State . TrainBrakePercent = Percentage ( rdata [ 3 ] , AutoBrakeRelease , FullAutoBrake ) ;
121- State . EngineBrakePercent = Percentage ( rdata [ 4 ] , IndependentBrakeRelease , IndependentBrakeFull ) ;
122- float a = .01f * State . EngineBrakePercent ;
123- float calOff = ( 1 - a ) * BailOffDisengagedRelease + a * BailOffDisengagedFull ;
124- float calOn = ( 1 - a ) * BailOffEngagedRelease + a * BailOffEngagedFull ;
125- State . BailOff = Percentage ( rdata [ 5 ] , calOff , calOn ) > 50 ;
126- if ( State . TrainBrakePercent >= 100 )
127- State . Emergency = Percentage ( rdata [ 3 ] , FullAutoBrake , EmergencyBrake ) > 50 ;
128-
129- State . Wipers = ( int ) ( .01 * Percentage ( rdata [ 6 ] , Rotary1Position1 , Rotary1Position2 , Rotary1Position3 ) + 2.5 ) ;
130- State . Lights = ( int ) ( .01 * Percentage ( rdata [ 7 ] , Rotary2Position1 , Rotary2Position2 , Rotary2Position3 ) + 2.5 ) ;
131- State . AddButtonData ( rdata ) ;
132- }
106+
107+ State . DirectionPercent = Percentage ( data [ 1 ] , FullReversed , Neutral , FullForward ) ;
108+
109+ State . ThrottlePercent = Percentage ( data [ 2 ] , ThrottleIdle , FullThrottle ) ;
110+
111+ State . DynamicBrakePercent = Percentage ( data [ 2 ] , ThrottleIdle , DynamicBrakeSetup , DynamicBrake ) ;
112+ State . TrainBrakePercent = Percentage ( data [ 3 ] , AutoBrakeRelease , FullAutoBrake ) ;
113+ State . EngineBrakePercent = Percentage ( data [ 4 ] , IndependentBrakeRelease , IndependentBrakeFull ) ;
114+ float a = .01f * State . EngineBrakePercent ;
115+ float calOff = ( 1 - a ) * BailOffDisengagedRelease + a * BailOffDisengagedFull ;
116+ float calOn = ( 1 - a ) * BailOffEngagedRelease + a * BailOffEngagedFull ;
117+ State . BailOff = Percentage ( data [ 5 ] , calOff , calOn ) > 50 ;
118+ if ( State . TrainBrakePercent >= 100 )
119+ State . Emergency = Percentage ( data [ 3 ] , FullAutoBrake , EmergencyBrake ) > 50 ;
120+
121+ State . Wipers = ( int ) ( .01 * Percentage ( data [ 6 ] , Rotary1Position1 , Rotary1Position2 , Rotary1Position3 ) + 2.5 ) ;
122+ State . Lights = ( int ) ( .01 * Percentage ( data [ 7 ] , Rotary2Position1 , Rotary2Position2 , Rotary2Position3 ) + 2.5 ) ;
123+ State . AddButtonData ( data ) ;
133124
134125 if ( State . IsPressed ( 4 , 0x30 ) )
135126 State . Emergency = true ;
@@ -157,7 +148,7 @@ public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice)
157148 /// </summary>
158149 /// <param name="error"></param>
159150 /// <param name="sourceDevice"></param>
160- public void HandlePIEHidError ( Int32 error , PIEDevice sourceDevice )
151+ public void HandleHidError ( PIEDevice sourceDevice , int error )
161152 {
162153 Trace . TraceWarning ( "RailDriver Error: {0}" , error ) ;
163154 }
0 commit comments