only:mild refactoring

This commit is contained in:
rusefillc 2024-06-03 10:11:03 -04:00
parent 71ec798191
commit 2a79b054aa
5 changed files with 31 additions and 19 deletions

View File

@ -9,7 +9,7 @@ public interface rusEFIVersion {
/**
* @see com.rusefi.autoupdate.Autoupdate#VERSION
*/
int CONSOLE_VERSION = 20240531;
int CONSOLE_VERSION = 20240603;
AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
static long classBuildTimeMillis() {

View File

@ -1,20 +1,11 @@
package com.rusefi.maintenance;
import com.rusefi.core.ui.AutoupdateUtil;
import com.rusefi.ui.StatusWindow;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import static com.rusefi.maintenance.StLinkFlasher.TITLE;
/**
* DEAD?!
*
* Andrey Belomutskiy, (c) 2013-2020
*/
/*
public class EraseChip {
private static final String FLASH_SIZE = "0x0100000";
private static final String ERASE_COMMAND_SUFFIX = " -c init -c targets -c \"halt\" -c \"flash erase_address 0x08000000 " + FLASH_SIZE + "\" -c shutdown";
@ -31,7 +22,7 @@ public class EraseChip {
if (dialogResult != JOptionPane.YES_OPTION)
return;
wnd.showFrame(TITLE);
StatusAnimation sa = new StatusAnimation(wnd);
StatusWindowAnimation sa = new StatusWindowAnimation(wnd);
ExecHelper.submitAction(() -> {
try {
StLinkFlasher.executeOpenOCDCommand(getEraseCommand(), wnd);
@ -55,3 +46,4 @@ public class EraseChip {
return button;
}
}
*/

View File

@ -69,7 +69,7 @@ public class StLinkFlasher {
wnd.setStatus("ERROR");
return;
}
StatusAnimation sa = new StatusAnimation(wnd);
StatusWindowAnimation sa = new StatusWindowAnimation(wnd);
String error = null;
try {
error = executeOpenOCDCommand(getOpenocdCommand() + " -c \"program " +

View File

@ -1,7 +1,5 @@
package com.rusefi.maintenance;
import com.rusefi.ui.StatusWindow;
import javax.swing.*;
import java.awt.event.ActionEvent;
@ -9,25 +7,24 @@ 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) {
public StatusAnimation(StatusConsumer consumer, String message) {
timer = new Timer(200 /*ms*/, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (isStopped)
return;
counter++;
StringBuilder status = new StringBuilder(WORKING);
StringBuilder status = new StringBuilder(message);
for (int i = 0; i < counter % DOTS_COUNT; i++) {
status.append(".");
}
wnd.setStatus(status.toString());
consumer.onStatus(status.toString());
}
});
timer.start();
@ -37,4 +34,8 @@ public class StatusAnimation {
timer.stop();
isStopped = true;
}
public interface StatusConsumer {
void onStatus(String niceStatus);
}
}

View File

@ -0,0 +1,19 @@
package com.rusefi.maintenance;
import com.rusefi.ui.StatusWindow;
public class StatusWindowAnimation {
private final StatusAnimation animation;
public StatusWindowAnimation(StatusWindow wnd) {
animation = new StatusAnimation(new StatusAnimation.StatusConsumer() {
@Override
public void onStatus(String niceStatus) {
wnd.setStatus(niceStatus);
}
}, "Working");
}
public void stop() {
animation.stop();
}
}