-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph.py
138 lines (100 loc) · 4.97 KB
/
graph.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
129
130
131
132
133
134
135
136
137
138
# the following function plots the environment sensors to an onscreen graph
def graphScreen(surface,humidGraph,tempGraph,pressGraph,moire,tock,graphinit,buttons,csvfile,rot):
status = "graphgo"
drawinterval = 1 #64
senseinterval = 10
#337
# Because the graph screen is slow to update it needs to pop a reading onto screen as soon as it is initiated I draw a value once and wait for the interval to lapse for the next draw. Once the interval has lapsed pop another value on screen.
moire.animate()
if (graphinit.get() == 0) or (tock.timelapsed() >= drawinterval):
#Sets a black screen ready for our UI elements
surface.fill(black)
#draws Background gridplane
graphback = Image()
graphback.update(backgraph, 0, 0)
graphback.draw(surface)
#instantiates 3 labels for our readout
templabel = Label()
humidlabel = Label()
presslabel = Label()
intervallabel = Label()
intervallabelshadow = Label()
slider1 = Image()
slider2 = Image()
slider3 = Image()
#gets our data
senseData = sensorget()
csvfile.logvalues(senseData)
#parses dictionary of data from sensor/weather.
#converts humid data to float
humidData = float(senseData['humidity'])
#scales the data to the limits of our screen
humidgraph = translate(humidData, 0, 100, 204, 17)
#grabs a simple 61 wide tuple for our values
humidbuffer = humidGraph.grablist()
#puts a new sensor value at the end
humidbuffer.append(humidgraph)
#pop the oldest value off
humidbuffer.pop(0)
#preps the list by adding the X coordinate to every sensor value
humidcords = humidGraph.graphprep(humidbuffer)
#repeat for each sensor
tempData = float(senseData['temp'])
tempgraph = translate(tempData, -40, 120, 204, 17)
tempbuffer = tempGraph.grablist()
tempbuffer.append(tempgraph)
tempbuffer.pop(0)
tempcords = tempGraph.graphprep(tempbuffer)
pressData = float(senseData['pressure'])
pressgraph = translate(pressData, 260, 1260, 204, 17)
pressbuffer = pressGraph.grablist()
pressbuffer.append(pressgraph)
pressbuffer.pop(0)
presscords = pressGraph.graphprep(pressbuffer)
tempcontent = str(int(tempData))
templabel.update(tempcontent + "\xb0" + " c",30,35,205,titleFont,red)
presscontent = str(int(pressData))
presslabel.update(presscontent + " hpa",30,114,205,titleFont,yellow)
humidcontent = str(int(humidData))
humidlabel.update(humidcontent + " %",30,246,205,titleFont,green)
#templabel.update(tempData + "\xb0",16,15,212,titleFont,yellow)
setting = str(float(drawinterval))
intervaltext = (setting + ' sec')
interx= (22)
intery= (21)
# intervallabel.update("~"+setting + " Hrs",30,22,167,titleFont,white)
#intervallabelshadow.update(setting + " Hrs",30,24,169,titleFont,(100,100,100))
intervallabel.update(intervaltext,30,interx,intery,titleFont,white)
intervallabelshadow.update(intervaltext, 30, interx + 2, intery + 2 ,titleFont,(100,100,100))
tempslide = translate(senseData['temp'], -40, 120, 194, 7)
pressslide = translate(senseData['pressure'], 260, 1260, 194, 7)
humidslide = translate(senseData['humidity'], 0, 100, 194, 7)
slider1.update(sliderb, 283, tempslide)
slider2.update(sliderb, 283, pressslide)
slider3.update(sliderb, 283, humidslide)
#draw the lines
pygame.draw.lines(surface, red, False, tempcords, 3)
pygame.draw.lines(surface, green, False, humidcords, 3)
pygame.draw.lines(surface, yellow, False, presscords, 3)
templabel.draw(surface)
presslabel.draw(surface)
humidlabel.draw(surface)
intervallabelshadow.draw(surface)
intervallabel.draw(surface)
#draws UI to frame buffer
slider1.draw(surface)
slider2.draw(surface)
slider3.draw(surface)
if (rot.read() == True):
surface.blit(pygame.transform.rotate(surface, 180), (0, 0))
pygame.display.flip()
if (graphinit.get() == 0):
graphinit.logstart()
if (tock.timelapsed() >= 10):
tock.logtime()
#status = "graphgo"
#returns state to main loop
status = butswitch(status,graphinit,moire,rot,buttons)
#button_readings = buttons.read()
#returns state to main loop
return status