-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform_pi_code.py
More file actions
90 lines (71 loc) · 2.19 KB
/
Copy pathplatform_pi_code.py
File metadata and controls
90 lines (71 loc) · 2.19 KB
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
import RPi.GPIO as GPIO
import firebase
import json
import time
PREV_STATION = 1
MY_STATION_ID = 2
NUM_PLATFORMS = 2
BLUE = 4
GREEN = 17
RED = 27
GREEN2 = 23
RED2 = 24
BLUE2 = 25
RED_THRESHOLD = 3
GREEN_THRESHOLD = 1
YELLOW_THRESHOLD = 2
def turnOn(colorNum):
GPIO.setwarnings(False)
GPIO.output(colorNum, False)
def turnOff(colorNum):
GPIO.setwarnings(False)
GPIO.output(colorNum, True)
def setUpPins():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
colorList = [GREEN, GREEN2, RED, RED2, BLUE, BLUE2]
for color in colorList:
GPIO.setup(color, GPIO.OUT)
def turnOffAll():
colorList = [GREEN, GREEN2, RED, RED2, BLUE, BLUE2]
for color in colorList:
turnOff(color)
def turnOnWithCertainNum(platform, numPassengers):
if platform == 0:
turnOn(GREEN)
if numPassengers >= RED_THRESHOLD:
turnOff(GREEN)
turnOn(RED)
elif numPassengers >= YELLOW_THRESHOLD:
turnOn(RED)
elif platform == 1:
turnOn(GREEN2)
if numPassengers >= RED_THRESHOLD:
turnOff(GREEN2)
turnOn(RED2)
elif numPassengers >= YELLOW_THRESHOLD:
turnOn(RED2)
def get_most_recent_cars():
cars = {}
all_history = firebase.get('/history', None)
# Get all from prev_station, group by car_id and then get the most recent timestamp for each car
for key, value in all_history.items():
if value["station_id"] == PREV_STATION:
try:
if cars[value["car_id"]] and cars[value["car_id"]]["timestamp"] < value["timestamp"]:
# Same car_id but newer data
cars[value["car_id"]] = value
except:
cars[value["car_id"]] = value
for key, value in cars.items():
print (key, value)
return cars
if __name__ == '__main__':
firebase = firebase.FirebaseApplication('https://metronome-nyc.firebaseio.com', None)
setUpPins()
cars = get_most_recent_cars()
for platform_num in range(NUM_PLATFORMS):
num_people_detected = cars[platform_num]["how_full"]
turnOnWithCertainNum(platform_num, num_people_detected)
time.sleep(2)
turnOffAll()