Convert py scripts for py2 and py3 compatibility (#13931)

2.0.x
Alexey Shvetsov 6 years ago committed by Scott Lahteine
parent 11adcf1ce3
commit af725c81e3

@ -1,3 +1,4 @@
#!/usr/bin/env python
#
# Builds custom upload command
# 1) Run platformio as a subprocess to find a COM port
@ -9,6 +10,9 @@
# Will continue on if a COM port isn't found so that the compilation can be done.
#
from __future__ import print_function
from __future__ import division
import subprocess
import os
import sys
@ -45,7 +49,7 @@ else:
global description_CDC
print '\nLooking for Serial Port\n'
print('\nLooking for Serial Port\n')
# stream output from subprocess and split it into lines
pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
@ -78,10 +82,10 @@ else:
com_CDC = com_CDC.replace('\r', '')
if com_CDC == 'COM_PORT_NOT_FOUND':
print com_CDC, '\n'
print(com_CDC, '\n')
else:
print 'FOUND: ' ,com_CDC
print 'DESCRIPTION: ', description_CDC , '\n'
print('FOUND: ' ,com_CDC)
print('DESCRIPTION: ', description_CDC , '\n')
if current_OS == 'Windows':
@ -114,7 +118,7 @@ else:
# upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
print 'upload_string: ', upload_string
print('upload_string: ', upload_string)

@ -1,5 +1,8 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import division
""" Generate the stepper delay lookup table for Marlin firmware. """
import argparse
@ -16,35 +19,35 @@ args = parser.parse_args()
cpu_freq = args.cpu_freq * 1000000
timer_freq = cpu_freq / args.divider
print "#ifndef SPEED_LOOKUPTABLE_H"
print "#define SPEED_LOOKUPTABLE_H"
print
print '#include "Marlin.h"'
print
print("#ifndef SPEED_LOOKUPTABLE_H")
print("#define SPEED_LOOKUPTABLE_H")
print()
print('#include "Marlin.h"')
print()
print "const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {"
print("const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {")
a = [ timer_freq / ((i*256)+(args.cpu_freq*2)) for i in range(256) ]
b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1])
for i in range(32):
print " ",
print(" ", end=' ')
for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
print
print "};"
print
print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
print()
print("};")
print()
print "const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {"
print("const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {")
a = [ timer_freq / ((i*8)+(args.cpu_freq*2)) for i in range(256) ]
b = [ a[i] - a[i+1] for i in range(255) ]
b.append(b[-1])
for i in range(32):
print " ",
print(" ", end=' ')
for j in range(8):
print "{%d, %d}," % (a[8*i+j], b[8*i+j]),
print
print "};"
print
print("{%d, %d}," % (a[8*i+j], b[8*i+j]), end=' ')
print()
print("};")
print()
print "#endif"
print("#endif")

@ -18,6 +18,9 @@ Options:
--num-temps=... the number of temperature points to calculate (default: 36)
"""
from __future__ import print_function
from __future__ import division
from math import *
import sys
import getopt
@ -47,9 +50,9 @@ class Thermistor:
a = y1 - (b + l1**2 *c)*l1
if c < 0:
print "//////////////////////////////////////////////////////////////////////////////////////"
print "// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //"
print "//////////////////////////////////////////////////////////////////////////////////////"
print("//////////////////////////////////////////////////////////////////////////////////////")
print("// WARNING: negative coefficient 'c'! Something may be wrong with the measurements! //")
print("//////////////////////////////////////////////////////////////////////////////////////")
c = -c
self.c1 = a # Steinhart-Hart coefficients
self.c2 = b
@ -97,7 +100,7 @@ def main(argv):
try:
opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
except getopt.GetoptError as err:
print str(err)
print(str(err))
usage()
sys.exit(2)
@ -129,27 +132,27 @@ def main(argv):
up_bound = t.temp(1);
min_temp = int(TMIN if TMIN > low_bound else low_bound)
max_temp = int(TMAX if TMAX < up_bound else up_bound)
temps = range(max_temp, TMIN+step, step);
temps = list(range(max_temp, TMIN+step, step));
print "// Thermistor lookup table for Marlin"
print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps)
print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3)
print "// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound)
print
print "const short temptable[][2] PROGMEM = {"
print("// Thermistor lookup table for Marlin")
print("// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps))
print("// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3))
print("// Theoretical limits of thermistor: %.2f to %.2f degC" % (low_bound, up_bound))
print()
print("const short temptable[][2] PROGMEM = {")
for temp in temps:
adc = t.adc(temp)
print " { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
print(" { OV(%7.2f), %4s }%s // v=%.3f\tr=%.3f\tres=%.3f degC/count" % (adc , temp, \
',' if temp != temps[-1] else ' ', \
t.voltage(adc), \
t.resist( adc), \
t.resol( adc) \
)
print "};"
))
print("};")
def usage():
print __doc__
print(__doc__)
if __name__ == "__main__":
main(sys.argv[1:])

@ -1,10 +1,12 @@
#!/usr/bin/python3
#!/usr/bin/python
# This file is for preprocessing gcode and the new G29 Autobedleveling from Marlin
# It will analyse the first 2 Layer and return the maximum size for this part
# After this it will replace with g29_keyword = ';MarlinG29Script' with the new G29 LRFB
# the new file will be created in the same folder.
from __future__ import print_function
# your gcode-file/folder
folder = './'
my_file = 'test.gcode'

Loading…
Cancel
Save