Reimplement missing events in commRefactoring.

This commit is contained in:
Ryan Press committed 2014-10-26 08:57:46 -07:00
1 parent 077486c838
commit bbd46fd3a6
5 files changed
+35 -5

No files matched your search

+24
View File
@@ -61,6 +61,15 @@ class Protocol(MessageReceiver, StateReceiver, LogReceiver):
self._transport.connect(opt)
def disconnect(self, on_error=False):
if self.is_printing():
payload = None
if self._current_file is not None:
payload = {
"file": self._current_file.getFilename(),
"filename": os.path.basename(self._current_file.getFilename()),
"origin": self._current_file.getFileLocation()
}
eventManager().fire(Events.PRINT_FAILED, payload)
self._transport.disconnect(on_error)
def send_manually(self, command, high_priority=False):
@@ -81,16 +90,31 @@ class Protocol(MessageReceiver, StateReceiver, LogReceiver):
self._current_file.start()
self._changeState(State.PRINTING)
eventManager().fire(Events.PRINT_STARTED, {
"file": self._current_file.getFilename(),
"filename": os.path.basename(self._current_file.getFilename()),
"origin": self._current_file.getFileLocation()
})
def pause_print(self):
payload = {
"file": self._current_file.getFilename(),
"filename": os.path.basename(self._current_file.getFilename()),
"origin": self._current_file.getFileLocation()
}
if self._state == State.PRINTING:
self._changeState(State.PAUSED)
eventManager().fire(Events.PRINT_PAUSED, payload)
elif self._state == State.PAUSED:
self._changeState(State.PRINTING)
eventManager().fire(Events.PRINT_RESUMED, payload)
def cancel_print(self):
eventManager().fire(Events.PRINT_CANCELLED, {
"file": self._current_file.getFilename(),
"filename": os.path.basename(self._current_file.getFilename()),
"origin": self._current_file.getFileLocation()
})
self._changeState(State.OPERATIONAL)
@@ -325,6 +325,11 @@ class RepRapProtocol(Protocol):
def _fileTransferFinished(self, current_file):
if isinstance(current_file, StreamingGcodeFileInformation):
self.send_manually(RepRapProtocol.COMMAND_SD_END_WRITE(current_file.getRemoteFilename()))
eventManager().fire(Events.TRANSFER_DONE, {
"local": local,
"remote": remote,
"time": self.getPrintTime()
})
else:
self._logger.warn("Finished file transfer to printer's SD card, but could not determine remote filename, assuming 'unknown.gco' for end-write-command")
self.send_manually(RepRapProtocol.COMMAND_SD_END_WRITE("unknown.gco"))
+2 -1
View File
@@ -5,6 +5,7 @@ __copyright__ = "Copyright (C) 2014 Gina Häußge - Released under terms of the
import logging
from octoprint.events import eventManager, Events
class Transport(object):
@@ -35,7 +36,7 @@ class Transport(object):
self.changeState(State.DISCONNECTED_WITH_ERROR)
else:
self.changeState(State.DISCONNECTED)
eventManager().fire(Events.DISCONNECTED)
def send(self, command):
pass
@@ -17,7 +17,7 @@ from . import Transport, TransportProperties, State
from octoprint.util import getExceptionString
from octoprint.util.virtual import VirtualPrinter
from octoprint.settings import settings
from octoprint.events import eventManager, Events
class SerialTransport(Transport):
@@ -126,17 +126,17 @@ class SerialTransport(Transport):
self._serial = VirtualPrinter(timeout=self._communicationTimeout, writeTimeout=self._writeTimeout)
self.changeState(State.CONNECTED)
self._transport_logger.debug("Connected to VIRTUAL printer")
return True
else:
try:
self._serial = serial.Serial(self._port, self._baudrate, timeout=self._communicationTimeout, writeTimeout=self._writeTimeout)
self.changeState(State.CONNECTED)
self._transport_logger.debug("Connected to %s" % self._serial)
return True
except:
self.logError("Unexpected error while connecting to serial port: %s %s" % (self._port, getExceptionString()))
self.onError("Failed to open serial port, permissions correct?")
return False
eventManager().fire(Events.CONNECTED, {"port": self._port, "baudrate": self._baudrate})
return True
def _readline(self):
if self._serial is None:
+1 -1
View File
@@ -293,7 +293,7 @@ class CommandTrigger(GenericEventListener):
def _executeGcodeCommand(self, command):
commands = [command]
if isinstance(command, (list, tuple, set)):
self.logger.debug("Executing GCode commands: %r" % command)
self._logger.debug("Executing GCode commands: %r" % command)
commands = list(command)
else:
self._logger.debug("Executing GCode command: %s" % command)