Package com.grt192.controller.hauntedhouse

Source Code of com.grt192.controller.hauntedhouse.HHLEDController

package com.grt192.controller.hauntedhouse;

import com.grt192.actuator.GRTLED;
import com.grt192.core.EventController;
import com.grt192.event.component.SwitchListener;
import com.grt192.mechanism.hauntedhouse.HauntedHouseMechanism;
import com.grt192.mechanism.hauntedhouse.HHLEDMechanism;
import com.grt192.sensor.GRTSwitch;

/**
* Master and Auto button state LED control
* @author data, ajc, nik.lele
*/
public class HHLEDController extends EventController implements SwitchListener {

    public static final String MECHANISM_ID = "HHLED";

    public static final boolean MASTER_DEFAULT_STATE = true;
    public static final boolean AUTO_DEFAULT_STATE = true;
    //private HauntedHouseController[] hhcs;
    private HHLEDMechanism om;
    private GRTSwitch masterSwitch;
    private GRTSwitch autoSwitch;
    private boolean master;
    private boolean auto;

    public HHLEDController() {
        initMechanism();

        //set default LED states
        master = MASTER_DEFAULT_STATE;
        auto = AUTO_DEFAULT_STATE;
    }

    public void initMechanism(){
        om = new HHLEDMechanism();
        addMechanism(MECHANISM_ID, om);
    }

    public void addListeners() {
        masterSwitch = (GRTSwitch) om.getSensor(HHLEDMechanism.MASTER_BUTTON_ID);
        autoSwitch = (GRTSwitch) om.getSensor(HHLEDMechanism.AUTO_BUTTON_ID);

        masterSwitch.addSwitchListener(this);
        autoSwitch.addSwitchListener(this);

        //TODO check if this was what worked-- both this and the
        //block above were implemented simultaneously
//        masterSwitch = (GRTSwitch) om.getSensor("MasterButton");
//        autoSwitch = (GRTSwitch) om.getSensor("AutoButton");
//        masterSwitch.addSwitchListener(this);
//        autoSwitch.addSwitchListener(this);
    }

    public void switchPressed(GRTSwitch source) {
        System.out.println("OperatorControl switch press");
    }

    public void switchReleased(GRTSwitch source) {
        System.out.println("OperatorControl switch release");
        if (source == autoSwitch) {
            auto = !auto;
            om.setAutoLED(auto);
            System.out.println("Auto switch to " + auto);
        }
        if (source == masterSwitch) {
            master = !master;
            om.setMasterLED(master);
            System.out.println("Master switch to " + master);
        }
    }
}
TOP

Related Classes of com.grt192.controller.hauntedhouse.HHLEDController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.