use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class TinyGFirmwareSettings method setValue.
@Override
public FirmwareSetting setValue(String key, String value) throws FirmwareSettingsException {
final FirmwareSetting oldSetting = getSetting(key).orElseThrow(() -> new FirmwareSettingsException("Couldn't find setting with key " + key + " to update."));
// The setting already contains the value so we do not update
if (oldSetting.getValue().equals(value)) {
return oldSetting;
}
// Make a copy of existing property and send it to our controller
final FirmwareSetting newSetting = new FirmwareSetting(oldSetting.getKey(), value, oldSetting.getUnits(), oldSetting.getDescription(), oldSetting.getShortDescription());
return serialCommunicatorDelegate.updateSettingOnController(newSetting).orElse(oldSetting);
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class GrblFirmwareSettingsTest method setValueShouldNotUpdateOnError.
@Test
public void setValueShouldNotUpdateOnError() throws Exception {
// Given
when(controller.isStreaming()).thenReturn(false);
when(controller.isCommOpen()).thenReturn(true);
target.rawResponseListener("$0=10");
// Add a listener
IFirmwareSettingsListener firmwareSettingsListener = mock(IFirmwareSettingsListener.class);
target.addListener(firmwareSettingsListener);
// When
// Try to update the value in it's own thread
Future<?> setValueFuture = Executors.newCachedThreadPool().submit(() -> {
try {
return target.setValue("$0", "11");
} catch (FirmwareSettingsException e) {
fail("Should never get here but got exception: " + e);
}
return null;
});
// Simulate the response from the controller
Thread.sleep(200);
target.rawResponseListener("error");
// Wait until the value gets updated
FirmwareSetting setting = (FirmwareSetting) setValueFuture.get();
// Then
assertNotNull(setting);
assertEquals("10", setting.getValue());
verify(controller, times(1)).sendCommandImmediately(any());
verify(firmwareSettingsListener, times(0)).onUpdatedFirmwareSetting(any());
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class GrblFirmwareSettingsTest method setValueShouldUpdateOnController.
@Test
public void setValueShouldUpdateOnController() throws Exception {
// Given
when(controller.isStreaming()).thenReturn(false);
when(controller.isCommOpen()).thenReturn(true);
target.rawResponseListener("$0=10");
// Add a listener
IFirmwareSettingsListener firmwareSettingsListener = mock(IFirmwareSettingsListener.class);
ArgumentCaptor<FirmwareSetting> firmwareSettingArgumentCaptor = ArgumentCaptor.forClass(FirmwareSetting.class);
doNothing().when(firmwareSettingsListener).onUpdatedFirmwareSetting(firmwareSettingArgumentCaptor.capture());
target.addListener(firmwareSettingsListener);
// When
// Try to update the value in it's own thread
Future<?> setValueFuture = Executors.newCachedThreadPool().submit(() -> {
try {
return target.setValue("$0", "11");
} catch (FirmwareSettingsException e) {
fail("Should never get here but got exception: " + e);
}
return null;
});
// Simulate the response from the controller
Thread.sleep(200);
target.rawResponseListener("ok");
// Wait until the value gets updated
FirmwareSetting firmwareSetting = (FirmwareSetting) setValueFuture.get();
// Then
assertEquals("11", firmwareSetting.getValue());
verify(controller, times(1)).sendCommandImmediately(any());
verify(firmwareSettingsListener, times(1)).onUpdatedFirmwareSetting(any());
assertEquals(1, firmwareSettingArgumentCaptor.getAllValues().size());
assertEquals("11", firmwareSettingArgumentCaptor.getAllValues().get(0).getValue());
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class WizardPanelSoftLimits method refeshControls.
private void refeshControls() {
ThreadHelper.invokeLater(() -> {
try {
checkboxEnableSoftLimits.setVisible(false);
if (getBackend().getController() != null && getBackend().getController().getFirmwareSettings().isHardLimitsEnabled() && getBackend().getController().getFirmwareSettings().isHomingEnabled() && getBackend().getController().getCapabilities().hasSoftLimits()) {
IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
try {
checkboxEnableSoftLimits.setSelected(firmwareSettings.isSoftLimitsEnabled());
boolean visible = firmwareSettings.isSoftLimitsEnabled();
setFormVisible(visible);
} catch (FirmwareSettingsException ignored) {
// Never mind..
}
checkboxEnableSoftLimits.setVisible(true);
labelSoftLimitsNotSupported.setVisible(false);
labelHomingIsNotEnabled.setVisible(false);
} else if (getBackend().getController() != null && getBackend().getController().getCapabilities().hasSoftLimits() && (!getBackend().getController().getFirmwareSettings().isHomingEnabled() || !getBackend().getController().getFirmwareSettings().isHardLimitsEnabled())) {
setFormVisible(false);
labelHomingIsNotEnabled.setVisible(true);
} else {
setFormVisible(false);
labelSoftLimitsNotSupported.setVisible(true);
}
// Redraw the panel to make sure that previously hidden fields are shown
getPanel().revalidate();
} catch (FirmwareSettingsException e) {
NotifyDescriptor nd = new NotifyDescriptor.Message("Couldn't fetch firmware settings: " + e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
}
}, 100);
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class WizardPanelSoftLimits method createKeyListenerChangeSetting.
private KeyListener createKeyListenerChangeSetting(Axis axis, JButton buttonUpdateSettings) {
return new KeyListener() {
@Override
public void keyTyped(KeyEvent event) {
}
@Override
public void keyPressed(KeyEvent event) {
}
@Override
public void keyReleased(KeyEvent event) {
try {
if (getBackend().getController() != null && getBackend().getController().getFirmwareSettings() != null) {
try {
JTextField source = (JTextField) event.getSource();
IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
double softLimit = firmwareSettings.getSoftLimit(axis);
if (Math.abs(decimalFormat.parse(source.getText().trim()).doubleValue()) == Math.abs(softLimit)) {
buttonUpdateSettings.setEnabled(false);
} else {
buttonUpdateSettings.setEnabled(true);
}
} catch (FirmwareSettingsException e) {
e.printStackTrace();
}
}
} catch (ParseException ignored) {
buttonUpdateSettings.setEnabled(false);
}
}
};
}
Aggregations