From 3b96cfc360e67e83dff7a77e28ef6015d6abdefc Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 18 Jan 2015 19:04:06 -0600 Subject: [PATCH] auto-sync --- .../models/src/com/rusefi/OutputChannel.java | 20 +++ java_console/ui/src/com/irnems/Launcher.java | 5 +- .../ui/src/com/rusefi/ui/FrameHelper.java | 11 ++ java_console/ui/src/com/rusefi/ui/Wizard.java | 143 ++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 java_console/models/src/com/rusefi/OutputChannel.java create mode 100644 java_console/ui/src/com/rusefi/ui/Wizard.java diff --git a/java_console/models/src/com/rusefi/OutputChannel.java b/java_console/models/src/com/rusefi/OutputChannel.java new file mode 100644 index 0000000000..effb6bf884 --- /dev/null +++ b/java_console/models/src/com/rusefi/OutputChannel.java @@ -0,0 +1,20 @@ +package com.rusefi; + +/** + * 1/18/2015 + */ +public enum OutputChannel { + WaveChartCurrentSize(11), + RunningTriggerError(12), + RunningOrderingTriggerError(13), + ; + private final int protocolId; + + OutputChannel(int protocolId) { + this.protocolId = protocolId; + } + + public int getProtocolId() { + return protocolId; + } +} diff --git a/java_console/ui/src/com/irnems/Launcher.java b/java_console/ui/src/com/irnems/Launcher.java index 22a0a4046a..739c06c073 100644 --- a/java_console/ui/src/com/irnems/Launcher.java +++ b/java_console/ui/src/com/irnems/Launcher.java @@ -19,10 +19,12 @@ import javax.swing.*; * @see WavePanel */ public class Launcher extends FrameHelper { - public static final int CONSOLE_VERSION = 20150112; + public static final int CONSOLE_VERSION = 20150118; public static final boolean SHOW_STIMULATOR = true; private final String port; + public static int defaultFontSize; + public Launcher(String port) { this.port = port; FileLog.MAIN.start(); @@ -51,6 +53,7 @@ public class Launcher extends FrameHelper { } // tabbedPane.addTab("live map adjustment", new Live3DReport().getControl()); tabbedPane.add("Messages", new MsgPanel(true).getContent()); + tabbedPane.add("Wizards", new Wizard().createPane()); if (!LinkManager.isLogViewerMode(port)) diff --git a/java_console/ui/src/com/rusefi/ui/FrameHelper.java b/java_console/ui/src/com/rusefi/ui/FrameHelper.java index 7618224ad9..2269c251ad 100644 --- a/java_console/ui/src/com/rusefi/ui/FrameHelper.java +++ b/java_console/ui/src/com/rusefi/ui/FrameHelper.java @@ -12,6 +12,7 @@ import java.awt.event.WindowEvent; */ public class FrameHelper { protected final JFrame frame = new JFrame(); + public static int defaultFontSize; protected void showFrame(JComponent component) { frame.setSize(800, 500); @@ -29,6 +30,12 @@ public class FrameHelper { } }); frame.add(component); + frame.addWindowListener(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + defaultFontSize = frame.getFont().getSize(); + } + }); frame.setVisible(true); } @@ -40,4 +47,8 @@ public class FrameHelper { FileLog.rlog("onWindowClosed"); FileLog.MAIN.close(); } + + public int getDefaultFontSize() { + return defaultFontSize; + } } diff --git a/java_console/ui/src/com/rusefi/ui/Wizard.java b/java_console/ui/src/com/rusefi/ui/Wizard.java new file mode 100644 index 0000000000..7546745914 --- /dev/null +++ b/java_console/ui/src/com/rusefi/ui/Wizard.java @@ -0,0 +1,143 @@ +package com.rusefi.ui; + +import com.irnems.core.Sensor; +import com.irnems.core.SensorCentral; +import com.rusefi.OutputChannel; +import com.rusefi.io.CommandQueue; +import com.rusefi.io.InvocationConfirmationListener; +import com.rusefi.trigger.TriggerShapeHolder; +import com.rusefi.ui.widgets.UpDownImage; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +/** + * 1/17/2015 + */ +public class Wizard { + private final JPanel content = new JPanel(); + private final JButton button = new JButton("Trigger Wizard"); + + interface WizardStep { + Component getContent(); + } + + abstract class WizardStepImpl implements WizardStep { + protected WizardStep nextStep; + + public WizardStepImpl() { + } + + public WizardStepImpl setNext(WizardStepImpl nextStep) { + this.nextStep = nextStep; + return nextStep; + } + } + + class SendCommand extends WizardStepImpl { + private final String command; + + SendCommand(String command) { + this.command = command; + } + + @Override + public Component getContent() { + CommandQueue.getInstance().write(command, CommandQueue.DEFAULT_TIMEOUT, new InvocationConfirmationListener() { + @Override + public void onCommandConfirmation() { + applyStep(nextStep); + } + }); + + return new JLabel("Sending " + command); + } + } + + private final WizardStepImpl TRIGGER_WIZARD_HELLO = new WizardStepImpl() { + @Override + public Component getContent() { + JButton button = new JButton("Hello, let's test trigger. Click this to process"); + button.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + applyStep(nextStep); + } + }); + return button; + } + }; + + { + TRIGGER_WIZARD_HELLO.setNext(new SendCommand("disable injection")) + .setNext(new SendCommand("disable ignition")) + .setNext(new SendCommand("chartsize " + (10 * TriggerShapeHolder.CURRENT.getTotalToothCount() * 2))) + .setNext(new SendCommand("subscribe " + OutputChannel.WaveChartCurrentSize.getProtocolId())) + .setNext(new SendCommand("subscribe " + OutputChannel.RunningTriggerError.getProtocolId())) + .setNext(new SendCommand("subscribe " + OutputChannel.RunningOrderingTriggerError.getProtocolId())) + .setNext(new SendCommand("set_analog_chart_freq " + 1)) + .setNext(new WaitForZeroRpm()) + + + ; + } + + public Component createPane() { + JPanel panel = new JPanel(new BorderLayout()); + panel.add(button, BorderLayout.NORTH); + + panel.add(content, BorderLayout.CENTER); + + button.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + button.setEnabled(false); + + applyStep(Wizard.this.TRIGGER_WIZARD_HELLO); + + + } + }); + return panel; + } + + private void applyStep(WizardStep step) { + Component newContent = getNextContent(step); + content.removeAll(); + this.content.add(newContent); + UpDownImage.trueRepaint(content); + } + + private Component getNextContent(WizardStep step) { + Component newContent; + if (step == null) { + newContent = new JLabel("Wizard is done!"); + button.setEnabled(true); + } else { + newContent = step.getContent(); + } + return newContent; + } + + private class WaitForZeroRpm extends WizardStepImpl { + public WaitForZeroRpm() { + } + + @Override + public Component getContent() { + double rpm = SensorCentral.getInstance().getValue(Sensor.RPM); + if (rpm == 0) { + return getNextContent(nextStep); + } + + + if (rpm != 0) { + return new JLabel("Current RPM: " + rpm + ", please stop the engine"); + } + + + return null; + } + } +}