@@ -48,7 +48,8 @@ public class RailDriverState : ExternalDeviceState
4848 public ExternalDeviceCabControl TrainBrake = new ExternalDeviceCabControl ( ) ; // 0 (release) to 100 (CS), does not include emergency
4949 public ExternalDeviceCabControl EngineBrake = new ExternalDeviceCabControl ( ) ; // 0 to 100
5050 public ExternalDeviceCabControl Lights = new ExternalDeviceCabControl ( ) ; // lights rotary, 1 off, 2 dim, 3 full
51-
51+ ExternalDeviceButton BailOff ;
52+ ExternalDeviceButton Wiper ;
5253 public RailDriverState ( Game game )
5354 {
5455 try
@@ -119,8 +120,16 @@ public RailDriverState(Game game)
119120
120121 for ( int i = 0 ; i < settings . UserCommands . Length ; i ++ )
121122 {
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+ }
124133 }
125134 }
126135 }
@@ -130,8 +139,10 @@ public RailDriverState(Game game)
130139 Trace . WriteLine ( error ) ;
131140 }
132141
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 ) ;
135146
136147 CabControls [ ( new CabViewControlType ( CABViewControlTypes . DIRECTION ) , - 1 ) ] = Direction ;
137148 CabControls [ ( new CabViewControlType ( CABViewControlTypes . THROTTLE ) , - 1 ) ] = Throttle ;
@@ -159,13 +170,16 @@ public void Update()
159170 float a = EngineBrake . Value ;
160171 float calOff = ( 1 - a ) * bailoffDisengaged . Item1 + a * bailoffDisengaged . Item2 ;
161172 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 ;
164175 Lights . Value = ( int ) ( .01 * Percentage ( readBuffer [ 7 ] , headlight ) + 2.5 ) ;
165176
166- foreach ( var button in Commands . Values )
177+ foreach ( var buttonList in Commands . Values )
167178 {
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+ }
169183 }
170184 }
171185 }
@@ -275,10 +289,10 @@ public class RailDriverButton : ExternalDeviceButton
275289 {
276290 int Index ;
277291 byte Mask ;
278- public RailDriverButton ( byte command )
292+ public RailDriverButton ( byte button )
279293 {
280- Index = 8 + command / 8 ;
281- Mask = ( byte ) ( 1 << ( command % 8 ) ) ;
294+ Index = 8 + button / 8 ;
295+ Mask = ( byte ) ( 1 << ( button % 8 ) ) ;
282296 }
283297 public void Update ( byte [ ] data )
284298 {
0 commit comments