use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class GrblFirmwareSettings method setValue.
/**
* Sets a property value on the controller. It will wait until the setting has been stored,
* if this fails a {@link FirmwareSettingsException} will be thrown.
*
* @param key the name of the setting to update
* @param value the value of the setting
* @return the value stored on the controller
* @throws FirmwareSettingsException if the value couldn't be persisted on the controller.
*/
@Override
public synchronized FirmwareSetting setValue(final String key, final 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 GrblFirmwareSettings method setValue.
/**
* Sets a property value on the controller. It will wait until the setting has been stored,
* if this fails a {@link FirmwareSettingsException} will be thrown.
*
* @param key the name of the setting to update
* @param value the value of the setting
* @return the value stored on the controller
* @throws FirmwareSettingsException if the value couldn't be persisted on the controller.
*/
public FirmwareSetting setValue(final String key, final double 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 (getValueAsDouble(key) == value) {
return oldSetting;
}
DecimalFormat decimalFormat = new DecimalFormat("0.0##", Localization.dfs);
return setValue(key, decimalFormat.format(value));
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class TinyGFirmwareSettingsCommunicatorListener method updateSettingOnController.
/**
* Sends a command to update a setting on the controller. The method will block until we get a response
* from the controller or if a timeout is triggered if the setting took too long to update.
*
* @param setting the setting to update
* @return the updated setting or an empty optional if it couldn't be updated.
* @throws FirmwareSettingsException will be thrown if the controller isn't ready to receive setting updates or if
* the update took to long and caused a timeout
*/
public Optional<FirmwareSetting> updateSettingOnController(FirmwareSetting setting) throws FirmwareSettingsException {
if (isUpdatingSettings()) {
throw new FirmwareSettingsException("The settings are being updated in another thread.");
}
if (!canSendToController()) {
throw new FirmwareSettingsException("The controller is not ready to receive commands.");
}
boolean previousSingleStepMode = controller.getSingleStepMode();
boolean previousStatusUpdatesEnabled = controller.getStatusUpdatesEnabled();
controller.setStatusUpdatesEnabled(false);
controller.setSingleStepMode(true);
try {
try {
updatedSetting = null;
newSetting = setting;
TinyGSettingGroupType groupType = TinyGSettingGroupType.fromSettingKey(setting.getKey()).orElseThrow(() -> new IllegalArgumentException("Unknown setting group for key " + setting.getKey()));
TinyGSettingType settingType = TinyGSettingType.fromSettingKey(setting.getKey()).orElseThrow(() -> new IllegalArgumentException("Unknown setting type for key " + setting.getKey()));
GcodeCommand command = controller.createCommand("{" + groupType.getGroupName() + ": {" + settingType.getSettingName() + ":" + setting.getValue() + "}}");
controller.sendCommandImmediately(command);
} catch (Exception e) {
throw new FirmwareSettingsException("Couldn't send update setting command to the controller: " + setting.getKey() + "=" + setting.getValue() + ".", e);
}
waitUntilUpdateFinished();
} finally {
controller.setSingleStepMode(previousSingleStepMode);
controller.setStatusUpdatesEnabled(previousStatusUpdatesEnabled);
}
// Reset internal states
Optional<FirmwareSetting> result = Optional.ofNullable(updatedSetting);
updatedSetting = null;
newSetting = null;
return result;
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class MachineBoundries method onUGSEvent.
private void onUGSEvent(UGSEvent event) {
if (!isFirmwareSettingsEvent(event)) {
return;
}
try {
IFirmwareSettings firmwareSettings = backendAPI.getController().getFirmwareSettings();
softLimitsEnabled = firmwareSettings.isSoftLimitsEnabled();
if (softLimitsEnabled) {
PartialPosition.Builder builder = PartialPosition.builder().copy(maxPosition);
for (Axis axis : Axis.values()) {
double maxPosition = firmwareSettings.getSoftLimit(axis);
// If the homing process for an axis is inverted so will the machine zero position
if (firmwareSettings.isHomingDirectionInverted(axis)) {
maxPosition = -maxPosition;
}
builder.setValue(axis, maxPosition);
}
maxPosition = builder.build();
}
} catch (FirmwareSettingsException ignored) {
// Never mind this.
}
}
use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.
the class FirmwareSettingsDialog method saveButtonActionPerformed.
private void saveButtonActionPerformed() {
// Make a copy of all settings
java.util.List<FirmwareSetting> settingsToUpdate = new ArrayList<>(firmwareSettingsTableModel.getSettings());
// Loop through them and try to set them in the settings manager
settingsToUpdate.forEach(s -> {
FirmwareSetting updatedSetting = s;
try {
updatedSetting = firmwareSettingsManager.setValue(s.getKey(), s.getValue());
} catch (FirmwareSettingsException ignored) {
logger.log(Level.SEVERE, "Couldn't save setting: " + s.getKey() + "=" + s.getValue());
} finally {
firmwareSettingsTableModel.updateSetting(updatedSetting);
}
});
}
Aggregations