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

fixes #69 #1222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -74,6 +74,21 @@ public AbstractCommunicator() {
/*********************/
abstract public void setSingleStepMode(boolean enable);
abstract public boolean getSingleStepMode();

/**
* Enable singleBlockMode, pausing the commandStream after every
* block sent to the controller.
* @param boolean enable true if enabled
*/
abstract public void setSingleBlockMode(boolean enable);
carneeki marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get the state of singleBlockMode, which pauses the commandStream
* after every block sent to the controller.
* @return boolean true if enabled
*/
abstract public boolean getSingleBlockMode();

abstract public void queueStringForComm(final String input);
abstract public void queueStreamForComm(final GcodeStreamReader input);
abstract public void sendByteImmediately(byte b) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,32 @@ public boolean getSingleStepMode() {
}
return false;
}

/**
* Wrapper to set singleBlockMode in the communicator
* @see AbstractCommunicator.setSingleBlockMode()
* @param boolean true to enable
*/
@Override
public void setSingleBlockMode(boolean enabled) {
if (this.comm != null) {
this.comm.setSingleBlockMode(enabled);
}
}

/**
* Wrapper to get the singleBlockMode in the communicator.
* getSingleBlockMode wrapper for AbstractCommunicator
* @see AbstractCommunicator.getSingleBlockMode()
* @return boolean true if enabled else false
*/
@Override
public boolean getSingleBlockMode() {
if (this.comm != null) {
return this.comm.getSingleBlockMode();
}
return false;
}

@Override
public void setStatusUpdatesEnabled(boolean enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class BufferedCommunicator extends AbstractCommunicator {
private int sentBufferSize = 0;

private Boolean singleStepModeEnabled = false;
private Boolean singleBlockModeEnabled = false;

abstract public int getBufferSize();

Expand All @@ -69,6 +70,16 @@ public void setSingleStepMode(boolean enable) {
public boolean getSingleStepMode() {
return this.singleStepModeEnabled;
}

@Override
public void setSingleBlockMode(boolean enable) {
this.singleBlockModeEnabled = enable;
}

@Override
public boolean getSingleBlockMode() {
return this.singleBlockModeEnabled;
}

/**
* Add command to the command queue outside file mode. This is the only way
Expand Down Expand Up @@ -187,6 +198,39 @@ else if (!this.commandBuffer.isEmpty()) {
}
return null;
}

/**
* See the next command to be sent out without popping from the
* commandBuffer or commandStream.
* @see BufferedCommunicator.getNextCommand()
* @see GcodeStreamReader.peekNextCommand()
* @return GcodeCommand the next command to be sent to the controller
*/
private GcodeCommand peekNextCommand() {
GcodeCommand nc = null;

if (nextCommand != null) {
nc = nextCommand;
}
else if (!this.commandBuffer.isEmpty()) {
nc = new GcodeCommand(commandBuffer.peek());
}
else
try {
if (commandStream != null && commandStream.ready())
{
nc = commandStream.peekNextCommand();
}
} catch (IOException ignored) {
// Fall through to null handling.
}

if (nc != null && nc.getCommandString().endsWith("\n")) {
nc.setCommand(nextCommand.getCommandString().trim());
}

return nc;
}

/**
* Streams anything in the command buffer to the comm port.
Expand Down Expand Up @@ -235,6 +279,18 @@ && allowMoreCommands()) {
e.printStackTrace();
System.exit(-1);
}

// Single block mode: pause after this command is sent
// iff the next command is from the commandStream
// (ie do not pause for commandBuffer commands)
if( this.getSingleBlockMode() &&
commandBuffer.isEmpty() &&
peekNextCommand() != null &&
!peekNextCommand().getCommandString().isEmpty() ) {

logger.log(Level.INFO, "singleBlockMode: pausing");
pauseSend();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dispatchListenerEvents(PAUSED, ""); is needed here.

}
}
}

Expand Down
15 changes: 15 additions & 0 deletions ugs-core/src/com/willwinder/universalgcodesender/IController.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ void jogMachine(int dirX, int dirY, int dirZ,
void setSingleStepMode(boolean enabled);
boolean getSingleStepMode();

/**
* Wrapper to set singleBlockMode in the communicator
* @see AbstractCommunicator.setSingleBlockMode()
* @param boolean true to enable
*/
void setSingleBlockMode(boolean enabled);
carneeki marked this conversation as resolved.
Show resolved Hide resolved

/**
* Wrapper to get the singleBlockMode in the communicator.
* getSingleBlockMode wrapper for AbstractCommunicator
* @see AbstractCommunicator.getSingleBlockMode()
* @return boolean true if enabled else false
*/
boolean getSingleBlockMode();

void setStatusUpdatesEnabled(boolean enabled);
boolean getStatusUpdatesEnabled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ public void applySettingsToController(Settings settings, IController controller)

try {
controller.setSingleStepMode(settings.isSingleStepMode());
controller.setSingleBlockMode(settings.isSingleStepMode());
controller.setStatusUpdatesEnabled(settings.isStatusUpdatesEnabled());
controller.setStatusUpdateRate(settings.getStatusUpdateRate());
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class ConnectionSettingsPanel extends AbstractUGSSettings {
Localization.getString("sender.step.separateZ"));
private final Checkbox singleStepMode = new Checkbox(
Localization.getString("sender.singlestep"));
private final Checkbox singleBlockMode = new Checkbox(
Localization.getString("sender.singleblock"));
private final Checkbox statusPollingEnabled = new Checkbox(
Localization.getString("sender.status"));
private final Spinner statusPollRate = new Spinner(
Expand Down Expand Up @@ -77,6 +79,7 @@ public ConnectionSettingsPanel(Settings settings) {
public String getHelpMessage() {
return Localization.getString("sender.help.verbose.console") + "\n\n" +
Localization.getString("sender.help.singlestep") + "\n\n" +
Localization.getString("sender.help.singleblock") + "\n\n" +
Localization.getString("sender.help.status") + "\n\n" +
Localization.getString("sender.help.status.rate") + "\n\n" +
Localization.getString("sender.help.state") + "\n\n";
Expand All @@ -87,6 +90,7 @@ public void save() {
settings.setVerboseOutputEnabled(verboseConsoleOutput.getValue());
settings.setUseZStepSize(useZStepSize.getValue());
settings.setSingleStepMode(singleStepMode.getValue());
settings.setSingleBlockMode(singleBlockMode.getValue());
settings.setStatusUpdatesEnabled(statusPollingEnabled.getValue());
settings.setStatusUpdateRate((int)statusPollRate.getValue());
//settings.setAutoConnectEnabled(autoConnect.getValue());
Expand Down Expand Up @@ -125,6 +129,9 @@ protected void updateComponentsInternal(Settings s) {
singleStepMode.setSelected(s.isSingleStepMode());
add(singleStepMode, "spanx, wrap");

singleBlockMode.setSelected(s.isSingleBlockMode());
add(singleBlockMode, "spanx, wrap");

statusPollingEnabled.setSelected(s.isStatusUpdatesEnabled());
add(statusPollingEnabled, "spanx, wrap");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ public GcodeCommand getNextCommand() throws IOException {
Integer.parseInt(nextLine[COL_COMMAND_NUMBER]));
}

/**
* Peek at the next command without moving the pointers
* NOTE: this calls mark() and reset() so reset() calls outside of
* peekNextCommand() may be interfered with by this.
* @return GcodeCommand containing next line
* @throws IOException
*/
public GcodeCommand peekNextCommand() throws IOException {
if (numRowsRemaining == 0) return null;

reader.mark(NUM_COLUMNS); // bookmark for rollback
String line = reader.readLine();
reader.reset(); // rollback to mark

String nextLine[] = parseLine(line);
if (nextLine.length != NUM_COLUMNS) {
throw new IOException("Corrupt data found while processing gcode stream: " + line);
}
return new GcodeCommand(
nextLine[COL_PROCESSED_COMMAND],
nextLine[COL_ORIGINAL_COMMAND],
nextLine[COL_COMMENT],
Integer.parseInt(nextLine[COL_COMMAND_NUMBER]));
}

@Override
public void close() throws IOException {
reader.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This file is part of Universal Gcode Sender (UGS).
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Settings {
Expand Down Expand Up @@ -64,6 +65,7 @@ public class Settings {
private WindowSettings mainWindowSettings = new WindowSettings(0,0,640,520);
private WindowSettings visualizerWindowSettings = new WindowSettings(0,0,640,480);
private boolean singleStepMode = false;
private boolean singleBlockMode = false;
private boolean statusUpdatesEnabled = true;
private int statusUpdateRate = 200;
private Units preferredUnits = Units.MM;
Expand Down Expand Up @@ -313,6 +315,29 @@ public void setSingleStepMode(boolean singleStepMode) {
changed();
}

/**
* Retrieve the setting to determine if communicator should pause
* streaming after each command in the communicator commandStream.
* @see AbstractCommunicator.getSingleBlockMode()
* @return true if singleBlockMode is enabled
*/
public boolean isSingleBlockMode() {
return singleBlockMode;
}

/**
* Enable / disable the pausing of streaming after each command in
* the commandStream of the communicator. Also requires
* singleStepMode to be enabled
* @see AbstractCommunicator.setSingleBlockMode()
* @param boolean singleBlockMode true if enabled
*/
public void setSingleBlockMode(boolean singleBlockMode) {
logger.log(Level.INFO, "Setting singleBlockMode to ".concat( ((Boolean)singleBlockMode).toString() ));
this.singleBlockMode = singleBlockMode;
changed();
}

public boolean isStatusUpdatesEnabled() {
return statusUpdatesEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private static void migrateOldSettings() {
out.setVerboseOutputEnabled(Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE)));
out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL"));
out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE)));
out.setSingleBlockMode(Boolean.valueOf(properties.getProperty("singleBlockMode", FALSE)));
out.setStatusUpdatesEnabled(Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true")));
out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200")));
out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;"));
Expand Down
2 changes: 2 additions & 0 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ sender.speed.percent = Speed override percent
sender.command.length = Max command length
sender.truncate = Truncate decimal digits
sender.singlestep = Enable single step mode
sender.singleblock = Enable single block mode
sender.whitespace = Remove all whitespace in commands
sender.status = Enable status polling
sender.status.rate = Status poll rate (ms)
Expand All @@ -180,6 +181,7 @@ sender.help.speed.percent = Speed override percent\: Factor that speeds will be
sender.help.command.length = Max command length\: Maximum length of a command before an error is triggered.
sender.help.truncate = Truncate decimal digits\: Number of fractional digits that will be sent to firmware.
sender.help.singlestep = Enable single step mode\: Turns on single step mode, this is very slow.
sender.help.singleblock = Enable single block mode\: Pause sender after every block, useful for testing programs though extremely slow.
sender.help.whitespace = Remove all whitespace\: Removes the usually unnecessary whitespace in gcode commands.
sender.help.status = Enable status polling\: Turns on status polling for firmware if supported.
sender.help.status.rate = Status poll rate\: The rate in milliseconds that status requests are sent at.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public void testSingleStepMode() {
fail("Not implemented yet.");
}

/**
* Test of setSingleBlockMode method of class BufferedCommunicator.
*/
@Test
@Ignore
public void testSingleBlockMode() {
System.out.println("testSingleBlockMode");
fail("Not implemented yet.");
}

/**
* Test of getBufferSize method, of class BufferedCommunicator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private void initComponents() {
this.labels.put("communicator:numActiveCommands", new JLabel("-----"));
this.labels.put("communicator:isPaused", new JLabel("-----"));
this.labels.put("communicator:getSingleStepMode", new JLabel("-----"));
this.labels.put("communicator:getSingleBlockMode", new JLabel("-----"));

this.labels.put("settings:isHomingEnabled", new JLabel("-----"));
this.labels.put("settings:getReportingUnits", new JLabel("-----"));
Expand Down