Search in sources :

Example 6 with FirmwareSettingsException

use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.

the class WizardPanelStepCalibration method updateEstimationFromMesurement.

private void updateEstimationFromMesurement(JTextField textFieldMesurement, Axis axis, JLabel label) {
    if (getBackend().getWorkPosition() != null) {
        try {
            DecimalFormat decimalFormat = new DecimalFormat(DECIMAL_FORMAT_PATTERN, Localization.dfs);
            double measured = decimalFormat.parse(textFieldMesurement.getText()).doubleValue();
            double real = getBackend().getWorkPosition().get(axis);
            double stepsPerMM = getBackend().getController().getFirmwareSettings().getStepsPerMillimeter(axis);
            double computed = (real / measured) * stepsPerMM;
            if (measured == 0 || real == 0) {
                computed = 0;
            }
            label.setText(decimalFormat.format(Math.abs(computed)) + " steps/mm est.");
        } catch (FirmwareSettingsException | ParseException ignored) {
        // Never mind
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) ParseException(java.text.ParseException)

Example 7 with FirmwareSettingsException

use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.

the class WizardPanelHardLimits method refreshComponents.

private void refreshComponents() {
    ThreadHelper.invokeLater(() -> {
        try {
            if (getBackend().getController() != null && getBackend().getController().getCapabilities().hasHardLimits()) {
                IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
                checkboxEnableHardLimits.setSelected(firmwareSettings.isHardLimitsEnabled());
                checkboxInvertLimitPins.setSelected(firmwareSettings.isHardLimitsInverted());
                checkboxEnableHardLimits.setVisible(true);
                checkboxInvertLimitPins.setVisible(firmwareSettings.isHardLimitsEnabled());
                labelInstructions.setVisible(firmwareSettings.isHardLimitsEnabled());
                labelLimitX.setVisible(firmwareSettings.isHardLimitsEnabled());
                labelLimitY.setVisible(firmwareSettings.isHardLimitsEnabled());
                labelLimitZ.setVisible(firmwareSettings.isHardLimitsEnabled());
                labelHardLimitsNotSupported.setVisible(false);
            } else {
                checkboxEnableHardLimits.setVisible(false);
                checkboxInvertLimitPins.setVisible(false);
                labelInstructions.setVisible(false);
                labelLimitX.setVisible(false);
                labelLimitY.setVisible(false);
                labelLimitZ.setVisible(false);
                labelHardLimitsNotSupported.setVisible(true);
            }
        } catch (FirmwareSettingsException e) {
            NotifyDescriptor nd = new NotifyDescriptor.Message("Couldn't fetch the hard limits settings: " + e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(nd);
        }
    }, 200);
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 8 with FirmwareSettingsException

use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.

the class WizardPanelHoming method initComponents.

private void initComponents() {
    labelDescription = new JLabel("<html><body><p>" + Localization.getString("platform.plugin.setupwizard.homing.intro") + "</p></body></html>");
    checkboxEnableHoming = new JCheckBox(Localization.getString("platform.plugin.setupwizard.homing.enable"));
    checkboxEnableHoming.addActionListener(event -> {
        try {
            getBackend().getController().getFirmwareSettings().setHomingEnabled(checkboxEnableHoming.isSelected());
        } catch (FirmwareSettingsException e) {
            NotifyDescriptor nd = new NotifyDescriptor.Message("Couldn't enable/disable the hard limits settings: " + e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(nd);
        }
    });
    labelHardLimitsNotEnabled = new JLabel("<html><body>" + Localization.getString("platform.plugin.setupwizard.homing.require-limit-switches") + "</body></html>", ImageUtilities.loadImageIcon("icons/information24.png", false), JLabel.LEFT);
    labelHardLimitsNotEnabled.setVisible(false);
    labelHomingNotSupported = new JLabel("<html><body>" + Localization.getString("platform.plugin.setupwizard.homing.not-available") + "</body></html>", ImageUtilities.loadImageIcon("icons/information24.png", false), JLabel.LEFT);
    labelHomingNotSupported.setVisible(false);
    separatorTop = new JSeparator(SwingConstants.HORIZONTAL);
    separatorTop.setVisible(false);
    labelHomingDirection = new JLabel("<html><body>" + Localization.getString("platform.plugin.setupwizard.homing.instruction1") + "</body></html>");
    labelHomingDirection.setVisible(false);
    initInvertComboBoxes();
    separatorBottom = new JSeparator(SwingConstants.HORIZONTAL);
    separatorBottom.setVisible(false);
    labelHomingInstructions = new JLabel("<html><body><p>" + Localization.getString("platform.plugin.setupwizard.homing.instruction2") + "</p></body></html>");
    labelHomingInstructions.setVisible(false);
    initButtons();
}
Also used : JCheckBox(javax.swing.JCheckBox) NotifyDescriptor(org.openide.NotifyDescriptor) JLabel(javax.swing.JLabel) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) JSeparator(javax.swing.JSeparator)

Example 9 with FirmwareSettingsException

use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.

the class WizardPanelMotorWiring method initComponents.

private void initComponents() {
    labelDescription = new JLabel("<html><body><p>" + Localization.getString("platform.plugin.setupwizard.motor-wiring.intro") + "</p></body></html>");
    softLimitsInfo = new RoundedPanel(8);
    softLimitsInfo.setLayout(new MigLayout("fill, inset 10, gap 0"));
    softLimitsInfo.setBackground(ThemeColors.VERY_LIGHT_BLUE_GREY);
    softLimitsInfo.setForeground(ThemeColors.LIGHT_GREY);
    softLimitsInfo.add(new JLabel(ImageUtilities.loadImageIcon("icons/information24.png", false)), "gapright 10");
    softLimitsInfo.add(new JLabel("<html><body>" + Localization.getString("platform.plugin.setupwizard.motor-wiring.soft-limits-enabled") + "</body></html>"));
    navigationButtons = new NavigationButtons(getBackend(), 0.1, 100);
    checkboxReverseX = new JCheckBox(Localization.getString("platform.plugin.setupwizard.motor-wiring.reverse-direction"));
    checkboxReverseX.addActionListener(event -> {
        if (getBackend().getController() != null) {
            try {
                getBackend().getController().getFirmwareSettings().setInvertDirection(Axis.X, checkboxReverseX.isSelected());
            } catch (FirmwareSettingsException e) {
                e.printStackTrace();
            }
        }
    });
    checkboxReverseY = new JCheckBox(Localization.getString("platform.plugin.setupwizard.motor-wiring.reverse-direction"));
    checkboxReverseY.addActionListener(event -> {
        if (getBackend().getController() != null) {
            try {
                getBackend().getController().getFirmwareSettings().setInvertDirection(Axis.Y, checkboxReverseY.isSelected());
            } catch (FirmwareSettingsException e) {
                e.printStackTrace();
            }
        }
    });
    checkboxReverseZ = new JCheckBox(Localization.getString("platform.plugin.setupwizard.motor-wiring.reverse-direction"));
    checkboxReverseZ.addActionListener(event -> {
        if (getBackend().getController() != null) {
            try {
                getBackend().getController().getFirmwareSettings().setInvertDirection(Axis.Z, checkboxReverseZ.isSelected());
            } catch (FirmwareSettingsException e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : MigLayout(net.miginfocom.swing.MigLayout) RoundedPanel(com.willwinder.universalgcodesender.uielements.components.RoundedPanel) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) NavigationButtons(com.willwinder.ugs.nbp.setupwizard.NavigationButtons)

Example 10 with FirmwareSettingsException

use of com.willwinder.universalgcodesender.firmware.FirmwareSettingsException in project Universal-G-Code-Sender by winder.

the class GrblFirmwareSettingsCommunicatorListener 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;
            GcodeCommand command = controller.createCommand(setting.getKey() + "=" + 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) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) TimeoutException(java.util.concurrent.TimeoutException)

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