Skip to content

Commit 764f8b2

Browse files
Merge pull request #83 from Retro-I/feature-68-settings-datei-gpio-pins
Feature 68 settings datei gpio pins
2 parents cd7b8d8 + fd803b9 commit 764f8b2

File tree

6 files changed

+65
-8
lines changed

6 files changed

+65
-8
lines changed

components/RotaryBass.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
from helper.Audio import Audio
66
from helper.AudioEffects import AudioEffects
7+
from helper.GpioHelper import GpioHelper
78

89
audio_helper = Audio()
910
audio_effects = AudioEffects()
11+
gpio_helper = GpioHelper()
1012

1113

1214
class RotaryBass:
1315
COUNTER = 0
1416
BASS_STEP = 2
1517

16-
CLK_PIN = 4 # PIN 7
17-
DT_PIN = 14 # PIN 8
18+
CLK_PIN = gpio_helper.rotary_bass_up()
19+
DT_PIN = gpio_helper.rotary_bass_down()
1820

1921
def __init__(self, on_taskbar_update):
2022
rotary = pyky040.Encoder(CLK=self.CLK_PIN, DT=self.DT_PIN)

components/RotaryPitch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
from pyky040 import pyky040
44

55
from helper.AudioEffects import AudioEffects
6+
from helper.GpioHelper import GpioHelper
67

78
audio_effects = AudioEffects()
9+
gpio_helper = GpioHelper()
810

911

1012
class RotaryPitch:
1113
COUNTER = 0
1214
PITCH_STEP = 1
13-
CLK_PIN = 11 # PIN 23
14-
DT_PIN = 8 # PIN 24
15+
CLK_PIN = gpio_helper.rotary_pitch_up()
16+
DT_PIN = gpio_helper.rotary_pitch_down()
1517

1618
taskbar = None
1719

components/RotaryVolume.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
from pyky040 import pyky040
44

55
from helper.Audio import Audio
6+
from helper.GpioHelper import GpioHelper
67

78
audio_helper = Audio()
9+
gpio_helper = GpioHelper()
810

911

1012
class RotaryVolume:
1113
COUNTER = 0
1214
VOLUME_STEP = 6
13-
SW_PIN = 13 # PIN 33
14-
DT_PIN = 12 # PIN 32
15-
CLK_PIN = 6 # PIN 31
15+
SW_PIN = gpio_helper.rotary_volume_up()
16+
DT_PIN = gpio_helper.rotary_volume_down()
17+
CLK_PIN = gpio_helper.rotary_volume_press()
1618

1719
def __init__(self, on_taskbar_update, on_strip_toggle_mute, on_strip_update_sound):
1820
rotary = pyky040.Encoder(CLK=self.CLK_PIN, DT=self.DT_PIN, SW=self.SW_PIN)

helper/GpioHelper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
3+
from helper.Constants import Constants
4+
5+
c = Constants()
6+
7+
8+
class GpioHelper:
9+
GPIO_SETTINGS_PATH = f"{c.settings_path()}/gpio-pin-mapping.json"
10+
11+
def get_mappings(self) -> dict:
12+
with open(self.GPIO_SETTINGS_PATH) as file:
13+
data = json.load(file)
14+
return data
15+
16+
def rotary_volume_up(self) -> int:
17+
return self.get_mappings()["ROTARY_VOLUME_UP"]
18+
19+
def rotary_volume_down(self) -> int:
20+
return self.get_mappings()["ROTARY_VOLUME_DOWN"]
21+
22+
def rotary_volume_press(self) -> int:
23+
return self.get_mappings()["ROTARY_VOLUME_PRESS"]
24+
25+
def rotary_bass_up(self) -> int:
26+
return self.get_mappings()["ROTARY_BASS_UP"]
27+
28+
def rotary_bass_down(self) -> int:
29+
return self.get_mappings()["ROTARY_BASS_DOWN"]
30+
31+
def rotary_pitch_up(self) -> int:
32+
return self.get_mappings()["ROTARY_PITCH_UP"]
33+
34+
def rotary_pitch_down(self) -> int:
35+
return self.get_mappings()["ROTARY_PITCH_DOWN"]
36+
37+
def start_party_button(self) -> int:
38+
return self.get_mappings()["START_PARTY_MODE_BUTTON"]

scripts/button.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import RPi.GPIO as GPIO
44

5+
from helper.GpioHelper import GpioHelper
56
from helper.SystemHelper import SystemHelper
67

8+
gpio_helper = GpioHelper()
9+
710
# Hierbei handelt es sich um ein Überbleibsel aus Zeiten des Radio's des BSZ Wiesau, um bei offiziellen Veranstaltungen
811
# das Soundboard zu verstecken. Dabei muss dieses Skript in der main.py importiert werden.
912
# Um das Soundboard zu aktivieren, ...
1013

1114
GPIO.setmode(GPIO.BCM)
1215

13-
PIN = 21
16+
PIN = gpio_helper.start_party_button()
1417

1518
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
1619

settings/gpio-pin-mapping.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ROTARY_VOLUME_UP": 6,
3+
"ROTARY_VOLUME_DOWN": 12,
4+
"ROTARY_VOLUME_PRESS": 13,
5+
"ROTARY_BASS_UP": 4,
6+
"ROTARY_BASS_DOWN": 14,
7+
"ROTARY_PITCH_UP": 11,
8+
"ROTARY_PITCH_DOWN": 8,
9+
"START_PARTY_MODE_BUTTON": 21
10+
}

0 commit comments

Comments
 (0)