configtool: stage 1 for making it compatible with python3

This commit is contained in:
Nico Tonnhofer 2018-12-21 20:24:00 +01:00
parent 8fc867ae72
commit 9b49097ac3
12 changed files with 83 additions and 71 deletions

View File

@ -11,6 +11,7 @@
# If you feel like porting Configtool to Python 3 compatibility altogether: # If you feel like porting Configtool to Python 3 compatibility altogether:
# patches are welcome! See https://docs.python.org/3/howto/pyporting.html # patches are welcome! See https://docs.python.org/3/howto/pyporting.html
from __future__ import print_function
import sys import sys
import time import time
if sys.version_info.major >= 3: if sys.version_info.major >= 3:

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os import os
import re import re
@ -180,17 +181,17 @@ class Board:
# Parsing done. All parsed stuff is now in these arrays and dicts. # Parsing done. All parsed stuff is now in these arrays and dicts.
if self.settings.verbose >= 2: if self.settings.verbose >= 2:
print self.sensors print(self.sensors)
print self.heaters print(self.heaters)
print self.candHeatPins print(self.candHeatPins)
print self.candThermPins print(self.candThermPins)
print self.candProcessors print(self.candProcessors)
print self.candClocks print(self.candClocks)
print self.tempTables print(self.tempTables)
print self.cfgValues # #defines with a value. print(self.cfgValues) # #defines with a value.
print self.cfgNames # Names found in the generic file. print(self.cfgNames) # Names found in the generic file.
if self.settings.verbose >= 3: if self.settings.verbose >= 3:
print self.helpText print(self.helpText)
for k in range(len(self.sensors)): for k in range(len(self.sensors)):
tn = self.sensors[k][0].upper() tn = self.sensors[k][0].upper()
@ -348,7 +349,7 @@ class Board:
if self.settings.verbose >= 1: if self.settings.verbose >= 1:
print("Saving board: %s." % path) print("Saving board: %s." % path)
if self.settings.verbose >= 2: if self.settings.verbose >= 2:
print values print(values)
fp = file(path, 'w') fp = file(path, 'w')
self.configFile = path self.configFile = path
@ -479,7 +480,7 @@ class Board:
# Known to be absent in the GUI, also won't be added anytime soon. # Known to be absent in the GUI, also won't be added anytime soon.
fp.write(ln) fp.write(ln)
else: else:
print "Boolean key " + t[0] + " not found in GUI." print("Boolean key " + t[0] + " not found in GUI.")
continue continue

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import wx import wx
import os.path import os.path
@ -25,9 +26,9 @@ class Decoration(object):
if backPic.IsOk(): if backPic.IsOk():
self.backPic = backPic self.backPic = backPic
else: else:
print "Background picture %s damaged." % backPicPath print("Background picture %s damaged." % backPicPath)
else: else:
print "Background picture %s doesn't exist." % backPicPath print("Background picture %s doesn't exist." % backPicPath)
def getBackgroundColour(self): def getBackgroundColour(self):
return wx.Colour(237, 237, 237) return wx.Colour(237, 237, 237)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import sys import sys
import time import time

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import wx import wx
@ -255,14 +256,14 @@ class Page:
else: else:
self.textControls[k].SetValue("") self.textControls[k].SetValue("")
else: else:
print "Key " + k + " not found in config data." print("Key " + k + " not found in config data.")
for k in self.choices.keys(): for k in self.choices.keys():
if k in cfgValues.keys(): if k in cfgValues.keys():
self.choicesOriginal[k] = cfgValues[k] self.choicesOriginal[k] = cfgValues[k]
self.setChoice(k, cfgValues, "-") self.setChoice(k, cfgValues, "-")
else: else:
print "Key " + k + " not found in config data." print("Key " + k + " not found in config data.")
for k in self.boolChoices.keys(): for k in self.boolChoices.keys():
choice = self.boolChoices[k] choice = self.boolChoices[k]

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os import os
import re import re
@ -136,10 +137,10 @@ class Printer:
# Parsing done. All parsed stuff is now in these array and dicts. # Parsing done. All parsed stuff is now in these array and dicts.
if self.settings.verbose >= 2: if self.settings.verbose >= 2:
print self.cfgValues # #defines with a value. print(self.cfgValues) # #defines with a value.
print self.cfgNames # Names found in the generic file. print(self.cfgNames) # Names found in the generic file.
if self.settings.verbose >= 3: if self.settings.verbose >= 3:
print self.helpText print(self.helpText)
return True, None return True, None
@ -237,7 +238,7 @@ class Printer:
if self.settings.verbose >= 1: if self.settings.verbose >= 1:
print("Saving printer: %s." % path) print("Saving printer: %s." % path)
if self.settings.verbose >= 2: if self.settings.verbose >= 2:
print values print(values)
fp = file(path, 'w') fp = file(path, 'w')
self.configFile = path self.configFile = path
@ -291,7 +292,7 @@ class Printer:
# done, this will lead to duplicates. # done, this will lead to duplicates.
fp.write(ln) fp.write(ln)
else: else:
print "Value key " + t[0] + " not found in GUI." print("Value key " + t[0] + " not found in GUI.")
continue continue
@ -305,7 +306,7 @@ class Printer:
fp.write("//") fp.write("//")
fp.write(defineBoolFormat % t[0]) fp.write(defineBoolFormat % t[0])
else: else:
print "Boolean key " + t[0] + " not found in GUI." print("Boolean key " + t[0] + " not found in GUI.")
continue continue

View File

@ -1,9 +1,10 @@
from __future__ import absolute_import
import wx import wx
from configtool.page import Page from configtool.page import Page
from configtool.data import pinNames, BSIZESMALL from configtool.data import pinNames, BSIZESMALL
from sensorlist import SensorList from .sensorlist import SensorList
from addsensordlg import AddSensorDlg from .addsensordlg import AddSensorDlg
class SensorsPage(wx.Panel, Page): class SensorsPage(wx.Panel, Page):

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import ConfigParser import ConfigParser
import os import os
@ -78,9 +79,9 @@ class Settings:
elif opt == "uploadspeed": elif opt == "uploadspeed":
self.uploadspeed = value self.uploadspeed = value
else: else:
print "Unknown %s option: %s - ignoring." % (self.section, opt) print("Unknown %s option: %s - ignoring." % (self.section, opt))
else: else:
print "Missing %s section - assuming defaults." % self.section print("Missing %s section - assuming defaults." % self.section)
return False return False
return True return True

View File

@ -1,3 +1,4 @@
from __future__ import print_function
from math import * from math import *
import sys import sys
@ -77,7 +78,7 @@ class BetaThermistor:
try: try:
return (self.beta / log(r / self.k)) - 273.15 return (self.beta / log(r / self.k)) - 273.15
except: 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 return None
def resistance(self, t): def resistance(self, t):

View File

@ -1,6 +1,7 @@
from __future__ import absolute_import
import os import os
from thermistor import SHThermistor, BetaThermistor from .thermistor import SHThermistor, BetaThermistor
class ThermistorTableFile: class ThermistorTableFile:

View File

@ -37,6 +37,7 @@ Options:
It is suggested to generate more values than you need, and delete some of the ones in the ranges 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. 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 * from math import *
import sys import sys
@ -69,7 +70,7 @@ class Thermistor:
try: try:
return (self.beta / log(r / self.k)) - 273.15 # temperature return (self.beta / log(r / self.k)) - 273.15 # temperature
except: 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 return 0
def resistance(self, t): def resistance(self, t):
@ -156,38 +157,38 @@ def main(argv):
if int(t.temp(adcs[i])*mult)<0: if int(t.temp(adcs[i])*mult)<0:
adcs[i] -=1 adcs[i] -=1
break break
print "// Thermistor lookup table for RepRap Temperature Sensor Boards (http://reprap.org/wiki/Temperature_Sensor_2_0)" 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("// 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("// (patched per https://github.com/drf5n/Teacup_Firmware/blob/Gen7/createTemperatureLookup.py)")
print "// default thermistor lookup table" print("// default thermistor lookup table")
print "// You may be able to improve the accuracy of this table in various ways." 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("// 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("// 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("// 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("// 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("// 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("// 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("// 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("// 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" % ( 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) r0, t0, r1, r2, beta, max_adc, min_adc, mult, vadc))
print "// r0: %s" % (r0) print("// r0: %s" % (r0))
print "// t0: %s" % (t0) print("// t0: %s" % (t0))
print "// r1: %s (parallel with rTherm)" % (r1) print("// r1: %s (parallel with rTherm)" % (r1))
print "// r2: %s (series with rTherm)" % (r2) print("// r2: %s (series with rTherm)" % (r2))
print "// beta: %s" % (beta) print("// beta: %s" % (beta))
print "// min adc: %s at %s V" % (min_adc, min_adc*t.vadc/1024) 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("// 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("// ADC counts from {min} to {max} by {x}".format(min=min_adc, max=max_adc, x=increment))
if table == True: if table == True:
print "// #define NUMTABLES 1 // These three lines open the temptable[NUMTABLES]... array" print("// #define NUMTABLES 1 // These three lines open the temptable[NUMTABLES]... array")
print "// #define NUMTEMPS %s // ... " % (len(adcs)) print("// #define NUMTEMPS %s // ... " % (len(adcs)))
print "// uint16_t temptable[NUMTABLES][NUMTEMPS][2] PROGMEM = { // ..." 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("{ //" + " 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: else:
print "#define NUMTEMPS %s " % (len(adcs)) print("#define NUMTEMPS %s " % (len(adcs)))
print "const uint16_t temptable[NUMTEMPS][2] PROGMEM = {" print("const uint16_t temptable[NUMTEMPS][2] PROGMEM = {")
print "// {ADC, temp*%s }, // temp Rtherm Vtherm resolution power" % (mult) print("// {ADC, temp*%s }, // temp Rtherm Vtherm resolution power" % (mult))
counter = 0 counter = 0
for adc in adcs: for adc in adcs:
@ -198,15 +199,15 @@ def main(argv):
ptherm= vTherm*vTherm/resistance ptherm= vTherm*vTherm/resistance
resolution = ( t.temp(adc-1)-t.temp(adc) if adc>1 else t.temp(adc) -t.temp(adc+1)) 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 ' ') 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: if table == False:
print "};" print("};")
else: else:
print '}, // remove comma for last table chunk' print('}, // remove comma for last table chunk')
print "// }; // Closure for the temptable[NUMTABLES] array" print("// }; // Closure for the temptable[NUMTABLES] array")
def usage(): def usage():
print __doc__ print(__doc__)
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

View File

@ -8,6 +8,7 @@
# Translate a point relative to some origin # Translate a point relative to some origin
from __future__ import print_function
def translate(point, origin): def translate(point, origin):
return tuple([a-b for a,b in zip(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): 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) plane = plane_from_three_points( *points)
print 'Plane coordinates: ', plane print('Plane coordinates: ', plane)
if plane[2] == 0: if plane[2] == 0:
print ' Error: points are colinear' print(' Error: points are colinear')
return return
valid = True valid = True
for p in points: for p in points:
if not validate(plane, p): if not validate(plane, p):
print "Failed: sample point not on plane, ", p print("Failed: sample point not on plane, ", p)
valid = False 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: for points in samples:
verify_plane(points) verify_plane(points)
print "====[Translated]=========" print("====[Translated]=========")
# Translate plane to origin at P (simplifies by removing K coefficient) # Translate plane to origin at P (simplifies by removing K coefficient)
# A*x' + B*y' + C*z' = 0 # A*x' + B*y' + C*z' = 0
P = points[0] P = points[0]
T = translate((0,0,0), P) T = translate((0,0,0), P)
xpoints = [translate(p, P) for p in points] xpoints = [translate(p, P) for p in points]
verify_plane(xpoints) verify_plane(xpoints)
print "=========================\n" print("=========================\n")