diff --git a/firmware/controllers/alternatorController.cpp b/firmware/controllers/alternatorController.cpp index 12324b88b9..7a408aab4d 100644 --- a/firmware/controllers/alternatorController.cpp +++ b/firmware/controllers/alternatorController.cpp @@ -81,6 +81,7 @@ static void applyAlternatorPinState(PwmConfig *state, int stateIndex) { void initAlternatorCtrl(Logging *sharedLogger) { logger = sharedLogger; + addConsoleAction("altinfo", showAltInfo); if (boardConfiguration->alternatorControlPin == GPIO_UNASSIGNED) return; @@ -91,7 +92,6 @@ void initAlternatorCtrl(Logging *sharedLogger) { (tfunc_t) AltCtrlThread, NULL); addConsoleActionF("set_alt_p", setAltPFactor); - addConsoleAction("altinfo", showAltInfo); applySettings(); } diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp index 810f15512e..c2a60fb827 100644 --- a/firmware/controllers/error_handling.cpp +++ b/firmware/controllers/error_handling.cpp @@ -9,6 +9,7 @@ #include "error_handling.h" #include "io_pins.h" #include "memstreams.h" +#include "efilib2.h" #if EFI_HD44780_LCD #include "lcd_HD44780.h" @@ -83,17 +84,17 @@ char *getWarninig(void) { return warningBuffer; } -uint64_t lastLockTime; +uint32_t lastLockTime; uint32_t maxLockTime = 0; bool isInsideTriggerHandler = false; void onLockHook(void) { - lastLockTime = getTimeNowNt(); + lastLockTime = GET_TIMESTAMP(); } void onUnlockHook(void) { - uint64_t t = getTimeNowNt() - lastLockTime; + uint64_t t = GET_TIMESTAMP() - lastLockTime; if (t > maxLockTime) { maxLockTime = t; } diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index bf3ec789bf..a3f778cf84 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -32,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see com.rusefi.StartupFrame */ public class Launcher { - public static final int CONSOLE_VERSION = 20150513; + public static final int CONSOLE_VERSION = 20150514; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; diff --git a/java_console/ui/src/com/rusefi/ui/GaugesPanel.java b/java_console/ui/src/com/rusefi/ui/GaugesPanel.java index 4cc4ae2133..977f1cec8b 100644 --- a/java_console/ui/src/com/rusefi/ui/GaugesPanel.java +++ b/java_console/ui/src/com/rusefi/ui/GaugesPanel.java @@ -6,6 +6,7 @@ import com.rusefi.ui.storage.Node; import com.rusefi.ui.util.UiUtils; import com.rusefi.ui.widgets.PopupMenuButton; import com.rusefi.ui.widgets.SensorGauge; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -160,19 +161,30 @@ public class GaugesPanel { gauges.removeAll(); for (int i = 0; i < rows * columns; i++) { - String gaugeName = config.getProperty("gauge_" + i, DEFAULT_LAYOUT[i].name()); + String gaugeName = config.getProperty(getKey(i), DEFAULT_LAYOUT[i].name()); Sensor sensor; try { sensor = Sensor.valueOf(Sensor.class, gaugeName); } catch (IllegalArgumentException e) { sensor = DEFAULT_LAYOUT[i]; } - gauges.add(SensorGauge.createGauge(sensor)); + final int currentGaugeIndex = i; + gauges.add(SensorGauge.createGauge(sensor, new SensorGauge.GaugeChangeListener() { + @Override + public void onSensorChange(Sensor sensor) { + config.setProperty(getKey(currentGaugeIndex), sensor.name()); + } + })); } saveConfig(rows, columns); } + @NotNull + private String getKey(int i) { + return "gauge_" + i; + } + private void saveConfig(int rows, int columns) { config.setProperty(GAUGES_ROWS, rows); config.setProperty(GAUGES_COLUMNS, columns); diff --git a/java_console/ui/src/com/rusefi/ui/MessagesView.java b/java_console/ui/src/com/rusefi/ui/MessagesView.java index 2029275a69..caaa124de1 100644 --- a/java_console/ui/src/com/rusefi/ui/MessagesView.java +++ b/java_console/ui/src/com/rusefi/ui/MessagesView.java @@ -27,6 +27,7 @@ public class MessagesView { public final JScrollPane messagesScroll = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); public MessagesView() { + messages.setEditable(false); StyledDocument d = (StyledDocument) messages.getDocument(); bold = d.addStyle("StyleName", null); bold.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE); diff --git a/java_console/ui/src/com/rusefi/ui/RecentCommands.java b/java_console/ui/src/com/rusefi/ui/RecentCommands.java index a7ebacae63..c98c56f309 100644 --- a/java_console/ui/src/com/rusefi/ui/RecentCommands.java +++ b/java_console/ui/src/com/rusefi/ui/RecentCommands.java @@ -7,10 +7,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; @@ -26,7 +24,7 @@ public class RecentCommands { private final JPanel content = new JPanel(new GridLayout(NUMBER_OF_COMMANDS + 1, 1)); - private final LinkedHashMap entries = new LinkedHashMap() { + private static final LinkedHashMap entries = new LinkedHashMap() { @Override protected boolean removeEldestEntry(Map.Entry eldest) { return size() > NUMBER_OF_COMMANDS; @@ -188,4 +186,15 @@ public class RecentCommands { return command.compareTo(o.command); } } + + public static String getRecent(int index) { + List elements; + index = Math.max(0, index); + synchronized (entries) { + elements = new ArrayList<>(entries.keySet()); + } + if (index >= elements.size()) + return elements.get(0).command; + return elements.get(elements.size() - 1 - index).command; + } } \ No newline at end of file diff --git a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java index 98eeceec08..bc38e8ee2a 100644 --- a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java +++ b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java @@ -1,6 +1,7 @@ package com.rusefi.ui.widgets; import com.rusefi.io.CommandQueue; +import com.rusefi.ui.RecentCommands; import com.rusefi.ui.storage.Node; import javax.swing.*; @@ -9,6 +10,8 @@ import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; /** * Date: 3/20/13 @@ -26,6 +29,7 @@ public class AnyCommand { private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT)); private boolean reentrant; + private int index; public AnyCommand(final Node config, boolean listenToCommands) { this(config, config.getProperty(KEY, ""), listenToCommands); @@ -36,6 +40,15 @@ public class AnyCommand { content.setBorder(BorderFactory.createLineBorder(Color.PINK)); content.add(new JLabel("Command: ")); content.add(text); + JButton go = new JButton("Go"); + go.setContentAreaFilled(false); + go.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + go(); + } + }); + content.add(go); CommandQueue.getInstance().addListener(new CommandQueue.CommandQueueListener() { @Override @@ -45,16 +58,23 @@ public class AnyCommand { } }); + text.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_UP) { + String command = RecentCommands.getRecent(++index); + text.setText(command); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + String command = RecentCommands.getRecent(--index); + text.setText(command); + } + } + }); + text.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - String cmd = text.getText(); - if (!isValidInput(text)) - return; - int timeout = CommandQueue.getTimeout(cmd); - reentrant = true; - CommandQueue.getInstance().write(cmd.toLowerCase(), timeout); - reentrant = false; + go(); } }); text.getDocument().addDocumentListener(new DocumentListener() { @@ -87,15 +107,21 @@ public class AnyCommand { // todo: limit the length of text in the text field } + private void go() { + index = 0; + String cmd = text.getText(); + if (!isValidInput(text)) + return; + int timeout = CommandQueue.getTimeout(cmd); + reentrant = true; + CommandQueue.getInstance().write(cmd.toLowerCase(), timeout); + reentrant = false; + } + public JTextField getText() { return text; } -// @Override -// public boolean requestFocusInWindow() { -// return text.requestFocusInWindow(); -// } - private static boolean isValidInput(JTextField text) { boolean isOk = true; for (char c : text.getText().toCharArray()) { diff --git a/java_console/ui/src/com/rusefi/ui/widgets/SensorGauge.java b/java_console/ui/src/com/rusefi/ui/widgets/SensorGauge.java index c566b9d9b1..454d7d635d 100644 --- a/java_console/ui/src/com/rusefi/ui/widgets/SensorGauge.java +++ b/java_console/ui/src/com/rusefi/ui/widgets/SensorGauge.java @@ -28,7 +28,7 @@ public class SensorGauge { return createGauge(sensor, GaugeChangeListener.VOID); } - private static Component createGauge(Sensor sensor, GaugeChangeListener listener) { + public static Component createGauge(Sensor sensor, GaugeChangeListener listener) { JPanel wrapper = new JPanel(new BorderLayout()); createGaugeBody(sensor, wrapper, listener); @@ -36,7 +36,7 @@ public class SensorGauge { return wrapper; } - interface GaugeChangeListener { + public interface GaugeChangeListener { GaugeChangeListener VOID = new GaugeChangeListener() { @Override public void onSensorChange(Sensor sensor) {