-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·69 lines (57 loc) · 1.82 KB
/
main.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
#!/usr/bin/python3
import os, sys, _thread, threading, time, subprocess
import RPi.GPIO as GPIO
# in das Verzeichnis des Skript wechseln
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
# conf Unterverzeichnis mit durchsuchen
sys.path.append('./conf')
import log
logger = log.setup_custom_logger('main')
from func_cardreader import cardreader
from func_usbbtn import usbbtn
from func_mopidy import mopidy
from func_mousebtn import mouse
# lade die Class usbbtn in die Variable usbbtn
usbbtn = usbbtn()
check_usbbtn = usbbtn.check_usbbtn()
cardreader = cardreader()
check_reader = cardreader.check_reader()
mouse = mouse()
check_mouse = mouse.check_mouse()
# Threads definieren
read_card_thread = threading.Thread(name='read_card', target=cardreader.read_card)
mouse_press_thread = threading.Thread(name='mouse_press', target=mouse.mouse_press)
button_press_thread = threading.Thread(name='button_press', target=usbbtn.button_press)
# lege das conf Verzeichnis an, falls es nicht existiert
if not os.path.exists('conf'):
os.mkdir('conf')
path = os.path.dirname(os.path.realpath(__file__))
try:
logger.info('Starte die Anwendung')
if check_usbbtn != 'n':
button_press_thread.start()
if check_reader != 'n':
read_card_thread.start()
if check_mouse != 'n':
mouse_press_thread.start()
except (SystemExit):
logger.info("Anwendung beendet")
usbbtn.destroy_led_blink()
exit()
except (KeyboardInterrupt):
logger.info("via Tastatur beendet")
usbbtn.destroy_led_blink()
exit()
except Exception as e:
logger.error("main crashed {0}".format(str(e)))
logger.exception("Error")
usbbtn.destroy_led_blink()
raise
except:
logger.info("Unbekannter Fehler:", sys.exc_info()[0])
usbbtn.destroy_led_blink()
raise
# else:
# pass