@@ -96,11 +96,15 @@ public void Initialize()
9696 switch ( ScriptName )
9797 {
9898 case "Automatic" :
99- Script = new AutomaticTractionCutOffRelay ( ) as TractionCutOffRelay ;
99+ Script = new AutomaticTractionCutOffRelay ( ) ;
100100 break ;
101101
102102 case "Manual" :
103- Script = new ManualTractionCutOffRelay ( ) as TractionCutOffRelay ;
103+ Script = new ManualTractionCutOffRelay ( ) ;
104+ break ;
105+
106+ case "PushButtons" :
107+ Script = new PushButtonsTractionCutOffRelay ( ) ;
104108 break ;
105109
106110 default :
@@ -399,4 +403,124 @@ public override void HandleEvent(PowerSupplyEvent evt)
399403 }
400404 }
401405 }
406+
407+ public class PushButtonsTractionCutOffRelay : TractionCutOffRelay
408+ {
409+ private Timer ClosingTimer ;
410+ private TractionCutOffRelayState PreviousState ;
411+ private bool QuickPowerOn ;
412+
413+ public override void Initialize ( )
414+ {
415+ ClosingTimer = new Timer ( this ) ;
416+ ClosingTimer . Setup ( ClosingDelayS ( ) ) ;
417+
418+ SetDriverClosingAuthorization ( true ) ;
419+ }
420+
421+ public override void Update ( float elapsedSeconds )
422+ {
423+ SetClosingAuthorization ( TCSClosingAuthorization ( ) && CurrentDieselEngineState ( ) == DieselEngineState . Running ) ;
424+
425+ switch ( CurrentState ( ) )
426+ {
427+ case TractionCutOffRelayState . Closed :
428+ if ( ! ClosingAuthorization ( ) || DriverOpeningOrder ( ) )
429+ {
430+ SetCurrentState ( TractionCutOffRelayState . Open ) ;
431+ }
432+ break ;
433+
434+ case TractionCutOffRelayState . Closing :
435+ if ( ClosingAuthorization ( ) && ( DriverClosingOrder ( ) || QuickPowerOn ) )
436+ {
437+ if ( ! ClosingTimer . Started )
438+ {
439+ ClosingTimer . Start ( ) ;
440+ }
441+
442+ if ( ClosingTimer . Triggered )
443+ {
444+ QuickPowerOn = false ;
445+ ClosingTimer . Stop ( ) ;
446+ SetCurrentState ( TractionCutOffRelayState . Closed ) ;
447+ }
448+ }
449+ else
450+ {
451+ QuickPowerOn = false ;
452+ ClosingTimer . Stop ( ) ;
453+ SetCurrentState ( TractionCutOffRelayState . Open ) ;
454+ }
455+ break ;
456+
457+ case TractionCutOffRelayState . Open :
458+ if ( ClosingAuthorization ( ) && ( DriverClosingOrder ( ) || QuickPowerOn ) )
459+ {
460+ SetCurrentState ( TractionCutOffRelayState . Closing ) ;
461+ }
462+ else if ( QuickPowerOn )
463+ {
464+ QuickPowerOn = false ;
465+ }
466+ break ;
467+ }
468+
469+ if ( PreviousState != CurrentState ( ) )
470+ {
471+ switch ( CurrentState ( ) )
472+ {
473+ case TractionCutOffRelayState . Open :
474+ SignalEvent ( Event . TractionCutOffRelayOpen ) ;
475+ break ;
476+
477+ case TractionCutOffRelayState . Closing :
478+ SignalEvent ( Event . TractionCutOffRelayClosing ) ;
479+ break ;
480+
481+ case TractionCutOffRelayState . Closed :
482+ SignalEvent ( Event . TractionCutOffRelayClosed ) ;
483+ break ;
484+ }
485+ }
486+
487+ PreviousState = CurrentState ( ) ;
488+ }
489+
490+ public override void HandleEvent ( PowerSupplyEvent evt )
491+ {
492+ switch ( evt )
493+ {
494+ case PowerSupplyEvent . CloseTractionCutOffRelayButtonPressed :
495+ SetDriverOpeningOrder ( false ) ;
496+ SetDriverClosingOrder ( true ) ;
497+ SignalEvent ( Event . TractionCutOffRelayClosingOrderOn ) ;
498+ Confirm ( CabControl . TractionCutOffRelayClosingOrder , CabSetting . On ) ;
499+ if ( ! ClosingAuthorization ( ) )
500+ {
501+ Message ( ConfirmLevel . Warning , Simulator . Catalog . GetString ( "Traction cut-off relay closing not authorized" ) ) ;
502+ }
503+ break ;
504+ case PowerSupplyEvent . CloseTractionCutOffRelayButtonReleased :
505+ SetDriverClosingOrder ( false ) ;
506+ break ;
507+ case PowerSupplyEvent . OpenTractionCutOffRelayButtonPressed :
508+ SetDriverClosingOrder ( false ) ;
509+ SetDriverOpeningOrder ( true ) ;
510+ SignalEvent ( Event . TractionCutOffRelayClosingOrderOff ) ;
511+ Confirm ( CabControl . TractionCutOffRelayClosingOrder , CabSetting . Off ) ;
512+ break ;
513+ case PowerSupplyEvent . OpenTractionCutOffRelayButtonReleased :
514+ SetDriverOpeningOrder ( false ) ;
515+ break ;
516+ case PowerSupplyEvent . QuickPowerOn :
517+ QuickPowerOn = true ;
518+ break ;
519+ case PowerSupplyEvent . QuickPowerOff :
520+ QuickPowerOn = false ;
521+ SetCurrentState ( TractionCutOffRelayState . Open ) ;
522+ break ;
523+ }
524+ }
525+ }
402526}
0 commit comments