flasher status UI control with activity animation

This commit is contained in:
rusEfi 2019-07-14 21:51:38 -04:00
parent 1769fdb770
commit efb2dc3106
4 changed files with 62 additions and 3 deletions

View File

@ -5,6 +5,8 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ActionEvent;
import static com.rusefi.maintenance.FirmwareFlasher.TITLE;
/**
* (c) Andrey Belomutskiy 2013-2018
*/
@ -22,8 +24,13 @@ public class EraseChip extends ProcessStatusWindow {
"Please disconnect from vehicle", JOptionPane.YES_NO_OPTION);
if (dialogResult != JOptionPane.YES_OPTION)
return;
wnd.showFrame("rusEfi Firmware Flasher");
ExecHelper.submitAction(() -> executeCommand(getEraseCommand()), EraseChip.this.getClass() + " extProcessThread");
wnd.showFrame(TITLE);
StatusAnimation sa = new StatusAnimation(wnd);
ExecHelper.submitAction(() -> {
executeCommand(getEraseCommand());
sa.stop();
wnd.setStatus(FirmwareFlasher.DONE);
}, EraseChip.this.getClass() + " extProcessThread");
}
});
}

View File

@ -20,6 +20,8 @@ public class FirmwareFlasher extends ProcessStatusWindow {
private static final String SUCCESS_MESSAGE_TAG = "shutdown command invoked";
private static final String FAILED_MESSAGE_TAG = "failed";
private static final String NO_DRIVER_MESSAGE_TAG = "failed with LIBUSB_ERROR_NOT_SUPPORTED";
public static final String TITLE = "rusEfi Firmware Flasher";
public static final String DONE = "DONE!";
private final JButton button;
private String fileName;
@ -37,7 +39,7 @@ public class FirmwareFlasher extends ProcessStatusWindow {
return;
wnd.showFrame("rusEfi Firmware Flasher");
wnd.showFrame(TITLE);
ExecHelper.submitAction(() -> doFlashFirmware(), getClass() + " extProcessThread");
}
@ -52,8 +54,10 @@ public class FirmwareFlasher extends ProcessStatusWindow {
private void doFlashFirmware() {
if (!new File(fileName).exists()) {
wnd.appendMsg(fileName + " not found, cannot proceed !!!");
wnd.setStatus("ERROR");
return;
}
StatusAnimation sa = new StatusAnimation(wnd);
StringBuffer error = executeCommand(getOpenocdCommad() + " -c \"program " +
fileName +
" verify reset exit 0x08000000\"");
@ -61,6 +65,8 @@ public class FirmwareFlasher extends ProcessStatusWindow {
wnd.appendMsg(" !!! ERROR: looks like stm32 driver is not installed? The link is above !!!");
} else if (error.toString().contains(SUCCESS_MESSAGE_TAG) && !error.toString().toLowerCase().contains(FAILED_MESSAGE_TAG)) {
wnd.appendMsg("Flashing looks good!");
sa.stop();
wnd.setStatus(DONE);
} else {
wnd.appendMsg("!!! FIRMWARE FLASH: DOES NOT LOOK RIGHT !!!");
}

View File

@ -0,0 +1,40 @@
package com.rusefi.maintenance;
import com.rusefi.ui.StatusWindow;
import javax.swing.*;
import java.awt.event.ActionEvent;
/**
* This class is in charge of status bar animation with dots running from empty to DOTS_COUNT
*/
public class StatusAnimation {
private static final String WORKING = "Working";
private static final int DOTS_COUNT = 5;
private final Timer timer;
private volatile boolean isStopped;
private int counter;
public StatusAnimation(StatusWindow wnd) {
timer = new Timer(200 /*ms*/, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (isStopped)
return;
counter++;
StringBuilder status = new StringBuilder(WORKING);
for (int i = 0; i < counter % DOTS_COUNT; i++) {
status.append(".");
}
wnd.setStatus(status.toString());
}
});
timer.start();
}
public void stop() {
timer.stop();
isStopped = true;
}
}

View File

@ -15,6 +15,7 @@ public class StatusWindow implements StatusConsumer {
// todo: extract driver from console bundle? find a separate driver bundle?
private final JTextArea log = new JTextArea();
private final JPanel content = new JPanel(new BorderLayout());
private final JLabel bottomStatusLabel = new JLabel();
private final JScrollPane messagesScroll = new JScrollPane(log, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED) {
@Override
public Dimension getPreferredSize() {
@ -27,6 +28,7 @@ public class StatusWindow implements StatusConsumer {
public StatusWindow() {
log.setLineWrap(true);
content.add(messagesScroll, BorderLayout.CENTER);
content.add(bottomStatusLabel, BorderLayout.SOUTH);
}
@NotNull
@ -59,4 +61,8 @@ public class StatusWindow implements StatusConsumer {
}
});
}
public void setStatus(String status) {
bottomStatusLabel.setText(status);
}
}