-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlP5.pde
258 lines (243 loc) · 8.57 KB
/
ControlP5.pde
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
void keyPressed() {
updateFlag = true;
}
void mousePressed() {
mX = mouseX;
mY = mouseY;
if (SettingsFlag) {
if (resolution.isOpen()) {
service.hide();
d1.hide();
}
if (resolution.isOpen()) {
service.hide();
d1.hide();
}
if (d1.isOpen()) {
service.hide();
resolution.hide();
}
FreezingBox.submit();
ColdBox.submit();
CoolBox.submit();
PerfectBox.submit();
WarmBox.submit();
HotBox.submit();
HellBox.submit();
apiBox.submit();
if ( apiBox.isActive() && ! activeTextField.equals("apiBox")) {
apiBoxOld = apiBox.getText(); //saves teh previous value to reuse if nothing entered
apiBox.setText(""); //Clear the text
activeTextField = "apiBox"; //set the flag so this cant be reentered without going to another box
}
if ( FreezingBox.isActive() && ! activeTextField.equals("FreezingBox")) {
FreezingBoxOld = float(FreezingBox.getText()); //saves teh previous value to reuse if nothing entered
FreezingBox.setText(""); //Clear the text
activeTextField = "FreezingBox"; //set the flag so this cant be reentered without going to another box
}
if ( ColdBox.isActive() && ! activeTextField.equals("ColdBox")) {
ColdBoxOld = float(ColdBox.getText());
ColdBox.setText("");
activeTextField = "ColdBox";
}
if ( CoolBox.isActive()&& ! activeTextField.equals("CoolBox" )) {
CoolBoxOld = float(CoolBox.getText());
CoolBox.setText("");
activeTextField = "CoolBox";
}
if ( PerfectBox.isActive()&& ! activeTextField.equals("PerfectBox" )) {
PerfectBoxOld = float(PerfectBox.getText());
PerfectBox.setText("");
activeTextField = "PerfectBox";
}
if ( WarmBox.isActive() && ! activeTextField.equals("WarmBox")) {
WarmBoxOld = float(WarmBox.getText());
WarmBox.setText("");
activeTextField = "WarmBox";
}
if ( HotBox.isActive() && ! activeTextField.equals("HotBox")) {
HotBoxOld = float(HotBox.getText());
HotBox.setText("");
activeTextField = "HotBox";
}
if ( HellBox.isActive() && ! activeTextField.equals("HellBox")) {
HellBoxOld = float(HellBox.getText());
HellBox.setText("");
activeTextField = "HellBox";
}
}
}
void mouseReleased() {
}
void mouseDragged() {
frame.setLocation(
MouseInfo.getPointerInfo().getLocation().x-mX,
MouseInfo.getPointerInfo().getLocation().y-mY);
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isGroup()) {
// check if the Event was triggered from a ControlGroup
println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
if (theEvent.getName().equals("comPort")) {
//drawSettingsWindow(false);
setupSerial(int(theEvent.getGroup().getValue()));
}
if (theEvent.getName().equals("resolution")) {
//drawSettingsWindow(false);
int sizeOld = sizeSelect;
sizeSelect = int(theEvent.getGroup().getValue());
}
if (theEvent.getName().equals("Service")) {
//drawSettingsWindow(false);
weatherService = int(theEvent.getGroup().getValue());
if (weatherService == 1) {
apiBox.setVisible(SettingsFlag);
}
updateWeather(weatherService);
}
if (theEvent.isFrom("Temp Scale")) {
// print("got an event from "+theEvent.getName()+"\t");
for (int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
if (int(theEvent.getGroup().getArrayValue()[i]) == 1) {
TempUnits = i;
}
}
}
if (theEvent.isFrom("Speed Scale")) {
// print("got an event from "+theEvent.getName()+"\t");
for (int i=0;i<theEvent.getGroup().getArrayValue().length;i++) {
if (int(theEvent.getGroup().getArrayValue()[i]) == 1) {
SpeedUnits = i;
}
}
}
}
else if (theEvent.isController()) {
// println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
if (theEvent.isFrom("Radar")) {
radarFlag = true;
if (radarFlag) {
updateRadar(); //fetches the first radar image when the disp is set to radar
radarButton.setVisible(false);
houseButton.setVisible(true);
}
}
if (theEvent.isFrom("House")) {
radarFlag = false;
if (!radarFlag) {
radarButton.setVisible(true);
houseButton.setVisible(false);
}
}
if (theEvent.isFrom("Settings")) {
SettingsFlag = ! SettingsFlag;
if (SettingsFlag) {
drawSettingsWindow(true);
}
if (!SettingsFlag) {
activeTextField = "";
FreezingBox.submit();
ColdBox.submit();
CoolBox.submit();
PerfectBox.submit();
WarmBox.submit();
HotBox.submit();
HellBox.submit();
}
d1.setVisible(SettingsFlag);
resolution.setVisible(SettingsFlag);
service.setVisible(SettingsFlag);
apiBox.setVisible(false);
if (weatherService == 1) {
apiBox.setVisible(SettingsFlag);
}
TempScale.setVisible(SettingsFlag);
TempScale.hideLabels();
SpeedScale.setVisible(SettingsFlag);
SpeedScale.hideLabels();
FreezingBox.setVisible(SettingsFlag);
ColdBox.setVisible(SettingsFlag);
CoolBox.setVisible(SettingsFlag);
PerfectBox.setVisible(SettingsFlag);
WarmBox.setVisible(SettingsFlag);
HotBox.setVisible(SettingsFlag);
HellBox.setVisible(SettingsFlag);
}
if (theEvent.isFrom("apiBox")) {
apiKey = (apiBox.getText());
if ((apiBox.getText()).equals("")) { //check if user didnt enter anything
println("got apiBox null");
apiKey = apiBoxOld; //roll setpoint back
println(apiKey);
}
}
if (theEvent.isFrom("FreezingBox")) {
FreezingTemp = float(FreezingBox.getText());
if ((FreezingBox.getText()).equals("")) { //check if user didnt enter anything
println("got freezingbox null");
FreezingTemp = FreezingBoxOld; //roll setpoint back
FreezingBox.setText(nfc(FreezingTemp, 1));
println(nf(FreezingTemp, 2, 1));
}
}
if (theEvent.isFrom("ColdBox")) {
ColdTemp = float(ColdBox.getText());
if ((ColdBox.getText()).equals("")) { //check if user didnt enter anything
println("got ColdBox null");
ColdTemp = ColdBoxOld; //roll setpoint back
ColdBox.setText(nf(ColdTemp, 2, 1));
println(nf(ColdTemp, 2, 1));
}
}
if (theEvent.isFrom("CoolBox")) {
CoolTemp = float(CoolBox.getText());
if ((CoolBox.getText()).equals("")) { //check if user didnt enter anything
println("got CoolBox null");
CoolTemp = CoolBoxOld; //roll setpoint back
CoolBox.setText(nf(CoolTemp, 2, 1));
println(nf(CoolTemp, 2, 1));
}
}
if (theEvent.isFrom("PerfectBox")) {
PerfectTemp = float(PerfectBox.getText());
if ((PerfectBox.getText()).equals("")) { //check if user didnt enter anything
println("got PerfectBox null");
PerfectTemp = PerfectBoxOld; //roll setpoint back
PerfectBox.setText(nf(PerfectTemp, 2, 1));
println(nf(PerfectTemp, 2, 1));
}
}
if (theEvent.isFrom("WarmBox")) {
WarmTemp = float(WarmBox.getText());
if ((WarmBox.getText()).equals("")) { //check if user didnt enter anything
println("got WarmBox null");
WarmTemp = WarmBoxOld; //roll setpoint back
WarmBox.setText(nf( WarmTemp, 2, 1));
println(nf( WarmTemp, 2, 1));
}
}
if (theEvent.isFrom("HotBox")) {
HotTemp = float(HotBox.getText());
if ((HotBox.getText()).equals("")) { //check if user didnt enter anything
println("got HotBox null");
HotTemp = HotBoxOld; //roll setpoint back
HotBox.setText(nf( HotTemp, 2, 1));
println(nf( HotTemp, 2, 1));
}
}
if (theEvent.isFrom("HellBox")) {
HellTemp = float(HellBox.getText());
if ((HellBox.getText()).equals("")) { //check if user didnt enter anything
println("got HellBox null");
HellTemp = HellBoxOld; //roll setpoint back
HellBox.setText(nf( HellTemp, 2, 1));
println(nf( HellTemp, 2, 1));
}
}
}
}