87 for n in range(p.logl, len(p.log)): |
87 for n in range(p.logl, len(p.log)): |
88 line = p.log[n] |
88 line = p.log[n] |
89 if 'T:' in line: |
89 if 'T:' in line: |
90 try: |
90 try: |
91 setattr(p, 'temp', int(line.split('T:')[1].split()[0])) |
91 setattr(p, 'temp', int(line.split('T:')[1].split()[0])) |
92 except: print line |
92 except: print(line) |
93 p.logl = len(p.log) |
93 p.logl = len(p.log) |
94 return p.temp |
94 return p.temp |
95 if not os.path.exists(port): |
95 if not os.path.exists(port): |
96 port = 0 |
96 port = 0 |
97 |
97 |
98 # Parse options |
98 # Parse options |
99 help = u""" |
99 help = """ |
100 %s [ -l DISTANCE ] [ -s STEPS ] [ -t TEMP ] [ -p PORT ] |
100 %s [ -l DISTANCE ] [ -s STEPS ] [ -t TEMP ] [ -p PORT ] |
101 -l --length Length of filament to extrude for each calibration step (default: %d mm) |
101 -l --length Length of filament to extrude for each calibration step (default: %d mm) |
102 -s --steps Initial amount of steps to use (default: %d steps) |
102 -s --steps Initial amount of steps to use (default: %d steps) |
103 -t --temp Extrusion temperature in degrees Celsius (default: %d \xb0C, max %d \xb0C) |
103 -t --temp Extrusion temperature in degrees Celsius (default: %d \xb0C, max %d \xb0C) |
104 -p --port Serial port the printer is connected to (default: %s) |
104 -p --port Serial port the printer is connected to (default: %s) |
105 -h --help This cruft. |
105 -h --help This cruft. |
106 """[1:-1].encode('utf-8') % (sys.argv[0], n, k, temp, tempmax, port if port else 'auto') |
106 """[1:-1].encode('utf-8') % (sys.argv[0], n, k, temp, tempmax, port if port else 'auto') |
107 try: |
107 try: |
108 opts, args = getopt.getopt(sys.argv[1:], "hl:s:t:p:", ["help", "length=", "steps=", "temp=", "port="]) |
108 opts, args = getopt.getopt(sys.argv[1:], "hl:s:t:p:", ["help", "length=", "steps=", "temp=", "port="]) |
109 except getopt.GetoptError, err: |
109 except getopt.GetoptError as err: |
110 print str(err) |
110 print(str(err)) |
111 print help |
111 print(help) |
112 sys.exit(2) |
112 sys.exit(2) |
113 for o, a in opts: |
113 for o, a in opts: |
114 if o in ('-h', '--help'): |
114 if o in ('-h', '--help'): |
115 print help |
115 print(help) |
116 sys.exit() |
116 sys.exit() |
117 elif o in ('-l', '--length'): |
117 elif o in ('-l', '--length'): |
118 n = float(a) |
118 n = float(a) |
119 elif o in ('-s', '--steps'): |
119 elif o in ('-s', '--steps'): |
120 k = int(a) |
120 k = int(a) |
121 elif o in ('-t', '--temp'): |
121 elif o in ('-t', '--temp'): |
122 temp = int(a) |
122 temp = int(a) |
123 if temp >= tempmax: |
123 if temp >= tempmax: |
124 print (u'%d \xb0C? Are you insane?'.encode('utf-8') % temp) + (" That's over nine thousand!" if temp > 9000 else '') |
124 print(('%d \xb0C? Are you insane?'.encode('utf-8') % temp) + (" That's over nine thousand!" if temp > 9000 else '')) |
125 sys.exit(255) |
125 sys.exit(255) |
126 elif o in ('-p', '--port'): |
126 elif o in ('-p', '--port'): |
127 port = a |
127 port = a |
128 |
128 |
129 # Show initial parameters |
129 # Show initial parameters |
130 print "Initial parameters" |
130 print("Initial parameters") |
131 print "Steps per mm: %3d steps" % k |
131 print("Steps per mm: %3d steps" % k) |
132 print "Length extruded: %3d mm" % n |
132 print("Length extruded: %3d mm" % n) |
133 print |
133 print() |
134 print "Serial port: %s" % (port if port else 'auto') |
134 print("Serial port: %s" % (port if port else 'auto')) |
135 |
135 |
136 p = None |
136 p = None |
137 try: |
137 try: |
138 # Connect to printer |
138 # Connect to printer |
139 w("Connecting to printer..") |
139 w("Connecting to printer..") |
140 try: |
140 try: |
141 p = printcore(port, 115200) |
141 p = printcore(port, 115200) |
142 except: |
142 except: |
143 print 'Error.' |
143 print('Error.') |
144 raise |
144 raise |
145 while not p.online: |
145 while not p.online: |
146 time.sleep(1) |
146 time.sleep(1) |
147 w('.') |
147 w('.') |
148 print " connected." |
148 print(" connected.") |
149 |
149 |
150 heatup(p, temp) |
150 heatup(p, temp) |
151 |
151 |
152 # Calibration loop |
152 # Calibration loop |
153 while n != m: |
153 while n != m: |