Code Part 2 (paste in directly where you left off from the code above)
Code:
If (LightSwitchPosChanged=True) Then 'The switch is in a different position so run the code below
'Create special case exceptions to the rules below based on locomotive features.
'Rule exception for BR294. This works because it is the only locomotive with a combined throttle with train and locomotive brakes
If (LtSwCombinedThrottle=True And LtSwTrainBrake=True And LtSwLocoBrake=True And LtSwDynamicBrake=False And LtSwGearLever=False) Then
HoldKeyTime=HoldKeyTime-100
LtSwSkipThrottleStyleCheck=True
'MsgBox("BR294 Detected.",1)
End If
If (LtSwSkipThrottleStyleCheck=False) Then 'no exceptions have been applied so use default ThrottleStyle timing configuration
'Check ThrottleStyle to modify hold key times
Select Case (ThrottleStyle)
Case 0 'throttle as labeled on RD (throttle on bottom half)
'MsgBox("Throttle as labeled on RD",1)
HoldKeyTime=HoldKeyTime-50
Case 1 'throttle/train brake
'MsgBox("Throttle-Train Brake",1)
HoldKeyTime=HoldKeyTime
Case 2 'throttle/dynamic brake
'MsgBox("Throttle-Dynamic Brake",1)
HoldKeyTime=HoldKeyTime-100
Case 3 'all throttle
'MsgBox("All Throttle",1)
HoldKeyTime=HoldKeyTime-50
End Select
End If
HoldKeyDoubleTime = (HoldKeyTime + HoldKeyTime + 200) 'This is used to calculate how long to hold down the key to simulate an extended keypress
Select Case (CurLightSWPos)
Case (0) 'Set lights to Off
'SetRailSimValue(eRailSimControlID.HEADLIGHTS_ID, 1) 'toggle off headlights
'The following ScanCodes tell RD to send SHIFT+H to RW long enough to ensure lights turn off
MW3.sendScanCode("42:1,35:1") 'Press SHIFT (42) H (35)
MW3.insertDelay(HoldKeyDoubleTime) 'Uses double HoldKeyTime for extended keypress
MW3.sendScanCode("35:0,42:0") 'Release SHIFT (42) H (35)
LtSwLEDVal=63 'LED Value for 0
LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
MsgBox("The current light switch position is: OFF. Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtOffLoDebug & " - " & LtOffHiDebug & ".",1)
Else
End If
Case (1) 'Set lights to position 1
MW3.sendScanCode("42:1,35:1") 'Press SHIFT (42) H (35) 'Hold down SHIFT+H long enough to turn off lights
MW3.insertDelay(HoldKeyDoubleTime ) 'HoldKeyTime is doubled for extended keypress
MW3.sendScanCode("35:0,42:0") 'Release SHIFT (42) H (35)
MW3.insertDelay(50) 'Small delay before sending new keystrokes
MW3.sendScanCode("35:1") 'Press lower-case h (35)
MW3.insertDelay(HoldKeyTime)
MW3.sendScanCode("35:0") 'Release lower-case h (35)
LtSwLEDVal=6 'LED Value for 1
LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
MsgBox("The current light switch position is: DIM (Front). Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtDimLoDebug & " - " & LtDimHiDebug & ".",1)
Else
End If
Case (2) 'Set lights to position 2
'SetRailSimValue(eRailSimControlID.HEADLIGHTS_ID, 1) 'toggle on headlights
MW3.sendScanCode("35:1") 'Press lower-case h (35)
MW3.insertDelay(HoldKeyDoubleTime) 'Double the HoldKeyTime for extended keypress
MW3.sendScanCode("35:0") 'Release lower-case h (35)
LtSwLEDVal=91 'LED Value for 2
LtSwWriteToLED=True 'Finished this code block so it is ok to write to the LED
If (LightSwitchDebug=True) Then 'Switch debugging messages are turned on so display them
MsgBox("The current light switch position is: FULL (Rear). Current switch value is: " & LightSwitchReportedValue & ". Valid numbers for the range are: " & LtFullLoDebug & " - " & LtFullHiDebug & ".",1)
Else
End If
Case (3) 'Light switch is in an area between positions so do nothing
End Select
'write switch position to LEDs
If (LtSwWriteToLED=True) Then 'OK to write to LEDs
Dim OutputReport() as Byte = {0,134,LtSwLEDVal,64,56,0,0,0,0}
Dim LtSwLEDDisplayCounter as Integer=0
Dim LtSwLEDWriteSpeedCounter as Integer=0
For LtSwLEDDisplayCounter=1 to 200
MW3.SendGenericOutput(MyDevice,OutputReport)
Next
'Finished writing L code so get current speed to display
Dim speed As Single = GetRailSimValue(30, 0) 'speedometer
'make absolute and put in desired units
speed=Math.Abs(speed)
If (speedunit=True) Then speed=Math.Abs(speed*1.609344)
Dim speeds As String=speed.ToString("000") 'assumes that the train will never be faster than 999, this rounds also
If (appactive=true) Then 'write current speed if RailWorks is still the active app
'write to LEDs
Dim AltOutputReport() as Byte = {0,134,ToDigits(speeds.Substring(2, 1)),ToDigits(speeds.Substring(1, 1)),ToDigits(speeds.Substring(0, 1)),0,0,0,0}
For LtSwLEDWriteSpeedCounter=1 to 5
MW3.SendGenericOutput(MyDevice,AltOutputReport)
Next
lastspeed=speeds
End If
LtSwLEDDisplayCounter=0
LtSwLEDWriteSpeedCounter=0
LtSwWriteToLED=False
Else 'Do not write to LEDs
End If
LtSwWriteToLED=False
Else 'The switch is in the same position as last time so do not run the code
End if
Else
End If
lever(6).LastValue=AnalogValue(0)
End Select 'Analog Check End [/MWTAG13]