From 9023f3fce9765abdb8d70eeb4a1d5ee1aa2daaa7 Mon Sep 17 00:00:00 2001 From: herkulessi Date: Tue, 31 Mar 2026 23:43:13 +0200 Subject: Bezahlommat 2.0 initial commit oder so --- echtgeld.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 echtgeld.py (limited to 'echtgeld.py') diff --git a/echtgeld.py b/echtgeld.py new file mode 100644 index 0000000..8e23124 --- /dev/null +++ b/echtgeld.py @@ -0,0 +1,56 @@ +import threading +import RPi.GPIO as g + +INHIBIT_PIN=40 +MONEY_PIN=38 +AMOUNT_PER_PULSE=5 +TIMEOUT = 30 + +g.setmode(g.BOARD) + +g.setup(INHIBIT_PIN, g.OUT) +g.output(INHIBIT_PIN, True) + +g.setup(MONEY_PIN, g.IN, pull_up_down = g.PUD_UP) + + +class MoneyTransaction: + def __init__(self, end_callback, add_money_callback) -> None: + self.end_callback = end_callback + self.add_money_callback = add_money_callback + self.lock = threading.Lock() + self.lock.acquire_lock(blocking=True) + self.timer = None + self.timer_lock = threading.Lock() + + def __end_callback(self, _ = None): + print("End Callback") + self.end_callback() + g.output(INHIBIT_PIN, True) # Disable Bill Acceptor + try: + g.remove_event_detect(MONEY_PIN) + except Exception: + pass + with self.timer_lock: + if self.timer is not None: + self.timer.cancel() + self.timer = None + self.lock.release_lock() + + def __add_money_callback(self, _ = None): + with self.timer_lock: + if self.timer is not None: + self.timer.cancel() + self.timer = threading.Timer(TIMEOUT, self.__end_callback) # create Timeout + self.timer.start() + self.add_money_callback(AMOUNT_PER_PULSE) + + def start(self): + print("Start Transaction") + g.output(INHIBIT_PIN, False) # Enable Bill Acceptor + with self.timer_lock: + self.timer = threading.Timer(TIMEOUT, self.__end_callback) # create Timeout + self.timer.start() + g.add_event_detect(MONEY_PIN, g.FALLING, callback = self.__add_money_callback, bouncetime=130) + def stop(self): + self.__end_callback() -- cgit v1.2.3