WIP locking & parking of plotter/scanner
This commit is contained in:
parent
9aee12decd
commit
fca62dbc83
2 changed files with 47 additions and 33 deletions
|
@ -36,6 +36,7 @@ class CentralManagement():
|
|||
self.eventQueue = Queue()
|
||||
self.isRunning = threading.Event()
|
||||
self.isScanning = threading.Event()
|
||||
self.scanLock = threading.Lock()
|
||||
|
||||
|
||||
def loadConfig(self, filename):
|
||||
|
@ -77,7 +78,7 @@ class CentralManagement():
|
|||
sqsThread.start()
|
||||
|
||||
# the plotter itself
|
||||
self.plotter = Plotter(self.config, self.eventQueue, self.isRunning)
|
||||
self.plotter = Plotter(self.config, self.eventQueue, self.isRunning, self.scanLock)
|
||||
plotterThread = threading.Thread(target=self.plotter.start, name='plotter')
|
||||
plotterThread.start()
|
||||
|
||||
|
@ -130,9 +131,9 @@ class CentralManagement():
|
|||
self.server.statusPage.set('state', self.currentHit.getStatus())
|
||||
self.makeHit()
|
||||
elif signal.name == 'scan.start':
|
||||
self.isScanning.set()
|
||||
pass
|
||||
elif signal.name == 'scan.finished':
|
||||
self.isScanning.clear()
|
||||
pass
|
||||
elif signal.name == 'hit.info':
|
||||
if signal.params['hit_id'] != self.currentHit.id:
|
||||
self.logger.warning(f"hit.info hit_id != currenthit.id: {signal}")
|
||||
|
@ -279,6 +280,7 @@ class CentralManagement():
|
|||
self.logger.debug(notification_info)
|
||||
|
||||
def cleanDrawing(self):
|
||||
with self.scanLock:
|
||||
self.eventQueue.put(Signal('scan.start'))
|
||||
# Scan to reset
|
||||
cmd = [
|
||||
|
@ -286,7 +288,7 @@ class CentralManagement():
|
|||
]
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||
# opens connection to scanner, but only starts scanning when output becomes ready:
|
||||
o, e = proc.communicate(80)
|
||||
_, e = proc.communicate(80)
|
||||
if e:
|
||||
self.logger.critical(f"Scanner caused: {e.decode()}")
|
||||
|
||||
|
@ -302,9 +304,7 @@ class CentralManagement():
|
|||
"""
|
||||
Run scanimage on scaner and returns a string with the filename
|
||||
"""
|
||||
if self.isScanning.is_set():
|
||||
raise Exception("Already scanning!")
|
||||
|
||||
with self.scanLock:
|
||||
self.eventQueue.put(Signal('scan.start'))
|
||||
cmd = [
|
||||
'sudo', 'scanimage', '-d', 'epkowa', '--format', 'jpeg',
|
||||
|
|
|
@ -2,12 +2,12 @@ import queue
|
|||
import logging
|
||||
from pyaxidraw import axidraw
|
||||
from queue import Queue
|
||||
from threading import Event
|
||||
from threading import Event, Lock
|
||||
from sorteerhoed.Signal import Signal
|
||||
import time
|
||||
|
||||
class Plotter:
|
||||
def __init__(self, config, eventQ: Queue, runningEvent: Event):
|
||||
def __init__(self, config, eventQ: Queue, runningEvent: Event, scannerLock: Lock):
|
||||
#TODO: scanningEvent -> CentralManagement.isScanning -> prevent plotter move during scan, failsafe
|
||||
self.config = config
|
||||
self.eventQ = eventQ
|
||||
|
@ -21,12 +21,14 @@ class Plotter:
|
|||
self.xPadding = self.config['scanner']['left_padding'] / 10 / 2.54;
|
||||
self.yPadding = self.config['scanner']['top_padding'] / 10 / 2.54;
|
||||
self.logger.info(f"Paddings x: {self.xPadding} inch y: {self.yPadding} inch")
|
||||
self.scannerLock = scannerLock
|
||||
self.goPark = False
|
||||
self.locked = False
|
||||
self.ad = None
|
||||
|
||||
def park(self):
|
||||
self.logger.info("Queue to park plotter")
|
||||
|
||||
if self.config['dummy_plotter']:
|
||||
# TODO: find a nice way to park the axidraw in the 0 position
|
||||
self.goPark = True
|
||||
self.q.put([(-1/2.54)/self.plotWidth,0,0])
|
||||
|
||||
def start(self):
|
||||
|
@ -60,6 +62,7 @@ class Plotter:
|
|||
finally:
|
||||
self.logger.warning("Close Axidraw connection")
|
||||
if self.ad:
|
||||
with self.scannerLock:
|
||||
self.ad.moveto(0,0)
|
||||
self.ad.disconnect()
|
||||
|
||||
|
@ -67,6 +70,11 @@ class Plotter:
|
|||
self.isRunning.clear()
|
||||
|
||||
def draw_segments(self, segments = []):
|
||||
if not self.locked:
|
||||
# acquire lock if not already done so
|
||||
self.scannerLock.acquire()
|
||||
self.locked = True
|
||||
|
||||
coordinates = []
|
||||
for segment in segments:
|
||||
coordinate = [
|
||||
|
@ -140,6 +148,12 @@ class Plotter:
|
|||
elif plotterRan:
|
||||
plotterRan = False
|
||||
self.eventQ.put(Signal('plotter.finished'))
|
||||
if self.goPark:
|
||||
self.eventQ.put(Signal('plotter.parked'))
|
||||
if self.locked:
|
||||
self.scannerLock.release()
|
||||
self.locked = False
|
||||
self.goPark = False
|
||||
# else:
|
||||
# time.sleep(.05)
|
||||
# self.logger.debug(f'Plotter move: {move}')
|
||||
|
|
Loading…
Reference in a new issue