-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue-display.py
94 lines (78 loc) · 1.8 KB
/
queue-display.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
import RPi.GPIO as GPIO
import time
from asterisk.ami import AMIClient
from asterisk.ami import SimpleAction
# Program variables
CallCount = 0
GPIO_PINS = [6, 5, 25, 24, 23, 22, 27, 18, 17, 4]
# Methods
def SequenceTest():
for i in GPIO_PINS:
GPIO.output(i,GPIO.HIGH)
time.sleep(0.1)
GPIO.output(i,GPIO.LOW)
def RangeTest():
for i in range(0,len(GPIO_PINS)+1):
OutputQueueCalls(i)
time.sleep(0.1)
for i in range(len(GPIO_PINS),-1,-1):
OutputQueueCalls(i)
time.sleep(0.1)
def AllOn():
for i in GPIO_PINS:
GPIO.output(i,GPIO.HIGH)
def AllOff():
for i in GPIO_PINS:
GPIO.output(i,GPIO.LOW)
def OutputQueueCalls(calls):
if calls < 0: calls = 0
if calls > len(GPIO_PINS) + 1: calls = len(GPIO_PINS) + 1
AllOff()
for i in range(calls):
GPIO.output(GPIO_PINS[i],GPIO.HIGH)
def event_listener(event, **kwargs):
print("Event: "+ event.name)
global CallCount
if event.name == "QueueStatusComplete":
# Reset The Call Count
OutputQueueCalls(CallCount)
CallCount = 0
return
if event.name == "QueueEntry":
# Increment the Call Count
CallCount = CallCount+1
return
# Setup
GPIO.setmode(GPIO.BCM)
for i in GPIO_PINS:
GPIO.setup(i, GPIO.OUT)
# Test LED
SequenceTest()
time.sleep(0.1)
RangeTest()
time.sleep(0.1)
AllOn()
time.sleep(0.1)
AllOff()
time.sleep(0.1)
AllOn()
time.sleep(0.1)
AllOff()
time.sleep(1)
client = AMIClient(address='127.0.0.1',port=5038)
client.login('python','password')
action = SimpleAction('Events', EventMask='on')
client.send_action(action)
client.add_event_listener(event_listener, white_list=['QueueStatusComplete','QueueEntry'])
# Main Loop
while True:
try:
action = SimpleAction('QueueStatus', Queue='default')
client.send_action(action)
except Exception as e:
print("Error setting queue calls")
print(e)
time.sleep(1)
# End
client.logoff()
GPIO.cleanup()