triggerImage: todo: support symmetrical crank

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

View File

@ -1,7 +1,6 @@
package com.rusefi.trigger; package com.rusefi.trigger;
import com.rusefi.StartupFrame; import com.rusefi.StartupFrame;
import com.rusefi.enums.trigger_type_e;
import com.rusefi.ui.engine.UpDownImage; import com.rusefi.ui.engine.UpDownImage;
import com.rusefi.core.ui.FrameHelper; import com.rusefi.core.ui.FrameHelper;
import com.rusefi.ui.util.UiUtils; import com.rusefi.ui.util.UiUtils;
@ -15,6 +14,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.Objects;
/** /**
* This utility produces images of trigger signals supported by rusEFI * This utility produces images of trigger signals supported by rusEFI
@ -37,14 +37,13 @@ public class TriggerImage {
*/ */
public static int EXTRA_COUNT = 1; public static int EXTRA_COUNT = 1;
private static int sleepAtEnd; private static int sleepAtEnd;
private static trigger_type_e onlyOneTrigger = null;
/** /**
* todo: https://github.com/rusefi/rusefi/issues/2077 * todo: https://github.com/rusefi/rusefi/issues/2077
* @see TriggerWheelInfo#isCrankBased * @see TriggerWheelInfo#isCrankBased
*/ */
private static String getTriggerName(TriggerWheelInfo triggerName) { private static String getTriggerName(TriggerWheelInfo triggerName) {
switch (findByOrdinal(triggerName.getId())) { switch (TriggerWheelInfo.findByOrdinal(triggerName.getId())) {
case TT_FORD_ASPIRE: case TT_FORD_ASPIRE:
return "Ford Aspire"; return "Ford Aspire";
case TT_VVT_BOSCH_QUICK_START: case TT_VVT_BOSCH_QUICK_START:
@ -102,7 +101,7 @@ public class TriggerImage {
} }
if (args.length > 1) if (args.length > 1)
onlyOneTrigger = findByOrdinal(Integer.parseInt(args[1])); TriggerWheelInfo.onlyOneTrigger = TriggerWheelInfo.findByOrdinal(Integer.parseInt(args[1]));
if (args.length > 2) if (args.length > 2)
sleepAtEnd = Integer.parseInt(args[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) { 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; return;
topPanel.removeAll(); topPanel.removeAll();
@ -198,7 +197,7 @@ public class TriggerImage {
UiUtils.trueRepaint(triggerPanel); UiUtils.trueRepaint(triggerPanel);
content.paintImmediately(content.getVisibleRect()); content.paintImmediately(content.getVisibleRect());
new File(OUTPUT_FOLDER).mkdir(); 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 @NotNull
@ -311,15 +310,6 @@ public class TriggerImage {
return waves; 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 { private static class TriggerPanel extends JPanel {
public String name = ""; public String name = "";
public String id; public String id;
@ -363,6 +353,7 @@ public class TriggerImage {
} }
g.drawString(" " + tdcMessage, 0, tdcFontSize); g.drawString(" " + tdcMessage, 0, tdcFontSize);
g.setColor(Color.darkGray); g.setColor(Color.darkGray);
Objects.requireNonNull(gaps.gapFrom, "gaps from " + name);
for (int i = 0; i < gaps.gapFrom.length; i++) { for (int i = 0; i < gaps.gapFrom.length; i++) {
String message = "Sync " + (i + 1) + ": From " + gaps.gapFrom[i] + " to " + gaps.gapTo[i]; String message = "Sync " + (i + 1) + ": From " + gaps.gapFrom[i] + " to " + gaps.gapTo[i];
g.drawString(" " + message, 0, tdcFontSize * (2 + i)); g.drawString(" " + message, 0, tdcFontSize * (2 + i));

View File

@ -1,11 +1,13 @@
package com.rusefi.trigger; package com.rusefi.trigger;
import com.rusefi.config.generated.Fields; import com.rusefi.config.generated.Fields;
import com.rusefi.enums.trigger_type_e;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.rusefi.config.generated.Fields.*; import static com.rusefi.config.generated.Fields.*;
@ -13,6 +15,7 @@ import static com.rusefi.config.generated.Fields.*;
public class TriggerWheelInfo { public class TriggerWheelInfo {
private static final String TRIGGERTYPE = "TRIGGERTYPE"; private static final String TRIGGERTYPE = "TRIGGERTYPE";
static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests"; static final String DEFAULT_WORK_FOLDER = ".." + File.separator + "unit_tests";
static trigger_type_e onlyOneTrigger = null;
private final int id; private final int id;
private final boolean isSecondWheelCam; private final boolean isSecondWheelCam;
@ -23,12 +26,14 @@ public class TriggerWheelInfo {
private final boolean hasSecondChannel; private final boolean hasSecondChannel;
private final boolean hardcodedOperationMode; private final boolean hardcodedOperationMode;
private final TriggerGaps gaps; private final TriggerGaps gaps;
private final int cycleDuration;
public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List<TriggerSignal> signals, public TriggerWheelInfo(int id, double tdcPosition, String triggerName, List<TriggerSignal> signals,
boolean isCrankBased, boolean isCrankBased,
boolean isSecondWheelCam, boolean isSecondWheelCam,
boolean hasSecondChannel, boolean hasSecondChannel,
boolean hardcodedOperationMode, TriggerGaps gaps) { boolean hardcodedOperationMode, TriggerGaps gaps,
int cycleDuration) {
this.id = id; this.id = id;
this.isSecondWheelCam = isSecondWheelCam; this.isSecondWheelCam = isSecondWheelCam;
this.tdcPosition = tdcPosition; this.tdcPosition = tdcPosition;
@ -37,7 +42,19 @@ public class TriggerWheelInfo {
this.isCrankBased = isCrankBased; this.isCrankBased = isCrankBased;
this.hasSecondChannel = hasSecondChannel; this.hasSecondChannel = hasSecondChannel;
this.hardcodedOperationMode = hardcodedOperationMode; 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 { private static TriggerWheelInfo readTriggerWheelInfo(String line, BufferedReader reader) throws IOException {
@ -111,7 +128,8 @@ public class TriggerWheelInfo {
isSecondWheelCam, isSecondWheelCam,
hasSecondChannel, hasSecondChannel,
hardcodedOperationMode, 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 @NotNull
public List<TriggerSignal> getFirstWheeTriggerSignals() { public List<TriggerSignal> getFirstWheeTriggerSignals() {
List<TriggerSignal> firstWheel = getTriggerSignals(0); List<TriggerSignal> firstWheel = getTriggerSignals(0);