triggerImage: todo: support symmetrical crank

This commit is contained in:
rusefillc 2022-10-19 15:12:51 -04:00
parent c376d4de90
commit f45347a00a
2 changed files with 36 additions and 18 deletions

View File

@ -1,7 +1,6 @@
package com.rusefi.trigger;
import com.rusefi.StartupFrame;
import com.rusefi.enums.trigger_type_e;
import com.rusefi.ui.engine.UpDownImage;
import com.rusefi.core.ui.FrameHelper;
import com.rusefi.ui.util.UiUtils;
@ -15,6 +14,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* This utility produces images of trigger signals supported by rusEFI
@ -37,14 +37,13 @@ public class TriggerImage {
*/
public static int EXTRA_COUNT = 1;
private static int sleepAtEnd;
private static trigger_type_e onlyOneTrigger = null;
/**
* todo: https://github.com/rusefi/rusefi/issues/2077
* @see TriggerWheelInfo#isCrankBased
*/
private static String getTriggerName(TriggerWheelInfo triggerName) {
switch (findByOrdinal(triggerName.getId())) {
switch (TriggerWheelInfo.findByOrdinal(triggerName.getId())) {
case TT_FORD_ASPIRE:
return "Ford Aspire";
case TT_VVT_BOSCH_QUICK_START:
@ -102,7 +101,7 @@ public class TriggerImage {
}
if (args.length > 1)
onlyOneTrigger = findByOrdinal(Integer.parseInt(args[1]));
TriggerWheelInfo.onlyOneTrigger = TriggerWheelInfo.findByOrdinal(Integer.parseInt(args[1]));
if (args.length > 2)
sleepAtEnd = Integer.parseInt(args[2]);
@ -137,7 +136,7 @@ public class TriggerImage {
}
private static void onWheel(TriggerPanel triggerPanel, JPanel topPanel, JPanel content, TriggerWheelInfo triggerWheelInfo) {
if (onlyOneTrigger != null && findByOrdinal(triggerWheelInfo.getId()) != onlyOneTrigger)
if (TriggerWheelInfo.onlyOneTrigger != null && TriggerWheelInfo.findByOrdinal(triggerWheelInfo.getId()) != TriggerWheelInfo.onlyOneTrigger)
return;
topPanel.removeAll();
@ -198,7 +197,7 @@ public class TriggerImage {
UiUtils.trueRepaint(triggerPanel);
content.paintImmediately(content.getVisibleRect());
new File(OUTPUT_FOLDER).mkdir();
UiUtils.saveImage(OUTPUT_FOLDER + File.separator + "trigger_" + findByOrdinal(triggerWheelInfo.getId()) + ".png", content);
UiUtils.saveImage(OUTPUT_FOLDER + File.separator + "trigger_" + TriggerWheelInfo.findByOrdinal(triggerWheelInfo.getId()) + ".png", content);
}
@NotNull
@ -311,15 +310,6 @@ public class TriggerImage {
return waves;
}
public static trigger_type_e findByOrdinal(int id) {
// todo: do we care about quicker implementation? probably not
for (trigger_type_e type : trigger_type_e.values()) {
if (type.ordinal() == id)
return type;
}
throw new IllegalArgumentException("No type for " + id);
}
private static class TriggerPanel extends JPanel {
public String name = "";
public String id;
@ -363,6 +353,7 @@ public class TriggerImage {
}
g.drawString(" " + tdcMessage, 0, tdcFontSize);
g.setColor(Color.darkGray);
Objects.requireNonNull(gaps.gapFrom, "gaps from " + name);
for (int i = 0; i < gaps.gapFrom.length; i++) {
String message = "Sync " + (i + 1) + ": From " + gaps.gapFrom[i] + " to " + gaps.gapTo[i];
g.drawString(" " + message, 0, tdcFontSize * (2 + i));

View File

@ -1,11 +1,13 @@
package com.rusefi.trigger;
import com.rusefi.config.generated.Fields;
import com.rusefi.enums.trigger_type_e;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.rusefi.config.generated.Fields.*;
@ -13,6 +15,7 @@ import static com.rusefi.config.generated.Fields.*;
public class TriggerWheelInfo {
private static final String TRIGGERTYPE = "TRIGGERTYPE";
static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests";
static trigger_type_e onlyOneTrigger = null;
private final int id;
private final boolean isSecondWheelCam;
@ -23,12 +26,14 @@ public class TriggerWheelInfo {
private final boolean hasSecondChannel;
private final boolean hardcodedOperationMode;
private final TriggerGaps gaps;
private final int cycleDuration;
public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List<TriggerSignal> signals,
boolean isCrankBased,
boolean isSecondWheelCam,
boolean hasSecondChannel,
boolean hardcodedOperationMode, TriggerGaps gaps) {
boolean hardcodedOperationMode, TriggerGaps gaps,
int cycleDuration) {
this.id = id;
this.isSecondWheelCam = isSecondWheelCam;
this.tdcPosition = tdcPosition;
@ -37,7 +42,19 @@ public class TriggerWheelInfo {
this.isCrankBased = isCrankBased;
this.hasSecondChannel = hasSecondChannel;
this.hardcodedOperationMode = hardcodedOperationMode;
this.gaps = gaps;
this.gaps = Objects.requireNonNull(gaps, "gaps " + triggerName);
this.cycleDuration = cycleDuration;
boolean crankCycled = cycleDuration == 360;
com.rusefi.enums.trigger_type_e ordinal = findByOrdinal(id);
if (ordinal == onlyOneTrigger) {
System.out.println("That's the one: " + ordinal);
}
if (id != trigger_type_e_TT_36_2_2_2) {
if (crankCycled && !isCrankBased)
throw new IllegalStateException("Not isCrankBased " + triggerName + " " + cycleDuration);
if (!crankCycled && isCrankBased)
throw new IllegalStateException("Not crankCycled " + triggerName);
}
}
private static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException {
@ -111,7 +128,8 @@ public class TriggerWheelInfo {
isSecondWheelCam,
hasSecondChannel,
hardcodedOperationMode,
gaps
gaps,
cycleDuration
);
}
@ -144,6 +162,15 @@ public class TriggerWheelInfo {
}
}
public static com.rusefi.enums.trigger_type_e findByOrdinal(int id) {
// todo: do we care about quicker implementation? probably not
for (trigger_type_e type : com.rusefi.enums.trigger_type_e.values()) {
if (type.ordinal() == id)
return type;
}
throw new IllegalArgumentException("No type for " + id);
}
@NotNull
public List<TriggerSignal> getFirstWheeTriggerSignals() {
List<TriggerSignal> firstWheel = getTriggerSignals(0);