001package jmri.jmrit.logix;
002
003import java.util.ArrayList;
004import java.util.ListIterator;
005
006/**
007*/
008
009public class RampData {
010
011    private int _timeInterval;
012    private float _throttleInterval;
013    private ArrayList<Float> _settings;
014    private float _rampLength;
015    private boolean _upRamp;
016
017    static float INCRE_RATE = 1.10f;  // multiplier to increase throttle increments
018
019    RampData(float throttleIncre, int timeIncre) {
020        _throttleInterval = throttleIncre; 
021        _timeInterval = timeIncre;
022    }
023    
024    protected boolean isUpRamp() {
025        return _upRamp;
026    }
027
028    protected void makeThrottleSettings(float fromSet, float toSet) {
029        _upRamp = (toSet >= fromSet);
030        _settings = new ArrayList<>();
031        float lowSetting;
032        float highSetting;
033        float throttleIncre = _throttleInterval;
034        if (_upRamp) {
035            lowSetting = fromSet;
036            highSetting = toSet;
037        } else {
038            lowSetting = toSet;
039            highSetting = fromSet;
040        }
041        while (lowSetting < highSetting) {
042            _settings.add(Float.valueOf(lowSetting));
043            lowSetting += throttleIncre;
044            throttleIncre *= INCRE_RATE;
045        }
046        _settings.add(Float.valueOf(highSetting));
047    }
048
049    protected void setRampLength(float rampLength) {
050        _rampLength =  rampLength;
051    }
052
053    protected float getRampLength() {
054        return _rampLength;
055    }
056
057    protected int getNumSteps() {
058        return _settings.size();
059    }
060
061    protected int getRamptime() {
062        return _settings.size()*_timeInterval;
063    }
064
065    protected float getMaxSpeed() {
066        if (_settings == null) {
067            throw new IllegalArgumentException("Null array of throttle settings"); 
068        }
069        return _settings.get(_settings.size() - 1).floatValue();
070    }
071
072    protected ListIterator<Float> speedIterator(boolean up) {
073        if (up) {
074            return _settings.listIterator(0);
075        } else {
076            return _settings.listIterator(_settings.size());
077            
078        }
079    }
080
081    protected int getRampTimeIncrement() {
082        return _timeInterval;
083    }
084
085}