My first TAD project is a Processing sketch to log data from the Emotiv EPOC via OSC messages, to a tab-delimited text file.
import oscP5.*;
// declare objects
OscP5 oscP5;
PrintWriter output;
Format formatter;
void setup() {
// listen for OSC messages on port 7400
oscP5 = new OscP5(this, 7400);
// create a file to log data to
output = createWriter("epoc_log.txt");
// format timestamp for the log entries
formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS");
}
void draw() {
// this sketch does not draw anything specific
}
// receive, parse, and write OSC data to the log file
void oscEvent(OscMessage theOscMessage) {
Date date = new Date(); // get the current timestamp
String dateTime = formatter.format(date); // format the timestamp
String event = theOscMessage.addrPattern(); // get the message's address pattern
float value = theOscMessage.get(0).floatValue(); // get the message's value
output.println(dateTime+"\t"+event+"\t"+value); // write it all to the log file
}
// press any key to save the data
void keyPressed() {
output.flush(); // write the remaining data
output.close(); // finish the file
exit(); // stop the program
}
This variation inserts the date into the file name, and only the time (instead of the date and time) into the log file.
/**
* EPOC Logger 2
* by Joshua Madara, hyperRitual.com
* This sketch logs data from the Emotiv EPOC via
* OSC messages, to a tab-delimited text file.
*/
import oscP5.*;
// declare objects
OscP5 oscP5;
PrintWriter output;
Format dateForm;
Format timeForm;
void setup() {
// listen for OSC messages on port 7400
oscP5 = new OscP5(this, 7400);
// format datestamp for the file name
dateForm = new SimpleDateFormat("yyyy_MM_dd");
// format timestamp for the the log entries
timeForm = new SimpleDateFormat("HH.mm.ss.SSS");
// create a file to log data to
Date date = new Date(); // get the current date
String dateS = dateForm.format(date); // format the date
output = createWriter("epoc_log_"+dateS+".txt"); // include the date in the file name
}
void draw() {
// this sketch does not draw anything specific
}
// receive, parse, and write OSC data to the log file
void oscEvent(OscMessage theOscMessage) {
Date time = new Date(); // get the current time
String timeS = timeForm.format(time); // format the time
String event = theOscMessage.addrPattern(); // get the message's address pattern
float value = theOscMessage.get(0).floatValue(); // get the message's value
output.println(timeS+"\t"+event+"\t"+value); // write it all to the log file
}
// press any key to save the data
void keyPressed() {
output.flush(); // write the remaining data
output.close(); // finish the file
exit(); // stop the program
}
One Reply to “TAD2011.01 Emotiv EPOC Data Logger”