Starting to wonder if this forum is dead. I'll continue to post my progress, in case someone else might need it.
I can now connect to a bluetooth device when it comes in range, and Processing continues to execute the code if I turn it off or it comes out of range.
The problem is that I can't keep the connection on enough to transmit enough data, because of the way I use the available() function.
I know the connection is gonna happen on COM4, so I start it by seeing if the device is available already. If it isn't, the execution just lags a bit, no problem here.
Code:import processing.serial.*;
Serial myPort;
// SHAKE information
ShakeParser shake;
vibProfile vib_pattern;
void setup() {
size(300, 300);
background(255);
// SHAKE begin
shake = new ShakeParser();
myPort = new Serial(this, "COM4", 230400);
Now, this is the trouble area. In order to have a loop here, I need to check if there's data available on the serial port. If there is, it means that the device is in range, and I upload the vibration pattern to it.
The problem is that if I don't close() or clear() the port at the end of the loop, even if the device isn't in range, the available() function will show data on the port.
That way I have to close() the port at the end the draw() phase, and attempt to connect to the port again, in order to have a valid available() test at the beginning of the next loop.
Code:
void draw() {
if (myPort.available() == 0) {
println("SHAKE not in range");
} else {
// SHAKE: Activates de motors and the capacitive sensors
shakeOn();
// SHAKE: Stop vibration if the Capacitive Sensor detects touch
if ((int)shake.data.cap0.x > 150)
vibPatStop();
else
vibPatThree();
// SHAKE: upload the vibration pattern
fireVibration();
println("SHAKE in range");
}
myPort.stop();
myPort = new Serial(this, "COM4", 230400);
}
The problem is that I can't get the data to the device quick enough before the close() statement.
Any ideas?