Die Architektur des Programms ist zu kompliziert. Benötigt wird lediglich eine zentrale while Schleife in der abgefragt wird:
- liegt eine Richtungsinformation vor?
- liegen Tastendruck-Ereignisse vor?
Anhand dieser Informationen wird eine Aktion ausgeführt, die möglichst schnell zurückkehren soll, damit auf weitere Ereignisse reagiert werden kann.
while Schleife mit Taster Abfrage
Mal so als Gerüst. Lässt sich auf auf Threading erweitern, falls dies erforderlich sein sollte.
Code: Alles auswählen
# here import statements
# and constants definitions
def init_rpio():
# set init states here
pass
def get_direction():
# return next direction or 0
return 0
def get_button_event():
# gets information about pressed buttons
# and returns an according result
def main_control():
while True:
direction = get_direction()
button_event = get_button_event()
# depending on direction and button_event
# call:
# handler()
# or:
# another_handler()
# and so on.
# entry point
def main():
try:
main_control()
except KeyboardInterrupt:
pass
# global call, so module can run standalone or get imported somewhere else.
init_rpio()
if __name__ == '__main__':
main()