-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·117 lines (97 loc) · 3.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python3
import os, sys, _thread, threading, time
import RPi.GPIO as GPIO
#from random import randint
#from mpd import MPDClient
#from select import select
# 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 mopidy in die Variable mopidy
#mopidy = mopidy()
# 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
mpd_connect_thread = threading.Thread(name='mpd_connect_thread', target=mopidy.mpdConnect)
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)
# in das Verzeichnis des Skript wechseln
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
global TunerPin
global AuxPin
TunerPin = 12
AuxPin = 10
# 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__))
def gpio_setup():
global p
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(TunerPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.output(TunerPin, GPIO.LOW) # Set LedPin to low(0V)
GPIO.setup(AuxPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.output(AuxPin, GPIO.LOW) # Set LedPin to low(0V)
def loop(source):
if source == 'Tuner':
p = GPIO.PWM(TunerPin, 1000) # set Frequece to 1KHz
p.start(0) # Duty Cycle = 0
elif source == 'Aux':
p = GPIO.PWM(AuxPin, 1000) # set Frequece to 1KHz
p.start(0) # Duty Cycle = 0
while True:
for dc in range(0, 101, 4): # Increase duty cycle: 0~100
p.ChangeDutyCycle(dc) # Change duty cycle
time.sleep(0.05)
time.sleep(1)
for dc in range(100, -1, -4): # Decrease duty cycle: 100~0
p.ChangeDutyCycle(dc)
time.sleep(0.05)
time.sleep(1)
def destroy():
p.stop()
GPIO.output(TunerPin, GPIO.HIGH) # turn off all leds
GPIO.output(AuxPin, GPIO.HIGH) # turn off all leds
GPIO.cleanup()
try:
logger.info('Starte die Anwendung')
gpio_setup()
loop('Tuner')
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")
destroy()
exit()
except (KeyboardInterrupt):
logger.info("via Tastatur beendet")
destroy()
exit()
except Exception as e:
logger.error("main crashed {0}".format(str(e)))
logger.exception("Error")
destroy()
raise
except:
logger.info("Unbekannter Fehler:", sys.exc_info()[0])
destroy()
raise
# else:
# pass