package com.googlecode.grt192.HH11.controller;
import com.googlecode.grt192.HH11.controller.autonomous.HHAutonomousController;
import com.googlecode.grt192.HH11.event.HHSwitchEvent;
import com.googlecode.grt192.HH11.event.HHSwitchListener;
import com.googlecode.grt192.HH11.mechanism.HHMechanism;
import com.googlecode.grt192.HH11.sensor.IHHSwitch;
/**
* A Haunted House Controller receives operator commands (HHSwitchEvent)s
* through the HHSwitch, and implements the behavior commanded.
*
* @author ajc, agd
*
*/
public class HHController implements HHSwitchListener {
private HHMechanism mech; // The mechanism the HHController is controlling
private IHHSwitch sw; // The switch the controller listens to to know when
// to actuate
private HHAutonomousController autoController; // Controller that takes care
// of actuation while in
// autonomous mode
// to actuate the mech.
/*
* Constructor
*
* @param mech The Mechanism the Controller is controlling
*
* @param sw The Switch the controller listens to for knowing when to
* actuate.
*
* @param sw The switch the controller listens to for events
*/
public HHController(HHMechanism mech, IHHSwitch sw, int[] wait_times) {
this.mech = mech;
this.sw = sw;
autoController = new HHAutonomousController(mech, wait_times);
}
@Override
public void auto(HHSwitchEvent hsev) {
System.out.println("auto");
autoController.enable();
}
/*
* Disables any HHAutonomousControllers that are actuating the mechanism
*/
@Override
public void manual(HHSwitchEvent hse) {
System.out.println("manual");
autoController.disable(); // Stop the autonomous controller
}
@Override
public void contract(HHSwitchEvent hse) {
mech.contract();
// System.out.println("contract");
}
@Override
public void retract(HHSwitchEvent hse) {
mech.retract();
// System.out.println("retract");
}
/*
* Start listening for switch events
*/
public void startListening() {
sw.addHHToggleSwitchListener(this);
}
/*
* Stop listening
*/
public void stopListening() {
sw.addHHToggleSwitchListener(this);
}
}