my first Lua

This commit is contained in:
rusefillc 2021-08-31 12:32:05 -04:00
parent 4e47e7bdb9
commit f47320fd70
5 changed files with 36 additions and 10 deletions

View File

@ -26,6 +26,8 @@ Release template (copy/paste this for new release):
All notable user-facing or behavior-altering changes will be documented in this file.
## Month 202x Release - "Release Name"
### Added
- rusEFI console Lua tab loads scripts from ECU on start
## August 2021 Release - "Lottery Day"

View File

@ -303,7 +303,7 @@ static int lua_stopEngine(lua_State*) {
void configureRusefiLuaHooks(lua_State* l) {
lua_register(l, "print", lua_efi_print);
lua_register(l, "readpin", lua_readpin);
lua_register(l, "readPin", lua_readpin);
lua_register(l, "getAnalog", lua_getAnalog);
lua_register(l, "getSensor", lua_getSensor);
lua_register(l, "getSensorRaw", lua_getSensorRaw);

View File

@ -449,6 +449,10 @@ static void configureInputs(void) {
addChannel("AUXF#1", engineConfiguration->auxFastSensor1_adcChannel, ADC_FAST);
for (int i = 0;i < LUA_ANALOG_INPUT_COUNT;i++) {
addChannel("LUA", engineConfiguration->luaAnalogInputs[i], ADC_FAST);
}
setAdcChannelOverrides();
}

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20210806;
public static final int CONSOLE_VERSION = 20210831;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -14,11 +14,14 @@ import java.awt.event.ActionListener;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import static com.rusefi.ui.util.UiUtils.trueLayout;
public class LuaScriptPanel {
private final UIContext context;
private final JPanel mainPanel = new JPanel(new BorderLayout());
private final AnyCommand command;
private final JTextArea scriptText = new JTextArea();
private boolean isFirstRender = true;
public LuaScriptPanel(UIContext context, Node config) {
this.context = context;
@ -31,7 +34,7 @@ public class LuaScriptPanel {
JButton writeButton = new JButton("Write to ECU");
JButton resetButton = new JButton("Reset/Reload Lua");
readButton.addActionListener(e -> read());
readButton.addActionListener(e -> readFromECU());
writeButton.addActionListener(e -> write());
resetButton.addActionListener(e -> resetLua());
@ -43,7 +46,7 @@ public class LuaScriptPanel {
// Center panel - script editor and log
JPanel scriptPanel = new JPanel(new BorderLayout());
scriptText.setTabSize(2);
scriptPanel.add(this.scriptText, BorderLayout.CENTER);
scriptPanel.add(scriptText, BorderLayout.CENTER);
//centerPanel.add(, BorderLayout.WEST);
JPanel messagesPanel = new JPanel(new BorderLayout());
@ -51,10 +54,27 @@ public class LuaScriptPanel {
messagesPanel.add(BorderLayout.NORTH, mp.getButtonPanel());
messagesPanel.add(BorderLayout.CENTER, mp.getMessagesScroll());
JSplitPane centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scriptPanel, messagesPanel);
JSplitPane centerPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scriptPanel, messagesPanel) {
@Override
public void paint(Graphics g) {
super.paint(g);
if (isFirstRender) {
readFromECU();
isFirstRender = true;
}
}
};
this.mainPanel.add(upperPanel, BorderLayout.NORTH);
this.mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(upperPanel, BorderLayout.NORTH);
mainPanel.add(centerPanel, BorderLayout.CENTER);
trueLayout(mainPanel);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
centerPanel.setDividerLocation(centerPanel.getSize().width / 2);
}
});
}
public JPanel getPanel() {
@ -68,11 +88,11 @@ public class LuaScriptPanel {
};
}
void read() {
BinaryProtocol bp = this.context.getLinkManager().getCurrentStreamState();
void readFromECU() {
BinaryProtocol bp = context.getLinkManager().getCurrentStreamState();
if (bp == null) {
// TODO: Handle missing ECU
scriptText.setText("No ECU located");
return;
}