import urllib
import time
+from Cura.util.printerConnection import printerConnectionBase
+
#Class to connect and print files with the doodle3d.com wifi box
# Auto-detects if the Doodle3D box is available with a printer
-class doodle3dConnect(object):
+class doodle3dConnect(printerConnectionBase.printerConnectionBase):
def __init__(self):
+ super(doodle3dConnect, self).__init__()
+
self._http = None
- self._connected = False
+ self._isAvailable = False
self._printing = False
self._fileBlocks = []
self._blockIndex = None
self._hotendTemperature = [0] * 4
self._bedTemperature = 0
- self.checkThread = threading.Thread(target=self._checkForDoodle3D)
+ self.checkThread = threading.Thread(target=self._doodle3Dthread)
self.checkThread.daemon = True
self.checkThread.start()
+ #Load the file into memory for printing.
def loadFile(self, filename):
if self._printing:
return
self._fileBlocks.append('\n'.join(block) + '\n')
f.close()
+ #Start printing the previously loaded file
def startPrint(self):
- if self._printing:
+ if self._printing or len(self._fileBlocks) < 1:
return
self._progressLine = 0
self._blockIndex = 0
self._printing = True
- def stopPrint(self):
+ #Abort the previously loaded print file
+ def cancelPrint(self):
if not self._printing:
return
if self._request('POST', '/d3dapi/printer/stop', {'gcode': 'M104 S0\nG28'}):
self._printing = False
- def isConnected(self):
- return self._connected
-
def isPrinting(self):
return self._printing
- def _checkForDoodle3D(self):
+ # Return if the printer with this connection type is available
+ def isAvailable(self):
+ return self._isAvailable
+
+ # Get the connection status string. This is displayed to the user and can be used to communicate
+ # various information to the user.
+ def getStatusString(self):
+ return "TODO"
+
+ def _doodle3Dthread(self):
while True:
stateReply = self._request('GET', '/d3dapi/printer/state')
if stateReply is None: #No API, wait 15 seconds before looking for Doodle3D again.
- self._connected = False
+ self._isAvailable = False
time.sleep(15)
continue
if not stateReply: #API gave back an error (this can happen if the Doodle3D box is connecting to the printer)
- self._connected = False
+ self._isAvailable = False
time.sleep(5)
continue
- self._connected = True
+ self._isAvailable = True
if stateReply['data']['state'] == 'idle':
if self._printing:
if __name__ == '__main__':
d = doodle3dConnect()
print 'Searching for Doodle3D box'
- while not d.isConnected():
+ while not d.isAvailable():
time.sleep(1)
while d.isPrinting():
print 'Doodle3D already printing! Requesting stop!'
- d.stopPrint()
+ d.cancelPrint()
time.sleep(5)
print 'Doodle3D box found, printing!'
d.loadFile("C:/Models/belt-tensioner-wave_export.gcode")
d.startPrint()
- while d.isPrinting() and d.isConnected():
+ while d.isPrinting() and d.isAvailable():
time.sleep(1)
print d._progressLine, d._lineCount, d._blockIndex, len(d._fileBlocks)
print 'Done'
--- /dev/null
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+
+#Base class for different printer connection implementations.
+# A printer connection can connect to printers in different ways, trough network, USB or carrier pigeons.
+# Each printer connection has different capabilities that you can query with the "has" functions.
+# Each printer connection has a state that you can query with the "is" functions.
+# Each printer connection has callback objects that receive status updates from the printer when information changes.
+
+class printerConnectionBase(object):
+ def __init__(self):
+ self._callbackList = []
+
+ #Load the file into memory for printing.
+ def loadFile(self, filename):
+ pass
+
+ #Start printing the previously loaded file
+ def startPrint(self):
+ pass
+
+ #Abort the previously loaded print file
+ def cancelPrint(self):
+ pass
+
+ def isPrinting(self):
+ return False
+
+ #Returns true if we need to establish an active connection.
+ # Depending on the type of the connection some types do not need an active connection (Doodle3D WiFi Box for example)
+ def hasActiveConnection(self):
+ return False
+
+ #Open the active connection to the printer so we can send commands
+ def openActiveConnection(self):
+ pass
+
+ #Close the active connection to the printer
+ def closeActiveConnection(self):
+ pass
+
+ #Is the active connection open right now.
+ def isActiveConnectionOpen(self):
+ return False
+
+ #Returns true if we have the ability to pause the file printing.
+ def hasPause(self):
+ return False
+
+ def isPaused(self):
+ return False
+
+ #Pause or unpause the printing depending on the value, if supported.
+ def pause(self, value):
+ pass
+
+ #Are we able to send a direct coammand with sendCommand at this moment in time.
+ def isAbleToSendDirectCommand(self):
+ return False
+
+ #Directly send a command to the printer.
+ def sendCommand(self, command):
+ pass
+
+ # Return if the printer with this connection type is available
+ # This means the printer is detected, but no connection has been made yet.
+ # Example: COM port is detected, but no connection has been made.
+ # Example: WiFi box is detected
+ def isAvailable(self):
+ return False
+
+ # Get the connection status string. This is displayed to the user and can be used to communicate
+ # various information to the user.
+ def getStatusString(self):
+ return "TODO"
+
+ def _doCallback(self):
+ for callback in self._callbackList:
+ callback(self)