Add global vars for the printer settings

This commit is contained in:
N07070 2020-01-14 17:18:15 +01:00
parent 8bb674e745
commit 0c20568a92

View File

@ -19,6 +19,9 @@ limiter = Limiter(
default_limits=["200 per day", "50 per hour"]
)
SERIAL_PORT = '/dev/ttyAMA0'
BAUDRATE = 19200
# session['logged_in'] = False
def error_handler_limiter():
@ -79,12 +82,12 @@ def logout():
def print_image():
if session.get('logged_in'):
img = random.choice(os.listdir("static/images/")) #change dir name to whatever
call(["lp", "-o fit-to-page", "static/images/" + img])
# printer = Adafruit_Thermal('/dev/serial0', 19200, timeout=5)
# printer.begin()
# printer.feed(1)
# # printer.printImage(dickbutt, True)
# # printer.feed(2)
# call(["lp", "-o fit-to-page", "static/images/" + img])
printer = Adafruit_Thermal(SERIAL_PORT, BAUDRATE, timeout=5)
printer.begin()
printer.feed(1)
printer.printImage("static/images/" + img, True)
printer.feed(2)
return redirect(url_for('display_index_page'))
else:
return redirect(url_for('login'))
@ -94,7 +97,7 @@ def print_image():
def print_text():
if session.get('logged_in'):
if len(request.form['message']) < 200:
printer = Adafruit_Thermal('/dev/ttyAMA0', 19200, timeout=5)
printer = Adafruit_Thermal(SERIAL_PORT, BAUDRATE, timeout=5)
printer.begin()
printer.justify('L')
printer.println((request.form['message']).encode())