Search in sources :

Example 11 with FirmwareSettingsException

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);
}
Also used : FirmwareSetting(com.willwinder.universalgcodesender.firmware.FirmwareSetting) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 12 with FirmwareSettingsException

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));
}
Also used : DecimalFormat(java.text.DecimalFormat) FirmwareSetting(com.willwinder.universalgcodesender.firmware.FirmwareSetting) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 13 with FirmwareSettingsException

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;
}
Also used : FirmwareSetting(com.willwinder.universalgcodesender.firmware.FirmwareSetting) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) TinyGGcodeCommand(com.willwinder.universalgcodesender.types.TinyGGcodeCommand) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) TimeoutException(java.util.concurrent.TimeoutException)

Example 14 with FirmwareSettingsException

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.
    }
}
Also used : IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 15 with FirmwareSettingsException

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);
        }
    });
}
Also used : FirmwareSetting(com.willwinder.universalgcodesender.firmware.FirmwareSetting) ArrayList(java.util.ArrayList) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Aggregations

FirmwareSettingsException (com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)25 IFirmwareSettings (com.willwinder.universalgcodesender.firmware.IFirmwareSettings)10 FirmwareSetting (com.willwinder.universalgcodesender.firmware.FirmwareSetting)8 NotifyDescriptor (org.openide.NotifyDescriptor)7 DecimalFormat (java.text.DecimalFormat)4 ParseException (java.text.ParseException)4 IController (com.willwinder.universalgcodesender.IController)3 IFirmwareSettingsListener (com.willwinder.universalgcodesender.firmware.IFirmwareSettingsListener)3 Test (org.junit.Test)3 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)2 TimeoutException (java.util.concurrent.TimeoutException)2 NavigationButtons (com.willwinder.ugs.nbp.setupwizard.NavigationButtons)1 TinyGGcodeCommand (com.willwinder.universalgcodesender.types.TinyGGcodeCommand)1 RoundedPanel (com.willwinder.universalgcodesender.uielements.components.RoundedPanel)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 ArrayList (java.util.ArrayList)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1