diff --git a/ugs-core/src/com/willwinder/universalgcodesender/GrblEsp32Controller.java b/ugs-core/src/com/willwinder/universalgcodesender/GrblEsp32Controller.java deleted file mode 100644 index 659170284a..0000000000 --- a/ugs-core/src/com/willwinder/universalgcodesender/GrblEsp32Controller.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright 2021-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 java.util.Optional; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static com.willwinder.universalgcodesender.CapabilitiesConstants.*; - -public class GrblEsp32Controller extends GrblController { - private final Capabilities capabilities = new Capabilities(); - private static final Logger logger = Logger.getLogger(GrblEsp32Controller.class.getName()); - static Pattern axisCountPattern = Pattern.compile("\\[MSG:Axis count (\\d*)]"); - - public GrblEsp32Controller() { - super(); - this.capabilities.addCapability(GrblCapabilitiesConstants.V1_FORMAT); - } - - public GrblEsp32Controller(ICommunicator communicator) { - super(communicator); - this.capabilities.addCapability(GrblCapabilitiesConstants.V1_FORMAT); - } - - Optional getAxisCount(String response) { - Matcher m = axisCountPattern.matcher(response); - if (!m.find()) { - return Optional.empty(); - } - return Optional.of(Integer.parseInt(m.group(1))); - } - - @Override - public Capabilities getCapabilities() { - return capabilities.merge(super.getCapabilities()); - } - - @Override - protected void openCommAfterEvent() { - // This doesn't seem to be required, but it's an option. - //this.comm.queueCommand(new GcodeCommand("[ESP444]RESTART")); - //this.comm.streamCommands(); - } - - @Override - protected void rawResponseHandler(String response) { - /* - [MSG:Grbl_ESP32 Ver 1.3a Date 20210203] - [MSG:Compiled with ESP32 SDK:v3.2.3-14-gd3e562907] - [MSG:Using machine:Test Drive - Demo Only No I/O!] - [MSG:Axis count 6] - [MSG:Timed Steps] - [MSG:Init Motors] - [MSG:No spindle] - - [MSG:Local access point GRBL_ESP started, 192.168.4.1] - [MSG:Captive Portal Started] - [MSG:HTTP Started] - [MSG:TELNET Started 23] - */ - - Optional axes = getAxisCount(response); - if (axes.isPresent()) { - logger.info("Axis Count: " + axes.get()); - this.capabilities.removeCapability(X_AXIS); - this.capabilities.removeCapability(Y_AXIS); - this.capabilities.removeCapability(Z_AXIS); - this.capabilities.removeCapability(A_AXIS); - this.capabilities.removeCapability(B_AXIS); - this.capabilities.removeCapability(C_AXIS); - - switch(axes.get()) { - case 6: - this.capabilities.addCapability(C_AXIS); - case 5: - this.capabilities.addCapability(B_AXIS); - case 4: - this.capabilities.addCapability(A_AXIS); - case 3: - this.capabilities.addCapability(Z_AXIS); - case 2: - this.capabilities.addCapability(Y_AXIS); - case 1: - this.capabilities.addCapability(X_AXIS); - } - } - - super.rawResponseHandler(response); - } -} diff --git a/ugs-core/src/com/willwinder/universalgcodesender/communicator/LoopBackCommunicator.java b/ugs-core/src/com/willwinder/universalgcodesender/communicator/LoopBackCommunicator.java deleted file mode 100644 index 8f8d66d346..0000000000 --- a/ugs-core/src/com/willwinder/universalgcodesender/communicator/LoopBackCommunicator.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * A diagnostic class to test application speed, overrides the connection - * with a handler that responds with "ok" as fast as possible. - */ -/* - Copyright 2016 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.communicator; - -import com.willwinder.universalgcodesender.connection.LoopBackConnection; - -/** - * - * @author wwinder - */ -public class LoopBackCommunicator extends GrblCommunicator { - public LoopBackCommunicator(int ms) { - this.connection = new LoopBackConnection(ms); - } - - public LoopBackCommunicator() { - this.connection = new LoopBackConnection(0); - } -} diff --git a/ugs-core/src/com/willwinder/universalgcodesender/connection/LoopBackConnection.java b/ugs-core/src/com/willwinder/universalgcodesender/connection/LoopBackConnection.java deleted file mode 100644 index 7b79f32d87..0000000000 --- a/ugs-core/src/com/willwinder/universalgcodesender/connection/LoopBackConnection.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - Copyright 2016-2018 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.connection; - -import com.willwinder.universalgcodesender.GrblUtils; -import com.willwinder.universalgcodesender.gcode.GcodeParser; -import com.willwinder.universalgcodesender.model.Position; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * A diagnostic class to test application speed, this is a connection that - * responds with "ok" as fast as possible. - * - * @author wwinder - */ -public class LoopBackConnection extends AbstractConnection { - private BlockingQueue sent; - private boolean exit = false; - private boolean open = false; - private Thread okThread; - private int ms = 0; - Runnable okRunnable = () -> { - try { - Thread.sleep(1000); - } catch (Exception e) { - } - // This is nested beneath a GrblController, notify it that we're ready. - initialize(); - - int count = 0; - Position lastCommand = null; - while (true) { - GcodeParser gcp = new GcodeParser(); - try { - String command = sent.take().trim(); - Thread.sleep(ms); - - if (command.equals(Byte.toString(GrblUtils.GRBL_STATUS_COMMAND))) { - String xyz = "0,0,0"; - if (lastCommand != null) { - xyz = String.format("%f,%f,%f", lastCommand.x, lastCommand.y, lastCommand.z); - } - handleResponse(String.format("", xyz, xyz)); - } else if (command.equals("G61")) { - handleResponse("error: G61 not supported."); - } else { - count++; - if (count == 2) { - initialize(); - } else if (count > 2) { - try { - gcp.addCommand(command); - lastCommand = gcp.getCurrentState().currentPoint; - } catch (Exception e) { - } - handleResponse("ok"); - } - } - } catch (InterruptedException ex) { - if (exit) return; - } - } - }; - - public LoopBackConnection(int ms) { - this("\r\n"); - this.ms = ms; - sent = new LinkedBlockingQueue<>(); - okThread = new Thread(okRunnable); - } - - public LoopBackConnection(String terminator) { - } - - private void initialize() { - handleResponse(" "); - handleResponse("Grbl 0.9z [ugs diagnostic mode]"); - handleResponse(" "); - handleResponse("This is a diagnostic end point which responds to each gcode"); - handleResponse("command as fast as possible while doing nothing else."); - } - - private void handleResponse(String response) { - connectionListenerManager.handleResponse(response.getBytes(), 0, response.length()); - } - - @Override - public void setUri(String uri) { - - } - - @Override - synchronized public boolean openPort() throws Exception { - okThread.start(); - exit = false; - - open = true; - return isOpen(); - } - - @Override - public boolean isOpen() { - return open; - } - - @Override - public List 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 17c2fb1daa..075e372ebc 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 e79731f2a3..7594288062 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 a08fc889a9..a71426099e 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 f34fa23bcc..dcd6ba3c3a 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 6a0ecec3a6..be3be0d0a2 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 b147269243..0000000000 --- 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)); - } -}