diff --git a/configtool.py b/configtool.py index ea4a43b..2edc2cf 100755 --- a/configtool.py +++ b/configtool.py @@ -11,6 +11,7 @@ # If you feel like porting Configtool to Python 3 compatibility altogether: # patches are welcome! See https://docs.python.org/3/howto/pyporting.html +from __future__ import print_function import sys import time if sys.version_info.major >= 3: diff --git a/configtool/board.py b/configtool/board.py index 211489e..ba3266b 100644 --- a/configtool/board.py +++ b/configtool/board.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import re @@ -180,17 +181,17 @@ class Board: # Parsing done. All parsed stuff is now in these arrays and dicts. if self.settings.verbose >= 2: - print self.sensors - print self.heaters - print self.candHeatPins - print self.candThermPins - print self.candProcessors - print self.candClocks - print self.tempTables - print self.cfgValues # #defines with a value. - print self.cfgNames # Names found in the generic file. + print(self.sensors) + print(self.heaters) + print(self.candHeatPins) + print(self.candThermPins) + print(self.candProcessors) + print(self.candClocks) + print(self.tempTables) + print(self.cfgValues) # #defines with a value. + print(self.cfgNames) # Names found in the generic file. if self.settings.verbose >= 3: - print self.helpText + print(self.helpText) for k in range(len(self.sensors)): tn = self.sensors[k][0].upper() @@ -348,7 +349,7 @@ class Board: if self.settings.verbose >= 1: print("Saving board: %s." % path) if self.settings.verbose >= 2: - print values + print(values) fp = file(path, 'w') self.configFile = path @@ -479,7 +480,7 @@ class Board: # Known to be absent in the GUI, also won't be added anytime soon. fp.write(ln) else: - print "Boolean key " + t[0] + " not found in GUI." + print("Boolean key " + t[0] + " not found in GUI.") continue diff --git a/configtool/decoration.py b/configtool/decoration.py index 4faeea3..e258206 100644 --- a/configtool/decoration.py +++ b/configtool/decoration.py @@ -1,3 +1,4 @@ +from __future__ import print_function import wx import os.path @@ -25,9 +26,9 @@ class Decoration(object): if backPic.IsOk(): self.backPic = backPic else: - print "Background picture %s damaged." % backPicPath + print("Background picture %s damaged." % backPicPath) else: - print "Background picture %s doesn't exist." % backPicPath + print("Background picture %s doesn't exist." % backPicPath) def getBackgroundColour(self): return wx.Colour(237, 237, 237) diff --git a/configtool/gui.py b/configtool/gui.py index 4b63f9b..1873fc2 100644 --- a/configtool/gui.py +++ b/configtool/gui.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import time diff --git a/configtool/page.py b/configtool/page.py index 0d4a97d..5daf22c 100644 --- a/configtool/page.py +++ b/configtool/page.py @@ -1,3 +1,4 @@ +from __future__ import print_function import wx @@ -255,14 +256,14 @@ class Page: else: self.textControls[k].SetValue("") else: - print "Key " + k + " not found in config data." + print("Key " + k + " not found in config data.") for k in self.choices.keys(): if k in cfgValues.keys(): self.choicesOriginal[k] = cfgValues[k] self.setChoice(k, cfgValues, "-") else: - print "Key " + k + " not found in config data." + print("Key " + k + " not found in config data.") for k in self.boolChoices.keys(): choice = self.boolChoices[k] diff --git a/configtool/printer.py b/configtool/printer.py index ba95981..06a822b 100644 --- a/configtool/printer.py +++ b/configtool/printer.py @@ -1,3 +1,4 @@ +from __future__ import print_function import os import re @@ -136,10 +137,10 @@ class Printer: # Parsing done. All parsed stuff is now in these array and dicts. if self.settings.verbose >= 2: - print self.cfgValues # #defines with a value. - print self.cfgNames # Names found in the generic file. + print(self.cfgValues) # #defines with a value. + print(self.cfgNames) # Names found in the generic file. if self.settings.verbose >= 3: - print self.helpText + print(self.helpText) return True, None @@ -237,7 +238,7 @@ class Printer: if self.settings.verbose >= 1: print("Saving printer: %s." % path) if self.settings.verbose >= 2: - print values + print(values) fp = file(path, 'w') self.configFile = path @@ -291,7 +292,7 @@ class Printer: # done, this will lead to duplicates. fp.write(ln) else: - print "Value key " + t[0] + " not found in GUI." + print("Value key " + t[0] + " not found in GUI.") continue @@ -305,7 +306,7 @@ class Printer: fp.write("//") fp.write(defineBoolFormat % t[0]) else: - print "Boolean key " + t[0] + " not found in GUI." + print("Boolean key " + t[0] + " not found in GUI.") continue diff --git a/configtool/sensorpage.py b/configtool/sensorpage.py index f0e05f7..aae2c2c 100644 --- a/configtool/sensorpage.py +++ b/configtool/sensorpage.py @@ -1,9 +1,10 @@ +from __future__ import absolute_import import wx from configtool.page import Page from configtool.data import pinNames, BSIZESMALL -from sensorlist import SensorList -from addsensordlg import AddSensorDlg +from .sensorlist import SensorList +from .addsensordlg import AddSensorDlg class SensorsPage(wx.Panel, Page): diff --git a/configtool/settings.py b/configtool/settings.py index 17d7d50..b902a46 100644 --- a/configtool/settings.py +++ b/configtool/settings.py @@ -1,3 +1,4 @@ +from __future__ import print_function import ConfigParser import os @@ -78,9 +79,9 @@ class Settings: elif opt == "uploadspeed": self.uploadspeed = value else: - print "Unknown %s option: %s - ignoring." % (self.section, opt) + print("Unknown %s option: %s - ignoring." % (self.section, opt)) else: - print "Missing %s section - assuming defaults." % self.section + print("Missing %s section - assuming defaults." % self.section) return False return True diff --git a/configtool/thermistor.py b/configtool/thermistor.py index c62a800..964444f 100644 --- a/configtool/thermistor.py +++ b/configtool/thermistor.py @@ -1,3 +1,4 @@ +from __future__ import print_function from math import * import sys @@ -77,7 +78,7 @@ class BetaThermistor: try: return (self.beta / log(r / self.k)) - 273.15 except: - print "// error for ADC = {adc}, {v}, {r}".format(adc = adc, v = v, r = r) + print("// error for ADC = {adc}, {v}, {r}".format(adc = adc, v = v, r = r)) return None def resistance(self, t): diff --git a/configtool/thermistortablefile.py b/configtool/thermistortablefile.py index 88fd264..2cffc19 100644 --- a/configtool/thermistortablefile.py +++ b/configtool/thermistortablefile.py @@ -1,6 +1,7 @@ +from __future__ import absolute_import import os -from thermistor import SHThermistor, BetaThermistor +from .thermistor import SHThermistor, BetaThermistor class ThermistorTableFile: diff --git a/createTemperatureLookup.py b/createTemperatureLookup.py index c75dd64..d726982 100755 --- a/createTemperatureLookup.py +++ b/createTemperatureLookup.py @@ -37,6 +37,7 @@ Options: It is suggested to generate more values than you need, and delete some of the ones in the ranges that aren't interesting. This will improve accuracy in the temperature ranges that are important to you. """ +from __future__ import print_function from math import * import sys @@ -69,7 +70,7 @@ class Thermistor: try: return (self.beta / log(r / self.k)) - 273.15 # temperature except: - print "// error for ADC={adc}, {v},{r}".format(adc=adc, v=v,r=r) + print("// error for ADC={adc}, {v},{r}".format(adc=adc, v=v,r=r)) return 0 def resistance(self, t): @@ -156,38 +157,38 @@ def main(argv): if int(t.temp(adcs[i])*mult)<0: adcs[i] -=1 break - print "// Thermistor lookup table for RepRap Temperature Sensor Boards (http://reprap.org/wiki/Temperature_Sensor_2_0)" - print "// Made with createTemperatureLookup.py (https://github.com/traumflug/Teacup_Firmware/blob/master/createTemperatureLookup.py)" - print "// (patched per https://github.com/drf5n/Teacup_Firmware/blob/Gen7/createTemperatureLookup.py)" - print "// default thermistor lookup table" - print "// You may be able to improve the accuracy of this table in various ways." - print "// 1. Measure the actual resistance of the resistor. It's \"nominally\" 4.7K, but that's ± 5%." - print "// 2. Measure the actual beta of your thermistor:http://reprap.org/wiki/MeasuringThermistorBeta" - print "// 3. Generate more table entries than you need, then trim down the ones in uninteresting ranges." - print "// In either case you'll have to regenerate this table, which requires python, which is difficult to install on windows." - print "// Since you'll have to do some testing to determine the correct temperature for your application anyway, you" - print "// may decide that the effort isn't worth it. Who cares if it's reporting the \"right\" temperature as long as it's" - print "// keeping the temperature steady enough to print, right?" - print "// Temp*%s table from https://github.com/drf5n/Teacup_Firmware/blob/Gen7/createTemperatureLookup.py" %mult - print "// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s --min-adc=%s --multiplier=%s --vadc=%s" % ( - r0, t0, r1, r2, beta, max_adc, min_adc, mult, vadc) - print "// r0: %s" % (r0) - print "// t0: %s" % (t0) - print "// r1: %s (parallel with rTherm)" % (r1) - print "// r2: %s (series with rTherm)" % (r2) - print "// beta: %s" % (beta) - print "// min adc: %s at %s V" % (min_adc, min_adc*t.vadc/1024) - print "// max adc: %s at %s V" % (max_adc, max_adc*t.vadc/1024) - print "// ADC counts from {min} to {max} by {x}".format(min=min_adc, max=max_adc, x=increment) + print("// Thermistor lookup table for RepRap Temperature Sensor Boards (http://reprap.org/wiki/Temperature_Sensor_2_0)") + print("// Made with createTemperatureLookup.py (https://github.com/traumflug/Teacup_Firmware/blob/master/createTemperatureLookup.py)") + print("// (patched per https://github.com/drf5n/Teacup_Firmware/blob/Gen7/createTemperatureLookup.py)") + print("// default thermistor lookup table") + print("// You may be able to improve the accuracy of this table in various ways.") + print("// 1. Measure the actual resistance of the resistor. It's \"nominally\" 4.7K, but that's ± 5%.") + print("// 2. Measure the actual beta of your thermistor:http://reprap.org/wiki/MeasuringThermistorBeta") + print("// 3. Generate more table entries than you need, then trim down the ones in uninteresting ranges.") + print("// In either case you'll have to regenerate this table, which requires python, which is difficult to install on windows.") + print("// Since you'll have to do some testing to determine the correct temperature for your application anyway, you") + print("// may decide that the effort isn't worth it. Who cares if it's reporting the \"right\" temperature as long as it's") + print("// keeping the temperature steady enough to print, right?") + print("// Temp*%s table from https://github.com/drf5n/Teacup_Firmware/blob/Gen7/createTemperatureLookup.py" %mult) + print("// ./createTemperatureLookup.py --r0=%s --t0=%s --r1=%s --r2=%s --beta=%s --max-adc=%s --min-adc=%s --multiplier=%s --vadc=%s" % ( + r0, t0, r1, r2, beta, max_adc, min_adc, mult, vadc)) + print("// r0: %s" % (r0)) + print("// t0: %s" % (t0)) + print("// r1: %s (parallel with rTherm)" % (r1)) + print("// r2: %s (series with rTherm)" % (r2)) + print("// beta: %s" % (beta)) + print("// min adc: %s at %s V" % (min_adc, min_adc*t.vadc/1024)) + print("// max adc: %s at %s V" % (max_adc, max_adc*t.vadc/1024)) + print("// ADC counts from {min} to {max} by {x}".format(min=min_adc, max=max_adc, x=increment)) if table == True: - print "// #define NUMTABLES 1 // These three lines open the temptable[NUMTABLES]... array" - print "// #define NUMTEMPS %s // ... " % (len(adcs)) - print "// uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = { // ..." - print "{ //" + " Table 0 chunk for B={b}, R0={r0}, R1={r1}, R2={r2}, Vref={v}".format(par="{",b=beta,r0=r0,r1=r1,r2=r2,v=vadc) + print("// #define NUMTABLES 1 // These three lines open the temptable[NUMTABLES]... array") + print("// #define NUMTEMPS %s // ... " % (len(adcs))) + print("// uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = { // ...") + print("{ //" + " Table 0 chunk for B={b}, R0={r0}, R1={r1}, R2={r2}, Vref={v}".format(par="{",b=beta,r0=r0,r1=r1,r2=r2,v=vadc)) else: - print "#define NUMTEMPS %s " % (len(adcs)) - print "const uint16_t temptable[NUMTEMPS][2] PROGMEM = {" - print "// {ADC, temp*%s }, // temp Rtherm Vtherm resolution power" % (mult) + print("#define NUMTEMPS %s " % (len(adcs))) + print("const uint16_t temptable[NUMTEMPS][2] PROGMEM = {") + print("// {ADC, temp*%s }, // temp Rtherm Vtherm resolution power" % (mult)) counter = 0 for adc in adcs: @@ -198,15 +199,15 @@ def main(argv): ptherm= vTherm*vTherm/resistance resolution = ( t.temp(adc-1)-t.temp(adc) if adc>1 else t.temp(adc) -t.temp(adc+1)) sep = (',' if counter != len(adcs) else ' ') - print " {%4s, %6s}%s // %7.2f C, %7.0f Ohm, %0.3f V, %0.2f C/count, %0.2fmW" % (adc, int(t.temp(adc)*mult), sep,degC, resistance,vTherm,resolution,ptherm*1000) + print(" {%4s, %6s}%s // %7.2f C, %7.0f Ohm, %0.3f V, %0.2f C/count, %0.2fmW" % (adc, int(t.temp(adc)*mult), sep,degC, resistance,vTherm,resolution,ptherm*1000)) if table == False: - print "};" + print("};") else: - print '}, // remove comma for last table chunk' - print "// }; // Closure for the temptable[NUMTABLES] array" + print('}, // remove comma for last table chunk') + print("// }; // Closure for the temptable[NUMTABLES] array") def usage(): - print __doc__ + print(__doc__) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/research/planes.py b/research/planes.py index 148af30..621a80a 100644 --- a/research/planes.py +++ b/research/planes.py @@ -8,6 +8,7 @@ # Translate a point relative to some origin +from __future__ import print_function def translate(point, origin): return tuple([a-b for a,b in zip(point, origin)]) @@ -55,21 +56,21 @@ def validate(plane, point): def verify_plane(points): - print ' ', '\n '.join([str(p) for p in points]) + print(' ', '\n '.join([str(p) for p in points])) plane = plane_from_three_points( *points) - print 'Plane coordinates: ', plane + print('Plane coordinates: ', plane) if plane[2] == 0: - print ' Error: points are colinear' + print(' Error: points are colinear') return valid = True for p in points: if not validate(plane, p): - print "Failed: sample point not on plane, ", p + print("Failed: sample point not on plane, ", p) valid = False - print "Validation:", "Failed" if not valid else "Passed" + print("Validation:", "Failed" if not valid else "Passed") @@ -97,11 +98,11 @@ samples = [ for points in samples: verify_plane(points) - print "====[Translated]=========" + print("====[Translated]=========") # Translate plane to origin at P (simplifies by removing K coefficient) # A*x' + B*y' + C*z' = 0 P = points[0] T = translate((0,0,0), P) xpoints = [translate(p, P) for p in points] verify_plane(xpoints) - print "=========================\n" + print("=========================\n")