-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.py
82 lines (64 loc) · 2.27 KB
/
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
#! /usr/bin/python3
if __name__ == '__main__':
import pygame
import threading
import time
import os
import sys
import signal
import setproctitle
from Clock import Clock
from Dashboard import Dashboard
from CANData import CANData
from GPSData import GPSData
from MotionData import MotionData
from NeoPixels import NeoPixels
from ErrorScreen import ErrorScreen
cwd = os.path.abspath(os.path.dirname(__file__))
log_path = cwd + "/log"
if not os.path.exists(log_path):
os.makedirs(log_path)
i = 0
while (os.path.exists(cwd + f"/log/{i:04d}can.csv") or os.path.exists(cwd + f"/log/{i:04d}gps.nmea") or os.path.exists(cwd + f"/log/{i:04d}motion.csv")):
i += 1
can_filename = log_path + "/{}can.csv".format(str(i).zfill(4))
gps_filename = log_path + "/{}gps.nmea".format(str(i).zfill(4))
motion_filename = log_path + "/{}motion.csv".format(str(i).zfill(4))
can_data = CANData(can_filename, test_mode=False)
gps_data = GPSData(gps_filename)
motion_data = MotionData(motion_filename)
neopixels = NeoPixels()
x = 800
y = 480
pygame.display.init()
pygame.font.init()
pygame.mouse.set_visible(0)
screen = pygame.display.set_mode((x,y))
clock = Clock(0, x, y, screen, show_fps=False)
dashboard = Dashboard(x, y, screen)
error = ErrorScreen(x, y, screen)
setproctitle.setproctitle("display.py")
def shutdown(signal=None, frame=None):
can_data.shutdown()
gps_data.shutdown()
motion_data.shutdown()
neopixels.shutdown()
pygame.display.quit()
pygame.quit()
sys.exit()
signal.signal(signal.SIGHUP, shutdown)
signal.signal(signal.SIGINT, shutdown)
signal.signal(signal.SIGTERM, shutdown)
while True:
if(time.time() - can_data.last_update.value >= 3 or not can_data.has_data.value):
error.show()
dashboard.intro.reset()
neopixels.update(0)
else:
dashboard.update(can_data, gps_data)
dashboard.show()
dashboard.intro.start()
neopixels.update(can_data.rpm.value)
clock.tick()
pygame.display.update()
screen.fill(0)