Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now parses snapshot from GRBL version #2196

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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