Skip to content

Commit

Permalink
Now parses snapshot from GRBL version (#2196)
Browse files Browse the repository at this point in the history
* Now parses snapshot from GRBL version
* Prevent the action from overwriting the firmware setting
  • Loading branch information
breiler committed Apr 11, 2023
1 parent 94b3158 commit 423e73b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class GrblVersion {
public static final GrblVersion NO_VERSION = new GrblVersion("");
public static final String VERSION_REGEX = "^\\[VER:[v]?(?<version>(?<major>\\d+)\\.(?<minor>\\d+))?(?<char>.)?(\\.(?<date>\\d+))?(:(?<name>.*))?]$";
public static final String VERSION_REGEX = "^\\[VER:[v]?(?<version>(?<major>\\d+)\\.(?<minor>\\d+)(?<char>.)?(-(?<snapshot>[a-bA-Z]+))?)?(\\.(?<date>[0-9a-z]+))?(:(?<name>.*))?]$";
private final double versionNumber; // The 0.8 in '[VER:0.8c.20220620:Machine1]'
private final Character versionLetter; // The c in '[VER:0.8c.20220620:Machine1]'
private final String buildDate; // The 20220620 in '[VER:0.8c.20220620:Machine1]'
Expand All @@ -25,7 +25,7 @@ public GrblVersion(String versionString) {
Pattern versionPattern = Pattern.compile(VERSION_REGEX);
Matcher matcher = versionPattern.matcher(versionString);
if (matcher.matches()) {
versionNumber = Double.parseDouble(StringUtils.defaultString(matcher.group("version"), "0.0"));
versionNumber = Double.parseDouble(StringUtils.defaultString(matcher.group("major"), "0") + "." + StringUtils.defaultString(matcher.group("minor"), "0"));
versionLetter = StringUtils.defaultString(matcher.group("char"), "-").charAt(0);
buildDate = StringUtils.defaultString(matcher.group("date"), "");
machineName = StringUtils.defaultString(matcher.group("name"), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public void parseVersionStringWithoutChar() {
assertEquals("Some string", version.getMachineName());
}

@Test
public void parseVersionStringWithSnapshotBuildDateAndMachine() {
GrblVersion version = new GrblVersion("[VER:1.1h-XCP.20220314a:abc]");
assertEquals(1.1d, version.getVersionNumber(), 0.001);
assertEquals('h', version.getVersionLetter().charValue());
assertEquals("20220314a", version.getBuildDate());
assertEquals("abc", version.getMachineName());
}

@Test
public void parseVersionStringWithSnapshot() {
GrblVersion version = new GrblVersion("[VER:1.1h-XCP]");
assertEquals(1.1d, version.getVersionNumber(), 0.001);
assertEquals('h', version.getVersionLetter().charValue());
assertEquals("", version.getBuildDate());
assertEquals("", version.getMachineName());
}

@Test
public void parseOldVersion() {
GrblVersion version = new GrblVersion("[VER:0.7]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private void setFirmware() {
}

private void firmwareUpdated() {
System.out.println("firmware updated " + backend.getSettings().getFirmwareVersion());
firmwareCombo.setSelectedItem( backend.getSettings().getFirmwareVersion());
}

Expand All @@ -99,9 +100,10 @@ public Component getToolbarPresenter() {

// Load firmware configuration in its own thread to make sure that
// the splash screen is not covering any firmware upgrade dialogs
ThreadHelper.invokeLater(this::loadFirmwareSelector);

firmwareCombo.addActionListener(a -> setFirmware());
ThreadHelper.invokeLater(() -> {
loadFirmwareSelector();
firmwareCombo.addActionListener(a -> setFirmware());
});
}
return c;
}
Expand Down

0 comments on commit 423e73b

Please sign in to comment.