all triggers should be documented way nicer #2001
This commit is contained in:
parent
5e70d622e8
commit
a92707266e
|
@ -15,6 +15,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This utility produces images of trigger signals supported by rusEFI
|
* This utility produces images of trigger signals supported by rusEFI
|
||||||
|
@ -29,8 +30,9 @@ public class TriggerImage {
|
||||||
private static final String TOP_MESSAGE = StartupFrame.LINK_TEXT;
|
private static final String TOP_MESSAGE = StartupFrame.LINK_TEXT;
|
||||||
private static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests";
|
private static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests";
|
||||||
|
|
||||||
public static final int WHEEL_BORDER = 20;
|
private static final int WHEEL_BORDER = 20;
|
||||||
public static final int WHEEL_DIAMETER = 300;
|
private static final int WHEEL_DIAMETER = 300;
|
||||||
|
private static final int SMALL_DIAMETER = 250;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* number of extra frames
|
* number of extra frames
|
||||||
|
@ -66,16 +68,16 @@ public class TriggerImage {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
generateImages(workingFolder, triggerPanel, topPanel);
|
generateImages(workingFolder, triggerPanel, topPanel, content);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
System.exit(-1);
|
// System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generateImages(String workingFolder, TriggerPanel trigger, JPanel topPanel) throws IOException {
|
private static void generateImages(String workingFolder, TriggerPanel trigger, JPanel topPanel, JPanel content) throws IOException {
|
||||||
String fileName = workingFolder + File.separator + INPUT_FILE_NAME;
|
String fileName = workingFolder + File.separator + INPUT_FILE_NAME;
|
||||||
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
||||||
|
|
||||||
|
@ -88,35 +90,28 @@ public class TriggerImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.startsWith(TRIGGERTYPE)) {
|
if (line.startsWith(TRIGGERTYPE)) {
|
||||||
readTrigger(br, line, trigger, topPanel);
|
readTrigger(br, line, trigger, topPanel, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readTrigger(BufferedReader reader, String line, TriggerPanel triggerPanel, JPanel topPanel) throws IOException {
|
private static void readTrigger(BufferedReader reader, String line, TriggerPanel triggerPanel, JPanel topPanel, JPanel content) throws IOException {
|
||||||
TriggerWheelInfo triggerWheelInfo = TriggerWheelInfo.readTriggerWheelInfo(line, reader);
|
TriggerWheelInfo triggerWheelInfo = TriggerWheelInfo.readTriggerWheelInfo(line, reader);
|
||||||
// if (triggerWheelInfo.id != Fields.TT_TT_SUBARU_7_6)
|
// if (triggerWheelInfo.id != Fields.TT_TT_SUBARU_7_6)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
JPanel clock = new JPanel() {
|
List<TriggerSignal> firstWheel = triggerWheelInfo.signals.stream().filter(signal -> signal.waveIndex == 0).collect(Collectors.toList());
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
super.paint(g);
|
|
||||||
|
|
||||||
g.setColor(Color.black);
|
if (1 == 1) {
|
||||||
|
firstWheel = compressAngle(firstWheel);
|
||||||
|
}
|
||||||
|
|
||||||
g.drawArc(WHEEL_BORDER, WHEEL_BORDER, WHEEL_DIAMETER, WHEEL_DIAMETER, 0, 90);
|
JPanel clock = createWheelPanel(firstWheel);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
return new Dimension(WHEEL_DIAMETER + 2 * WHEEL_BORDER, WHEEL_DIAMETER + 2 * WHEEL_BORDER);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
clock.setBackground(Color.orange);
|
|
||||||
|
|
||||||
topPanel.removeAll();
|
topPanel.removeAll();
|
||||||
// topPanel.add(clock);
|
topPanel.add(clock);
|
||||||
|
UiUtils.trueLayout(topPanel);
|
||||||
|
UiUtils.trueLayout(content);
|
||||||
|
|
||||||
triggerPanel.tdcPosition = triggerWheelInfo.tdcPosition;
|
triggerPanel.tdcPosition = triggerWheelInfo.tdcPosition;
|
||||||
List<WaveState> waves = triggerWheelInfo.waves;
|
List<WaveState> waves = triggerWheelInfo.waves;
|
||||||
|
@ -162,7 +157,60 @@ public class TriggerImage {
|
||||||
UiUtils.trueLayout(triggerPanel);
|
UiUtils.trueLayout(triggerPanel);
|
||||||
UiUtils.trueRepaint(triggerPanel);
|
UiUtils.trueRepaint(triggerPanel);
|
||||||
new File(OUTPUT_FOLDER).mkdir();
|
new File(OUTPUT_FOLDER).mkdir();
|
||||||
UiUtils.saveImage(OUTPUT_FOLDER + File.separator + "trigger_" + triggerWheelInfo.id + ".png", triggerPanel);
|
UiUtils.saveImage(OUTPUT_FOLDER + File.separator + "trigger_" + triggerWheelInfo.id + ".png", content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<TriggerSignal> compressAngle(List<TriggerSignal> firstWheel) {
|
||||||
|
return firstWheel.stream().map(triggerSignal -> new TriggerSignal(triggerSignal.waveIndex, triggerSignal.state, triggerSignal.angle / 2)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static JPanel createWheelPanel(List<TriggerSignal> wheel) {
|
||||||
|
JPanel clock = new JPanel() {
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
g.setColor(Color.black);
|
||||||
|
|
||||||
|
for (int i = 0; i < wheel.size(); i++) {
|
||||||
|
TriggerSignal current = wheel.get(i);
|
||||||
|
|
||||||
|
drawRadialLine(g, current.angle);
|
||||||
|
|
||||||
|
double nextAngle = i == wheel.size() - 1 ? 360 : wheel.get(i + 1).angle;
|
||||||
|
int arcDuration = (int) (nextAngle - current.angle);
|
||||||
|
if (current.state == 0) {
|
||||||
|
g.drawArc(WHEEL_BORDER, WHEEL_BORDER, WHEEL_DIAMETER, WHEEL_DIAMETER, (int) current.angle, arcDuration);
|
||||||
|
} else {
|
||||||
|
int corner = WHEEL_BORDER + (WHEEL_DIAMETER - SMALL_DIAMETER) / 2;
|
||||||
|
g.drawArc(corner, corner, SMALL_DIAMETER, SMALL_DIAMETER, (int) current.angle, arcDuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(WHEEL_DIAMETER + 2 * WHEEL_BORDER, WHEEL_DIAMETER + 2 * WHEEL_BORDER);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
clock.setBackground(Color.orange);
|
||||||
|
return clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawRadialLine(Graphics g, double angle) {
|
||||||
|
int center = WHEEL_BORDER + WHEEL_DIAMETER / 2;
|
||||||
|
|
||||||
|
// converting to 'drawArc' angle convention
|
||||||
|
angle = 90 + angle;
|
||||||
|
double radianAngle = Math.toRadians(angle);
|
||||||
|
|
||||||
|
int smallX = (int) (SMALL_DIAMETER / 2 * Math.sin(radianAngle));
|
||||||
|
int smallY = (int) (SMALL_DIAMETER / 2 * Math.cos(radianAngle));
|
||||||
|
int largeX = (int) (WHEEL_DIAMETER / 2 * Math.sin(radianAngle));
|
||||||
|
int largeY = (int) (WHEEL_DIAMETER / 2 * Math.cos(radianAngle));
|
||||||
|
|
||||||
|
g.drawLine(center + smallX, center + smallY, center + largeX, center + largeY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTriggerName(TriggerWheelInfo triggerName) {
|
private static String getTriggerName(TriggerWheelInfo triggerName) {
|
||||||
|
@ -174,10 +222,39 @@ public class TriggerImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
static List<WaveState> readTrigger(BufferedReader reader, int count) throws IOException {
|
static List<WaveState> convertSignalsToWaves(List<TriggerSignal> signals) {
|
||||||
|
/**
|
||||||
|
* todo: what does this code do? does this work?
|
||||||
|
* looks to be repeating trigger share couple of times? but not visible on images somehow?
|
||||||
|
*/
|
||||||
|
List<TriggerSignal> toShow = new ArrayList<>(signals);
|
||||||
|
for (int i = 1; i <= 2 + EXTRA_COUNT; i++) {
|
||||||
|
for (TriggerSignal s : signals)
|
||||||
|
toShow.add(new TriggerSignal(s.waveIndex, s.state, s.angle + i * 720));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<WaveState> waves = new ArrayList<>();
|
||||||
|
waves.add(new WaveState());
|
||||||
|
waves.add(new WaveState());
|
||||||
|
waves.add(new WaveState());
|
||||||
|
|
||||||
|
for (TriggerSignal s : toShow) {
|
||||||
|
WaveState.trigger_value_e signal = (s.state == 0) ? WaveState.trigger_value_e.TV_LOW : WaveState.trigger_value_e.TV_HIGH;
|
||||||
|
|
||||||
|
WaveState waveState = waves.get(s.waveIndex);
|
||||||
|
waveState.handle(signal, s.angle);
|
||||||
|
}
|
||||||
|
for (WaveState wave : waves)
|
||||||
|
wave.wrap();
|
||||||
|
|
||||||
|
return waves;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
static List<TriggerSignal> readSignals(BufferedReader reader, int count) throws IOException {
|
||||||
String line;
|
String line;
|
||||||
String[] tokens;
|
String[] tokens;
|
||||||
List<Signal> signals = new ArrayList<>();
|
List<TriggerSignal> signals = new ArrayList<>();
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (index < count) {
|
while (index < count) {
|
||||||
|
@ -191,59 +268,18 @@ public class TriggerImage {
|
||||||
int signalState = Integer.parseInt(tokens[3]);
|
int signalState = Integer.parseInt(tokens[3]);
|
||||||
double angle = Double.parseDouble(tokens[4]);
|
double angle = Double.parseDouble(tokens[4]);
|
||||||
|
|
||||||
Signal s = new Signal(signalIndex, signalState, angle);
|
TriggerSignal s = new TriggerSignal(signalIndex, signalState, angle);
|
||||||
// System.out.println(s);
|
// System.out.println(s);
|
||||||
signals.add(s);
|
signals.add(s);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
return signals;
|
||||||
List<Signal> toShow = new ArrayList<>(signals);
|
|
||||||
for (int i = 1; i <= 2 + EXTRA_COUNT; i++) {
|
|
||||||
for (Signal s : signals)
|
|
||||||
toShow.add(new Signal(s.waveIndex, s.state, s.angle + i * 720));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<WaveState> waves = new ArrayList<>();
|
|
||||||
waves.add(new WaveState());
|
|
||||||
waves.add(new WaveState());
|
|
||||||
waves.add(new WaveState());
|
|
||||||
|
|
||||||
for (Signal s : toShow) {
|
|
||||||
WaveState.trigger_value_e signal = (s.state == 0) ? WaveState.trigger_value_e.TV_LOW : WaveState.trigger_value_e.TV_HIGH;
|
|
||||||
|
|
||||||
WaveState waveState = waves.get(s.waveIndex);
|
|
||||||
waveState.handle(signal, s.angle);
|
|
||||||
}
|
|
||||||
for (WaveState wave : waves)
|
|
||||||
wave.wrap();
|
|
||||||
|
|
||||||
return waves;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int angleToTime(double prevUp) {
|
public static int angleToTime(double prevUp) {
|
||||||
return (int) (prevUp);
|
return (int) (prevUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Signal {
|
|
||||||
private final double angle;
|
|
||||||
private final int state;
|
|
||||||
private final int waveIndex;
|
|
||||||
|
|
||||||
public Signal(int waveIndex, int state, double angle) {
|
|
||||||
this.waveIndex = waveIndex;
|
|
||||||
this.state = state;
|
|
||||||
this.angle = angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Signal{" +
|
|
||||||
"signal=" + waveIndex +
|
|
||||||
", angle=" + angle +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TriggerPanel extends JPanel {
|
private static class TriggerPanel extends JPanel {
|
||||||
public String name = "";
|
public String name = "";
|
||||||
public String id;
|
public String id;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
public class TriggerSignal {
|
||||||
|
final double angle;
|
||||||
|
final int state;
|
||||||
|
final int waveIndex;
|
||||||
|
|
||||||
|
public TriggerSignal(int waveIndex, int state, double angle) {
|
||||||
|
this.waveIndex = waveIndex;
|
||||||
|
this.state = state;
|
||||||
|
this.angle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Signal{" +
|
||||||
|
"signal=" + waveIndex +
|
||||||
|
", state=" + state +
|
||||||
|
", angle=" + angle +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,12 +11,14 @@ class TriggerWheelInfo {
|
||||||
final double tdcPosition;
|
final double tdcPosition;
|
||||||
final String triggerName;
|
final String triggerName;
|
||||||
final List<WaveState> waves;
|
final List<WaveState> waves;
|
||||||
|
final List<TriggerSignal> signals;
|
||||||
|
|
||||||
public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List<WaveState> waves) {
|
public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List<WaveState> waves, List<TriggerSignal> signals) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.tdcPosition = tdcPosition;
|
this.tdcPosition = tdcPosition;
|
||||||
this.triggerName = triggerName;
|
this.triggerName = triggerName;
|
||||||
this.waves = waves;
|
this.waves = waves;
|
||||||
|
this.signals = signals;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException {
|
static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException {
|
||||||
|
@ -31,9 +33,10 @@ class TriggerWheelInfo {
|
||||||
|
|
||||||
System.out.println("id=" + id + ", count=" + eventCount + ", name=" + triggerName);
|
System.out.println("id=" + id + ", count=" + eventCount + ", name=" + triggerName);
|
||||||
|
|
||||||
List<WaveState> waves = TriggerImage.readTrigger(reader, eventCount);
|
List<TriggerSignal> signals = TriggerImage.readSignals(reader, eventCount);
|
||||||
|
|
||||||
|
List<WaveState> waves = TriggerImage.convertSignalsToWaves(signals);
|
||||||
|
|
||||||
return new TriggerWheelInfo(id, tdcPosition, triggerName, waves);
|
return new TriggerWheelInfo(id, tdcPosition, triggerName, waves, signals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue