23
23
using Orts . Simulation . RollingStocks ;
24
24
using ORTS . Common ;
25
25
using ORTS . Common . Input ;
26
- using PIEHidDotNet ;
26
+ using RailDriver ;
27
27
28
28
namespace Orts . Viewer3D
29
29
{
30
30
/// <summary>
31
31
/// Class to get data from RailDriver and translate it into something useful for UserInput
32
32
/// </summary>
33
- public class UserInputRailDriver : PIEDataHandler , PIEErrorHandler
33
+ public class UserInputRailDriver : IDataHandler , IErrorHandler
34
34
{
35
35
PIEDevice Device ; // Our RailDriver
36
36
byte [ ] WriteBuffer ; // Buffer for sending data to RailDriver
@@ -69,15 +69,15 @@ public UserInputRailDriver(string basePath)
69
69
{
70
70
try
71
71
{
72
- PIEDevice [ ] devices = PIEHidDotNet . PIEDevice . EnumeratePIE ( ) ;
72
+ PIEDevice [ ] devices = PIEDevice . EnumeratePIE ( ) ;
73
73
for ( int i = 0 ; i < devices . Length ; i ++ )
74
74
{
75
75
if ( devices [ i ] . HidUsagePage == 0xc && devices [ i ] . Pid == 210 )
76
76
{
77
77
Device = devices [ i ] ;
78
78
Device . SetupInterface ( ) ;
79
79
Device . SetErrorCallback ( this ) ;
80
- Device . SetDataCallback ( this , DataCallbackFilterType . callOnChangedData ) ;
80
+ Device . SetDataCallback ( this ) ;
81
81
WriteBuffer = new byte [ Device . WriteLength ] ;
82
82
State = new RailDriverState ( ) ;
83
83
SetLEDs ( 0x40 , 0x40 , 0x40 ) ;
@@ -98,38 +98,29 @@ public UserInputRailDriver(string basePath)
98
98
/// </summary>
99
99
/// <param name="data"></param>
100
100
/// <param name="sourceDevice"></param>
101
- public void HandlePIEHidData ( Byte [ ] data , PIEDevice sourceDevice )
101
+ public void HandleHidData ( byte [ ] data , PIEDevice sourceDevice , int error )
102
102
{
103
103
if ( sourceDevice != Device )
104
104
return ;
105
105
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 ) ;
133
124
134
125
if ( State . IsPressed ( 4 , 0x30 ) )
135
126
State . Emergency = true ;
@@ -157,7 +148,7 @@ public void HandlePIEHidData(Byte[] data, PIEDevice sourceDevice)
157
148
/// </summary>
158
149
/// <param name="error"></param>
159
150
/// <param name="sourceDevice"></param>
160
- public void HandlePIEHidError ( Int32 error , PIEDevice sourceDevice )
151
+ public void HandleHidError ( PIEDevice sourceDevice , int error )
161
152
{
162
153
Trace . TraceWarning ( "RailDriver Error: {0}" , error ) ;
163
154
}
0 commit comments