-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.py
More file actions
135 lines (107 loc) · 4.05 KB
/
MainFile.py
File metadata and controls
135 lines (107 loc) · 4.05 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
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
129
130
131
132
133
134
135
import PoliticalGPS as PGPS
import time
from gps3 import gps3
import json
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
import pigpio
# For use with LED or LCD backlight. Have to start pigpio daemon before using
pi = pigpio.pi()
if not pi.connected:
print("exit")
exit()
def setColor(Red, Green, Blue):
pi.set_PWM_dutycycle(5,Red)#RED
pi.set_PWM_dutycycle(6,Green) #GREEN
pi.set_PWM_dutycycle(13,Blue) #BLUE
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2
# Raspberry Pi Pin Config (CHRIS'S PINOUT):
lcd_rs = digitalio.DigitalInOut(board.D17)
lcd_en = digitalio.DigitalInOut(board.D27)
lcd_d7 = digitalio.DigitalInOut(board.D25)
lcd_d6 = digitalio.DigitalInOut(board.D24)
lcd_d5 = digitalio.DigitalInOut(board.D23)
lcd_d4 = digitalio.DigitalInOut(board.D22)
lcd_backlight = digitalio.DigitalInOut(board.D26)
# Initialise the lcd class
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
lcd.backlight = False
setColor(150,255,255)
lcd.message = "Loading Data"
lcd.blink= True
NonRingShapes = []
RingShapes = []
startTime = time.time()
PGPS.readData(NonRingShapes, '/home/pi/Desktop/Merged Attributes Nodes Test/Non-Rings.csv')
PGPS.readData(RingShapes, '/home/pi/Desktop/Merged Attributes Nodes Test/Rings.csv')
endTime = time.time()
totalTime = str(endTime-startTime)
print(endTime-startTime)
setColor(0,0,0)
time.sleep(1)
setColor(150,255,255)
lcd.message = "Data Loaded: " + totalTime
lcd.blink= True
time.sleep(3)
lcd.message = "Acquiring\nSatellites"
lcd.blink= True
#TestX = float(input('Lat: '))
#TestY = float(input('Long: '))
#Lat = 44.1596
#Lon = -79.3945
curLat = 0
curLon = 0
dataClass = "Null"
gps_socket = gps3.GPSDSocket()
data_stream = gps3.DataStream()
gps_socket.connect()
gps_socket.watch()
curWinner = "none"
while(True):
for new_data in gps_socket:
if new_data:
data_stream.unpack(new_data)
print(new_data)
try:
data = json.loads(new_data)
#print(data)
dataClass = data['class']
#print(dataClass)
except:
print("ERROR: Missing start char")
if dataClass == "TPV":
try:
curLon = float(data_stream.TPV['lon'])
curLat = float(data_stream.TPV['lat'])
PGPS.calcDistance(curLat, curLon, NonRingShapes)
PGPS.calcDistance(curLat, curLon, RingShapes)
NonRingShapes = sorted(NonRingShapes, key=lambda Shapes: Shapes.Distance)
RingShapes = sorted(RingShapes, key=lambda Shapes: Shapes.Distance)
Name, Winner = PGPS.findRiding(NonRingShapes, RingShapes, curLat, curLon)
print(Name)
print(Winner)
if Winner != curWinner:
curWinner = Winner
lcd.clear()
lcd.blink = False
lcd.message = Name + "\n" + Winner
if Winner == "Liberal":
setColor(255,0,0)
elif Winner == "Bloc Quebecois":
setColor(0,200,200)
elif Winner == "Conservative":
setColor(0,0,255)
elif Winner == "NDP-New Democratic Party":
setColor(200,50,0)
elif Winner == "Green Party":
setColor(0,255,0)
except:
print("ERROR: No data")
#make this into blinking LED (finding satellites)
else:
print("wrong data type")
#time.sleep(5)