Search in sources :

Example 1 with LnPr2ThrottleManager

use of jmri.jmrix.loconet.LnPr2ThrottleManager in project JMRI by JMRI.

the class LnPr2PowerManager method setPower.

@Override
public void setPower(int v) throws JmriException {
    power = UNKNOWN;
    // Instead of GPON/GPOFF, PR2 uses ops-mode writes to CV 128 for control
    if (v == ON) {
        // get current active address
        DccLocoAddress activeAddress = ((LnPr2ThrottleManager) InstanceManager.throttleManagerInstance()).getActiveAddress();
        if (activeAddress != null) {
            pm = new LnOpsModeProgrammer(sm, memo, activeAddress.getNumber(), activeAddress.isLongAddress());
            checkOpsProg();
            // set bit 1 in CV 128
            pm.writeCV(128, 1, null);
            power = ON;
            // NOI18N
            firePropertyChange("Power", null, null);
            // start making sure that the power is refreshed
            if (timer == null) {
                timer = new javax.swing.Timer(2 * 1000, new java.awt.event.ActionListener() {

                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        refresh();
                    }
                });
                timer.setInitialDelay(2 * 1000);
                // in case we run by
                timer.setRepeats(true);
            }
            timer.start();
        }
    } else if (v == OFF) {
        if (timer != null) {
            timer.stop();
        }
        // get current active address
        DccLocoAddress activeAddress = ((LnPr2ThrottleManager) InstanceManager.throttleManagerInstance()).getActiveAddress();
        if (activeAddress != null) {
            pm = new LnOpsModeProgrammer(sm, memo, activeAddress.getNumber(), activeAddress.isLongAddress());
            checkOpsProg();
            // reset bit 1 in CV 128
            pm.writeCV(128, 0, null);
            power = OFF;
        }
    }
    // notify of change
    // NOI18N
    firePropertyChange("Power", null, null);
}
Also used : LnOpsModeProgrammer(jmri.jmrix.loconet.LnOpsModeProgrammer) LnPr2ThrottleManager(jmri.jmrix.loconet.LnPr2ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

Aggregations

DccLocoAddress (jmri.DccLocoAddress)1 LnOpsModeProgrammer (jmri.jmrix.loconet.LnOpsModeProgrammer)1 LnPr2ThrottleManager (jmri.jmrix.loconet.LnPr2ThrottleManager)1