package org.usfirst.frc2832.Robot_2016.HID;

import java.util.ArrayList;

public class VirtualGamepad {
	private ArrayList<GamepadState> states;
	private boolean done;
	
	
	// Millisecond timings
	long startTime, recordedOffset;
	int lastIndex = 0;
	
	public VirtualGamepad(ArrayList<GamepadState> states) {
		this.states = states;
	}
	
	public void start() {
		startTime = System.currentTimeMillis();
		recordedOffset = states.get(0).timestamp;
		
		done = false;
		lastIndex = 0;
	}
	
	public boolean isDone() {
		return (done);
	}
	
	public GamepadState getCurrentState() {
		long time = System.currentTimeMillis();
		
		// Interpolate the times, using the last recorded gamepad state.
		while (states.get(lastIndex).timestamp - recordedOffset <= time - startTime)
			lastIndex++;
		lastIndex--;
		
		if (lastIndex >= states.size()) {
			done = true;
			return (null);
		}
		
		// lastIndex now has the latest recorded data from the gamepad at this current time.
		return (states.get(lastIndex));
	}
}

@@ -723,16 +723,53 @@
 %09%09while 
+(lastIndex %3C states.size()) %7B%0D%0A%09%09%09if 
 (states.
@@ -835,16 +835,17 @@
 me)%0D%0A%09%09%09
+%09
 lastInde
@@ -856,20 +856,9 @@
 %0D%0A%09%09
-lastIndex--;
+%7D
 %0D%0A%09%09
@@ -937,24 +937,127 @@
 ;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A
+%09%09// We overshot in that interpolation stage, that was the first time it %22failed%22%0D%0A%09%09lastIndex--;%0D%0A%09%09%0D%0A
 %09%09// lastInd

Fix issue with out of bounds array check in recordable autonomous