-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKumo-Pi-Remote.py
executable file
·96 lines (77 loc) · 2.48 KB
/
Kumo-Pi-Remote.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
#! /usr/bin/python3
import RPi.GPIO as GPIO
import time
import sys
import traceback
from kumoManager import kumoManager
BUTTON_IN = [5, 10, 27, 3]
LED_OUT = [6, 9, 22, 4]
DEBUG = False
kumo_sources = {
1: 14, # Stage 3
2: 12, # Stage 5
4: 11, # Stage 7
8: 13, # Stage 11 (Drum)
3: 9, # KiPro Out
6: 4, # FOH Tie18
12: 8} # DVD GLS SAT
kumo_dest = 4 # Switcher Channel 4
kumo_ip = "http://10.70.58.25"
kumo_manager = None
kumo_drop_next = False # Flag to drop next status check, becasue it might be stale
def set_led(v):
for i in range(len(LED_OUT)):
GPIO.output(LED_OUT[i], not (v & 2**i))
def button_callback(button, e = None):
try:
time.sleep(0.100)
button_value = 0
button_count = 0
for i in range(len(BUTTON_IN)):
if not GPIO.input(BUTTON_IN[i]):
button_value += 2**i
button_count += 1
if (button_value == 0x0F):
set_led(0)
sys.exit()
if (button_count):
if (button_value in kumo_sources):
set_led(button_value)
kumo_drop_next = True
if DEBUG: print (kumo_sources[button_value])
if kumo_manager:
kumo_manager.setChannel(kumo_dest, kumo_sources[button_value])
except:
traceback.print_exc()
# Use BCM pin numbering convention
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Button 4
# GPIO.setup(BUTTON_IN[3], GPIO.IN) #GPIO 3, Pin 5 # A physical pull up resistor is fitted on this channel
# GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
for g in BUTTON_IN:
GPIO.setup(g, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(g, GPIO.BOTH, callback=button_callback, bouncetime=120)
for g in LED_OUT:
GPIO.setup(g, GPIO.OUT)
GPIO.output(g, 0)
while True:
# This "thread" maintains the link to the Kumo, and gets status updates
led_value = 0
if not kumo_manager:
time.sleep(3) # Wait 3 seconds and try to re-establish
kumo_manager = kumoManager(kumo_ip)
if kumo_manager.online:
kumo_current_source = kumo_manager.getChannel(kumo_dest)
if kumo_drop_next:
kumo_drop_next = false
else:
for s in kumo_sources:
if kumo_current_source == kumo_sources[s]:
led_value = s
break
else:
kumo_manager = None
kumo_drop_next = False
set_led(led_value)
time.sleep(0.5)