/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.oastem.frc.sensor;

import edu.wpi.first.wpilibj.CounterBase;
import edu.wpi.first.wpilibj.Encoder;

/**
 *
 * @author mduong15
 */
public class QuadratureEncoder {
    private Encoder enc;
    private double pulsesPerRevolution;
    
    public QuadratureEncoder(int channelA, int channelB)
    {
        enc = new Encoder(channelA, channelB);
        enc.start();
    }
    
    public QuadratureEncoder(int channelA, int channelB, double pulsesPerRev)
    {
        enc = new Encoder(channelA, channelB);
        pulsesPerRevolution = pulsesPerRev;
        enc.start();
    }
    
    public QuadratureEncoder(int channelA, int channelB, boolean isReversed, double pulsesPerRev)
    {
        enc = new Encoder(channelA, channelB, isReversed);
        pulsesPerRevolution = pulsesPerRev;
        enc.start();
    }
    
    public QuadratureEncoder(int channelA, int channelB, int scaleValue, double pulsesPerRev)
    {
        if (scaleValue == 1)
            enc = new Encoder(channelA, channelB, false, CounterBase.EncodingType.k1X);
        else if (scaleValue == 2)
            enc = new Encoder(channelA, channelB, false, CounterBase.EncodingType.k2X);
        else if (scaleValue == 4)
            enc = new Encoder(channelA, channelB, false, CounterBase.EncodingType.k4X);
        else
            enc = new Encoder(channelA, channelB, false, CounterBase.EncodingType.k4X);
        
        pulsesPerRevolution = pulsesPerRev;
        enc.start();
    }
    
    public QuadratureEncoder(int channelA, int channelB, boolean isReversed,
                            int scaleValue, double pulsesPerRev)
    {
        if (scaleValue == 1)
            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k1X);
        else if (scaleValue == 2)
            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k2X);
        else if (scaleValue == 4)
            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k4X);
        else
            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k4X);
        
        pulsesPerRevolution = pulsesPerRev;
        enc.start();
    }
    
    
    public void free()
    {
        enc.free();
    }
    
    public int get()
    {
        return enc.get();
    }
    
    public double getDistance()
    {
        return enc.getDistance();
    }
    
    public double getRate()
    {
        return enc.getRate();
    }
    
    public int getRaw()
    {
        return enc.getRaw();
    }
    
    public boolean isGoingForward()
    {
        return enc.getDirection();
    }
    
    public boolean isStopped()
    {
        return enc.getStopped();
    }
    
    public void reset()
    {
        enc.reset();
    }
    
    public void setDistancePerPulse(int wheelCircumference)
    {
        enc.setDistancePerPulse(wheelCircumference / pulsesPerRevolution);
    }
    
    public void setDistanceWithRatio(int distancePerPulse, double gearRatio)
    {
        enc.setDistancePerPulse(distancePerPulse * gearRatio);
    }
    
}

@@ -1069,16 +1069,64 @@
 hannelB,
+ boolean isReversed,%0A                           
  int sca
@@ -1173,85 +1173,132 @@
     
-if (scaleValue == 1)%0A            enc = new Encoder(channelA, channelB, false,
+CounterBase.EncodingType encType = CounterBase.EncodingType.k4X;%0A        %0A        if (scaleValue == 1)%0A            encType =
  Cou
@@ -1314,33 +1314,32 @@
 EncodingType.k1X
-)
 ;%0A        else i
@@ -1377,49 +1377,14 @@
  enc
- = new Encoder(channelA, channelB, false,
+Type =
  Cou
@@ -1400,33 +1400,32 @@
 EncodingType.k2X
-)
 ;%0A        else i
@@ -1463,49 +1463,14 @@
  enc
- = new Encoder(channelA, channelB, false,
+Type =
  Cou
@@ -1486,33 +1486,32 @@
 EncodingType.k4X
-)
 ;%0A        else%0A 
@@ -1500,33 +1500,25 @@
 4X;%0A        
-else%0A    
+%0A
         enc 
@@ -1555,43 +1555,27 @@
 lB, 
-false, CounterBase.EncodingType.k4X
+isReversed, encType
 );%0A 
@@ -1718,56 +1718,8 @@
 elB,
- boolean isReversed,%0A                           
  int
@@ -1770,553 +1770,64 @@
     
-if (scaleValue == 1)%0A            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k1X);%0A        else if (scaleValue == 2)%0A            enc = new Encoder(channelA, channelB, isRever
+this(channelA, channelB, fal
 se
-d
 , 
-CounterBase.EncodingType.k2X);%0A        else if (scaleValue == 4)%0A            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k4X);%0A        else%0A            enc = new Encoder(channelA, channelB, isReversed, CounterBase.EncodingType.k4X);%0A        %0A        pulsesPerRevolution = pulsesPerRev;%0A        enc.start(
+scaleValue, pulsesPerRev
 );%0A 
@@ -1836,21 +1836,16 @@
  %7D%0A    %0A
-    %0A
     publ

Update QuadratureEncoder.java. Hopefully you're not doing anything.