-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugging.pde
215 lines (180 loc) · 6.4 KB
/
Debugging.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
//////////////////////////////////////
//
// This file contains classes that are helpful for debugging, as well as the HelpWidget,
// which is used to give feedback to the GUI user in the small text window at the bottom of the GUI
//
// Created: Conor Russomanno, June 2016
// Based on code: Chip Audette, Oct 2013 - Dec 2014
//
//
/////////////////////////////////////
//------------------------------------------------------------------------
// Global Variables & Instances
//------------------------------------------------------------------------
//set true if you want more verbosity in console.. verbosePrint("print_this_thing") is used to output feedback when isVerbose = true
boolean isVerbose = true;
//Help Widget initiation
HelpWidget helpWidget;
//use signPost(String identifier) to print 'identifier' text and time since last signPost() for debugging latency/timing issues
boolean printSignPosts = true;
float millisOfLastSignPost = 0.0;
float millisSinceLastSignPost = 0.0;
final static int OUTPUT_LEVEL_DEFAULT = 0;
final static int OUTPUT_LEVEL_INFO = 1;
final static int OUTPUT_LEVEL_SUCCESS = 2;
final static int OUTPUT_LEVEL_WARN = 3;
final static int OUTPUT_LEVEL_ERROR = 4;
//------------------------------------------------------------------------
// Global Functions
//------------------------------------------------------------------------
void verbosePrint(String _string) {
if (isVerbose) {
println(_string);
}
}
void delay(int delay)
{
int time = millis();
while (millis() - time <= delay);
}
//this class is used to create the help widget that provides system feedback in response to interactivity
//it is intended to serve as a pseudo-console, allowing us to print useful information to the interface as opposed to an IDE console
class HelpWidget {
public float x, y, w, h;
// ArrayList<String> prevOutputs; //growing list of all previous system interactivity
String currentOutput = "Learn how to use this application and more at docs.openbci.com/OpenBCI%20Software/01-OpenBCI_GUI"; //current text shown in help widget, based on most recent command
int padding = 5;
int outputStart = 0;
int outputDurationMs = 3000;
boolean animatingMessage = false;
int curOutputLevel = OUTPUT_LEVEL_DEFAULT;
HelpWidget(float _xPos, float _yPos, float _width, float _height) {
x = _xPos;
y = _yPos;
w = _width;
h = _height;
}
public void update() {
if (animatingMessage) {
if (millis() > outputStart + outputDurationMs) {
animatingMessage = false;
curOutputLevel = OUTPUT_LEVEL_DEFAULT;
}
}
}
public void draw() {
pushStyle();
if(colorScheme == COLOR_SCHEME_DEFAULT){
// draw background of widget
stroke(bgColor);
fill(255);
rect(-1, height-h, width+2, h);
noStroke();
//draw bg of text field of widget
strokeWeight(1);
stroke(color(0, 5, 11));
fill(color(0, 5, 11));
rect(x + padding, height-h + padding, width - padding*2, h - padding *2);
textFont(p4);
textSize(14);
fill(255);
textAlign(LEFT, TOP);
text(currentOutput, padding*2, height - h + padding);
} else if (colorScheme == COLOR_SCHEME_ALTERNATIVE_A){
// draw background of widget
stroke(bgColor);
fill(31,69,110);
rect(-1, height-h, width+2, h);
noStroke();
//draw bg of text field of widget
strokeWeight(1);
stroke(getBackgroundColor());
// fill(200);
// fill(255);
fill(getBackgroundColor());
// fill(57,128,204);
rect(x + padding, height-h + padding, width - padding*2, h - padding *2);
textFont(p4);
textSize(14);
// fill(bgColor);
fill(getTextColor());
// fill(57,128,204);
// fill(openbciBlue);
textAlign(LEFT, TOP);
text(currentOutput, padding*2, height - h + padding);
}
popStyle();
}
private color getTextColor() {
switch (curOutputLevel) {
case OUTPUT_LEVEL_INFO:
return #00529B;
case OUTPUT_LEVEL_SUCCESS:
return #4F8A10;
case OUTPUT_LEVEL_WARN:
return #9F6000;
case OUTPUT_LEVEL_ERROR:
return #D8000C;
case OUTPUT_LEVEL_DEFAULT:
default:
return color(0, 5, 11);
}
}
private color getBackgroundColor() {
switch (curOutputLevel) {
case OUTPUT_LEVEL_INFO:
return #BDE5F8;
case OUTPUT_LEVEL_SUCCESS:
return #DFF2BF;
case OUTPUT_LEVEL_WARN:
return #FEEFB3;
case OUTPUT_LEVEL_ERROR:
return #FFD2D2;
case OUTPUT_LEVEL_DEFAULT:
default:
return color(255);
}
}
public void output(String _output, int level) {
if (OUTPUT_LEVEL_DEFAULT == level) {
animatingMessage = false;
} else {
animatingMessage = true;
outputStart = millis();
}
curOutputLevel = level;
currentOutput = _output;
// prevOutputs.add(_output);
}
};
public void output(String _output) {
output(_output, OUTPUT_LEVEL_DEFAULT);
}
public void output(String _output, int level) {
helpWidget.output(_output, level);
}
public void outputError(String _output) {
output(_output, OUTPUT_LEVEL_ERROR);
}
public void outputInfo(String _output) {
output(_output, OUTPUT_LEVEL_INFO);
}
public void outputSuccess(String _output) {
output(_output, OUTPUT_LEVEL_SUCCESS);
}
public void outputWarn(String _output) {
output(_output, OUTPUT_LEVEL_WARN);
}
// created 2/10/16 by Conor Russomanno to dissect the aspects of the GUI that are slowing it down
// here I will create methods used to identify where there are inefficiencies in the code
// note to self: make sure to check the frameRate() in setup... switched from 16 to 30... working much faster now... still a useful method below.
// -------------------------------------------------------------- START -------------------------------------------------------------------------------
//method for printing out an ["indentifier"][millisSinceLastSignPost] for debugging purposes... allows us to look at what is taking too long.
void signPost(String identifier) {
if (printSignPosts) {
millisSinceLastSignPost = millis() - millisOfLastSignPost;
println("SIGN POST: [" + identifier + "][" + millisSinceLastSignPost + "]");
millisOfLastSignPost = millis();
}
}
// ---------------------------------------------------------------- FINISH -----------------------------------------------------------------------------