Search in sources :

Example 16 with FirmwareSettingsException

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

the class GrblFirmwareSettingsTest method setValueShouldTimeoutIfNoResponseFromController.

@Test
public void setValueShouldTimeoutIfNoResponseFromController() 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 {
        target.setValue("$0", "11");
    } catch (FirmwareSettingsException e) {
        assertTrue("Make sure the exception contains the word 'Timeout'", e.getMessage().contains("Timeout"));
    }
    // Then
    verify(controller, times(1)).sendCommandImmediately(any());
    verify(firmwareSettingsListener, times(0)).onUpdatedFirmwareSetting(any());
}
Also used : IFirmwareSettingsListener(com.willwinder.universalgcodesender.firmware.IFirmwareSettingsListener) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) Test(org.junit.Test)

Example 17 with FirmwareSettingsException

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

the class WizardPanelSoftLimits method onSave.

private void onSave(Axis axis) {
    if (getBackend().getController() != null) {
        try {
            IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
            switch(axis) {
                case X:
                    double limitX = Math.abs(decimalFormat.parse(textFieldSoftLimitX.getText()).doubleValue());
                    firmwareSettings.setSoftLimit(axis, limitX);
                    buttonUpdateSettingsX.setEnabled(false);
                    break;
                case Y:
                    double limitY = Math.abs(decimalFormat.parse(textFieldSoftLimitY.getText()).doubleValue());
                    firmwareSettings.setSoftLimit(axis, limitY);
                    buttonUpdateSettingsY.setEnabled(false);
                    break;
                case Z:
                    double limitZ = Math.abs(decimalFormat.parse(textFieldSoftLimitZ.getText()).doubleValue());
                    firmwareSettings.setSoftLimit(axis, limitZ);
                    buttonUpdateSettingsZ.setEnabled(false);
                    break;
                default:
            }
        } catch (ParseException | FirmwareSettingsException ignored) {
        // Never mind
        }
    }
}
Also used : IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) ParseException(java.text.ParseException) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 18 with FirmwareSettingsException

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

the class WizardPanelSoftLimits method initialize.

@Override
public void initialize() {
    getBackend().addUGSEventListener(this);
    refeshControls();
    try {
        IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
        textFieldSoftLimitX.setText(decimalFormat.format(firmwareSettings.getSoftLimit(Axis.X)));
        textFieldSoftLimitY.setText(decimalFormat.format(firmwareSettings.getSoftLimit(Axis.Y)));
        textFieldSoftLimitZ.setText(decimalFormat.format(firmwareSettings.getSoftLimit(Axis.Z)));
    } catch (FirmwareSettingsException e) {
        NotifyDescriptor nd = new NotifyDescriptor.Message("Couldn't fetch firmware settings: " + e.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 19 with FirmwareSettingsException

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

the class WizardPanelStepCalibration method checkUpdatedValues.

/**
 * Check if values are updated in the text fields. It will enable the update buttons if it's a new setting.
 */
private void checkUpdatedValues() {
    if (getBackend().getController() != null && getBackend().getController().getFirmwareSettings() != null) {
        try {
            IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();
            for (Axis axis : Axis.values()) {
                double stepsPerMillimeter = MathUtils.round(firmwareSettings.getStepsPerMillimeter(axis), 3);
                JTextField textField = getSettingsTextField(axis);
                JButton buttonUpdateSettings = getUpdateSettingsButton(axis);
                if (textField == null || buttonUpdateSettings == null) {
                    continue;
                }
                buttonUpdateSettings.setEnabled(false);
                try {
                    DecimalFormat decimalFormat = new DecimalFormat(DECIMAL_FORMAT_PATTERN, Localization.dfs);
                    double newValue = decimalFormat.parse(textField.getText()).doubleValue();
                    if (stepsPerMillimeter != newValue) {
                        buttonUpdateSettings.setEnabled(true);
                    }
                } catch (ParseException ignored) {
                // Never mind
                }
            }
        } catch (FirmwareSettingsException e) {
            e.printStackTrace();
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) ParseException(java.text.ParseException) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException)

Example 20 with FirmwareSettingsException

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

the class WizardPanelStepCalibration method checkPulseIntervalLimits.

/**
 * Calculates if the pulse interval would exceed the max computing speed and will set an warning message.
 * <p>
 * It's calculated as:
 * maxFeedRate / 60 * stepsPerMM
 * <p>
 * Where maxFeedRate is given in mm/minute
 */
private void checkPulseIntervalLimits() {
    IController controller = getBackend().getController();
    IFirmwareSettings firmwareSettings = controller.getFirmwareSettings();
    int maxComputingSpeed = 0;
    for (Axis axis : Axis.values()) {
        try {
            // Get the maximum feed rate in mm/min
            double maxFeedRate = firmwareSettings.getMaximumRate(axis);
            // Fetch the current steps per mm setting
            JTextField settingsTextField = getSettingsTextField(axis);
            if (settingsTextField == null) {
                continue;
            }
            double newStepsPerMMSetting = parseDouble(settingsTextField.getText());
            double currentStepsPerMMSetting = firmwareSettings.getStepsPerMillimeter(axis);
            double stepsPerMMSetting = Math.max(newStepsPerMMSetting, currentStepsPerMMSetting);
            // Calculate the currently needed processing speed
            double computingSpeed = (maxFeedRate / 60.0) * stepsPerMMSetting;
            maxComputingSpeed = (int) Math.max(computingSpeed, maxComputingSpeed);
        } catch (FirmwareSettingsException ignored) {
        // Never mind
        }
    }
    if (maxComputingSpeed > 30000) {
        setErrorMessage(" " + String.format(Localization.getString("platform.plugin.setupwizard.calibration.computer-speed-warning"), (maxComputingSpeed / 1000) + "kHz"));
    } else {
        setErrorMessage("");
    }
}
Also used : IController(com.willwinder.universalgcodesender.IController) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) 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