Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for smoothie #2216

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private void onEvent(UGSEvent event) {
}

private boolean canConfigureFirmware() {
return this.backend.isConnected() && this.backend.isIdle();
return backend.isConnected() &&
backend.isIdle() &&
backend.getController().getCapabilities().hasFirmwareSettings();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.universalgcodesender.communicator;

import com.willwinder.universalgcodesender.GrblUtils;
import com.willwinder.universalgcodesender.SmoothieUtils;

/**
* @author wwinder
*/
public class SmoothieCommunicator extends BufferedCommunicator {

public SmoothieCommunicator() {
super();
setSingleStepMode(true);
super.setSingleStepMode(true);
}

@Override
Expand All @@ -38,7 +34,6 @@ public int getBufferSize() {

@Override
protected void sendingCommand(String command) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.firmware.smoothie;

import com.willwinder.universalgcodesender.firmware.smoothie.commands.SmoothieCommand;
import com.willwinder.universalgcodesender.gcode.ICommandCreator;
import com.willwinder.universalgcodesender.types.GcodeCommand;

/**
* A command creator for smoothie firmware controllers
*/
public class SmoothieCommandCreator implements ICommandCreator {
@Override
public GcodeCommand createCommand(String command) {
return new SmoothieCommand(command);
}

@Override
public GcodeCommand createCommand(String command, String originalCommand, String comment, int lineNumber) {
return new SmoothieCommand(command, originalCommand, comment, lineNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,37 @@ This file is part of Universal Gcode Sender (UGS).
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender;
package com.willwinder.universalgcodesender.firmware.smoothie;

import com.willwinder.universalgcodesender.AbstractController;
import com.willwinder.universalgcodesender.Capabilities;
import com.willwinder.universalgcodesender.CapabilitiesConstants;
import com.willwinder.universalgcodesender.GrblUtils;
import com.willwinder.universalgcodesender.StatusPollTimer;
import com.willwinder.universalgcodesender.communicator.ICommunicator;
import com.willwinder.universalgcodesender.communicator.SmoothieCommunicator;
import com.willwinder.universalgcodesender.firmware.IFirmwareSettings;
import com.willwinder.universalgcodesender.firmware.smoothie.SmoothieFirmwareSettings;
import com.willwinder.universalgcodesender.gcode.DefaultCommandCreator;
import com.willwinder.universalgcodesender.firmware.smoothie.commands.GetVersionCommand;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.listeners.ControllerState;
import com.willwinder.universalgcodesender.listeners.ControllerStatus;
import com.willwinder.universalgcodesender.listeners.ControllerStatusBuilder;
import com.willwinder.universalgcodesender.listeners.MessageType;
import com.willwinder.universalgcodesender.model.*;
import com.willwinder.universalgcodesender.model.CommunicatorState;
import com.willwinder.universalgcodesender.model.Overrides;
import com.willwinder.universalgcodesender.model.PartialPosition;
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;
import com.willwinder.universalgcodesender.types.GcodeCommand;
import com.willwinder.universalgcodesender.utils.ControllerUtils;
import com.willwinder.universalgcodesender.utils.ThreadHelper;
import org.apache.commons.lang3.StringUtils;

import static com.willwinder.universalgcodesender.model.CommunicatorState.*;
import java.util.Optional;

import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_CHECK;
import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_DISCONNECTED;
import static com.willwinder.universalgcodesender.model.CommunicatorState.COMM_IDLE;

/**
* Controller implementation for Smoothieware
Expand All @@ -56,7 +69,7 @@ public SmoothieController() {
}

public SmoothieController(ICommunicator communicator) {
super(communicator, new DefaultCommandCreator());
super(communicator, new SmoothieCommandCreator());
capabilities = new Capabilities();
firmwareSettings = new SmoothieFirmwareSettings();
controllerStatus = new ControllerStatus(ControllerState.DISCONNECTED, new Position(0, 0, 0, UnitUtils.Units.MM), new Position(0, 0, 0, UnitUtils.Units.MM));
Expand Down Expand Up @@ -147,38 +160,21 @@ protected void rawResponseHandler(String response) {
dispatchConsoleMessage(MessageType.INFO, response + "\n");
return;
} else if (isSmoothieReady && !isReady && response.equalsIgnoreCase("ok")) {
comm.queueCommand(getCommandCreator().createCommand("version"));
comm.streamCommands();
return;
} else if (isSmoothieReady && !isReady && response.startsWith("Build version:")) {
dispatchConsoleMessage(MessageType.INFO, response + "\n");
firmwareVersion = "Smoothie " + StringUtils.substringBetween(response, "Build date:", ",").trim();
commandComplete(response);

capabilities.addCapability(CapabilitiesConstants.X_AXIS);
capabilities.addCapability(CapabilitiesConstants.Y_AXIS);
capabilities.addCapability(CapabilitiesConstants.Z_AXIS);
capabilities.addCapability(CapabilitiesConstants.JOGGING);
capabilities.addCapability(CapabilitiesConstants.HOMING);
capabilities.addCapability(CapabilitiesConstants.RETURN_TO_ZERO);
controllerStatus = ControllerStatusBuilder.newInstance(controllerStatus).setState(ControllerState.IDLE).build();
dispatchStatusString(controllerStatus);
setCurrentState(COMM_IDLE);
isReady = true;

viewParserState();
statusPollTimer.start();
queryVersion();
return;
}

if(SmoothieUtils.isOkErrorAlarmResponse(response)) {
dispatchConsoleMessage(MessageType.INFO, response + "\n");
// Clear the ci
Optional<GcodeCommand> activeCommand = getActiveCommand();
if (activeCommand.isPresent() && activeCommand.get().isDone()) {
commandComplete(response);
} else if(SmoothieUtils.isStatusResponse(response)) {
}

if (SmoothieUtils.isStatusResponse(response)) {
statusPollTimer.receivedStatus();
handleStatusResponse(response);
checkStreamFinished();
} else if(SmoothieUtils.isParserStateResponse(response)) {
} else if (SmoothieUtils.isParserStateResponse(response)) {
String parserStateCode = StringUtils.substringBetween(response, "[", "]");
dispatchConsoleMessage(MessageType.INFO, response + "\n");
updateParserModalState(getCommandCreator().createCommand(parserStateCode));
Expand All @@ -191,6 +187,32 @@ protected void rawResponseHandler(String response) {
}
}

private void queryVersion() {
ThreadHelper.invokeLater(() -> {
try {
GetVersionCommand command = ControllerUtils.sendAndWaitForCompletion(this, new GetVersionCommand());
firmwareVersion = command.getVersion();
dispatchConsoleMessage(MessageType.INFO, command.getResponse() + "\n");

capabilities.addCapability(CapabilitiesConstants.X_AXIS);
capabilities.addCapability(CapabilitiesConstants.Y_AXIS);
capabilities.addCapability(CapabilitiesConstants.Z_AXIS);
capabilities.addCapability(CapabilitiesConstants.JOGGING);
capabilities.addCapability(CapabilitiesConstants.HOMING);
capabilities.addCapability(CapabilitiesConstants.RETURN_TO_ZERO);
controllerStatus = ControllerStatusBuilder.newInstance(controllerStatus).setState(ControllerState.IDLE).build();
dispatchStatusString(controllerStatus);
setCurrentState(COMM_IDLE);
isReady = true;

viewParserState();
statusPollTimer.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}

private void handleStatusResponse(String response) {
dispatchConsoleMessage(MessageType.VERBOSE, response + "\n");

Expand Down Expand Up @@ -263,7 +285,7 @@ public void setWorkPosition(PartialPosition axisPosition) throws Exception {

@Override
public void killAlarmLock() throws Exception {
if(controllerStatus.getState().equals(ControllerState.ALARM)) {
if (controllerStatus.getState().equals(ControllerState.ALARM)) {
GcodeCommand command = createCommand(SmoothieUtils.KILL_ALARM_LOCK_COMMAND);
sendCommandImmediately(command);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Will Winder
Copyright 2020-2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand All @@ -16,8 +16,9 @@ This file is part of Universal Gcode Sender (UGS).
You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender;
package com.willwinder.universalgcodesender.firmware.smoothie;

import com.willwinder.universalgcodesender.GrblUtils;
import com.willwinder.universalgcodesender.gcode.GcodeState;
import com.willwinder.universalgcodesender.listeners.ControllerStatus;
import com.willwinder.universalgcodesender.model.*;
Expand All @@ -42,7 +43,7 @@ public class SmoothieUtils {
/**
* Parse state out of position string.
*/
private static final Pattern PARSER_STATE_PATTERN = Pattern.compile("\\[.*]");
private static final Pattern PARSER_STATE_PATTERN = Pattern.compile("$\\[.*]");

protected static ControllerStatus getStatusFromStatusString(ControllerStatus lastStatus, final String status, UnitUtils.Units reportingUnits) {
return GrblUtils.getStatusFromStatusStringV1(lastStatus, status, reportingUnits);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.firmware.smoothie.commands;

import org.apache.commons.lang3.StringUtils;

public class GetVersionCommand extends SmoothieCommand {
public GetVersionCommand() {
super("version");
}

public String getVersion() {
return "Smoothie " + StringUtils.substringBetween(getResponse(), "Build date:", ",").trim();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2023 Will Winder

This file is part of Universal Gcode Sender (UGS).

UGS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

UGS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with UGS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.willwinder.universalgcodesender.firmware.smoothie.commands;

import com.willwinder.universalgcodesender.types.GcodeCommand;

import static com.willwinder.universalgcodesender.firmware.smoothie.SmoothieUtils.isVersionResponse;

public class SmoothieCommand extends GcodeCommand {
public SmoothieCommand(String command) {
super(command);
}

public SmoothieCommand(String command, String originalCommand, String comment, int lineNumber) {
super(command, originalCommand, comment, lineNumber);
}

@Override
public void appendResponse(String response) {
super.appendResponse(response);

// Handle special case in protocol
if (isVersionResponse(response)) {
setOk(true);
setDone(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.universalgcodesender.GrblEsp32Controller;
import com.willwinder.universalgcodesender.IController;
import com.willwinder.universalgcodesender.communicator.LoopBackCommunicator;
import com.willwinder.universalgcodesender.SmoothieController;
import com.willwinder.universalgcodesender.firmware.smoothie.SmoothieController;
import com.willwinder.universalgcodesender.TinyGController;
import com.willwinder.universalgcodesender.communicator.XLCDCommunicator;
import com.willwinder.universalgcodesender.gcode.processors.CommandProcessor;
Expand Down