Setting up for per-pen settings

This commit is contained in:
Adam Goldsmith 2018-06-11 21:25:19 -04:00
parent 9487dda02c
commit c5e3afbd95

View File

@ -1,12 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import re
import sys import sys
def write_pen_values(values, char): def write_pen_values(values, char):
return "!v64" + char + "".join(["{:04d}".format(value) for value in values]) return "!v64" + char + "".join(["{:04d}".format(value) for value in values])
def pre_content(filename, power=50, speed=50, rate=2500): def pre_content(filename, power, speed, rate, pen_settings):
jobName = os.path.basename(filename)[:80] jobName = os.path.basename(filename)[:80]
# Start # Start
outString = "@PJL JOB NAME={}\r\n".format(jobName) outString = "@PJL JOB NAME={}\r\n".format(jobName)
@ -35,13 +36,28 @@ def pre_content(filename, power=50, speed=50, rate=2500):
# Use same value for all 16 pens # Use same value for all 16 pens
# doesn't seem to affect vector settings # doesn't seem to affect vector settings
outString += write_pen_values([speed * 10] * 16, 'V') # Velocity, 1000=100% # TODO: try unsetting values in HPGL and see if these take over
outString += write_pen_values([power * 10] * 16, 'P') # Power, 1000=100% outString += write_pen_values(pen_settings['power'], 'P') # Power, 1000=100%
outString += write_pen_values([rate] * 16, 'I') # PPI outString += write_pen_values(pen_settings['speed'], 'V') # Velocity, 1000=100%
outString += write_pen_values(pen_settings['rate'], 'I') # PPI, does affect vector
# Enter HPGL vector mode
outString += "%1B" outString += "%1B"
return outString return outString
def set_vector_pens(content, pen_settings):
settings = "".join(
["FS{power:d},{penNum:d};VS{speed:d},{penNum:d};".format(
power=pen_settings['power'][num],
speed=pen_settings['speed'][num],
penNum=num+1) for num in range(0, 16)])
content = re.sub(
"FS\d{1,4};VS\d{1,4};SP1;",
settings + "SP1;",
content, count=1)
return content
def post_content(): def post_content():
outString = "%1A" # Leave HPGL vector mode outString = "%1A" # Leave HPGL vector mode
outString += "E" # Reset outString += "E" # Reset
@ -49,11 +65,16 @@ def post_content():
return outString return outString
def main(infile, outfile, power=50, speed=50, rate=100): def main(infile, outfile, power=50, speed=50, rate=100):
with open(infile, 'r') as f: # set all pens the same
data = f.read() pen_settings = {'power': [int(power) * 10] * 16,
'speed': [int(speed) * 10] * 16,
'rate': [int(rate)] * 16}
with open(outfile, 'w') as f: with open(outfile, 'w') as f:
f.write(pre_content(outfile, int(power), int(speed), int(rate))) f.write(pre_content(
f.write(data) outfile, int(power), int(speed), int(rate), pen_settings))
with open(infile, 'r') as input_f:
f.write(set_vector_pens(input_f.read(), pen_settings))
f.write(post_content()) f.write(post_content())
if __name__ == '__main__': if __name__ == '__main__':