make the svg parsing a bit more robust

safe up the wait time on the serial
This commit is contained in:
Adam Mayer 2017-12-04 16:39:34 -05:00
parent 197026f385
commit ad458c9ba3
3 changed files with 18 additions and 19 deletions

View File

@ -13,9 +13,9 @@ class Apple410:
def sendchar(self, c):
self.serial.flush()
while not self.serial.cts:
time.sleep(0.1)
time.sleep(0.2)
while not self.serial.dsr:
time.sleep(0.1)
time.sleep(0.2)
self.serial.write(c.encode('ascii'))
self.serial.flush()

View File

@ -1,9 +0,0 @@
#!/usr/bin/python3
import serial
print("opening port")
s = serial.Serial("/dev/ttyUSB0", 9600, timeout=1)
print("opened")
s.write(b'PS4\x03')
print("Sent pen select\n")
print("recv {}\n".format(s.read(100)))

View File

@ -16,15 +16,23 @@ def parse_coord(d):
def d_to_commands(d):
segs = []
(cmd, remain) = (d[0],d[1:].strip())
if cmd == 'm':
(coord, remain) = parse_coord(remain)
while remain and (remain[0] == '-' or remain[0] in string.digits):
(delta, remain) = parse_coord(remain)
nc = (delta[0]+coord[0],delta[1]+coord[1])
segs.append( (coord, nc) )
while d:
(cmd, d) = (d[0],d[1:].strip())
if cmd == 'm':
(coord, d) = parse_coord(d)
while d and (d[0] == '-' or d[0] in string.digits):
(delta, d) = parse_coord(remain)
nc = (delta[0]+coord[0],delta[1]+coord[1])
segs.append( (coord, nc) )
coord = nc
elif cmd == 'M':
(coord, d) = parse_coord(d)
elif cmd == 'L':
(nc, d) = parse_coord(d)
segs.append( (coord,nc) )
coord = nc
return segs
else:
raise("Unrecognized: {}".format(d[0:50]))
return segs