Commit 2e710bf3 authored by anthraxx's avatar anthraxx
Browse files

implemented proper ascii fifo display for better local development

parent 194d48b6
......@@ -7,7 +7,7 @@ from sqlalchemy import create_engine
from argparse import ArgumentParser
from foobarpay.db import Database
from foobarpay.display import Display
from foobarpay.display import HIDrawDisplay, FifoDisplay
from foobarpay.scanner import EvdevScanner, FifoScanner
from foobarpay.logic import Logic
from foobarpay.model.product import Product
......@@ -22,7 +22,10 @@ class FooBarPay:
logging.basicConfig(level=logging.DEBUG if cli_arguments.debug else logging.INFO)
self.database = Database(cli_arguments.database, debug=cli_arguments.debug_sql)
self.display = Display(cli_arguments.display)
if cli_arguments.display_driver == "fifo":
self.display = FifoDisplay(cli_arguments.display)
else:
self.display = HIDrawDisplay(cli_arguments.display)
if cli_arguments.scanner_driver == "fifo":
self.scanner = FifoScanner(cli_arguments.scanner)
else:
......@@ -46,6 +49,7 @@ if __name__ == "__main__":
parser.add_argument('-v', '--debug', dest='debug', action='store_true', help='general debug messages')
parser.add_argument('--debug-sql', dest='debug_sql', action='store_true', help='sql debug messages')
parser.add_argument('--display', dest='display', default=FooBarPay.DEFAULT_DISPLAY, help='specify display device')
parser.add_argument('--display-driver', dest='display_driver', choices=['hidraw', 'fifo'], default='hidraw', help='specify display driver')
parser.add_argument('--scanner', dest='scanner', default=FooBarPay.DEFAULT_SCANNER, help='specify scanner device')
parser.add_argument('--scanner-driver', dest='scanner_driver', choices=['evdev', 'fifo'], default='evdev', help='specify scanner driver')
parser.add_argument('--db', dest='database', default=FooBarPay.DEFAULT_DATABASE, help='specify database file')
......
class Display(object):
class HIDrawDisplay(object):
def __init__(self, path):
self.path = path
self.device = open(self.path, "wb")
......@@ -35,3 +35,14 @@ class Display(object):
message = b"\x02\x00" + bytes([len(command)]) + command + bytes(29 - len(command))
self.device.write(message)
self.device.flush()
class FifoDisplay(HIDrawDisplay):
def set_position(self, pos_x, pos_y):
self.__send_command__(b"\n" + b" " * pos_x)
def clear(self):
self.__send_command__(b"\n")
def __send_command__(self, command):
self.device.write(bytes(command))
self.device.flush()
......@@ -55,7 +55,7 @@ class Logic(object):
self.transaction_start(customer_id)
else:
self.transaction_end()
if scanned_text.startswith(self.LOAD_PREFIX):
elif scanned_text.startswith(self.LOAD_PREFIX):
if self.state == self.State.Idle: # Product without active transaction
self.display.show_two_messages("Error", "Scan UID first")
sleep(3)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment