mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Added window for usb printing
This commit is contained in:
parent
c0d39ff287
commit
5e8f767b78
2 changed files with 82 additions and 14 deletions
|
@ -32,6 +32,8 @@ class PrinterConnection(SignalEmitter):
|
|||
# response. If the baudrate is correct, this should make sense, else we get giberish.
|
||||
self._required_responses_auto_baud = 10
|
||||
|
||||
self._progress = 0
|
||||
|
||||
self._listen_thread = threading.Thread(target=self._listen)
|
||||
self._listen_thread.daemon = True
|
||||
|
||||
|
@ -327,7 +329,24 @@ class PrinterConnection(SignalEmitter):
|
|||
checksum = functools.reduce(lambda x,y: x^y, map(ord, 'N%d%s' % (self._gcode_position, line)))
|
||||
|
||||
self._sendCommand("N%d%s*%d" % (self._gcode_position, line, checksum))
|
||||
self._gcode_position += 1
|
||||
self._gcode_position += 1
|
||||
self.setProgress(( self._gcode_position / len(self._gcode)) * 100)
|
||||
self.progressChanged.emit(self._progress, self._serial_port)
|
||||
|
||||
progressChanged = Signal()
|
||||
|
||||
def setProgress(self, progress):
|
||||
self._progress = progress
|
||||
self.progressChanged.emit(self._progress, self._serial_port)
|
||||
|
||||
def cancelPrint(self):
|
||||
self._gcode_position = 0
|
||||
self.setProgress(0)
|
||||
self._gcode = []
|
||||
# Turn of temperatures
|
||||
self._sendCommand("M140 S0")
|
||||
self._sendCommand("M109 S0")
|
||||
self._is_printing = False
|
||||
|
||||
def hasError(self):
|
||||
return False
|
||||
|
|
|
@ -10,16 +10,27 @@ import glob
|
|||
import time
|
||||
import os
|
||||
|
||||
class USBPrinterManager(SignalEmitter,PluginObject):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
from PyQt5.QtQuick import QQuickView
|
||||
from PyQt5.QtCore import QUrl, QObject,pyqtSlot , pyqtProperty,pyqtSignal
|
||||
|
||||
class USBPrinterManager(QObject, SignalEmitter,PluginObject):
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
self._serial_port_list = []
|
||||
self._printer_connections = []
|
||||
self._check_ports_thread = threading.Thread(target=self._updateConnectionList)
|
||||
self._check_ports_thread.daemon = True
|
||||
self._check_ports_thread.start()
|
||||
|
||||
self._progress = 50
|
||||
|
||||
|
||||
## DEBUG CODE
|
||||
self.view = QQuickView()
|
||||
self.view.setSource(QUrl("plugins/USBPrinting/ControlWindow.qml"))
|
||||
self.view.show()
|
||||
self.view.engine().rootContext().setContextProperty('manager',self)
|
||||
|
||||
#time.sleep(1)
|
||||
#self.connectAllConnections()
|
||||
#time.sleep(5)
|
||||
|
@ -31,9 +42,27 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
#print("sending heat " , self.sendCommandToAllActive("M104 S190"))
|
||||
|
||||
|
||||
#def spawnInterface(self):
|
||||
#view = QQuickView()
|
||||
#view.setSource(QUrl("plugins/USBPrinting/ControlWindow.qml"))
|
||||
#view.show()
|
||||
|
||||
## Check all serial ports and create a PrinterConnection object for them.
|
||||
# Note that this does not validate if the serial ports are actually usable!
|
||||
# This is only done when the connect function is called.
|
||||
|
||||
|
||||
processingProgress = pyqtSignal(float, arguments = ['amount'])
|
||||
#@pyqtProperty(float, notify = processingProgress)
|
||||
@pyqtProperty(float,notify = processingProgress)
|
||||
def progress(self):
|
||||
return self._progress
|
||||
|
||||
@pyqtSlot()
|
||||
def test(self):
|
||||
print("derp")
|
||||
|
||||
|
||||
def _updateConnectionList(self):
|
||||
while True:
|
||||
temp_serial_port_list = self.getSerialPortList(only_list_usb = True)
|
||||
|
@ -46,6 +75,7 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
connection = PrinterConnection.PrinterConnection(serial_port)
|
||||
connection.connect()
|
||||
connection.connectionStateChanged.connect(self.serialConectionStateCallback)
|
||||
connection.progressChanged.connect(self.onProgress)
|
||||
self._printer_connections.append(connection)
|
||||
|
||||
for serial_port in disconnected_ports: # Close connections and remove them from list.
|
||||
|
@ -55,6 +85,11 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
connection.close()
|
||||
time.sleep(5) #Throttle, as we don't need this information to be updated every single second.
|
||||
|
||||
def onProgress(self, progress, serial_port):
|
||||
self._progress = progress
|
||||
self.processingProgress.emit(progress)
|
||||
pass
|
||||
|
||||
## Attempt to connect with all possible connections.
|
||||
def connectAllConnections(self):
|
||||
for connection in self._printer_connections:
|
||||
|
@ -67,6 +102,10 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
printer_connection.printGCode(gcode_list)
|
||||
return True
|
||||
return False
|
||||
@pyqtSlot()
|
||||
def cancelPrint(self):
|
||||
for printer_connection in self.getActiveConnections():
|
||||
printer_connection.cancelPrint()
|
||||
|
||||
## Send gcode to all active printers.
|
||||
# \return True if there was at least one active connection.
|
||||
|
@ -103,17 +142,27 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
|
||||
def serialConectionStateCallback(self,serial_port):
|
||||
connection = self.getConnectionByPort(serial_port)
|
||||
if connection.isConnected():
|
||||
Application.getInstance().addOutputDevice(serial_port, {
|
||||
'id': serial_port,
|
||||
'function': self._writeToSerial,
|
||||
'description': 'Write to USB {0}'.format(serial_port),
|
||||
'icon': 'print_usb',
|
||||
'priority': 1
|
||||
})
|
||||
else:
|
||||
Application.getInstance().removeOutputDevice(serial_port)
|
||||
if connection is not None:
|
||||
if connection.isConnected():
|
||||
Application.getInstance().addOutputDevice(serial_port, {
|
||||
'id': serial_port,
|
||||
'function': self._writeToSerial,
|
||||
'description': 'Write to USB {0}'.format(serial_port),
|
||||
'icon': 'print_usb',
|
||||
'priority': 1
|
||||
})
|
||||
else:
|
||||
Application.getInstance().removeOutputDevice(serial_port)
|
||||
|
||||
|
||||
def _writeToSerial(self, serial_port):
|
||||
## Create USB control window
|
||||
#self.view = QQuickView()
|
||||
#self.view.setSource(QUrl("plugins/USBPrinting/ControlWindow.qml"))
|
||||
#self.view.show()
|
||||
|
||||
#self.view.engine().rootContext().setContextProperty('manager',self)
|
||||
|
||||
for node in DepthFirstIterator(Application.getInstance().getController().getScene().getRoot()):
|
||||
if type(node) is not SceneNode or not node.getMeshData():
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue