forked from asinghani/labeltron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlqueue.py
executable file
·60 lines (45 loc) · 1.17 KB
/
lqueue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from print import print_label
from serial_iface import *
import copy
import time
import threading
pq = []
lock = threading.Lock()
def queue_add(text):
global pq
with lock:
pq.append(text)
def queue_get():
with lock:
return copy.deepcopy(pq)
def queue_reset():
global pq
with lock:
pq = []
def queue_loop():
global pq
set_state(STATE_IDLE)
hanging = False
while True:
evt = get_pressed()
if len(pq):
set_state(STATE_READY)
if len(pq) and (evt == EVT_RESET):
print("Reset Queue")
queue_reset()
set_state(STATE_IDLE)
if len(pq) and (evt == EVT_PRINT):
set_state(STATE_PRINTING)
while len(pq):
with lock:
if len(pq) == 0: continue
txt = pq[0]
pq = pq[1:]
is_last = (len(pq) == 0)
hanging = not is_last
print_label(txt, last=is_last)
if hanging:
hanging = False
print_label(" ", last=False)
set_state(STATE_IDLE)
time.sleep(1)