@@ -48,7 +48,8 @@ public class RailDriverState : ExternalDeviceState
48
48
public ExternalDeviceCabControl TrainBrake = new ExternalDeviceCabControl ( ) ; // 0 (release) to 100 (CS), does not include emergency
49
49
public ExternalDeviceCabControl EngineBrake = new ExternalDeviceCabControl ( ) ; // 0 to 100
50
50
public ExternalDeviceCabControl Lights = new ExternalDeviceCabControl ( ) ; // lights rotary, 1 off, 2 dim, 3 full
51
-
51
+ ExternalDeviceButton BailOff ;
52
+ ExternalDeviceButton Wiper ;
52
53
public RailDriverState ( Game game )
53
54
{
54
55
try
@@ -119,8 +120,16 @@ public RailDriverState(Game game)
119
120
120
121
for ( int i = 0 ; i < settings . UserCommands . Length ; i ++ )
121
122
{
122
- byte command = settings . UserCommands [ i ] ;
123
- if ( command >= 0 && command != byte . MaxValue ) Commands . Add ( ( UserCommand ) i , new RailDriverButton ( command ) ) ;
123
+ var userCommand = ( UserCommand ) i ;
124
+ byte button = settings . UserCommands [ i ] ;
125
+ if ( button >= 0 && button != byte . MaxValue )
126
+ {
127
+ RegisterCommand ( userCommand , new RailDriverButton ( button ) ) ;
128
+ if ( userCommand == UserCommand . ControlHorn || userCommand == UserCommand . ControlEmergencyPushButton )
129
+ {
130
+ RegisterCommand ( userCommand , new RailDriverButton ( ( byte ) ( button + 1 ) ) ) ;
131
+ }
132
+ }
124
133
}
125
134
}
126
135
}
@@ -130,8 +139,10 @@ public RailDriverState(Game game)
130
139
Trace . WriteLine ( error ) ;
131
140
}
132
141
133
- Commands [ UserCommand . ControlBailOff ] = new ExternalDeviceButton ( ) ;
134
- Commands [ UserCommand . ControlWiper ] = new ExternalDeviceButton ( ) ;
142
+ BailOff = new ExternalDeviceButton ( ) ;
143
+ Wiper = new ExternalDeviceButton ( ) ;
144
+ RegisterCommand ( UserCommand . ControlBailOff , BailOff ) ;
145
+ RegisterCommand ( UserCommand . ControlWiper , Wiper ) ;
135
146
136
147
CabControls [ ( new CabViewControlType ( CABViewControlTypes . DIRECTION ) , - 1 ) ] = Direction ;
137
148
CabControls [ ( new CabViewControlType ( CABViewControlTypes . THROTTLE ) , - 1 ) ] = Throttle ;
@@ -159,13 +170,16 @@ public void Update()
159
170
float a = EngineBrake . Value ;
160
171
float calOff = ( 1 - a ) * bailoffDisengaged . Item1 + a * bailoffDisengaged . Item2 ;
161
172
float calOn = ( 1 - a ) * bailoffEngaged . Item1 + a * bailoffEngaged . Item2 ;
162
- Commands [ UserCommand . ControlBailOff ] . IsDown = Percentage ( readBuffer [ 5 ] , calOff , calOn ) > 50 ;
163
- Commands [ UserCommand . ControlWiper ] . IsDown = ( int ) ( .01 * Percentage ( readBuffer [ 6 ] , wipers ) + 2.5 ) != 1 ;
173
+ BailOff . IsDown = Percentage ( readBuffer [ 5 ] , calOff , calOn ) > 50 ;
174
+ Wiper . IsDown = ( int ) ( .01 * Percentage ( readBuffer [ 6 ] , wipers ) + 2.5 ) != 1 ;
164
175
Lights . Value = ( int ) ( .01 * Percentage ( readBuffer [ 7 ] , headlight ) + 2.5 ) ;
165
176
166
- foreach ( var button in Commands . Values )
177
+ foreach ( var buttonList in Commands . Values )
167
178
{
168
- if ( button is RailDriverButton rd ) rd . Update ( readBuffer ) ;
179
+ foreach ( var button in buttonList )
180
+ {
181
+ if ( button is RailDriverButton rd ) rd . Update ( readBuffer ) ;
182
+ }
169
183
}
170
184
}
171
185
}
@@ -275,10 +289,10 @@ public class RailDriverButton : ExternalDeviceButton
275
289
{
276
290
int Index ;
277
291
byte Mask ;
278
- public RailDriverButton ( byte command )
292
+ public RailDriverButton ( byte button )
279
293
{
280
- Index = 8 + command / 8 ;
281
- Mask = ( byte ) ( 1 << ( command % 8 ) ) ;
294
+ Index = 8 + button / 8 ;
295
+ Mask = ( byte ) ( 1 << ( button % 8 ) ) ;
282
296
}
283
297
public void Update ( byte [ ] data )
284
298
{
0 commit comments