mirror of
https://github.com/phooky/Apple-410.git
synced 2024-05-28 23:41:32 +00:00
make the svg parsing a bit more robust
safe up the wait time on the serial
This commit is contained in:
parent
197026f385
commit
ad458c9ba3
|
@ -13,9 +13,9 @@ class Apple410:
|
||||||
def sendchar(self, c):
|
def sendchar(self, c):
|
||||||
self.serial.flush()
|
self.serial.flush()
|
||||||
while not self.serial.cts:
|
while not self.serial.cts:
|
||||||
time.sleep(0.1)
|
time.sleep(0.2)
|
||||||
while not self.serial.dsr:
|
while not self.serial.dsr:
|
||||||
time.sleep(0.1)
|
time.sleep(0.2)
|
||||||
self.serial.write(c.encode('ascii'))
|
self.serial.write(c.encode('ascii'))
|
||||||
self.serial.flush()
|
self.serial.flush()
|
||||||
|
|
||||||
|
|
|
@ -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)))
|
|
|
@ -16,15 +16,23 @@ def parse_coord(d):
|
||||||
|
|
||||||
def d_to_commands(d):
|
def d_to_commands(d):
|
||||||
segs = []
|
segs = []
|
||||||
(cmd, remain) = (d[0],d[1:].strip())
|
while d:
|
||||||
if cmd == 'm':
|
(cmd, d) = (d[0],d[1:].strip())
|
||||||
(coord, remain) = parse_coord(remain)
|
if cmd == 'm':
|
||||||
while remain and (remain[0] == '-' or remain[0] in string.digits):
|
(coord, d) = parse_coord(d)
|
||||||
(delta, remain) = parse_coord(remain)
|
while d and (d[0] == '-' or d[0] in string.digits):
|
||||||
nc = (delta[0]+coord[0],delta[1]+coord[1])
|
(delta, d) = parse_coord(remain)
|
||||||
segs.append( (coord, nc) )
|
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
|
coord = nc
|
||||||
return segs
|
else:
|
||||||
|
raise("Unrecognized: {}".format(d[0:50]))
|
||||||
return segs
|
return segs
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user