Search in sources :

Example 1 with FirmwareSettingsException

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

Example 2 with FirmwareSettingsException

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

Example 3 with FirmwareSettingsException

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

Example 4 with FirmwareSettingsException

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

Example 5 with FirmwareSettingsException

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);
            }
        }
    };
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyListener(java.awt.event.KeyListener) IFirmwareSettings(com.willwinder.universalgcodesender.firmware.IFirmwareSettings) FirmwareSettingsException(com.willwinder.universalgcodesender.firmware.FirmwareSettingsException) ParseException(java.text.ParseException) JTextField(javax.swing.JTextField)

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