// Path: src/core/GRTMacro.java
// public abstract class GRTMacro extends EventController {
// 
//     protected boolean hasCompletedExecution = false;
// 
//     public GRTMacro(String name) {
//         super(name);
//     }
// 
//     /**
//      * A GRTMacro will perform its desired function, and then quietly die.
//      *
//      * @param robot
//      */
//     public void execute(GRTRobot robot) {
//         while (!hasCompletedExecution)
//             perform();
//         die();
//     }
// 
//     /**
//      * Implemented on a per-macro basis
//      */
//     protected abstract void perform();
// 
//     /**
//      * After executing
//      */
//     public abstract void die();
// }
// 
// Path: src/event/events/GyroEvent.java
// public class GyroEvent extends SensorEvent {
// 
//     public GyroEvent(GRTGyro source, double rotation) {
//         super(source, 0, rotation);
//     }
// 
//     public double getAngle() {
//         return getData();
//     }
// }
// 
// Path: src/sensor/GRTGyro.java
// public class GRTGyro extends Sensor {
// 
//     public static final int KEY_ANGLE = 0;
//     public static final int NUM_DATA = 1;
//     private Gyro gyro;
//     private Vector gyroListeners;
// 
//     /**
//      * Instantiates a new gyroscope on the default analog module.
//      *
//      * @param channel channel gyro is connected to
//      * @param pollTime how often to poll
//      * @param name name of sensor
//      */
//     public GRTGyro(int channel, int pollTime, String name) {
//         super(name, pollTime, NUM_DATA);
//         gyro = new Gyro(channel);
//         gyroListeners = new Vector();
//     }
// 
//     /**
//      * Instantiates a new gyroscope.
//      *
//      * @param moduleNum number of analog module
//      * @param channel channel gyro is connected to
//      * @param pollTime how often to poll
//      * @param name name of sensor
//      */
//     public GRTGyro(int moduleNum, int channel, int pollTime, String name) {
//         super(name, pollTime, NUM_DATA);
//         gyro = new Gyro(moduleNum, channel);
//         gyroListeners = new Vector();
//     }
// 
//     /**
//      * Returns the total rotation of the gyro.
//      *
//      * @return the amount the gyroscope has rotated since its initialization, in
//      * degrees
//      */
//     public double getAngle() {
//         return gyro.getAngle();
//     }
// 
//     protected void poll() {
//         setState(KEY_ANGLE, gyro.getAngle());
//     }
// 
//     protected void notifyListeners(int id, double newDatum) {
//         if (id == KEY_ANGLE) {
//             GyroEvent e = new GyroEvent(this, newDatum);
//             for (Enumeration en = gyroListeners.elements(); en.hasMoreElements();)
//                 ((GyroListener) en.nextElement()).angleChanged(e);
//         }
//     }
// 
//     public void addListener(GyroListener l) {
//         gyroListeners.addElement(l);
//     }
// 
//     public void removeListener(GyroListener l) {
//         gyroListeners.removeElement(l);
//     }
// }


import core.GRTMacro;
import event.events.GyroEvent;
import event.listeners.GyroListener;
import sensor.GRTGyro;
package macro;


/**
 *
 * @author student
 */
public class GRTTurnMacro extends GRTMacro implements GyroListener {

    private double desiredTurnAngle;	//The desired angle of rotation.
    private double lastAngle;
    private double deltaAngle = 0;
    private GRTGyro gyro = null;

    public GRTTurnMacro(double degrees, GRTGyro gyro) {
        super("Turn Macro");
        this.desiredTurnAngle = degrees;
        this.gyro = gyro;
    }

    protected void perform() {
        startListening();
        //TODO
    }

    public void die() {
        stopListening();
    }

    protected void startListening() {
        gyro.addListener(this);
    }

    protected void stopListening() {
        gyro.removeListener(this);
    }

// Path: src/core/GRTMacro.java
// public abstract class GRTMacro extends EventController {
// 
//     protected boolean hasCompletedExecution = false;
// 
//     public GRTMacro(String name) {
//         super(name);
//     }
// 
//     /**
//      * A GRTMacro will perform its desired function, and then quietly die.
//      *
//      * @param robot
//      */
//     public void execute(GRTRobot robot) {
//         while (!hasCompletedExecution)
//             perform();
//         die();
//     }
// 
//     /**
//      * Implemented on a per-macro basis
//      */
//     protected abstract void perform();
// 
//     /**
//      * After executing
//      */
//     public abstract void die();
// }
// 
// Path: src/event/events/GyroEvent.java
// public class GyroEvent extends SensorEvent {
// 
//     public GyroEvent(GRTGyro source, double rotation) {
//         super(source, 0, rotation);
//     }
// 
//     public double getAngle() {
//         return getData();
//     }
// }
// 
// Path: src/sensor/GRTGyro.java
// public class GRTGyro extends Sensor {
// 
//     public static final int KEY_ANGLE = 0;
//     public static final int NUM_DATA = 1;
//     private Gyro gyro;
//     private Vector gyroListeners;
// 
//     /**
//      * Instantiates a new gyroscope on the default analog module.
//      *
//      * @param channel channel gyro is connected to
//      * @param pollTime how often to poll
//      * @param name name of sensor
//      */
//     public GRTGyro(int channel, int pollTime, String name) {
//         super(name, pollTime, NUM_DATA);
//         gyro = new Gyro(channel);
//         gyroListeners = new Vector();
//     }
// 
//     /**
//      * Instantiates a new gyroscope.
//      *
//      * @param moduleNum number of analog module
//      * @param channel channel gyro is connected to
//      * @param pollTime how often to poll
//      * @param name name of sensor
//      */
//     public GRTGyro(int moduleNum, int channel, int pollTime, String name) {
//         super(name, pollTime, NUM_DATA);
//         gyro = new Gyro(moduleNum, channel);
//         gyroListeners = new Vector();
//     }
// 
//     /**
//      * Returns the total rotation of the gyro.
//      *
//      * @return the amount the gyroscope has rotated since its initialization, in
//      * degrees
//      */
//     public double getAngle() {
//         return gyro.getAngle();
//     }
// 
//     protected void poll() {
//         setState(KEY_ANGLE, gyro.getAngle());
//     }
// 
//     protected void notifyListeners(int id, double newDatum) {
//         if (id == KEY_ANGLE) {
//             GyroEvent e = new GyroEvent(this, newDatum);
//             for (Enumeration en = gyroListeners.elements(); en.hasMoreElements();)
//                 ((GyroListener) en.nextElement()).angleChanged(e);
//         }
//     }
// 
//     public void addListener(GyroListener l) {
//         gyroListeners.addElement(l);
//     }
// 
//     public void removeListener(GyroListener l) {
//         gyroListeners.removeElement(l);
//     }
// }


// Path: src/macro/GRTTurnMacro.java
import core.GRTMacro;
import event.events.GyroEvent;
import event.listeners.GyroListener;
import sensor.GRTGyro;

package macro;


/**
 *
 * @author student
 */
public class GRTTurnMacro extends GRTMacro implements GyroListener {

    private double desiredTurnAngle;	//The desired angle of rotation.
    private double lastAngle;
    private double deltaAngle = 0;
    private GRTGyro gyro = null;

    public GRTTurnMacro(double degrees, GRTGyro gyro) {
        super("Turn Macro");
        this.desiredTurnAngle = degrees;
        this.gyro = gyro;
    }

    protected void perform() {
        startListening();
        //TODO
    }

    public void die() {
        stopListening();
    }

    protected void startListening() {
        gyro.addListener(this);
    }

    protected void stopListening() {
        gyro.removeListener(this);
    }

    public void angleChanged(GyroEvent e) {