-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMindGlyphs.pde
118 lines (93 loc) · 3.68 KB
/
MindGlyphs.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
import processing.serial.*;
import pt.citar.diablu.processing.mindset.*;
MindSet mindSet;
Serial serialPort;
String serialPortId = "COM6";
ArrayList<MindFlexDataSet> mindFlexData = new ArrayList<MindFlexDataSet>(); // This is the array list that stores each data point read from the MindFlex headset. It has a .get() method that returns an array of the data points
int cols = 15; // How many cols across the page
int rows = 25; // How many rows down the page
float circleSize = 5; // This is the overall size of each glyph
float randomOffSet = 0; // Does nothing now
// Calculated variables
int colSpacing;
int rowSpacing;
// Event updated variables
int gMeditationLevel;
int gAttentionLevel;
boolean activeHeadset = false;
boolean readyToReceive = false;
int previousCount = 0;
float feed = 1000;
// A0 = 841, 1188
// A1 = 594, 841
// A2 = 420, 594
// A3 = 297, 420
// A4 = 210, 297
PrintWriter gcodeFile;
void setup() {
size(290, 420);
gcodeFile = createWriter("mind-glyphs.gcode");
mindSet = new MindSet(this, "COM11");
senderInit("G10 L2 P2 X-140 Y-550 Z5", true);
//senderInit("", true);
// FluidNC wallbot A2 offset "G10 L2 P1 X? Y? Z?" Note: This plots from bottom up ?!?!
sender("G0 Z5"); // Lift pen
sender("G55 X0 Y0 F1500"); // Go to home for G55 work offset (defined by L2)
// TODO: Slow down data collection so we are keeping up with the plotter. Can we know when a plot event has completed?
// Setup the page
frameRate(1);
background(255);
noFill();
stroke(150);
// Calculate the row and column spacing for the given screen size and number of rows and cols
colSpacing = width/cols;
rowSpacing = height/rows;
println("col count:" + cols + " col spacing:" + colSpacing);
println("row count:" + rows + " row spacing:" + rowSpacing);
}
int currentIndex = 0;
void draw() {
//clear();
//background(255);
//println(mindFlexData);
// Every 10 seconds (10 frames @ 1 frame/sec) check to see if we have received any data from the mindset
// If not try to re-initialize it
if (frameCount % 1 == 0){
println("Check every 10 secs");
println("We have " + mindFlexData.size() + " mindflex data points");
readyToReceive = true;
//println("Previous count = " + previousCount + " number of items = " + mindFlexData.size() + "");
while (previousCount != mindFlexData.size()){
//println("Waiting for new mindFlex data...");
}
// Don't draw anything until we have some data
if ((mindFlexData.size()>0) && (activeHeadset)){
// Now loop over the array that we have and draw circles for each point
while (currentIndex<mindFlexData.size()){
int x = currentIndex % cols; // Work out what x would be for the current index
int y = currentIndex / cols; // Work out what y would be for the current index
//println("i="+i+" x="+x+" y="+y);
drawGlyph(x*colSpacing+(colSpacing/2), y*rowSpacing + (rowSpacing/2), mindFlexData.get(currentIndex).rand()); // Draw a circle for the current x,y cooridinates
plotGlyph(x*colSpacing+(colSpacing/2), y*rowSpacing + (rowSpacing/2), mindFlexData.get(currentIndex).rand());
// Test plotting by faking the data for a mindflex headset
//plotGlyph(x*colSpacing+(colSpacing/2), y*rowSpacing + (rowSpacing/2), mindFlexData.get(currentIndex).rand());
currentIndex++;
}
}
}
}
//public void restartMindSet() {
// //checkSerialPort();
// mindSet = new MindSet(this, serialPortId);
//}
void exit() {
// Close the com port when we exit
println("Exiting");
mindSet.quit();
super.exit();
}
void keyPressed() {
gcodeFile.flush(); // Writes the remaining data to the file
gcodeFile.close(); // Finishes the file
exit(); // Stops the program
}