This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.py
140 lines (109 loc) · 4.2 KB
/
printer.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pip install python-escpos fastapi uvicorn pydantic
from escpos.printer import Network
from datetime import datetime
from pydantic import BaseModel
from flask import Flask
from flask import request, jsonify
from flask_cors import CORS
import subprocess
import concurrent.futures
import time
executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)
try:
subprocess.run(['adb', 'start-server'])
except subprocess.CalledProcessError as e:
print("no tablet!")
'''
text 500,500
clear 1048, 628
enter 125, 630
mealswipe 726, 250
svc 400, 250
cancel 980, 1169
pay 183, 1169
Choose swat dining or garnet cash 590 720
dining 480 1120
'''
def tablet(thing):
print("tablet run")
if thing['payment'] == 'swipe':
try:
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "726", "250"])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "500", "500"])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "keyboard", "text", thing['oc']])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "125", "630"])
except subprocess.CalledProcessError as e:
print (e.output)
return
elif thing['payment'] == 'dining':
try:
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "400", "250"])
time.sleep(0.05)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "590", "720"])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "480", "1120"])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "500", "500"])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "keyboard", "text", thing['oc']])
time.sleep(0.025)
subprocess.run(["adb", "shell", "input", "touchscreen", "tap", "125", "630"])
time.sleep(0.1)
subprocess.run(["adb", "shell", "input", "keyboard", "text", str(int(thing['total'])*100)])
except subprocess.CalledProcessError as e:
print (e.output)
return
def PRINT(thing):
current_time = datetime.now().strftime("%H:%M:%S")
kitchen = Network("192.168.192.168",profile="TM-T88V") #Printer IP Address
kitchen.set(align="center",custom_size=True ,height=2, width=2)
kitchen.textln("CrumbCafe")
kitchen.set(align="center",custom_size=True ,height=1, width=1)
kitchen.textln(thing['type'] + " Sale Ticket\n")
kitchen.textln("------------------------------------------")
kitchen.textln(current_time)
kitchen.textln("------------------------------------------")
kitchen.print_and_feed(n=1)
#for something in something
kitchen.set(align="center",custom_size=True ,height=1, width=1)
for item in thing['dishes']:
print(item)
kitchen.textln(item["friendlyName"][0:15] + ' ................... $' + str(item["price"]) )
for option in item["options"]:
kitchen.textln('\t + ' + option["friendlyName"])
kitchen.set(align="center",custom_size=True ,height=2, width=2)
kitchen.print_and_feed(n=3)
kitchen.textln(thing["customerName"])
kitchen.cut()
kitchen.close()
app = Flask(__name__)
CORS(app)
@app.route('/', methods =['POST'])
def test():
data = request.json
if(data['receipt'] == True):
food=[]
drink=[]
print(data['dishes'])
for i, val in enumerate(data['dishes']):
if(val['tag'] == 'food'):
food.append(val)
if(val['tag'] == 'drink'):
drink.append(val)
if(len(food)>0):
copy = data.copy()
copy['dishes'] = food
copy['type']= "Food"
executor.submit(PRINT,copy)
if(len(drink)>0):
copy2 = data.copy()
copy2['type']= "Drink"
copy2['dishes'] = drink
executor.submit(PRINT,copy2)
executor.submit(tablet, data)
return "200"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)