-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConferenceClock.py
128 lines (102 loc) · 3.28 KB
/
ConferenceClock.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
118
119
120
121
122
123
124
125
126
127
128
# http://weblogs.asp.net/yousefjadallah/grid-layout-in-jquery-mobile
from flask import Flask, render_template, request, jsonify
from threading import Thread
import pirsclockfull as clock
import time
durationTime = 0
sumupTime = 0
timeRemaining = 0
timerState = False
app = Flask(__name__)
# return index page when IP address of RPi is typed in the browser
@app.route("/")
def Index():
return render_template("index.html", uptime=GetUptime())
# ajax GET call this function to set led state
# depeding on the GET parameter sent
@app.route("/_onAir")
def _onAir():
state = request.args.get('state')
if state=="on":
clock.setInd(0, 1)
else:
clock.setInd(0, 0)
return ""
@app.route("/_timer")
def _timer():
global timerState
global timeRemaining
global sumupTime
global durationTime
state = request.args.get('state')
if state=="start":
if timeRemaining <= 0:
durationTime = int(request.args.get('duration')) * 60
sumupTime = int(request.args.get('sumup')) * 60
timeRemaining = durationTime
timerState = True
elif state=="stop":
timerState = False
elif state=="clear":
timerState = False
timeRemaining = 0
clock.setInd(1, 0) # Clear Indicators
clock.setInd(2, 0)
clock.setInd(3, 0)
return ""
# ajax GET call this function periodically to read button state
# the state is sent back as json data
@app.route("/_status")
def _status():
if clock.readInd(0):
onAirstatus = "on"
else:
onAirstatus = "off"
if clock.readInd(1):
indStatus = clock.txt2
elif clock.readInd(2):
indStatus = clock.txt3
elif clock.readInd(3):
indStatus = clock.txt4
else:
indStatus = "None"
return jsonify(indState=indStatus,onAirState=onAirstatus,time=(timeRemaining/60),duration=(durationTime/60),sumup=(sumupTime/60))
def GetUptime():
# get uptime from the linux terminal command
from subprocess import check_output
output = check_output(["uptime"])
# return only uptime info
uptime = output[output.find("up"):output.find("user")-5]
return uptime
def indicators_timer():
global timeRemaining
global timerState
global sumupTime
while True:
if timerState == True:
timeRemaining -= 1
if timeRemaining > sumupTime:
clock.setInd(1, 1) # "Talk"
clock.setInd(2, 0)
clock.setInd(3, 0)
elif timeRemaining <= sumupTime and timeRemaining > 0:
clock.setInd(1, 0) # "Sum-up"
clock.setInd(2, 1)
clock.setInd(3, 0)
elif timeRemaining <= 0:
clock.setInd(1, 0) # "Stop"
clock.setInd(2, 0)
clock.setInd(3, 1)
timerState = False
time.sleep(1)
def start_web_server():
# run the webserver on standard port 80, requires sudo
app.run(host='0.0.0.0', port=80, debug=False, use_reloader=False, threaded=True)
t = Thread(target=start_web_server)
t.daemon = True
t.start()
c = Thread(target=indicators_timer)
c.daemon = True
c.start()
while True:
clock.drawclock()