diff --git a/ugs-core/src/com/willwinder/universalgcodesender/CapabilitiesConstants.java b/ugs-core/src/com/willwinder/universalgcodesender/CapabilitiesConstants.java index 62194b038..59537e019 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/CapabilitiesConstants.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/CapabilitiesConstants.java @@ -98,12 +98,11 @@ public class CapabilitiesConstants { * in the right, far, upper corner which is then set to 0, therefore all coordinates in the machine space is * defined with negative values. *
- * Some controllers have the option to inverse this, making the machine zero at the left, lower, close corner of - * the machine. + * Some controllers have the option to set the homed position as machine zero. *
* By defining this capability we can account for this in the visualizer. */ - public static final String MACHINE_POSITION_IN_POSITIVE_SPACE = "MACHINE_POSITION_IN_POSITIVE_SPACE"; + public static final String HOMING_SETS_MACHINE_ZERO_POSITION = "HOMING_SETS_ZERO_POSITION"; /** * Does the controller support variable spindles (typically PWM or through RS484 interfaces) diff --git a/ugs-core/src/com/willwinder/universalgcodesender/GrblUtils.java b/ugs-core/src/com/willwinder/universalgcodesender/GrblUtils.java index eeea7cf68..6acba9938 100644 --- a/ugs-core/src/com/willwinder/universalgcodesender/GrblUtils.java +++ b/ugs-core/src/com/willwinder/universalgcodesender/GrblUtils.java @@ -270,7 +270,7 @@ protected static Capabilities getGrblStatusCapabilities(final double version, fi } if (options.isEnabled(GrblBuildOption.HOMING_FORCE_ORIGIN_ENABLED)) { - ret.addCapability(CapabilitiesConstants.MACHINE_POSITION_IN_POSITIVE_SPACE); + ret.addCapability(CapabilitiesConstants.HOMING_SETS_MACHINE_ZERO_POSITION); } if (options.isEnabled(GrblBuildOption.VARIABLE_SPINDLE_ENABLED)) { diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java index f143b5197..eff66228c 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java @@ -18,19 +18,32 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbm.visualizer.renderables; +import static com.jogamp.opengl.GL.GL_LINES; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BOUNDARY_INVERT_X; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BOUNDARY_INVERT_Y; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BOUNDARY_INVERT_Z; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BOUNDRY; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_X; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_Y; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_Z; import com.willwinder.ugs.nbm.visualizer.shared.Renderable; import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; +import com.willwinder.universalgcodesender.CapabilitiesConstants; import com.willwinder.universalgcodesender.firmware.FirmwareSettingsException; import com.willwinder.universalgcodesender.firmware.IFirmwareSettings; -import com.willwinder.universalgcodesender.model.*; +import com.willwinder.universalgcodesender.listeners.ControllerState; +import com.willwinder.universalgcodesender.model.Axis; +import com.willwinder.universalgcodesender.model.BackendAPI; +import com.willwinder.universalgcodesender.model.PartialPosition; +import com.willwinder.universalgcodesender.model.Position; +import com.willwinder.universalgcodesender.model.UGSEvent; +import com.willwinder.universalgcodesender.model.UnitUtils; +import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; import com.willwinder.universalgcodesender.model.events.FirmwareSettingEvent; -import static com.jogamp.opengl.GL.GL_LINES; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.*; - /** * Displays the machine boundries based on the soft limits * @@ -61,7 +74,7 @@ public MachineBoundries(String title) { } private void onUGSEvent(UGSEvent event) { - if (!isFirmwareSettingsEvent(event)) { + if (!isFirmwareSettingsEvent(event) && !isControllerIdleEvent(event)) { return; } @@ -78,11 +91,16 @@ private void onUGSEvent(UGSEvent event) { minPositionBuilder.setValue(axis, -softLimit); } minPosition = minPositionBuilder.build(); + updateSettingsFromController(); } catch (FirmwareSettingsException ignored) { // Never mind this. } } + private boolean isControllerIdleEvent(UGSEvent event) { + return event instanceof ControllerStateEvent controllerStateEvent && (controllerStateEvent.getState() == ControllerState.IDLE || controllerStateEvent.getState() == ControllerState.ALARM); + } + private boolean isFirmwareSettingsEvent(UGSEvent event) { // This will prevent us from accessing the firmware settings before the init // processes has finished and it will also prevent us from accessing the @@ -118,9 +136,34 @@ public void reloadPreferences(VisualizerOptions vo) { xAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_X).value); yAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_Y).value); zAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_Z).value); + updateSettingsFromController(); + } + + private void updateSettingsFromController() { + BackendAPI backendAPI = CentralLookup.getDefault().lookup(BackendAPI.class); invertX = VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_BOUNDARY_INVERT_X, false) ? -1 : 1; invertY = VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_BOUNDARY_INVERT_Y, false) ? -1 : 1; invertZ = VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_BOUNDARY_INVERT_Z, false) ? -1 : 1; + + if (backendAPI == null || backendAPI.getController() == null) { + return; + } + + boolean homingSetsZeroPosition = backendAPI.getController().getCapabilities().hasCapability(CapabilitiesConstants.HOMING_SETS_MACHINE_ZERO_POSITION); + if (homingSetsZeroPosition) { + invertBasedOnHomingDirection(backendAPI); + } + } + + private void invertBasedOnHomingDirection(BackendAPI backendAPI) { + IFirmwareSettings settings = backendAPI.getController().getFirmwareSettings(); + invertX = isHomingDirectionInverted(settings, Axis.X) ? -invertX : invertX; + invertY = isHomingDirectionInverted(settings, Axis.Y) ? -invertY : invertY; + invertZ = isHomingDirectionInverted(settings, Axis.Z) ? -invertZ : invertZ; + } + + private static boolean isHomingDirectionInverted(IFirmwareSettings settings, Axis axis) { + return settings.isHomingDirectionInverted(axis); } @Override