001package jmri.jmrit.ussctc; 002 003import jmri.*; 004import jmri.jmrit.Sound; 005 006/** 007 * Derive a CTC machine bell via a Turnout output. 008 * 009 * @author Bob Jacobsen Copyright (C) 2007, 2017 010 */ 011public class PhysicalBell implements Bell { 012 013 public PhysicalBell(String output) { 014 NamedBeanHandleManager hm = InstanceManager.getDefault(NamedBeanHandleManager.class); 015 TurnoutManager tm = InstanceManager.getDefault(TurnoutManager.class); 016 017 hOutput = hm.getNamedBeanHandle(output, tm.provideTurnout(output)); 018 } 019 020 public PhysicalBell(String output, Sound sound) { 021 this(output); 022 this.sound = sound; 023 } 024 025 NamedBeanHandle<Turnout> hOutput; 026 Sound sound = null; 027 028 public static int STROKE_DELAY = 250; 029 030 @Override 031 public void ring() { 032 hOutput.getBean().setCommandedState(Turnout.THROWN); 033 jmri.util.ThreadingUtil.runOnLayoutDelayed( 034 ()->{ 035 hOutput.getBean().setCommandedState(Turnout.CLOSED); 036 if (sound !=null) sound.play(); 037 }, 038 STROKE_DELAY); 039 } 040 041}