package imseProc.stepperMotor.controllers;

import java.util.HashMap;
import java.util.List;

public class StepperCommand implements Comparable<StepperCommand>{
	/** Time to start movement */
	public int time;
	/** Axis to move */
	public int axis;
	/** Position to get to at end of movement */
	public int position;
	/** Speed of movement (steps/sec) */
	public int speed;
	/** start speed */
	public int rampStartSpeed;
	/** ramp duration (ms) */
	public int rampDuration;
	
	@Override
	public int compareTo(StepperCommand o) {			
		return ((Integer)time).compareTo(o.time);
	}
	
	public static HashMap<String, Object> toMap(List<StepperCommand> cmds, String prefix) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		int n = cmds.size();
		Integer timeArr[] = new Integer[n];
		Integer axisArr[] = new Integer[n];
		Integer positionArr[] = new Integer[n];
		Integer speedArr[] = new Integer[n];
		int i=0;
		for(StepperCommand cmd : cmds){
			timeArr[i] = cmd.time;
			axisArr[i] = cmd.axis;
			positionArr[i] = cmd.position;
			speedArr[i] = cmd.speed;
			i++;
		}
		
		map.put(prefix + "/time", timeArr);
		map.put(prefix + "/axis", axisArr);
		map.put(prefix + "/position", positionArr);
		map.put(prefix + "/speed", speedArr);
		return map;
	}

}
