package com.thegongoliers.output.motors;

import com.thegongoliers.input.current.HighCurrentSensor;
import com.thegongoliers.input.time.Clock;
import com.thegongoliers.input.time.RobotClock;

public class CircuitBreakerMotorModule implements MotorModule {

    private final HighCurrentSensor mCurrentSensor;
    private final double mBreakDuration;
    private final Clock mClock;

    private double mLastTripTime;

    private boolean mIsTripped;

    public CircuitBreakerMotorModule(HighCurrentSensor currentSensor, double breakDuration, Clock clock){
        mCurrentSensor = currentSensor;
        mBreakDuration = breakDuration;
        mClock = clock;
    }

    public CircuitBreakerMotorModule(HighCurrentSensor currentSensor, double breakDuration){
        this(currentSensor, breakDuration, new RobotClock());
    }

    @Override
    public double run(double currentSpeed, double desiredSpeed, double deltaTime) {
        if (mCurrentSensor.isTriggered()){
            trip();
        }

        if (mIsTripped && mClock.getTime() - mLastTripTime < mBreakDuration){
            mIsTripped = false;
        }

        if (mIsTripped){
            return 0;
        }

        return desiredSpeed;
    }

    private void trip(){
        mIsTripped = true;
        mLastTripTime = mClock.getTime();
    }

}

@@ -70,33 +70,23 @@
 put.
-current.HighCurrentSensor
+switches.Switch
 ;%0Aim
@@ -173,16 +173,59 @@
 otClock;
+%0Aimport com.thegongoliers.utils.Resettable;
 %0A%0Apublic
@@ -305,40 +305,22 @@
 nal 
-HighCurrentSensor mCurrentSensor
+Switch mSwitch
 ;%0A  
@@ -500,39 +500,25 @@
 ule(
-HighCurrentSensor currentSensor
+Switch tripSwitch
 , do
@@ -564,37 +564,27 @@
    m
-CurrentSensor = currentSensor
+Switch = tripSwitch
 ;%0A  
@@ -693,39 +693,25 @@
 ule(
-HighCurrentSensor currentSensor
+Switch tripSwitch
 , do
@@ -748,21 +748,18 @@
 his(
-currentSensor
+tripSwitch
 , br
@@ -912,21 +912,14 @@
 f (m
-CurrentSensor
+Switch
 .isT
@@ -947,24 +947,134 @@
     trip();%0A
+            if (mSwitch instanceof Resettable)%7B%0A                ((Resettable) mSwitch).reset();%0A            %7D%0A
         %7D%0A%0A 

Make circuit breaker module more generic