refactoring

This commit is contained in:
rusefi 2020-05-26 01:29:01 -04:00
parent 6bb0a1c56b
commit 7cec254bb0
4 changed files with 35 additions and 28 deletions

View File

@ -19,7 +19,7 @@ import static com.rusefi.config.generated.Fields.PROTOCOL_ES_UP;
* *
* @see SensorSnifferPane * @see SensorSnifferPane
*/ */
public class EngineReport implements TimeAxisTranslator { public class EngineReport {
public static final String ENGINE_CHART = Fields.PROTOCOL_ENGINE_SNIFFER; public static final String ENGINE_CHART = Fields.PROTOCOL_ENGINE_SNIFFER;
public static final EngineReport MOCK = new EngineReport(Collections.singletonList(new UpDown(0, -1, 1, -1))); public static final EngineReport MOCK = new EngineReport(Collections.singletonList(new UpDown(0, -1, 1, -1)));
/** /**
@ -68,6 +68,8 @@ public class EngineReport implements TimeAxisTranslator {
return list; return list;
} }
private TimeAxisTranslator timeAxisTranslator = new TimeAxisTranslator() {
@Override @Override
public int getMaxTime() { public int getMaxTime() {
return maxTime; return maxTime;
@ -78,6 +80,23 @@ public class EngineReport implements TimeAxisTranslator {
return minTime; return minTime;
} }
@Override
public int timeToScreen(int time, int width) {
double translated = (time - minTime) * 1.0 / getDuration();
return (int) (width * translated);
}
@Override
public double screenToTime(int screenX, int screenWidth) {
double time = 1.0 * screenX * getDuration() / screenWidth + minTime;
return (int) time;
}
};
public TimeAxisTranslator getTimeAxisTranslator() {
return timeAxisTranslator;
}
/** /**
* @see EngineChartParser#unpackToMap(String) * @see EngineChartParser#unpackToMap(String)
*/ */
@ -121,18 +140,6 @@ public class EngineReport implements TimeAxisTranslator {
return times; return times;
} }
@Override
public int timeToScreen(int time, int width) {
double translated = (time - minTime) * 1.0 / getDuration();
return (int) (width * translated);
}
@Override
public double screenToTime(int screenX, int screenWidth) {
double time = 1.0 * screenX * getDuration() / screenWidth + minTime;
return (int) time;
}
/** /**
* @return Length of this chart in Engine Sniffer ticks * @return Length of this chart in Engine Sniffer ticks
*/ */

View File

@ -17,9 +17,9 @@ public class EngineReportTest {
EngineReport wr = new EngineReport(report); EngineReport wr = new EngineReport(report);
assertEquals(14, wr.getList().size()); assertEquals(14, wr.getList().size());
assertEquals(14679, wr.getMinTime()); assertEquals(14679, wr.getTimeAxisTranslator().getMinTime());
assertEquals(43849, wr.getMaxTime()); assertEquals(43849, wr.getTimeAxisTranslator().getMaxTime());
assertEquals(59, wr.timeToScreen(18134, 500)); assertEquals(59, wr.getTimeAxisTranslator().timeToScreen(18134, 500));
} }
} }

View File

@ -24,7 +24,7 @@ public class EngineSnifferStatusPanel {
private final JLabel timeLabel = new JLabel(); private final JLabel timeLabel = new JLabel();
private final JLabel angleLabel = new JLabel(); private final JLabel angleLabel = new JLabel();
private final JLabel rpmLabel = new JLabel(); private final JLabel rpmLabel = new JLabel();
private TimeAxisTranslator translator = EngineReport.MOCK; private TimeAxisTranslator translator = EngineReport.MOCK.getTimeAxisTranslator();
private RevolutionLog time2rpm = RevolutionLog.parseRevolutions(null); private RevolutionLog time2rpm = RevolutionLog.parseRevolutions(null);

View File

@ -119,22 +119,22 @@ public class UpDownImage extends JPanel {
return new TimeAxisTranslator() { return new TimeAxisTranslator() {
@Override @Override
public int timeToScreen(int time, int width) { public int timeToScreen(int time, int width) {
return UpDownImage.this.engineReport.timeToScreen(time, width); return UpDownImage.this.engineReport.getTimeAxisTranslator().timeToScreen(time, width);
} }
@Override @Override
public double screenToTime(int screen, int width) { public double screenToTime(int screen, int width) {
return UpDownImage.this.engineReport.screenToTime(screen, width); return UpDownImage.this.engineReport.getTimeAxisTranslator().screenToTime(screen, width);
} }
@Override @Override
public int getMaxTime() { public int getMaxTime() {
return UpDownImage.this.engineReport.getMaxTime(); return UpDownImage.this.engineReport.getTimeAxisTranslator().getMaxTime();
} }
@Override @Override
public int getMinTime() { public int getMinTime() {
return UpDownImage.this.engineReport.getMinTime(); return UpDownImage.this.engineReport.getTimeAxisTranslator().getMinTime();
} }
@Override @Override