getDevices() {
- return Arrays.asList(new DefaultConnectionDevice("loopback"));
- }
-
- @Override
- public void closePort() throws Exception {
- exit = true;
- open = false;
- okThread.interrupt();
- }
-
- @Override
- public void sendStringToComm(String command) throws Exception {
- this.sent.put(command);
- }
-
- @Override
- public void sendByteImmediately(byte b) throws Exception {
- this.sent.put(Byte.toString(b));
- }
-}
-
diff --git a/ugs-core/src/com/willwinder/universalgcodesender/utils/ControllerSettings.java b/ugs-core/src/com/willwinder/universalgcodesender/utils/ControllerSettings.java
index 17c2fb1da..075e372eb 100644
--- a/ugs-core/src/com/willwinder/universalgcodesender/utils/ControllerSettings.java
+++ b/ugs-core/src/com/willwinder/universalgcodesender/utils/ControllerSettings.java
@@ -20,15 +20,13 @@ This file is part of Universal Gcode Sender (UGS).
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.willwinder.universalgcodesender.firmware.fluidnc.FluidNCController;
import com.willwinder.universalgcodesender.G2CoreController;
import com.willwinder.universalgcodesender.GrblController;
-import com.willwinder.universalgcodesender.GrblEsp32Controller;
import com.willwinder.universalgcodesender.IController;
-import com.willwinder.universalgcodesender.communicator.LoopBackCommunicator;
-import com.willwinder.universalgcodesender.firmware.smoothie.SmoothieController;
import com.willwinder.universalgcodesender.TinyGController;
import com.willwinder.universalgcodesender.communicator.XLCDCommunicator;
+import com.willwinder.universalgcodesender.firmware.fluidnc.FluidNCController;
+import com.willwinder.universalgcodesender.firmware.smoothie.SmoothieController;
import com.willwinder.universalgcodesender.gcode.processors.CommandProcessor;
import com.willwinder.universalgcodesender.gcode.util.CommandProcessorLoader;
@@ -44,19 +42,21 @@ This file is part of Universal Gcode Sender (UGS).
public class ControllerSettings {
String Name;
Integer Version = 0;
+
+ /**
+ * If the config file should be deleted
+ */
+ Boolean Deleted = false;
ControllerConfig Controller;
ProcessorConfigGroups GcodeProcessors;
public enum CONTROLLER {
GRBL("GRBL"),
- GRBL_ESP32("GRBL ESP32"),
FLUIDNC("FluidNC"),
SMOOTHIE("SmoothieBoard"),
TINYG("TinyG"),
G2CORE("g2core"),
- XLCD("XLCD"),
- LOOPBACK("Loopback"),
- LOOPBACK_SLOW("Loopback_Slow");
+ XLCD("XLCD");
final String name;
CONTROLLER(String name) {
@@ -81,6 +81,10 @@ public Integer getVersion() {
return Version;
}
+ public boolean isDeleted() {
+ return Deleted;
+ }
+
/**
* Parse the "Controller" object in the firmware config json.
*
@@ -99,8 +103,6 @@ public Optional getController() {
switch (controller) {
case GRBL:
return Optional.of(new GrblController());
- case GRBL_ESP32:
- return Optional.of(new GrblEsp32Controller());
case SMOOTHIE:
return Optional.of(new SmoothieController());
case TINYG:
@@ -109,10 +111,6 @@ public Optional getController() {
return Optional.of(new G2CoreController());
case XLCD:
return Optional.of(new GrblController(new XLCDCommunicator()));
- case LOOPBACK:
- return Optional.of(new GrblController(new LoopBackCommunicator()));
- case LOOPBACK_SLOW:
- return Optional.of(new GrblController(new LoopBackCommunicator(100)));
case FLUIDNC:
return Optional.of(new FluidNCController());
default:
diff --git a/ugs-core/src/com/willwinder/universalgcodesender/utils/FirmwareUtils.java b/ugs-core/src/com/willwinder/universalgcodesender/utils/FirmwareUtils.java
index e79731f2a..759428806 100644
--- a/ugs-core/src/com/willwinder/universalgcodesender/utils/FirmwareUtils.java
+++ b/ugs-core/src/com/willwinder/universalgcodesender/utils/FirmwareUtils.java
@@ -58,7 +58,8 @@ This file is part of Universal Gcode Sender (UGS).
* @author wwinder
*/
public class FirmwareUtils {
- final private static String FIRMWARE_CONFIG_DIRNAME = "firmware_config";
+ public static final String FIRMWARE_CONFIG_DIRECTORY = "/resources/firmware_config/";
+ private static final String FIRMWARE_CONFIG_DIRNAME = "firmware_config";
private static final Logger logger = Logger.getLogger(FirmwareUtils.class.getName());
private static final Map configFiles = new HashMap<>();
private static boolean userNotified = false;
@@ -128,6 +129,26 @@ private static ControllerSettings getSettingsForStream(InputStream is)
*/
public synchronized static void initialize() {
logger.info("Initializing firmware... ...");
+ File firmwareConfigDirectory = getFirmwareConfigDirectory();
+
+ updateConfigFiles(firmwareConfigDirectory);
+
+ configFiles.clear();
+ for (File f : firmwareConfigDirectory.listFiles()) {
+ try (InputStream fileInputStream = new FileInputStream(f)) {
+ ControllerSettings config = new Gson().fromJson(new InputStreamReader(fileInputStream, StandardCharsets.UTF_8), ControllerSettings.class);
+ if (config.isDeleted()) {
+ f.delete();
+ continue;
+ }
+ configFiles.put(config.getName(), new ConfigTuple(config, f));
+ } catch (JsonSyntaxException | JsonIOException | IOException ex) {
+ GUIHelpers.displayErrorDialog("Unable to load configuration files: " + f.getAbsolutePath());
+ }
+ }
+ }
+
+ private static File getFirmwareConfigDirectory() {
File firmwareConfig = new File(SettingsFactory.getSettingsDirectory(),
FIRMWARE_CONFIG_DIRNAME);
@@ -135,14 +156,15 @@ public synchronized static void initialize() {
if (!firmwareConfig.exists()) {
firmwareConfig.mkdirs();
}
+ return firmwareConfig;
+ }
+ private static void updateConfigFiles(File firmwareConfigDirectory) {
FileSystem fileSystem = null;
// Copy firmware config files.
try {
- final String dir = "/resources/firmware_config/";
-
- URI location = FirmwareUtils.class.getResource(dir).toURI();
+ URI location = FirmwareUtils.class.getResource(FIRMWARE_CONFIG_DIRECTORY).toURI();
Path myPath;
if (location.getScheme().equals("jar")) {
@@ -155,7 +177,7 @@ public synchronized static void initialize() {
Collections.emptyMap());
}
- myPath = fileSystem.getPath(dir);
+ myPath = fileSystem.getPath(FIRMWARE_CONFIG_DIRECTORY);
} else {
myPath = Paths.get(location);
}
@@ -164,7 +186,7 @@ public synchronized static void initialize() {
for (Path path : (Iterable) files::iterator) {
logger.info(path.toString());
final String name = path.getFileName().toString();
- File fwConfig = new File(firmwareConfig, name);
+ File fwConfig = new File(firmwareConfigDirectory, name);
if (name.endsWith(".json")) {
boolean copyFile = !fwConfig.exists();
ControllerSettings jarSetting =
@@ -219,16 +241,6 @@ public synchronized static void initialize() {
}
}
}
-
- configFiles.clear();
- for (File f : firmwareConfig.listFiles()) {
- try (InputStream fileInputStream = new FileInputStream(f)) {
- ControllerSettings config = new Gson().fromJson(new InputStreamReader(fileInputStream, StandardCharsets.UTF_8), ControllerSettings.class);
- configFiles.put(config.getName(), new ConfigTuple(config, f));
- } catch (JsonSyntaxException | JsonIOException | IOException ex) {
- GUIHelpers.displayErrorDialog("Unable to load configuration files: " + f.getAbsolutePath());
- }
- }
}
public static void save(File f, ControllerSettings cs) throws IOException {
diff --git a/ugs-core/src/resources/firmware_config/grbl_esp32.json b/ugs-core/src/resources/firmware_config/grbl_esp32.json
index a08fc889a..a71426099 100644
--- a/ugs-core/src/resources/firmware_config/grbl_esp32.json
+++ b/ugs-core/src/resources/firmware_config/grbl_esp32.json
@@ -1,6 +1,7 @@
{
"Name": "GRBL ESP32",
- "Version": 7,
+ "Version": 8,
+ "Deleted": true,
"Controller": {
"name": "GRBL ESP32",
"args": null
diff --git a/ugs-core/src/resources/firmware_config/test_1.json b/ugs-core/src/resources/firmware_config/test_1.json
index f34fa23bc..dcd6ba3c3 100644
--- a/ugs-core/src/resources/firmware_config/test_1.json
+++ b/ugs-core/src/resources/firmware_config/test_1.json
@@ -1,6 +1,7 @@
{
"Name": "Testing",
- "Version": 5,
+ "Version": 6,
+ "Deleted": true,
"Controller": {
"name": "Loopback",
"args": null
diff --git a/ugs-core/src/resources/firmware_config/test_2.json b/ugs-core/src/resources/firmware_config/test_2.json
index 6a0ecec3a..be3be0d0a 100644
--- a/ugs-core/src/resources/firmware_config/test_2.json
+++ b/ugs-core/src/resources/firmware_config/test_2.json
@@ -1,6 +1,7 @@
{
"Name": "Testing (Delay)",
- "Version": 5,
+ "Version": 6,
+ "Deleted": true,
"Controller": {
"name": "Loopback_Slow",
"args": null
diff --git a/ugs-core/test/com/willwinder/universalgcodesender/GrblEsp32ControllerTest.java b/ugs-core/test/com/willwinder/universalgcodesender/GrblEsp32ControllerTest.java
deleted file mode 100644
index b14726924..000000000
--- a/ugs-core/test/com/willwinder/universalgcodesender/GrblEsp32ControllerTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- Copyright 2022 Will Winder
-
- This file is part of Universal Gcode Sender (UGS).
-
- UGS is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- UGS is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with UGS. If not, see .
- */
-package com.willwinder.universalgcodesender;
-
-import com.willwinder.universalgcodesender.communicator.ICommunicator;
-import com.willwinder.universalgcodesender.types.GcodeCommand;
-import org.junit.Test;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import static com.willwinder.universalgcodesender.CapabilitiesConstants.*;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-public class GrblEsp32ControllerTest {
- @Test
- public void TestGetAxesCount() {
- GrblEsp32Controller instance = new GrblEsp32Controller();
-
- instance.rawResponseHandler("[MSG:Axis count 6]");
- assertTrue(instance.getCapabilities().hasCapability(X_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Y_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Z_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(A_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(B_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(C_AXIS));
-
- instance.rawResponseHandler("[MSG:Axis count 3]");
- assertTrue(instance.getCapabilities().hasCapability(X_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Y_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Z_AXIS));
- assertFalse(instance.getCapabilities().hasCapability(A_AXIS));
- assertFalse(instance.getCapabilities().hasCapability(B_AXIS));
- assertFalse(instance.getCapabilities().hasCapability(C_AXIS));
-
- instance.rawResponseHandler("[MSG:Axis count 4]");
- assertTrue(instance.getCapabilities().hasCapability(X_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Y_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(Z_AXIS));
- assertTrue(instance.getCapabilities().hasCapability(A_AXIS));
- assertFalse(instance.getCapabilities().hasCapability(B_AXIS));
- assertFalse(instance.getCapabilities().hasCapability(C_AXIS));
- }
-}