33 Commits

Autor SHA1 Mensagem Data
AJ Keller 04f20ed19b Merge pull request #117 from OpenBCI/staging
Fix #111
2017-01-31 18:57:02 -05:00
AJ Keller d34c9dc2a0 Merge pull request #114 from aj-ptw/fix-111
Fix #111 - Windows users saw unpleasent error message from ganglion h…
2017-01-31 18:56:29 -05:00
AJ Keller f98ffefebf Fix #111 - Add fixes in GanglionSync.pde 2017-01-31 18:26:05 -05:00
AJ Keller f81407334c Merge pull request #115 from OpenBCI/staging
Staging
2017-01-20 16:12:43 -05:00
AJ Keller 8293b9d351 Fix #111 - Windows users saw unpleasent error message from ganglion hub is no compatiable usb 4.0 ble device found 2017-01-20 11:24:50 -05:00
AJ Keller 9901d7e33d Merge pull request #113 from aj-ptw/patches
Patches
2017-01-20 09:20:30 -05:00
AJ Keller 0bb7ec9fbe Bump version number 2017-01-20 09:16:40 -05:00
AJ Keller 9bedcde9fd Add changelog 2017-01-20 09:14:18 -05:00
AJ Keller ff46af0905 Remove space in Ganglion Hub name 2017-01-19 13:57:29 -05:00
AJ Keller 0ca326c631 Fix for cyton V2 raw byte id 2017-01-10 21:29:08 -05:00
Conor Russomanno 65af974303 Merge pull request #110 from OpenBCI/development
Development
2017-01-10 16:08:02 -05:00
Conor Russomanno 83079cf2c9 Merge pull request #109 from conorrussomanno/development
OpenBCI GUI v2.0.0
2017-01-10 16:07:19 -05:00
Conor Russomanno 9354f353b6 OpenBCI GUI v2.0.0 2017-01-10 16:04:08 -05:00
Conor Russomanno e08b8f4083 Merge pull request #108 from conorrussomanno/development
Development
2017-01-10 13:39:47 -05:00
Conor Russomanno 5acb6fcff0 Merge branch 'master' of https://github.com/OpenBCI/OpenBCI_GUI_v2.0 into development 2017-01-10 13:36:56 -05:00
Conor Russomanno a61c01a775 Merge pull request #107 from conorrussomanno/development
Development
2017-01-10 13:35:24 -05:00
Conor Russomanno cd4f70e4ec Merge branch 'development' of https://github.com/conorrussomanno/OpenBCI_GUI_v2.0 into development 2017-01-10 13:34:04 -05:00
Conor Russomanno 6a08af2712 near railed verbosity added 2017-01-10 13:31:18 -05:00
AJ Keller 9467e6b2a2 Merge pull request #106 from OpenBCI/development
Development
2017-01-10 13:27:26 -05:00
AJ Keller 0132b045d1 Merge branch 'master' into development 2017-01-10 13:26:57 -05:00
Conor Russomanno 3372e1c12a Merge pull request #105 from conorrussomanno/development
EMG widget is production ready and a few other bug fixes
2017-01-09 21:30:06 -05:00
Conor Russomanno e9b30d1441 EMG widget is production ready and a few other bug fixes 2017-01-09 21:29:14 -05:00
biomurph d341697768 Fixed the broken Radio Config tools
Trimmed down the Radio Config panel functionality, fixed bugs in
rcConfig print_onscreen output, repaired broken serial port
connection/disconnection,
2017-01-07 16:39:16 -05:00
AJ Keller 8d46b3b8af Merge pull request #94 from cfausn/master
New EMG widget created
2017-01-06 15:13:29 -05:00
AJ Keller 30411a1c46 Merge pull request #104 from OpenBCI/development
Development
2017-01-06 15:09:57 -05:00
AJ Keller 49b11027be Merge branch 'development' into master 2017-01-06 15:06:42 -05:00
Colin Fausnaught d78d86ee8f Euruka! Open Bionics widget working! 2016-12-22 17:33:03 -05:00
Colin Fausnaught b52ab1d5ec Added basic OpenBionics functionality, more to come (NOT WORKING YET DON'T MERGE) 2016-12-22 16:37:54 -05:00
Colin Fausnaught bef37245bf Fixed some minor bugs, should be working now 2016-12-22 14:27:20 -05:00
Colin Fausnaught 7138b90059 Added new EMG widget 2016-12-19 22:08:09 -05:00
Colin Fausnaught 8a69084f8e Merge branch 'development' of https://github.com/OpenBCI/OpenBCI_GUI_v2.0 2016-12-19 16:37:17 -05:00
Colin Fausnaught bcb0be39c3 Merge https://github.com/OpenBCI/OpenBCI_GUI_v2.0 2016-12-16 14:26:53 -05:00
Colin Fausnaught 3158f18a04 Small UI change 2016-11-20 19:37:21 -05:00
17 arquivos alterados com 4933 adições e 3299 exclusões
+16
Ver Arquivo
@@ -0,0 +1,16 @@
# 2.1.1
### Bug Fixes
* Fix #111 - No compatible USB now shows error in output, not an annoying popup.
# 2.1.0
### Breaking Changes
* Removed space in GanglionHub to be able to kill the hub on windows.
### Bug Fixes
* Issue #111 where Windows users saw error message from Ganglion Hub on start up if no hub selected.
# 2.0.0
* Initial Release
+140 -141
Ver Arquivo
@@ -102,13 +102,13 @@ Button popOut;
Button getChannel;
Button setChannel;
Button ovrChannel;
Button getPoll;
Button setPoll;
Button defaultBAUD;
Button highBAUD;
// Button getPoll;
// Button setPoll;
// Button defaultBAUD;
// Button highBAUD;
Button autoscan;
Button autoconnectNoStartDefault;
Button autoconnectNoStartHigh;
// Button autoconnectNoStartDefault;
// Button autoconnectNoStartHigh;
Button systemStatus;
Button synthChanButton4;
@@ -127,16 +127,6 @@ RadioConfigBox rcBox;
public void controlEvent(ControlEvent theEvent) {
if (theEvent.isFrom("serialListConfig")) {
Map bob = ((MenuList)theEvent.getController()).getItem(int(theEvent.getValue()));
serialNameEMG = (String)bob.get("headline");
println(serialNameEMG);
}
if (theEvent.isFrom("baudList")) {
Map bob = ((MenuList)theEvent.getController()).getItem(int(theEvent.getValue()));
baudEMG = (String)bob.get("headline");
println(baudEMG);
}
if (theEvent.isFrom("sourceList")) {
controlPanel.hideAllBoxes();
@@ -154,6 +144,10 @@ public void controlEvent(ControlEvent theEvent) {
chanButton16.color_notPressed = autoFileName.color_notPressed; //default color of button
} else if(newDataSource == DATASOURCE_GANGLION){
updateToNChan(4);
if (isWindows() && isHubInitialized == false) {
hubInit();
timeOfSetup = millis();
}
} else if(newDataSource == DATASOURCE_PLAYBACKFILE){
updateToNChan(8);
} else if(newDataSource == DATASOURCE_SYNTHETIC){
@@ -221,14 +215,14 @@ public void controlEvent(ControlEvent theEvent) {
}
if (theEvent.isFrom("pollList")){
int setChannelInt = int(theEvent.getValue());
//Map bob = ((MenuList)theEvent.getController()).getItem(int(theEvent.getValue()));
cp5Popup.get(MenuList.class, "pollList").setVisible(false);
channelPopup.setClicked(false);
set_poll(rcBox,setChannelInt);
setPoll.wasPressed = false;
}
// if (theEvent.isFrom("pollList")){
// int setChannelInt = int(theEvent.getValue());
// //Map bob = ((MenuList)theEvent.getController()).getItem(int(theEvent.getValue()));
// cp5Popup.get(MenuList.class, "pollList").setVisible(false);
// channelPopup.setClicked(false);
// set_poll(rcBox,setChannelInt);
// setPoll.wasPressed = false;
// }
}
//------------------------------------------------------------------------
@@ -387,7 +381,7 @@ class ControlPanel {
convertSDFile();
}
if (isGanglion) {
if (isHubInitialized && isGanglionObjectInitialized) {
if (!calledForBLEList) {
calledForBLEList = true;
if (ganglion.isHubRunning()) {
@@ -707,40 +701,40 @@ class ControlPanel {
ovrChannel.wasPressed = true;
}
if (getPoll.isMouseHere()){
getPoll.setIsActive(true);
getPoll.wasPressed = true;
}
// if (getPoll.isMouseHere()){
// getPoll.setIsActive(true);
// getPoll.wasPressed = true;
// }
if (setPoll.isMouseHere()){
setPoll.setIsActive(true);
setPoll.wasPressed = true;
}
// if (setPoll.isMouseHere()){
// setPoll.setIsActive(true);
// setPoll.wasPressed = true;
// }
if (defaultBAUD.isMouseHere()){
defaultBAUD.setIsActive(true);
defaultBAUD.wasPressed = true;
}
// if (defaultBAUD.isMouseHere()){
// defaultBAUD.setIsActive(true);
// defaultBAUD.wasPressed = true;
// }
if (highBAUD.isMouseHere()){
highBAUD.setIsActive(true);
highBAUD.wasPressed = true;
}
// if (highBAUD.isMouseHere()){
// highBAUD.setIsActive(true);
// highBAUD.wasPressed = true;
// }
if (autoscan.isMouseHere()){
autoscan.setIsActive(true);
autoscan.wasPressed = true;
}
if (autoconnectNoStartDefault.isMouseHere()){
autoconnectNoStartDefault.setIsActive(true);
autoconnectNoStartDefault.wasPressed = true;
}
// if (autoconnectNoStartDefault.isMouseHere()){
// autoconnectNoStartDefault.setIsActive(true);
// autoconnectNoStartDefault.wasPressed = true;
// }
if (autoconnectNoStartHigh.isMouseHere()){
autoconnectNoStartHigh.setIsActive(true);
autoconnectNoStartHigh.wasPressed = true;
}
// if (autoconnectNoStartHigh.isMouseHere()){
// autoconnectNoStartHigh.setIsActive(true);
// autoconnectNoStartHigh.wasPressed = true;
// }
if (systemStatus.isMouseHere()){
@@ -844,8 +838,8 @@ class ControlPanel {
}
if(getChannel.isMouseHere() && getChannel.wasPressed){
if(board != null) get_channel( rcBox);
// if(board != null) // Radios_Config will handle creating the serial port JAM 1/2017
get_channel( rcBox);
getChannel.wasPressed=false;
getChannel.setIsActive(false);
}
@@ -863,66 +857,66 @@ class ControlPanel {
}
if (getPoll.isMouseHere() && getPoll.wasPressed){
get_poll(rcBox);
getPoll.setIsActive(false);
getPoll.wasPressed = false;
}
// if (getPoll.isMouseHere() && getPoll.wasPressed){
// get_poll(rcBox);
// getPoll.setIsActive(false);
// getPoll.wasPressed = false;
// }
if (setPoll.isMouseHere() && setPoll.wasPressed){
pollPopup.setClicked(true);
channelPopup.setClicked(false);
setPoll.setIsActive(false);
}
// if (setPoll.isMouseHere() && setPoll.wasPressed){
// pollPopup.setClicked(true);
// channelPopup.setClicked(false);
// setPoll.setIsActive(false);
// }
if (defaultBAUD.isMouseHere() && defaultBAUD.wasPressed){
set_baud_default(rcBox,openBCI_portName);
defaultBAUD.setIsActive(false);
defaultBAUD.wasPressed=false;
}
// if (defaultBAUD.isMouseHere() && defaultBAUD.wasPressed){
// set_baud_default(rcBox,openBCI_portName);
// defaultBAUD.setIsActive(false);
// defaultBAUD.wasPressed=false;
// }
if (highBAUD.isMouseHere() && highBAUD.wasPressed){
set_baud_high(rcBox,openBCI_portName);
highBAUD.setIsActive(false);
highBAUD.wasPressed=false;
}
// if (highBAUD.isMouseHere() && highBAUD.wasPressed){
// set_baud_high(rcBox,openBCI_portName);
// highBAUD.setIsActive(false);
// highBAUD.wasPressed=false;
// }
if(autoconnectNoStartDefault.isMouseHere() && autoconnectNoStartDefault.wasPressed){
// if(autoconnectNoStartDefault.isMouseHere() && autoconnectNoStartDefault.wasPressed){
//
// if(board == null){
// try{
// board = autoconnect_return_default();
// rcBox.print_onscreen("Successfully connected to board");
// }
// catch (Exception e){
// rcBox.print_onscreen("Error connecting to board...");
// }
//
//
// }
// else rcBox.print_onscreen("Board already connected!");
// autoconnectNoStartDefault.setIsActive(false);
// autoconnectNoStartDefault.wasPressed = false;
// }
if(board == null){
try{
board = autoconnect_return_default();
rcBox.print_onscreen("Successfully connected to board");
}
catch (Exception e){
rcBox.print_onscreen("Error connecting to board...");
}
}
else rcBox.print_onscreen("Board already connected!");
autoconnectNoStartDefault.setIsActive(false);
autoconnectNoStartDefault.wasPressed = false;
}
if(autoconnectNoStartHigh.isMouseHere() && autoconnectNoStartHigh.wasPressed){
if(board == null){
try{
board = autoconnect_return_high();
rcBox.print_onscreen("Successfully connected to board");
}
catch (Exception e2){
rcBox.print_onscreen("Error connecting to board...");
}
}
else rcBox.print_onscreen("Board already connected!");
autoconnectNoStartHigh.setIsActive(false);
autoconnectNoStartHigh.wasPressed = false;
}
// if(autoconnectNoStartHigh.isMouseHere() && autoconnectNoStartHigh.wasPressed){
//
// if(board == null){
//
// try{
//
// board = autoconnect_return_high();
// rcBox.print_onscreen("Successfully connected to board");
// }
// catch (Exception e2){
// rcBox.print_onscreen("Error connecting to board...");
// }
//
// }
// else rcBox.print_onscreen("Board already connected!");
// autoconnectNoStartHigh.setIsActive(false);
// autoconnectNoStartHigh.wasPressed = false;
// }
if(autoscan.isMouseHere() && autoscan.wasPressed){
autoscan.wasPressed = false;
@@ -960,9 +954,13 @@ class ControlPanel {
//open or close serial port if serial port button is pressed (left button in serial widget)
if (refreshBLE.isMouseHere() && refreshBLE.wasPressed) {
output("BLE Devices Refreshing");
bleList.items.clear();
ganglion.searchDeviceStart();
if (isGanglionObjectInitialized) {
output("BLE Devices Refreshing");
bleList.items.clear();
ganglion.searchDeviceStart();
} else {
output("Please wait till BLE is fully initalized");
}
}
//open or close serial port if serial port button is pressed (left button in serial widget)
@@ -1703,34 +1701,34 @@ class RadioConfigBox {
x = _x + _w;
y = _y;
w = _w;
h = 355;
h = 255;
padding = _padding;
isShowing = false;
getChannel = new Button(x + padding, y + padding*2 + 18, (w-padding*3)/2, 24, "GET CHANNEL", fontInfo.buttonLabel_size);
setChannel = new Button(x + padding + (w-padding*2)/2, y + padding*2 + 18, (w-padding*3)/2, 24, "SET CHANNEL", fontInfo.buttonLabel_size);
ovrChannel = new Button(x + padding, y + padding*3 + 18 + 24, (w-padding*3)/2, 24, "OVERRIDE CHAN", fontInfo.buttonLabel_size);
getPoll = new Button(x + padding + (w-padding*2)/2, y + padding*3 + 18 + 24, (w-padding*3)/2, 24, "GET POLL", fontInfo.buttonLabel_size);
setPoll = new Button(x + padding, y + padding*4 + 18 + 24*2, (w-padding*3)/2, 24, "SET POLL", fontInfo.buttonLabel_size);
defaultBAUD = new Button(x + padding + (w-padding*2)/2, y + padding*4 + 18 + 24*2, (w-padding*3)/2, 24, "DEFAULT BAUD", fontInfo.buttonLabel_size);
highBAUD = new Button(x + padding, y + padding*5 + 18 + 24*3, (w-padding*3)/2, 24, "HIGH BAUD", fontInfo.buttonLabel_size);
autoscan = new Button(x + padding + (w-padding*2)/2, y + padding*5 + 18 + 24*3, (w-padding*3)/2, 24, "AUTOSCAN CHANS", fontInfo.buttonLabel_size);
autoconnectNoStartDefault = new Button(x + padding, y + padding*6 + 18 + 24*4, (w-padding*3 )/2 , 24, "CONNECT 115200", fontInfo.buttonLabel_size);
systemStatus = new Button(x + padding + (w-padding*2)/2, y + padding*6 + 18 + 24*4, (w-padding*3 )/2, 24, "STATUS", fontInfo.buttonLabel_size);
autoconnectNoStartHigh = new Button(x + padding, y + padding*7 + 18 + 24*5, (w-padding*3 )/2, 24, "CONNECT 230400", fontInfo.buttonLabel_size);
systemStatus = new Button(x + padding + (w-padding*2)/2, y + padding*2 + 18, (w-padding*3)/2, 24, "STATUS", fontInfo.buttonLabel_size);
setChannel = new Button(x + padding, y + padding*3 + 18 + 24, (w-padding*3)/2, 24, "CHANGE CHANNEL", fontInfo.buttonLabel_size);
ovrChannel = new Button(x + padding, y + padding*4 + 18 + 24*2, (w-padding*3)/2, 24, "OVERRIDE DONGLE", fontInfo.buttonLabel_size);
autoscan = new Button(x + padding + (w-padding*2)/2, y + padding*4 + 18 + 24*2, (w-padding*3)/2, 24, "AUTOSCAN", fontInfo.buttonLabel_size);
// getPoll = new Button(x + padding + (w-padding*2)/2, y + padding*3 + 18 + 24, (w-padding*3)/2, 24, "GET POLL", fontInfo.buttonLabel_size);
// highBAUD = new Button(x + padding, y + padding*5 + 18 + 24*3, (w-padding*3)/2, 24, "HIGH BAUD", fontInfo.buttonLabel_size);
// setPoll = new Button(x + padding + (w-padding*2)/2, y + padding*5 + 18 + 24*3, (w-padding*3)/2, 24, "", fontInfo.buttonLabel_size);
// autoconnectNoStartDefault = new Button(x + padding, y + padding*6 + 18 + 24*4, (w-padding*3 )/2 , 24, "CONNECT 115200", fontInfo.buttonLabel_size);
// deraultBaud = new Button(x + padding + (w-padding*2)/2, y + padding*6 + 18 + 24*4, (w-padding*3 )/2, 24, "", fontInfo.buttonLabel_size);
// autoconnectNoStartHigh = new Button(x + padding, y + padding*7 + 18 + 24*5, (w-padding*3 )/2, 24, "CONNECT 230400", fontInfo.buttonLabel_size);
//Set help text
getChannel.setHelpText("Gets the current channel that your OpenBCI board and radio is on.");
setChannel.setHelpText("Sets the current channel that your OpenBCI board and radio are on.");
ovrChannel.setHelpText("Overrides the current channel of the OpenBCI radio, and sets it to that channel.");
getPoll.setHelpText("Gets the current POLL value.");
setPoll.setHelpText("Sets the current POLL value.");
defaultBAUD.setHelpText("Sets the BAUD rate to 115200.");
highBAUD.setHelpText("Sets the BAUD rate to 230400.");
autoscan.setHelpText("Scans through channels and finds a nearby OpenBCI board, then connects to that board.");
systemStatus.setHelpText("Gets the connection status of your OpenBCI board.");
autoconnectNoStartDefault.setHelpText("Automatically connects to a board with the DEFAULT (115200) BAUD");
autoconnectNoStartHigh.setHelpText("Automatically connects to a board with the HIGH (230400) BAUD");
getChannel.setHelpText("Get the current channel of your Cyton and USB Dongle");
setChannel.setHelpText("Change the channel of your Cyton and USB Dongle");
ovrChannel.setHelpText("Change the channel of the USB Dongle only");
autoscan.setHelpText("Scan through channels and connect to a nearby Cyton");
systemStatus.setHelpText("Get the connection status of your Cyton system");
// getPoll.setHelpText("Gets the current POLL value.");
// setPoll.setHelpText("Sets the current POLL value.");
// defaultBAUD.setHelpText("Sets the BAUD rate to 115200.");
// highBAUD.setHelpText("Sets the BAUD rate to 230400.");
// autoconnectNoStartDefault.setHelpText("Automatically connects to a board with the DEFAULT (115200) BAUD");
// autoconnectNoStartHigh.setHelpText("Automatically connects to a board with the HIGH (230400) BAUD");
}
public void update() {
@@ -1745,19 +1743,20 @@ class RadioConfigBox {
fill(bgColor);
textFont(h3, 16);
textAlign(LEFT, TOP);
text("RADIO CONFIGURATION (V2)", x + padding, y + padding);
text("RADIO CONFIGURATION (v2)", x + padding, y + padding);
popStyle();
getChannel.draw();
setChannel.draw();
ovrChannel.draw();
getPoll.draw();
setPoll.draw();
defaultBAUD.draw();
highBAUD.draw();
autoscan.draw();
autoconnectNoStartDefault.draw();
autoconnectNoStartHigh.draw();
systemStatus.draw();
autoscan.draw();
// getPoll.draw();
// setPoll.draw();
// defaultBAUD.draw();
// highBAUD.draw();
// autoconnectNoStartDefault.draw();
// autoconnectNoStartHigh.draw();
this.print_onscreen(last_message);
//the drawing of the sdTimes is handled earlier in ControlPanel.draw()
@@ -1767,9 +1766,9 @@ class RadioConfigBox {
public void print_onscreen(String localstring){
textAlign(LEFT);
fill(0);
rect(x + padding, y + (padding*8) + 18 + (24*6), (w-padding*3 + 5), 135 - 24 - padding);
rect(x + padding, y + (padding*8) + 18 + (24*2), (w-padding*3 + 5), 135 - 24 - padding);
fill(255);
text(localstring, x + padding + 10, y + (padding*8) + 18 + (24*6) + 15, (w-padding*3 ), 135 - 24 - padding -15);
text(localstring, x + padding + 10, y + (padding*8) + 18 + (24*2) + 15, (w-padding*3 ), 135 - 24 - padding -15);
this.last_message = localstring;
}
+7 -4
Ver Arquivo
@@ -150,8 +150,8 @@ void processNewData() {
// ...yLittleBuff_uV[Ichan] is the most recent raw data since the last call to this processing routine
// ...dataBuffY_filtY_uV[Ichan] is the full set of filtered data as shown in the time-domain plot in the GUI
// ...fftBuff[Ichan] is the FFT data structure holding the frequency spectrum as shown in the freq-domain plot in the GUI
// emg_widget.process(yLittleBuff_uV, dataBuffY_uV, dataBuffY_filtY_uV, fftBuff); //%%%
// ob_widget.process(); //%%%
// w_emg.process(yLittleBuff_uV, dataBuffY_uV, dataBuffY_filtY_uV, fftBuff); //%%%
// w_openbionics.process();
dataProcessing_user.process(yLittleBuff_uV, dataBuffY_uV, dataBuffY_filtY_uV, fftBuff);
@@ -353,7 +353,7 @@ class DataProcessing {
FilterConstants[] filtCoeff_bp = new FilterConstants[N_FILT_CONFIGS];
final int N_NOTCH_CONFIGS = 3;
FilterConstants[] filtCoeff_notch = new FilterConstants[N_NOTCH_CONFIGS];
private int currentFilt_ind = 0;
private int currentFilt_ind = 3;
private int currentNotch_ind = 0; // set to 0 to default to 60Hz, set to 1 to default to 50Hz
float data_std_uV[];
float polarity[];
@@ -626,10 +626,13 @@ class DataProcessing {
double foo;
//update the FFT (frequency spectrum)
// println("nchan = " + nchan);
for (int Ichan=0; Ichan < nchan; Ichan++) {
//copy the previous FFT data...enables us to apply some smoothing to the FFT data
for (int I=0; I < fftBuff[Ichan].specSize(); I++) prevFFTdata[I] = fftBuff[Ichan].getBand(I); //copy the old spectrum values
for (int I=0; I < fftBuff[Ichan].specSize(); I++) {
prevFFTdata[I] = fftBuff[Ichan].getBand(I); //copy the old spectrum values
}
//prepare the data for the new FFT
float[] fooData;
+1737 -1737
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+50 -6
Ver Arquivo
@@ -16,6 +16,9 @@
// Global Functions
//------------------------------------------------------------------------
boolean werePacketsDroppedGang = false;
int numPacketsDroppedGang = 0;
void clientEvent(Client someClient) {
// print("Server Says: ");
@@ -80,6 +83,7 @@ class OpenBCI_Ganglion {
final static int RESP_ERROR_UNKNOWN = 499;
final static int RESP_ERROR_BAD_PACKET = 500;
final static int RESP_ERROR_BAD_NOBLE_START = 501;
final static int RESP_ERROR_ALREADY_CONNECTED = 408;
final static int RESP_ERROR_COMMAND_NOT_RECOGNIZED = 406;
final static int RESP_ERROR_DEVICE_NOT_FOUND = 405;
@@ -265,11 +269,7 @@ class OpenBCI_Ganglion {
println("OpenBCI_Ganglion: Log: " + list[1]);
break;
case 'q':
if (waitingForResponse) {
waitingForResponse = false;
println("Node process up!");
}
println("OpenBCI_Ganglion: Status: 200");
processStatus(msg);
break;
default:
println("OpenBCI_Ganglion: parseMessage: default: " + msg);
@@ -316,7 +316,15 @@ class OpenBCI_Ganglion {
if ((dataPacket.sampleIndex - prevSampleIndex) != 1) {
if(dataPacket.sampleIndex != 0){ // if we rolled over, don't count as error
bleErrorCounter++;
werePacketsDroppedGang = true; //set this true to activate packet duplication in serialEvent
if(dataPacket.sampleIndex < prevSampleIndex){ //handle the situation in which the index jumps from 250s past 255, and back to 0
numPacketsDroppedGang = (dataPacket.sampleIndex+200) - prevSampleIndex; //calculate how many times the last received packet should be duplicated...
} else {
numPacketsDroppedGang = dataPacket.sampleIndex - prevSampleIndex; //calculate how many times the last received packet should be duplicated...
}
println("OpenBCI_Ganglion: apparent sampleIndex jump from Serial data: " + prevSampleIndex + " to " + dataPacket.sampleIndex + ". Keeping packet. (" + bleErrorCounter + ")");
println("numPacketsDropped = " + numPacketsDropped);
}
}
prevSampleIndex = dataPacket.sampleIndex;
@@ -335,7 +343,28 @@ class OpenBCI_Ganglion {
getRawValues(dataPacket);
// println(binary(dataPacket.values[0], 24) + '\n' + binary(dataPacket.rawValues[0][0], 8) + binary(dataPacket.rawValues[0][1], 8) + binary(dataPacket.rawValues[0][2], 8) + '\n'); //<>//
curDataPacketInd = (curDataPacketInd+1) % dataPacketBuff.length; // This is also used to let the rest of the code that it may be time to do something
ganglion.copyDataPacketTo(dataPacketBuff[curDataPacketInd]); // Resets isNewDataPacketAvailable to false
// KILL SPIKES!!!
if(werePacketsDroppedGang){
// println("Packets Dropped ... doing some stuff...");
for(int i = numPacketsDroppedGang; i > 0; i--){
int tempDataPacketInd = curDataPacketInd - i; //
if(tempDataPacketInd >= 0 && tempDataPacketInd < dataPacketBuff.length){
// println("i = " + i);
ganglion.copyDataPacketTo(dataPacketBuff[tempDataPacketInd]);
} else {
ganglion.copyDataPacketTo(dataPacketBuff[tempDataPacketInd+200]);
}
//put the last stored packet in # of packets dropped after that packet
}
//reset werePacketsDropped & numPacketsDropped
werePacketsDroppedGang = false;
numPacketsDroppedGang = 0;
}
switch (outputDataSource) {
case OUTPUT_SOURCE_ODF:
fileoutput_odf.writeRawData_dataPacket(dataPacketBuff[curDataPacketInd], ganglion.get_scale_fac_uVolts_per_count(), get_scale_fac_accel_G_per_count());
@@ -390,6 +419,21 @@ class OpenBCI_Ganglion {
}
}
}
private void processStatus(String msg) {
String[] list = split(msg, ',');
int code = Integer.parseInt(list[1]);
if (waitingForResponse) {
waitingForResponse = false;
println("Node process up!");
}
if (code == RESP_ERROR_BAD_NOBLE_START) {
println("OpenBCI_Ganglion: processStatus: Problem in the Hub");
output("Problem starting Ganglion Hub. Please make sure compatible USB is configured, then restart this GUI.");
} else {
println("OpenBCI_Ganglion: processStatus: Started Successfully");
}
}
private void processScan(String msg) {
String[] list = split(msg, ',');
@@ -617,7 +661,7 @@ class OpenBCI_Ganglion {
} else {
println("OpenBCI_Ganglion: changeChannelState(): deactivate: sending " + command_deactivate_channel[Ichan]);
safeTCPWrite(TCP_CMD_COMMAND + "," + command_deactivate_channel[Ichan] + TCP_STOP);
w_timeSeries.hsc.powerUpChannel(Ichan);
w_timeSeries.hsc.powerDownChannel(Ichan);
}
}
}
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+199 -186
Ver Arquivo
@@ -1,4 +1,4 @@
//<>//
///////////////////////////////////////////////////////////////////////////////
//
// GUI for controlling the ADS1299-based OpenBCI
@@ -60,7 +60,7 @@ final int NCHAN_CYTON = 8;
final int NCHAN_CYTON_DAISY = 16;
final int NCHAN_GANGLION = 4;
boolean hasIntroAnimation = false;
boolean hasIntroAnimation = true;
PImage cog;
Gif loadingGIF;
Gif loadingGIF_blue;
@@ -218,7 +218,7 @@ PFont p6; //small Open Sans
ButtonHelpText buttonHelpText;
EMG_Widget emg_widget;
//EMG_Widget emg_widget;
PulseSensor_Widget pulseWidget;
boolean no_start_connection = false;
@@ -230,7 +230,8 @@ int indices = 0;
boolean synthesizeData = false;
int timeOfSetup = 0;
boolean isGanglion = false;
boolean isHubInitialized = false;
boolean isGanglionObjectInitialized = false;
color bgColor = color(1, 18, 41);
color openbciBlue = color(31, 69, 110);
int COLOR_SCHEME_DEFAULT = 1;
@@ -240,7 +241,7 @@ int colorScheme = COLOR_SCHEME_ALTERNATIVE_A;
Process nodeHubby;
int hubPid = 0;
String nodeHubName = "Ganglion Hub";
String nodeHubName = "GanglionHub";
Robot rob3115;
//-----------------------------------------1-------------------------------
@@ -255,9 +256,12 @@ void setup() {
// server on shut down of this app, the main process.
// prepareExitHandler();
if (dev == false) {
// On windows wait to start the hub until Ganglion is clicked on in the control panel.
// See issue #111
hubStop(); //kill any existing hubs before starting a new one..
hubStart();
prepareExitHandler();
if (!isWindows()) {
hubInit();
}
}
println("Welcome to the Processing-based OpenBCI GUI!"); //Welcome line.
@@ -333,12 +337,12 @@ void setup() {
//attempt to open a serial port for "output"
try {
verbosePrint("OpenBCI_GUI.pde: attempting to open serial port for data output = " + serial_output_portName);
verbosePrint("OpenBCI_GUI.pde: attempting to open serial/COM port for data output = " + serial_output_portName);
serial_output = new Serial(this, serial_output_portName, serial_output_baud); //open the com port
serial_output.clear(); // clear anything in the com port's buffer
}
catch (RuntimeException e) {
verbosePrint("OpenBCI_GUI.pde: *** ERROR ***: Could not open " + serial_output_portName);
verbosePrint("OpenBCI_GUI.pde: could not open " + serial_output_portName);
}
// println("OpenBCI_GUI: setup: hub is running " + ganglion.isHubRunning());
@@ -373,20 +377,31 @@ void draw() {
* This allows us to kill the running node process on quit.
*/
private void prepareExitHandler () {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run () {
System.out.println("SHUTDOWN HOOK");
try {
if (hubStop()) {
System.out.println("SHUTDOWN HUB");
} else {
System.out.println("FAILED TO SHUTDOWN HUB");
}
} catch (Exception ex){
ex.printStackTrace(); // not much else to do at this point
}
}
}));
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run () {
System.out.println("SHUTDOWN HOOK");
try {
if (hubStop()) {
System.out.println("SHUTDOWN HUB");
} else {
System.out.println("FAILED TO SHUTDOWN HUB");
}
}
catch (Exception ex) {
ex.printStackTrace(); // not much else to do at this point
}
}
}
));
}
/**
* Starts the hub and sets prepares the exit handler.
*/
void hubInit() {
isHubInitialized = true;
hubStart();
prepareExitHandler();
}
/**
@@ -398,16 +413,17 @@ void hubStart() {
// https://forum.processing.org/two/discussion/13053/use-launch-for-applications-kept-in-data-folder
if (isWindows()) {
println("OpenBCI_GUI: hubStart: OS Detected: Windows");
nodeHubby = launch(dataPath("Ganglion Hub.exe"));
nodeHubby = launch(dataPath("GanglionHub.exe"));
} else if (isLinux()) {
println("OpenBCI_GUI: hubStart: OS Detected: Linux");
nodeHubby = exec(dataPath("Ganglion Hub"));
nodeHubby = exec(dataPath("GanglionHub"));
} else {
println("OpenBCI_GUI: hubStart: OS Detected: Mac");
nodeHubby = launch(dataPath("Ganglion Hub.app"));
nodeHubby = launch(dataPath("GanglionHub.app"));
}
// hubRunning = true;
} catch (Exception e) {
}
catch (Exception e) {
println("hubStart: " + e);
}
}
@@ -449,20 +465,22 @@ void killRunningProcessMac() {
String line;
Process p = Runtime.getRuntime().exec("ps -e");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (line.contains(nodeHubName)) {
try {
endProcess(getProcessIdFromLineMac(line));
println("Killed: " + line);
} catch (Exception err) {
}
catch (Exception err) {
println("Failed to stop process: " + line + "\n\n");
err.printStackTrace();
}
}
}
input.close();
} catch (Exception err) {
}
catch (Exception err) {
err.printStackTrace();
}
}
@@ -473,9 +491,10 @@ void killRunningProcessMac() {
*/
boolean killRunningprocessWin() {
try {
Runtime.getRuntime().exec("taskkill /F /IM Ganglion Hub.exe");
Runtime.getRuntime().exec("taskkill /F /IM GanglionHub.exe");
return true;
} catch (Exception err) {
}
catch (Exception err) {
err.printStackTrace();
return false;
}
@@ -495,7 +514,8 @@ void endProcess(int pid) {
Runtime rt = Runtime.getRuntime();
try {
rt.exec("kill -9 " + pid);
} catch (IOException err) {
}
catch (IOException err) {
err.printStackTrace();
}
}
@@ -507,144 +527,147 @@ int byteRate_perSec = 0;
int drawLoop_counter = 0;
//used to init system based on initial settings...Called from the "Start System" button in the GUI's ControlPanel
void setupWidgetManager() {
wm = new WidgetManager(this);
}
void initSystem() {
println();
println();
println("=================================================");
println("|| INITIALIZING SYSTEM ||");
println("=================================================");
println();
println();
println();
println("=================================================");
println("|| INITIALIZING SYSTEM ||");
println("=================================================");
println();
verbosePrint("OpenBCI_GUI: initSystem: -- Init 0 -- " + millis());
timeOfInit = millis(); //store this for timeout in case init takes too long
verbosePrint("timeOfInit = " + timeOfInit);
verbosePrint("OpenBCI_GUI: initSystem: -- Init 0 -- " + millis());
timeOfInit = millis(); //store this for timeout in case init takes too long
verbosePrint("timeOfInit = " + timeOfInit);
//prepare data variables
verbosePrint("OpenBCI_GUI: initSystem: Preparing data variables...");
dataBuffX = new float[(int)(dataBuff_len_sec * get_fs_Hz_safe())];
dataBuffY_uV = new float[nchan][dataBuffX.length];
dataBuffY_filtY_uV = new float[nchan][dataBuffX.length];
accelerometerBuff = new float[3][500]; // 500 points
for (int i=0; i<n_aux_ifEnabled; i++) {
for (int j=0; j<accelerometerBuff[0].length; j++) {
accelerometerBuff[i][j] = 0;
//prepare data variables
verbosePrint("OpenBCI_GUI: initSystem: Preparing data variables...");
dataBuffX = new float[(int)(dataBuff_len_sec * get_fs_Hz_safe())];
dataBuffY_uV = new float[nchan][dataBuffX.length];
dataBuffY_filtY_uV = new float[nchan][dataBuffX.length];
accelerometerBuff = new float[3][500]; // 500 points
for (int i=0; i<n_aux_ifEnabled; i++) {
for (int j=0; j<accelerometerBuff[0].length; j++) {
accelerometerBuff[i][j] = 0;
}
}
//data_std_uV = new float[nchan];
data_elec_imp_ohm = new float[nchan];
is_railed = new DataStatus[nchan];
for (int i=0; i<nchan; i++) is_railed[i] = new DataStatus(threshold_railed, threshold_railed_warn);
for (int i=0; i<nDataBackBuff; i++) {
dataPacketBuff[i] = new DataPacket_ADS1299(nchan, n_aux_ifEnabled);
}
dataProcessing = new DataProcessing(nchan, get_fs_Hz_safe());
dataProcessing_user = new DataProcessing_User(nchan, get_fs_Hz_safe());
//initialize the data
prepareData(dataBuffX, dataBuffY_uV, get_fs_Hz_safe());
verbosePrint("OpenBCI_GUI: initSystem: -- Init 1 -- " + millis());
//initialize the FFT objects
for (int Ichan=0; Ichan < nchan; Ichan++) {
verbosePrint("Init FFT Buff – "+Ichan);
fftBuff[Ichan] = new FFT(Nfft, get_fs_Hz_safe());
} //make the FFT objects
initializeFFTObjects(fftBuff, dataBuffY_uV, Nfft, get_fs_Hz_safe());
//prepare some signal processing stuff
//for (int Ichan=0; Ichan < nchan; Ichan++) { detData_freqDomain[Ichan] = new DetectionData_FreqDomain(); }
verbosePrint("OpenBCI_GUI: initSystem: -- Init 2 -- " + millis());
//prepare the source of the input data
switch (eegDataSource) {
case DATASOURCE_NORMAL_W_AUX:
int nEEDataValuesPerPacket = nchan;
boolean useAux = false;
if (eegDataSource == DATASOURCE_NORMAL_W_AUX) useAux = true; //switch this back to true CHIP 2014-11-04
openBCI = new OpenBCI_ADS1299(this, openBCI_portName, openBCI_baud, nEEDataValuesPerPacket, useAux, n_aux_ifEnabled); //this also starts the data transfer after XX seconds
break;
case DATASOURCE_SYNTHETIC:
//do nothing
break;
case DATASOURCE_PLAYBACKFILE:
//open and load the data file
println("OpenBCI_GUI: initSystem: loading playback data from " + playbackData_fname);
try {
playbackData_table = new Table_CSV(playbackData_fname);
}
catch (Exception e) {
println("OpenBCI_GUI: initSystem: could not open file for playback: " + playbackData_fname);
println(" : quitting...");
exit();
}
println("OpenBCI_GUI: initSystem: loading complete. " + playbackData_table.getRowCount() + " rows of data, which is " + round(float(playbackData_table.getRowCount())/get_fs_Hz_safe()) + " seconds of EEG data");
//removing first column of data from data file...the first column is a time index and not eeg data
playbackData_table.removeColumn(0);
break;
case DATASOURCE_GANGLION:
ganglion.connectBLE(ganglion_portName);
break;
default:
break;
}
verbosePrint("OpenBCI_GUI: initSystem: -- Init 3 -- " + millis());
if (abandonInit) {
haltSystem();
println("Failed to connect to data source...");
output("Failed to connect to data source...");
} else {
println(" 3a -- " + millis());
//initilize the GUI
// initializeGUI(); //will soon be destroyed... and replaced with ... wm = new WidgetManager(this);
topNav.initSecondaryNav();
println(" 3b -- " + millis());
// wm = new WidgetManager(this);
setupWidgetManager();
if (!abandonInit) {
println(" 3c -- " + millis());
// setupGUIWidgets(); //####
//open data file
if (eegDataSource == DATASOURCE_NORMAL_W_AUX) openNewLogFile(fileName); //open a new log file
if (eegDataSource == DATASOURCE_GANGLION) openNewLogFile(fileName); // println("open ganglion output file");
nextPlayback_millis = millis(); //used for synthesizeData and readFromFile. This restarts the clock that keeps the playback at the right pace.
if (eegDataSource != DATASOURCE_GANGLION && eegDataSource != DATASOURCE_NORMAL_W_AUX) {
systemMode = SYSTEMMODE_POSTINIT; //tell system it's ok to leave control panel and start interfacing GUI
}
}
//data_std_uV = new float[nchan];
data_elec_imp_ohm = new float[nchan];
is_railed = new DataStatus[nchan];
for (int i=0; i<nchan; i++) is_railed[i] = new DataStatus(threshold_railed, threshold_railed_warn);
for (int i=0; i<nDataBackBuff; i++) {
dataPacketBuff[i] = new DataPacket_ADS1299(nchan, n_aux_ifEnabled);
}
dataProcessing = new DataProcessing(nchan, get_fs_Hz_safe());
dataProcessing_user = new DataProcessing_User(nchan, get_fs_Hz_safe());
//initialize the data
prepareData(dataBuffX, dataBuffY_uV, get_fs_Hz_safe());
verbosePrint("OpenBCI_GUI: initSystem: -- Init 1 -- " + millis());
//initialize the FFT objects
for (int Ichan=0; Ichan < nchan; Ichan++) {
verbosePrint("Init FFT Buff – "+Ichan);
fftBuff[Ichan] = new FFT(Nfft, get_fs_Hz_safe());
} //make the FFT objects
initializeFFTObjects(fftBuff, dataBuffY_uV, Nfft, get_fs_Hz_safe());
//prepare some signal processing stuff
//for (int Ichan=0; Ichan < nchan; Ichan++) { detData_freqDomain[Ichan] = new DetectionData_FreqDomain(); }
verbosePrint("OpenBCI_GUI: initSystem: -- Init 2 -- " + millis());
//prepare the source of the input data
switch (eegDataSource) {
case DATASOURCE_NORMAL_W_AUX:
int nEEDataValuesPerPacket = nchan;
boolean useAux = false;
if (eegDataSource == DATASOURCE_NORMAL_W_AUX) useAux = true; //switch this back to true CHIP 2014-11-04
openBCI = new OpenBCI_ADS1299(this, openBCI_portName, openBCI_baud, nEEDataValuesPerPacket, useAux, n_aux_ifEnabled); //this also starts the data transfer after XX seconds
break;
case DATASOURCE_SYNTHETIC:
//do nothing
break;
case DATASOURCE_PLAYBACKFILE:
//open and load the data file
println("OpenBCI_GUI: initSystem: loading playback data from " + playbackData_fname);
try {
playbackData_table = new Table_CSV(playbackData_fname);
}
catch (Exception e) {
println("OpenBCI_GUI: initSystem: could not open file for playback: " + playbackData_fname);
println(" : quitting...");
exit();
}
println("OpenBCI_GUI: initSystem: loading complete. " + playbackData_table.getRowCount() + " rows of data, which is " + round(float(playbackData_table.getRowCount())/get_fs_Hz_safe()) + " seconds of EEG data");
//removing first column of data from data file...the first column is a time index and not eeg data
playbackData_table.removeColumn(0);
break;
case DATASOURCE_GANGLION:
ganglion.connectBLE(ganglion_portName);
break;
default:
break;
}
verbosePrint("OpenBCI_GUI: initSystem: -- Init 3 -- " + millis());
if(abandonInit){
haltSystem();
println("Failed to connect to data source...");
output("Failed to connect to data source...");
} else{
println(" 3a -- " + millis());
//initilize the GUI
// initializeGUI(); //will soon be destroyed... and replaced with ... wm = new WidgetManager(this);
topNav.initSecondaryNav();
println(" 3b -- " + millis());
wm = new WidgetManager(this);
if(!abandonInit){
println(" 3c -- " + millis());
// setupGUIWidgets(); //####
//open data file
if (eegDataSource == DATASOURCE_NORMAL_W_AUX) openNewLogFile(fileName); //open a new log file
if (eegDataSource == DATASOURCE_GANGLION) openNewLogFile(fileName); // println("open ganglion output file");
nextPlayback_millis = millis(); //used for synthesizeData and readFromFile. This restarts the clock that keeps the playback at the right pace.
if (eegDataSource != DATASOURCE_GANGLION && eegDataSource != DATASOURCE_NORMAL_W_AUX) {
systemMode = SYSTEMMODE_POSTINIT; //tell system it's ok to leave control panel and start interfacing GUI
}
if(!abandonInit){
println("WOOHOO!!!");
controlPanel.close();
} else {
haltSystem();
println("Failed to connect to data source...");
output("Failed to connect to data source...");
}
if (!abandonInit) {
println("WOOHOO!!!");
controlPanel.close();
} else {
haltSystem();
println("Failed to connect to data source...");
output("Failed to connect to data source...");
}
} else {
haltSystem();
println("Failed to connect to data source...");
output("Failed to connect to data source...");
}
}
verbosePrint("OpenBCI_GUI: initSystem: -- Init 4 -- " + millis());
verbosePrint("OpenBCI_GUI: initSystem: -- Init 4 -- " + millis());
//reset init variables
midInit = false;
abandonInit = false;
}
/**
@@ -662,7 +685,7 @@ float get_fs_Hz_safe() {
//halt the data collection
void haltSystem() {
println("openBCI_GUI: haltSystem: Halting system for reconfiguration of settings...");
if(initSystemButton.but_txt == "STOP SYSTEM"){
if (initSystemButton.but_txt == "STOP SYSTEM") {
initSystemButton.but_txt = "START SYSTEM";
}
stopRunning(); //stop data transfer
@@ -680,7 +703,7 @@ void haltSystem() {
//set all data source list items inactive
//reset connect loadStrings
openBCI_portName = "";
openBCI_portName = "N/A"; // Fixes inability to reconnect after halding JAM 1/2017
ganglion_portName = "";
controlPanel.resetListItems();
@@ -699,14 +722,14 @@ void haltSystem() {
void systemUpdate() { // for updating data values and variables
if(millis() - timeOfSetup >= 1000 && isGanglion == false){
if (isHubInitialized && isGanglionObjectInitialized == false && millis() - timeOfSetup >= 1500) {
ganglion = new OpenBCI_Ganglion(this);
println("Instantiating Ganglion object...");
isGanglion = true;
isGanglionObjectInitialized = true;
}
//update the sync state with the OpenBCI hardware
if(openBCI.state == openBCI.STATE_NOCOM || openBCI.state == openBCI.STATE_COMINIT || openBCI.state == openBCI.STATE_SYNCWITHHARDWARE){
if (openBCI.state == openBCI.STATE_NOCOM || openBCI.state == openBCI.STATE_COMINIT || openBCI.state == openBCI.STATE_SYNCWITHHARDWARE) {
openBCI.updateSyncState(sdSetting);
}
@@ -723,8 +746,6 @@ void systemUpdate() { // for updating data values and variables
if (widthOfLastScreen != width || heightOfLastScreen != height) {
topNav.screenHasBeenResized(width, height);
}
}
if (systemMode == SYSTEMMODE_POSTINIT) {
if (isRunning) {
@@ -759,12 +780,10 @@ void systemUpdate() { // for updating data values and variables
}
redrawScreenNow=true;
} else {
//not enough data has arrived yet... only update the channel controller
}
} else if(eegDataSource == DATASOURCE_PLAYBACKFILE && !has_processed && !isOldData) {
} else if (eegDataSource == DATASOURCE_PLAYBACKFILE && !has_processed && !isOldData) {
lastReadDataPacketInd = 0;
pointCounter = 0;
try {
@@ -804,7 +823,6 @@ void systemUpdate() { // for updating data values and variables
wm.update();
playground.update();
}
}
@@ -826,16 +844,16 @@ void systemDraw() { //for drawing to the screen
switch (eegDataSource) {
case DATASOURCE_NORMAL_W_AUX:
switch (outputDataSource) {
case OUTPUT_SOURCE_ODF:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps" + ", " + int(float(fileoutput_odf.getRowsWritten())/get_fs_Hz_safe()) + " secs Saved, Writing to " + output_fname);
break;
case OUTPUT_SOURCE_BDF:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps" + ", " + int(fileoutput_bdf.getRecordsWritten()) + " secs Saved, Writing to " + output_fname);
break;
case OUTPUT_SOURCE_NONE:
default:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps");
break;
case OUTPUT_SOURCE_ODF:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps" + ", " + int(float(fileoutput_odf.getRowsWritten())/get_fs_Hz_safe()) + " secs Saved, Writing to " + output_fname);
break;
case OUTPUT_SOURCE_BDF:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps" + ", " + int(fileoutput_bdf.getRecordsWritten()) + " secs Saved, Writing to " + output_fname);
break;
case OUTPUT_SOURCE_NONE:
default:
surface.setTitle(int(frameRate) + " fps, Byte Count = " + openBCI_byteCount + ", bit rate = " + byteRate_perSec*8 + " bps");
break;
}
break;
case DATASOURCE_SYNTHETIC:
@@ -881,9 +899,6 @@ void systemDraw() { //for drawing to the screen
//dataProcessing_user.draw();
drawContainers();
} else { //systemMode != 10
//still print title information about fps
surface.setTitle(int(frameRate) + " fps — OpenBCI GUI");
@@ -934,7 +949,7 @@ void systemDraw() { //for drawing to the screen
//draw presentation last, bc it is intended to be rendered on top of the GUI ...
if (drawPresentation) {
myPresentation.draw();
// emg_widget.drawTriggerFeedback();
//emg_widget.drawTriggerFeedback();
//dataProcessing_user.drawTriggerFeedback();
}
@@ -960,11 +975,11 @@ void introAnimation() {
tint(255, transparency);
//draw OpenBCI Logo Front & Center
image(cog, width/2, height/2, width/6, width/6);
textFont(p3,16);
textFont(p3, 16);
textLeading(24);
fill(31,69,110, transparency);
textAlign(CENTER,CENTER);
text("OpenBCI GUI v2.0\nDecember 2016", width/2, height/2 + width/9);
fill(31, 69, 110, transparency);
textAlign(CENTER, CENTER);
text("OpenBCI GUI v2.1.1\nJanuary 2017", width/2, height/2 + width/9);
}
//exit intro animation at t2
@@ -999,7 +1014,6 @@ void mouseOutOfBounds() {
catch (RuntimeException e) {
verbosePrint("Error happened while cursor left application...");
}
} else {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
loc = getWindowLocation(P2D);
@@ -1007,7 +1021,6 @@ void mouseOutOfBounds() {
appletOriginY = (int)loc.y;
windowOriginSet = true;
mouseInFrame = true;
}
}
}
-509
Ver Arquivo
@@ -1,509 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
//
// OpenBionics Widget is an easy way to interface with your OpenBionics
// hand using the OpenBCI gui! Use '\' to toggle between FFT and the widget!
//
// Colin Fausnaught, October 2016
//
// KNOWN BUGS: Research mode is sometimes not toggled correctly, will need to fix this by v2 release.
//
///////////////////////////////////////////////////////////////////////////////
ControlP5 configP5;
String obName;
String obBaud;
List serialListOB;
List baudListOB;
int drawConfig;
int[] fingerChans;
class OpenBionics_Widget {
int x, y, w, h;
PApplet parent;
Serial OpenBionicsHand;
PFont f = createFont("Arial Bold", 24); //for "FFT Plot" Widget Title
PFont f2 = createFont("Arial", 18); //for dropdown name titles (above dropdown widgets)
int parentContainer = 9; //which container is it mapped to by default?
boolean thumbPressed,indexPressed,middlePressed,ringPressed,littlePressed,palmPressed = false;
boolean researchMode = false;
PImage hand;
PImage thumb;
PImage index;
PImage middle;
PImage ring;
PImage little;
PImage palm;
int last_command;
Button configClose;
Button configConfirm;
Button connect;
MenuList obChanList;
//constructor 1
OpenBionics_Widget(PApplet _parent) {
parent = _parent;
baudListOB = Arrays.asList("230400","115200","57600","38400","28800","19200","14400","9600","7200","4800","3600","2400","1800","1200","600","300");
drawConfig = -1;
fingerChans = new int[6];
for(int i = 0; i<6; i++) fingerChans[i] = -1;
configP5 = new ControlP5(parent);
hand = loadImage("hand.png");
thumb = loadImage("thumb_over.png");
index = loadImage("index_over.png");
middle = loadImage("middle_over.png");
ring = loadImage("ring_over.png");
little = loadImage("little_over.png");
palm = loadImage("palm_over.png");
x = (int)container[parentContainer].x;
y = (int)container[parentContainer].y;
w = (int)container[parentContainer].w;
h = (int)container[parentContainer].h;
configClose = new Button(int(x) + w/4,int(y) + 3*navHeight,int(w/25.3),int(w/25.3),"X",fontInfo.buttonLabel_size);
configConfirm = new Button(int(x) + w/2 + w/7,int(y) + 12*navHeight,int(w/10.12),int(w/25.3),"OKAY",fontInfo.buttonLabel_size);
connect = new Button(int(x) + w - (w/6), int(y) + 14*navHeight, int(w/8), int(w/25.3), "CONNECT", fontInfo.buttonLabel_size);
obChanList = new MenuList(configP5, "obChanList", 100, 120, f2);
obChanList.setPosition(x+w/3 + w/12, y + h/3 + h/16);
obChanList.addItem(makeItem("NONE"));
obChanList.activeItem = 0;
for(int i = 0; i < nchan; i++) obChanList.addItem(makeItem("" + (i+1)));
String[] serialPortsLocal = Serial.list();
serialListOB = new ArrayList();
for (int i = 0; i < serialPortsLocal.length; i++) {
String tempPort = serialPortsLocal[(serialPortsLocal.length-1) - i]; //list backwards... because usually our port is at the bottom
if(!tempPort.equals(openBCI_portName)) serialListOB.add(tempPort);
}
setupDropdownMenus(parent);
}
void process(){
int output_normalized;
StringBuilder researchCommand = new StringBuilder();
if(OpenBionicsHand != null ){
if(!researchMode){
OpenBionicsHand.write("A10\n");
researchMode = true;
}
byte inByte = byte(OpenBionicsHand.read());
println(inByte);
}
if(fingerChans[5] == -1){
if(OpenBionicsHand != null){
for(int i = 0; i<5; i++){
//================= OpenBionics Analog Movement =======================
if(fingerChans[i] == -1) output_normalized = 0;
else output_normalized = int(map(emg_widget.motorWidgets[fingerChans[i]].output_normalized, 0, 1, 0, 1023));
if(i == 4) researchCommand.append(output_normalized + "\n");
else researchCommand.append(output_normalized + ",");
}
OpenBionicsHand.write(researchCommand.toString());
}
}
else {
if(OpenBionicsHand != null){
output_normalized = int(map(emg_widget.motorWidgets[fingerChans[5]].output_normalized, 0, 1, 0, 100));
OpenBionicsHand.write("G0P" + output_normalized + "\n");
}
}
}
void setupDropdownMenus(PApplet _parent) {
//ControlP5 Stuff
int dropdownPos;
int dropdownWidth = 100;
cp5_colors = new CColor();
cp5_colors.setActive(color(150, 170, 200)); //when clicked
cp5_colors.setForeground(color(125)); //when hovering
cp5_colors.setBackground(color(255)); //color of buttons
cp5_colors.setCaptionLabel(color(1, 18, 41)); //color of text
cp5_colors.setValueLabel(color(0, 0, 255));
configP5.setColor(cp5_colors);
configP5.setAutoDraw(false);
//-------------------------------------------------------------
//MAX FREQUENCY (ie X Axis) DROPDOWN
//-------------------------------------------------------------
dropdownPos = 4; //work down from 4 since we're starting on the right side now...
configP5.addScrollableList("OpenBionicsSerialOut")
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-((dropdownPos+1)), navHeight+(y+2)) //float right
.setOpen(false)
.setSize(dropdownWidth, (serialListOB.size()+1)*(navBarHeight-4))
.setScrollSensitivity(0.0)
.setBarHeight(navHeight - 4)
.setItemHeight(navHeight - 4)
.addItems(serialListOB)
.setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
;
configP5.getController("OpenBionicsSerialOut")
.getCaptionLabel()
.setText("Serial Port")
.setSize(12)
.getStyle()
;
//-------------------------------------------------------------
//Logarithmic vs. Linear DROPDOWN
//-------------------------------------------------------------
dropdownPos = 0;
configP5.addScrollableList("BaudList")
//.setPosition(w-(dropdownWidth*dropdownPos)-(2*(dropdownPos+1)), navHeight+(y+2)) // float left
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1)), navHeight+(y+2))
.setOpen(false)
.setSize(dropdownWidth, (baudListOB.size()+1)*(navBarHeight-4))
.setScrollSensitivity(0.0)
.setBarHeight(navHeight - 4)
.setItemHeight(navHeight - 4)
.addItems(baudListOB)
.setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST
;
configP5.getController("BaudList")
.getCaptionLabel()
.setText("BAUD")
.setSize(12)
.getStyle()
;
}
void update() { } //may be used later
void draw() {
if(drawBionics){
pushStyle();
configP5.setVisible(true);
//draw FFT Graph w/ all plots
noStroke();
fill(255);
rect(x, y, w, h);
//draw nav bars and button bars
fill(150, 150, 150);
rect(x, y, w, navHeight); //top bar
fill(200, 200, 200);
rect(x, y+navHeight, w, navHeight); //button bar
fill(255);
rect(x+2, y+2, navHeight-4, navHeight-4);
fill(bgColor, 100);
//rect(x+3,y+3, (navHeight-7)/2, navHeight-10);
rect(x+4, y+4, (navHeight-10)/2, (navHeight-10)/2);
rect(x+4, y+((navHeight-10)/2)+5, (navHeight-10)/2, (navHeight-10)/2);
rect(x+((navHeight-10)/2)+5, y+4, (navHeight-10)/2, (navHeight-10)/2);
rect(x+((navHeight-10)/2)+5, y+((navHeight-10)/2)+5, (navHeight-10)/2, (navHeight-10 )/2);
//text("FFT Plot", x+w/2, y+navHeight/2)
fill(bgColor);
textAlign(LEFT, CENTER);
textFont(f);
textSize(18);
text("OpenBionics", x+navHeight+2, y+navHeight/2 - 2); //title of widget -- left
//textAlign(CENTER,CENTER); text("FFT Plot", w/2, y+navHeight/2 - 2); //title of widget -- left
//fill(255,0,0,150);
//rect(x,y,w,h);
//draw dropdown titles
int dropdownPos = 1; //used to loop through drop down titles ... should use for loop with titles in String array, but... laziness has ensued. -Conor
int dropdownWidth = 100;
textFont(f2);
textSize(12);
textAlign(CENTER, BOTTOM);
fill(bgColor);
text("OpenBionics Serial Out", x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1))+dropdownWidth/2, y+(navHeight-2));
dropdownPos = 0;
text("Baud List", x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1))+dropdownWidth/2, y+(navHeight-2));
//draw dropdown menus
switch(drawConfig){
case -1:
image(hand,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
if(overThumb()) image(thumb,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overIndex()) image(index,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overMiddle()) image(middle,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overRing()) image(ring,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overLittle()) image(little,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overPalm()) image(palm,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
configP5.get(MenuList.class, "obChanList").setVisible(false);
configP5.get(MenuList.class, "obChanList").activeItem = 0;
connect.draw();
break;
case 0:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Thumb Finger Channel Selection", x + w/2, y + 4*navHeight);
break;
case 1:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Index Finger Channel Selection", x + w/2, y + 4*navHeight);
break;
case 2:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Middle Finger Channel Selection", x + w/2, y + 4*navHeight);
break;
case 3:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Ring Finger Channel Selection", x + w/2, y + 4*navHeight);
break;
case 4:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Little Finger Channel Selection", x + w/2, y + 4*navHeight);
break;
case 5:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
textFont(f);
textSize(12);
text("Hand Channel Selection", x + w/2, y + 4*navHeight);
break;
}
configP5.draw();
popStyle();
}
}
void screenResized(PApplet _parent, int _winX, int _winY) {
//when screen is resized...
//update position/size of FFT widget
x = (int)container[parentContainer].x;
y = (int)container[parentContainer].y;
w = (int)container[parentContainer].w;
h = (int)container[parentContainer].h;
configClose = new Button(int(x) + w/4,int(y) + 3*navHeight,int(w/25.3),int(w/25.3),"X",fontInfo.buttonLabel_size);
configConfirm = new Button(int(x) + w/2 + w/7,int(y) + 12*navHeight,int(w/10.12),int(w/25.3),"OKAY",fontInfo.buttonLabel_size);
//update dropdown menu positions
configP5.setGraphics(_parent, 0, 0); //remaps the cp5 controller to the new PApplet window size
int dropdownPos;
int dropdownWidth = 60;
dropdownPos = 1; //work down from 4 since we're starting on the right side now...
configP5.getController("OpenBionicsSerialOut")
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1)), navHeight+(y+2)) //float right
;
dropdownPos = 0;
try{
configP5.getController("LogLin")
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1)), navHeight+(y+2)) //float right
;
}
catch(Exception e){
println("error resizing...");
}
}
void mousePressed() {
//called by GUI_Widgets.pde
if(drawConfig == -1){
if(overThumb()) thumbPressed = true;
else if(overIndex()) indexPressed = true;
else if(overMiddle()) middlePressed = true;
else if(overRing()) ringPressed = true;
else if(overLittle()) littlePressed = true;
else if(overPalm()) palmPressed = true;
else if(connect.isMouseHere()) connect.wasPressed = true;
}
else{
if(configClose.isMouseHere()) configClose.wasPressed= true;
else if(configConfirm.isMouseHere()) configConfirm.wasPressed= true;
}
}
void mouseReleased() {
//called by GUI_Widgets.pde
if(drawConfig == -1){
if (overThumb() && thumbPressed){drawConfig = 0;}
else if (overIndex() && indexPressed){drawConfig= 1;}
else if (overMiddle() && middlePressed){drawConfig = 2;}
else if (overRing() && ringPressed){drawConfig = 3;}
else if (overLittle() && littlePressed){drawConfig = 4;}
else if (overPalm() && palmPressed){drawConfig = 5;}
else if(connect.isMouseHere() && connect.wasPressed){
//Connect to OpenBionics Hand
try{
OpenBionicsHand = new Serial(parent,obName,Integer.parseInt(obBaud));
verbosePrint("Connected to OpenBionics Hand");
}
catch(Exception e){
println(e);
verbosePrint("Could not connect to OpenBionics Hand");
}
}
thumbPressed = false;
indexPressed = false;
middlePressed = false;
ringPressed = false;
littlePressed = false;
palmPressed = false;
cursor(ARROW);
}
else{
if(configClose.isMouseHere() && configClose.wasPressed) {
configClose.wasPressed= false;
drawConfig = -1;
}
else if(configConfirm.isMouseHere() && configConfirm.wasPressed){
configConfirm.wasPressed= false;
drawConfig = -1;
}
}
}
boolean overThumb(){
if(mouseX >= x + w/3.9 && mouseX <=x + w/2.5 && mouseY >= y + h/1.8 && mouseY <= y + h/1.32){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overIndex(){
if(mouseX >= x + w/2.65 && mouseX <=x + w/2.07 && mouseY >= y + h/4.89 && mouseY <= y + h/1.99){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overMiddle(){
if(mouseX >= x + w/2.01 && mouseX <=x + w/1.79 && mouseY >= y + h/7.08 && mouseY <= y + h/2.14){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overRing(){
if(mouseX >= x + w/1.73 && mouseX <=x + w/1.5 && mouseY >= y + h/5.59 && mouseY <= y + h/1.95){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overLittle(){
if(mouseX >= x + w/1.54 && mouseX <=x + w/1.34 && mouseY >= y + h/3.13 && mouseY <= y + h/1.78){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overPalm(){
if(mouseX >= x + w/2.47 && mouseX <=x + w/1.48 && mouseY >= y + h/1.89 && mouseY <= y + h/1.05){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
//void keyPressed() {
// //called by GUI_Widgets.pde
//}
//void keyReleased() {
// //called by GUI_Widgets.pde
//}
}
void OpenBionicsSerialOut(int n){
obName = (String)serialListOB.get(n);
}
void BaudList(int n){
obBaud = (String)baudListOB.get(n);
}
void obChanList(int n){
//println("Value: "+ (n-1));
fingerChans[drawConfig] = n - 1;
}
+11 -3
Ver Arquivo
@@ -74,9 +74,10 @@ class Presentation {
public void draw() {
// ----- Drawing Presentation -------
if (drawPresentation == true) {
image(presentationSlides[currentSlide], 0, 0, width, height);
}
pushStyle();
image(presentationSlides[currentSlide], 0, 0, width, height);
if(lockSlides){
//draw red rectangle to indicate that slides are locked
@@ -85,5 +86,12 @@ class Presentation {
rect(width - 50, 25, 25, 25);
popStyle();
}
textFont(p3, 16);
fill(openbciBlue);
textAlign(CENTER);
text("Press [Enter] to exit presentation mode.", width/2, 31*(height/32));
popStyle();
}
}
+340 -210
Ver Arquivo
@@ -11,6 +11,9 @@
// rather than the OpenBCI_ADS1299 class. I just found this easier to work
// with.
//
// Modified by Joel Murphy, January 2017
//
//
// KNOWN ISSUES:
//
// TODO:
@@ -25,154 +28,267 @@ void autoconnect(){
serialPorts = Serial.list();
for(int i = 0; i < serialPorts.length; i++){
// for(int i = serialPorts.length-1; i >= 0; i--){
try{
serialPort = serialPorts[i];
board = new Serial(this,serialPort,115200);
println(serialPort);
print("try "); print(i); print(" "); print(serialPort); println(" at 115200 baud");
output("Attempting to connect at 115200 baud to " + serialPort); // not working
delay(5000);
delay(1000);
board.write('?');
// board.write('?');
board.write('v'); //modified by JAM 1/17
//board.write(0x07);
delay(1000);
delay(2000);
if(confirm_openbci()) {
println("Board connected on port " +serialPorts[i] + " with BAUD 115200");
output("Connected to " + serialPort + "!");
openBCI_portName = serialPorts[i];
openBCI_baud = 115200;
board.stop();
return;
} else {
println("Board not on port " + serialPorts[i] +" with BAUD 115200");
board.stop();
}
}
catch (Exception e){
println("Board not on port " + serialPorts[i] +" with BAUD 115200");
println("Exception " + serialPorts[i] + " " + e);
}
try{
board = new Serial(this,serialPort,230400);
println(serialPort);
print("try "); print(i); print(" "); print(serialPort); println(" at 230400 baud");
output("Attempting to connect at 230400 baud to " + serialPort); // not working
delay(5000);
delay(1000);
board.write('?');
// board.write('?');
board.write('v'); //modified by JAM 1/17
//board.write(0x07);
delay(1000);
if(confirm_openbci()) {
delay(2000);
if(confirm_openbci()) { // was just confrim_openbci JAM 1/2017
println("Board connected on port " +serialPorts[i] + " with BAUD 230400");
output("Connected to " + serialPort + "!"); // not working
openBCI_baud = 230400;
openBCI_portName = serialPorts[i];
board.stop();
return;
} else {
println("Board not on port " + serialPorts[i] +" with BAUD 230400");
board.stop();
}
}
catch (Exception e){
println("Board not on port " + serialPorts[i] +" with BAUD 230400");
println("Exception " + serialPorts[i] + " " + e);
}
}
}
Serial autoconnect_return_default() throws Exception{
// Serial autoconnect_return_default() throws Exception{
//
// Serial locBoard; //local serial instance just to make sure it's openbci, then connect to it if it is
// Serial retBoard;
// String[] serialPorts = new String[Serial.list().length];
// String serialPort = "";
// serialPorts = Serial.list();
//
//
// for(int i = 0; i < serialPorts.length; i++){
//
// try{
// serialPort = serialPorts[i];
// locBoard = new Serial(this,serialPort,115200);
//
// delay(100);
//
// locBoard.write(0xF0);
// locBoard.write(0x07);
// delay(1000);
//
// if(confirm_openbci_v2()) {
// println("Board connected on port " +serialPorts[i] + " with BAUD 115200");
// no_start_connection = true;
// openBCI_portName = serialPorts[i];
// openBCI_baud = 115200;
// isOpenBCI = false;
//
// return locBoard;
// }
// else locBoard.stop();
// }
// catch (Exception e){
// println("Board not on port " + serialPorts[i] +" with BAUD 115200");
// }
// }
//
//
// throw new Exception();
// }
Serial locBoard; //local serial instance just to make sure it's openbci, then connect to it if it is
Serial retBoard;
String[] serialPorts = new String[Serial.list().length];
String serialPort = "";
serialPorts = Serial.list();
for(int i = 0; i < serialPorts.length; i++){
try{
serialPort = serialPorts[i];
locBoard = new Serial(this,serialPort,115200);
delay(100);
locBoard.write(0xF0);
locBoard.write(0x07);
delay(1000);
if(confirm_openbci_v2()) {
println("Board connected on port " +serialPorts[i] + " with BAUD 115200");
no_start_connection = true;
openBCI_portName = serialPorts[i];
openBCI_baud = 115200;
isOpenBCI = false;
return locBoard;
}
else locBoard.stop();
}
catch (Exception e){
println("Board not on port " + serialPorts[i] +" with BAUD 115200");
}
}
throw new Exception();
}
Serial autoconnect_return_high() throws Exception{
Serial localBoard; //local serial instance just to make sure it's openbci, then connect to it if it is
String[] serialPorts = new String[Serial.list().length];
String serialPort = "";
serialPorts = Serial.list();
for(int i = 0; i < serialPorts.length; i++){
try{
serialPort = serialPorts[i];
localBoard = new Serial(this,serialPort,230400);
delay(100);
localBoard.write(0xF0);
localBoard.write(0x07);
delay(1000);
if(confirm_openbci_v2()) {
println("Board connected on port " +serialPorts[i] + " with BAUD 230400");
no_start_connection = true;
openBCI_portName = serialPorts[i];
openBCI_baud = 230400;
isOpenBCI = false;
return localBoard;
}
}
catch (Exception e){
println("Board not on port " + serialPorts[i] +" with BAUD 230400");
}
}
throw new Exception();
}
// Serial autoconnect_return_high() throws Exception{
//
// Serial localBoard; //local serial instance just to make sure it's openbci, then connect to it if it is
// String[] serialPorts = new String[Serial.list().length];
// String serialPort = "";
// serialPorts = Serial.list();
//
//
// for(int i = 0; i < serialPorts.length; i++){
// try{
// serialPort = serialPorts[i];
// localBoard = new Serial(this,serialPort,230400);
//
// delay(100);
//
// localBoard.write(0xF0);
// localBoard.write(0x07);
// delay(1000);
// if(confirm_openbci_v2()) {
// println("Board connected on port " +serialPorts[i] + " with BAUD 230400");
// no_start_connection = true;
// openBCI_portName = serialPorts[i];
// openBCI_baud = 230400;
// isOpenBCI = false;
//
// return localBoard;
// }
// }
// catch (Exception e){
// println("Board not on port " + serialPorts[i] +" with BAUD 230400");
// }
//
// }
// throw new Exception();
// }
/**** Helper function for connection of boards ****/
boolean confirm_openbci(){
//println(board_message.toString());
if(board_message.toString().toLowerCase().contains("registers")) return true;
else return false;
// if(board_message.toString().toLowerCase().contains("registers")) return true;
// print("board "); print(board_message.toString()); println("message");
if(board_message != null){
if(board_message.toString().toLowerCase().contains("ads")){
return true;
}
}
return false;
}
boolean confirm_openbci_v2(){
//println(board_message.toString());
if(board_message.toString().toLowerCase().contains("success")) return true;
// if(board_message.toString().contains("v2.")) return true;
else return false;
}
/**** Helper function for autoscan ****/
boolean confirm_connected(){
if( board_message != null && board_message.toString().charAt(0) == 'S') return true;
if( board_message != null && board_message.toString().toLowerCase().contains("success")) return true; // JAM added .containes("success")
else return false;
}
/**** Helper function to read from the serial easily ****/
void print_bytes(RadioConfigBox rc){
println(board_message.toString());
rc.print_onscreen(board_message.toString());
boolean print_bytes(RadioConfigBox rc){
if(board_message != null){
println(board_message.toString());
rc.print_onscreen(board_message.toString());
return true;
} else {
return false;
}
}
void print_bytes_error(RadioConfigBox rcConfig){
println("Error reading from Serial/COM port");
rcConfig.print_onscreen("Error reading from Serial port. Try a different port?");
board = null;
}
/**** Function to connect to a selected port ****/ // JAM 1/2017
// Needs to be connected to something to perform the Radio_Config tasks
boolean connect_to_portName(RadioConfigBox rcConfig){
if(openBCI_portName != "N/A"){
output("Attempting to open Serial/COM port: " + openBCI_portName);
try {
println("Radios_Config: connect_to_portName: attempting to open serial port: " + openBCI_portName);
serial_output = new Serial(this,openBCI_portName,openBCI_baud); //open the com port
serial_output.clear(); // clear anything in the com port's buffer
// portIsOpen = true;
println("Radios_Config: connect_to_portName: port is open!");
// changeState(STATE_COMINIT);
board = serial_output;
return true;
}
catch (RuntimeException e){
if (e.getMessage().contains("<init>")) {
serial_output = null;
System.out.println("Radios_Config: connect_to_portName: port in use, trying again later...");
// portIsOpen = false;
} else{
println("RunttimeException: " + e);
output("Error connecting to selected Serial/COM port. Make sure your board is powered up and your dongle is plugged in.");
rcConfig.print_onscreen("Error connecting to Serial port. Try a different port?");
}
board = null;
println("Radios_Config: connect_to_portName: failed to connect to " + openBCI_portName);
return false;
}
} else {
output("No Serial/COM port selected. Please select your Serial/COM port and retry");
rcConfig.print_onscreen("Select a Serial/COM port, then try again");
return false;
}
}
//=========== GET SYSTEM STATUS ============
//= Get's the current status of the system
//=
//= First writes 0xF0 to let the board know
//= a command is coming, then writes the
//= command (0x07).
//=
//= After a short delay it then prints bytes
//= from the board.
//==========================================
void system_status(RadioConfigBox rcConfig){
if(board == null){
if(!connect_to_portName(rcConfig)){
return;
}
}
if(board != null){
board.write(0xF0);
board.write(0x07);
delay(100);
if(!print_bytes(rcConfig)){
print_bytes_error(rcConfig);
}
} else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
//Scans through channels until a success message has been found
void scan_channels(RadioConfigBox rcConfig){
if(board == null){
if(!connect_to_portName(rcConfig)){
return;
}
}
for(int i = 1; i < 26; i++){
set_channel_over(rcConfig,i);
system_status(rcConfig);
if(confirm_connected()) return; // break;
}
}
//============== GET CHANNEL ===============
//= Gets channel information from the radio.
@@ -186,12 +302,19 @@ void print_bytes(RadioConfigBox rc){
//==========================================
void get_channel(RadioConfigBox rcConfig){
if(board == null){
if(!connect_to_portName(rcConfig)){
return;
}
}
if(board != null){
board.write(0xF0);
board.write(0x00);
delay(100);
print_bytes(rcConfig);
if(!print_bytes(rcConfig)){
print_bytes_error(rcConfig);
}
}
else {
println("Error, no board connected");
@@ -213,13 +336,20 @@ void get_channel(RadioConfigBox rcConfig){
//==========================================
void set_channel(RadioConfigBox rcConfig, int channel_number){
if(board == null){
if(!connect_to_portName(rcConfig)){
return;
}
}
if(board != null){
if(channel_number > 0){
board.write(0xF0);
board.write(0x01);
board.write(byte(channel_number));
delay(1000);
print_bytes(rcConfig);
if(!print_bytes(rcConfig)){
print_bytes_error(rcConfig);
}
}
else rcConfig.print_onscreen("Please Select a Channel");
}
@@ -243,13 +373,20 @@ void set_channel(RadioConfigBox rcConfig, int channel_number){
//==========================================
void set_channel_over(RadioConfigBox rcConfig, int channel_number){
if(board == null){
if(!connect_to_portName(rcConfig)){
return;
}
}
if(board != null){
if(channel_number > 0){
board.write(0xF0);
board.write(0x02);
board.write(byte(channel_number));
delay(100);
print_bytes(rcConfig);
if(!print_bytes(rcConfig)){
print_bytes_error(rcConfig);
}
}
else rcConfig.print_onscreen("Please Select a Channel");
@@ -272,23 +409,30 @@ void set_channel_over(RadioConfigBox rcConfig, int channel_number){
//= from the board.
//==========================================
void get_poll(RadioConfigBox rcConfig){
if(board != null){
board.write(0xF0);
board.write(0x03);
isGettingPoll = true;
delay(100);
board_message.append(hexToInt);
print_bytes(rcConfig);
isGettingPoll = false;
spaceFound = false;
}
else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
// void get_poll(RadioConfigBox rcConfig){
// if(board == null){
// if(!connect_to_portName(rcConfig)){
// return;
// }
// }
// if(board != null){
// board.write(0xF0);
// board.write(0x03);
// isGettingPoll = true;
// delay(100);
// board_message.append(hexToInt);
// if(!print_bytes(rcConfig)){
// print_bytes_error(rcConfig);
// }
// isGettingPoll = false;
// spaceFound = false;
// }
//
// else {
// println("Error, no board connected");
// rcConfig.print_onscreen("No board connected!");
// }
// }
//=========== SET POLL OVERRIDE ============
//= Sets the poll time
@@ -303,19 +447,26 @@ void get_poll(RadioConfigBox rcConfig){
//= from the board.
//==========================================
void set_poll(RadioConfigBox rcConfig, int poll_number){
if(board != null){
board.write(0xF0);
board.write(0x04);
board.write(byte(poll_number));
delay(1000);
print_bytes(rcConfig);
}
else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
// void set_poll(RadioConfigBox rcConfig, int poll_number){
// if(board == null){
// if(!connect_to_portName(rcConfig)){
// return;
// }
// }
// if(board != null){
// board.write(0xF0);
// board.write(0x04);
// board.write(byte(poll_number));
// delay(1000);
// if(!print_bytes(rcConfig)){
// print_bytes_error(rcConfig);
// }
// }
// else {
// println("Error, no board connected");
// rcConfig.print_onscreen("No board connected!");
// }
// }
//========== SET BAUD TO DEFAULT ===========
//= Sets BAUD to it's default value (115200)
@@ -328,29 +479,36 @@ void set_poll(RadioConfigBox rcConfig, int poll_number){
//= from the board.
//==========================================
void set_baud_default(RadioConfigBox rcConfig, String serialPort){
if(board != null){
board.write(0xF0);
board.write(0x05);
delay(1000);
print_bytes(rcConfig);
delay(1000);
try{
board.stop();
board = null;
board = autoconnect_return_default();
}
catch (Exception e){
println("error setting serial to BAUD 115200");
}
}
else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
// void set_baud_default(RadioConfigBox rcConfig, String serialPort){
// if(board == null){
// if(!connect_to_portName(rcConfig)){
// return;
// }
// }
// if(board != null){
// board.write(0xF0);
// board.write(0x05);
// delay(1000);
// if(!print_bytes(rcConfig)){
// print_bytes_error(rcConfig);
// }
// delay(1000);
//
//
// try{
// board.stop();
// board = null;
// board = autoconnect_return_default();
// }
// catch (Exception e){
// println("error setting serial to BAUD 115200");
// }
// }
// else {
// println("Error, no board connected");
// rcConfig.print_onscreen("No board connected!");
// }
// }
//====== SET BAUD TO HIGH-SPEED MODE =======
//= Sets BAUD to a higher rate (230400)
@@ -363,61 +521,33 @@ void set_baud_default(RadioConfigBox rcConfig, String serialPort){
//= from the board.
//==========================================
void set_baud_high(RadioConfigBox rcConfig, String serialPort){
if(board != null){
board.write(0xF0);
board.write(0x06);
delay(1000);
print_bytes(rcConfig);
delay(1000);
try{
board.stop();
board = null;
board = autoconnect_return_high();
}
catch (Exception e){
println("error setting serial to BAUD 230400");
}
}
else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
//=========== GET SYSTEM STATUS ============
//= Get's the current status of the system
//=
//= First writes 0xF0 to let the board know
//= a command is coming, then writes the
//= command (0x07).
//=
//= After a short delay it then prints bytes
//= from the board.
//==========================================
void system_status(RadioConfigBox rcConfig){
if(board != null){
board.write(0xF0);
board.write(0x07);
delay(100);
print_bytes(rcConfig);
}
else {
println("Error, no board connected");
rcConfig.print_onscreen("No board connected!");
}
}
//Scans through channels until a success message has been found
void scan_channels(RadioConfigBox rcConfig){
for(int i = 1; i < 26; i++){
set_channel_over(rcConfig,i);
system_status(rcConfig);
if(confirm_connected()) break;
}
}
// void set_baud_high(RadioConfigBox rcConfig, String serialPort){
// if(board == null){
// if(!connect_to_portName(rcConfig)){
// return;
// }
// }
// if(board != null){
// board.write(0xF0);
// board.write(0x06);
// delay(1000);
// if(!print_bytes(rcConfig)){
// print_bytes_error(rcConfig);
// }
// delay(1000);
//
// try{
// board.stop();
// board = null;
// board = autoconnect_return_high();
// }
// catch (Exception e){
// println("error setting serial to BAUD 230400");
// }
// }
// else {
// println("Error, no board connected");
// rcConfig.print_onscreen("No board connected!");
// }
//
// }
Arquivo binário não exibido.

Antes

Largura:  |  Altura:  |  Tamanho: 167 KiB

Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+13 -1
Ver Arquivo
@@ -110,12 +110,24 @@ class W_fft extends Widget {
//put your code here...
//update the points of the FFT channel arrays
//update fft point arrays
// println("LENGTH = " + fft_points.length);
// println("LENGTH = " + fftBuff.length);
// println("LENGTH = " + FFT_indexLim);
for (int i = 0; i < fft_points.length; i++) {
for (int j = 0; j < FFT_indexLim + 2; j++) { //loop through frequency domain data, and store into points array
//GPoint powerAtBin = new GPoint(j, 15*random(0.1*j));
GPoint powerAtBin;
GPoint powerAtBin = new GPoint((1.0*get_fs_Hz_safe()/Nfft)*j, fftBuff[i].getBand(j));
// println("i = " + i);
// float a = get_fs_Hz_safe();
// float aa = fftBuff[i].getBand(j);
// float b = fftBuff[i].getBand(j);
// float c = Nfft;
powerAtBin = new GPoint((1.0*get_fs_Hz_safe()/Nfft)*j, fftBuff[i].getBand(j));
fft_points[i].set(j, powerAtBin);
// GPoint powerAtBin = new GPoint((1.0*get_fs_Hz_safe()/Nfft)*j, fftBuff[i].getBand(j));
//println("=========================================");
//println(j);
//println(fftBuff[i].getBand(j) + " :: " + fft_points[i].getX(j) + " :: " + fft_points[i].getY(j));
+449
Ver Arquivo
@@ -0,0 +1,449 @@
////////////////////////////////////////////////////
//
// W_template.pde (ie "Widget Template")
//
// This is a Template Widget, intended to be used as a starting point for OpenBCI Community members that want to develop their own custom widgets!
// Good luck! If you embark on this journey, please let us know. Your contributions are valuable to everyone!
//
// Created by: Conor Russomanno, November 2016
//
///////////////////////////////////////////////////,
class W_openBionics extends Widget {
//to see all core variables/methods of the Widget class, refer to Widget.pde
//put your custom variables here...
PApplet parent;
Serial OpenBionicsHand;
PFont f = createFont("Arial Bold", 24); //for "FFT Plot" Widget Title
PFont f2 = createFont("Arial", 18); //for dropdown name titles (above dropdown widgets)
int parentContainer = 9; //which container is it mapped to by default?
boolean thumbPressed,indexPressed,middlePressed,ringPressed,littlePressed,palmPressed = false;
boolean researchMode = false;
PImage hand;
PImage thumb;
PImage index;
PImage middle;
PImage ring;
PImage little;
PImage palm;
int last_command;
Button configClose;
Button configConfirm;
Button connect;
MenuList obChanList;
ControlP5 configP5;
String obName;
String obBaud;
List serialListOB;
List baudListOB;
int drawConfig;
int[] fingerChans;
boolean wasConnected;
W_openBionics(PApplet _parent){
super(_parent); //calls the parent CONSTRUCTOR method of Widget (DON'T REMOVE)
//This is the protocol for setting up dropdowns.
//Note that these 3 dropdowns correspond to the 3 global functions below
//You just need to make sure the "id" (the 1st String) has the same name as the corresponding function
configP5 = new ControlP5(_parent);
wasConnected = false;
parent = _parent;
baudListOB = Arrays.asList("NONE","230400","115200","57600","38400","28800","19200","14400","9600","7200","4800","3600","2400","1800","1200","600","300");
drawConfig = -1;
fingerChans = new int[6];
for(int i = 0; i<6; i++) fingerChans[i] = -1;
hand = loadImage("hand.png");
thumb = loadImage("thumb_over.png");
index = loadImage("index_over.png");
middle = loadImage("middle_over.png");
ring = loadImage("ring_over.png");
little = loadImage("little_over.png");
palm = loadImage("palm_over.png");
String[] serialPortsLocal = Serial.list();
serialListOB = new ArrayList();
serialListOB.add("NONE");
for (int i = 0; i < serialPortsLocal.length; i++) {
String tempPort = serialPortsLocal[(serialPortsLocal.length-1) - i]; //list backwards... because usually our port is at the bottom
if(!tempPort.equals(openBCI_portName)) serialListOB.add(tempPort);
}
configClose = new Button(int(x) + w/4,int(y) + 3*navHeight,int(w/25.3),int(w/25.3),"X",fontInfo.buttonLabel_size);
configConfirm = new Button(int(x) + w/2 + w/7,int(y) + 12*navHeight,int(w/10.12),int(w/25.3),"OKAY",fontInfo.buttonLabel_size);
connect = new Button(int(x) + w - (w/7), int(y) + 10*navHeight, int(w/8), int(w/25.3), "CONNECT", fontInfo.buttonLabel_size);
obChanList = new MenuList(configP5, "obChanList", 100, 120, f2);
obChanList.setPosition(x+w/3 + w/12, y + h/3 + h/16);
obChanList.addItem(makeItem("NONE"));
obChanList.activeItem = 0;
for(int i = 0; i < nchan; i++) obChanList.addItem(makeItem("" + (i+1)));
addDropdown("OpenBionicsSerialOut", "Serial Output", serialListOB, 0);
addDropdown("BaudList", "Baud List", baudListOB, 0);
configP5.get(MenuList.class, "obChanList").setVisible(false);
// addDropdown("Dropdown3", "Drop 3", Arrays.asList("F", "G", "H", "I"), 3);
}
void process(){
int output_normalized;
StringBuilder researchCommand = new StringBuilder();
if(OpenBionicsHand != null ){
if(!researchMode){
OpenBionicsHand.write("A10\n");
researchMode = true;
}
byte inByte = byte(OpenBionicsHand.read());
println(inByte);
}
if(fingerChans[5] == -1){
if(OpenBionicsHand != null){
for(int i = 0; i<5; i++){
//================= OpenBionics Analog Movement =======================
if(fingerChans[i] == -1) output_normalized = 0;
else output_normalized = int(map(w_emg.motorWidgets[fingerChans[i]].output_normalized, 0, 1, 0, 1023));
if(i == 4) researchCommand.append(output_normalized + "\n");
else researchCommand.append(output_normalized + ",");
}
OpenBionicsHand.write(researchCommand.toString());
}
}
else {
if(OpenBionicsHand != null){
output_normalized = int(map(w_emg.motorWidgets[fingerChans[5]].output_normalized, 0, 1, 0, 100));
OpenBionicsHand.write("G0P" + output_normalized + "\n");
}
}
}
void update(){
super.update(); //calls the parent update() method of Widget (DON'T REMOVE)
//put your code here...
process();
}
void draw(){
super.draw(); //calls the parent draw() method of Widget (DON'T REMOVE)
//put your code here... //remember to refer to x,y,w,h which are the positioning variables of the Widget class
pushStyle();
//configP5.setVisible(true);
//draw FFT Graph w/ all plots
noStroke();
fill(255);
rect(x, y, w, h);
obChanList.setPosition(x+w/3 + w/12, y + h/3 + h/16);
switch(drawConfig){
case -1:
image(hand,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
if(overThumb()) image(thumb,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overIndex()) image(index,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overMiddle()) image(middle,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overRing()) image(ring,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overLittle()) image(little,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
else if(overPalm()) image(palm,x + w/4,y+2*navHeight + 2, w/2,h/2 + h/3 );
configP5.get(MenuList.class, "obChanList").setVisible(false);
configP5.get(MenuList.class, "obChanList").activeItem = 0;
if(wasConnected){
fill(0,250,0);
ellipse(x + 5 * (w/6) ,y + 7 * (h/10),20,20);
}
else{
fill(250,0,0);
ellipse(x + 5 * (w/6),y + 7 * (h/10),20,20);
}
connect.draw();
break;
case 0:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Thumb Channel Selection", x + w/3, y + 4*navHeight);
break;
case 1:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Index Finger Channel Selection", x + w/3, y + 4*navHeight);
break;
case 2:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Middle Finger Channel Selection", x + w/3, y + 4*navHeight);
break;
case 3:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Ring Finger Channel Selection", x + w/3, y + 4*navHeight);
break;
case 4:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Little Finger Channel Selection", x + w/3, y + 4*navHeight);
break;
case 5:
configP5.get(MenuList.class, "obChanList").activeItem = fingerChans[drawConfig] + 1;
configP5.get(MenuList.class, "obChanList").setVisible(true);
fill(180,180,180);
rect(int(x) + w/4,int(y) + 3*navHeight, w/2, h/2 + 2*navHeight + navHeight/2);
configClose.draw();
configConfirm.draw();
fill(10,10,10);
textFont(f);
textSize(12);
text("Hand Channel Selection", x + w/3, y + 4*navHeight);
break;
}
configP5.draw();
popStyle();
}
void screenResized(){
super.screenResized(); //calls the parent screenResized() method of Widget (DON'T REMOVE)
//put your code here...
configClose = new Button(int(x) + w/4,int(y) + 3*navHeight,int(w/25.3),int(w/25.3),"X",fontInfo.buttonLabel_size);
configConfirm = new Button(int(x) + w/2 + w/7,int(y) + 12*navHeight,int(w/10.12),int(w/25.3),"OKAY",fontInfo.buttonLabel_size);
//update dropdown menu positions
configP5.setGraphics(parent, 0, 0); //remaps the cp5 controller to the new PApplet window size
int dropdownPos;
int dropdownWidth = 60;
dropdownPos = 1; //work down from 4 since we're starting on the right side now...
configP5.getController("OpenBionicsSerialOut")
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1)), navHeight+(y+2)) //float right
;
dropdownPos = 0;
try{
configP5.getController("LogLin")
.setPosition(x+w-(dropdownWidth*(dropdownPos+1))-(2*(dropdownPos+1)), navHeight+(y+2)) //float right
;
}
catch(Exception e){
println("error resizing...");
}
}
void mousePressed(){
super.mousePressed(); //calls the parent mousePressed() method of Widget (DON'T REMOVE)
//put your code here...
if(drawConfig == -1){
if(overThumb()) thumbPressed = true;
else if(overIndex()) indexPressed = true;
else if(overMiddle()) middlePressed = true;
else if(overRing()) ringPressed = true;
else if(overLittle()) littlePressed = true;
else if(overPalm()) palmPressed = true;
else if(connect.isMouseHere()) connect.wasPressed = true;
}
else{
if(configClose.isMouseHere()) configClose.wasPressed= true;
else if(configConfirm.isMouseHere()) configConfirm.wasPressed= true;
}
}
void mouseReleased(){
super.mouseReleased(); //calls the parent mouseReleased() method of Widget (DON'T REMOVE)
if(drawConfig == -1){
if (overThumb() && thumbPressed){drawConfig = 0;}
else if (overIndex() && indexPressed){drawConfig= 1;}
else if (overMiddle() && middlePressed){drawConfig = 2;}
else if (overRing() && ringPressed){drawConfig = 3;}
else if (overLittle() && littlePressed){drawConfig = 4;}
else if (overPalm() && palmPressed){drawConfig = 5;}
else if(connect.isMouseHere() && connect.wasPressed){
//Connect to OpenBionics Hand
try{
OpenBionicsHand = new Serial(parent,obName,Integer.parseInt(obBaud));
verbosePrint("Connected to OpenBionics Hand");
wasConnected = true;
}
catch(Exception e){
wasConnected = false;
println(e);
verbosePrint("Could not connect to OpenBionics Hand");
}
}
thumbPressed = false;
indexPressed = false;
middlePressed = false;
ringPressed = false;
littlePressed = false;
palmPressed = false;
cursor(ARROW);
}
else{
if(configClose.isMouseHere() && configClose.wasPressed) {
configClose.wasPressed= false;
drawConfig = -1;
}
else if(configConfirm.isMouseHere() && configConfirm.wasPressed){
configConfirm.wasPressed= false;
drawConfig = -1;
}
}
}
boolean overThumb(){
if(mouseX >= x + w/3.9 && mouseX <=x + w/2.5 && mouseY >= y + h/1.8 && mouseY <= y + h/1.32){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overIndex(){
if(mouseX >= x + w/2.65 && mouseX <=x + w/2.07 && mouseY >= y + h/4.89 && mouseY <= y + h/1.99){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overMiddle(){
if(mouseX >= x + w/2.01 && mouseX <=x + w/1.79 && mouseY >= y + h/7.08 && mouseY <= y + h/2.14){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overRing(){
if(mouseX >= x + w/1.73 && mouseX <=x + w/1.5 && mouseY >= y + h/5.59 && mouseY <= y + h/1.95){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overLittle(){
if(mouseX >= x + w/1.54 && mouseX <=x + w/1.34 && mouseY >= y + h/3.13 && mouseY <= y + h/1.78){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
boolean overPalm(){
if(mouseX >= x + w/2.47 && mouseX <=x + w/1.48 && mouseY >= y + h/1.89 && mouseY <= y + h/1.05){
cursor(HAND);
return true;
}
else{
cursor(ARROW);
return false;
}
}
//add custom classes functions here
void customFunction(){
//this is a fake function... replace it with something relevant to this widget
}
};
//These functions need to be global! These functions are activated when an item from the corresponding dropdown is selected
void OpenBionicsSerialOut(int n){
if(!w_openbionics.serialListOB.get(n).equals("NONE")) w_openbionics.obName = (String)w_openbionics.serialListOB.get(n);
closeAllDropdowns(); // do this at the end of all widget-activated functions to ensure proper widget interactivity ... we want to make sure a click makes the menu close
}
void BaudList(int n){
if(!w_openbionics.baudListOB.get(n).equals("NONE")) w_openbionics.obBaud = (String)w_openbionics.baudListOB.get(n);
closeAllDropdowns();
}
void obChanList(int n){
w_openbionics.fingerChans[w_openbionics.drawConfig] = n - 1;
closeAllDropdowns();
}
+2 -2
Ver Arquivo
@@ -472,7 +472,7 @@ class ChannelBar{
if (is_railed[channelNumber-1].is_railed == true) {
voltageValue.string = "RAILED";
} else if (is_railed[channelNumber-1].is_railed_warn == true) {
voltageValue.string = "NEAR RAILED";
voltageValue.string = "NEAR RAILED - " + String.format(getFmt(val),val) + " uVrms";
}
}
@@ -626,7 +626,7 @@ class ChannelBar{
onOffButton.but_dx = onOff_diameter;
onOffButton.but_dy = onOff_diameter;
} else{
println("h = " + h);
// println("h = " + h);
onOff_diameter = h - 2;
onOffButton.but_dx = onOff_diameter;
onOffButton.but_dy = onOff_diameter;
+2 -2
Ver Arquivo
@@ -93,7 +93,7 @@ class W_ganglionImpedance extends Widget {
popStyle();
}
if(isGanglion && eegDataSource == DATASOURCE_GANGLION){
if(isHubInitialized && isGanglionObjectInitialized && eegDataSource == DATASOURCE_GANGLION){
if(ganglion.isCheckingImpedance()){
image(loadingGIF_blue, x + padding + startStopCheck.but_dx + 15, y + padding - 8, 40, 40);
}
@@ -138,7 +138,7 @@ class W_ganglionImpedance extends Widget {
//put your code here...
if(startStopCheck.isActive && startStopCheck.isMouseHere()){
if(isGanglion && eegDataSource == DATASOURCE_GANGLION){
if(isHubInitialized && isGanglionObjectInitialized && eegDataSource == DATASOURCE_GANGLION){
if(ganglion.isCheckingImpedance()){
ganglion.impedanceStop();
startStopCheck.but_txt = "Start Impedance Check";
+14 -6
Ver Arquivo
@@ -19,8 +19,8 @@ W_accelerometer w_accelerometer;
W_networking w_networking;
W_ganglionImpedance w_ganglionImpedance;
W_template w_template1;
W_template w_template2;
W_template w_template3;
W_emg w_emg;
W_openBionics w_openbionics;
//ADD YOUR WIDGET TO WIDGETS OF WIDGETMANAGER
void setupWidgets(PApplet _this, ArrayList<Widget> w){
@@ -46,18 +46,26 @@ void setupWidgets(PApplet _this, ArrayList<Widget> w){
w_accelerometer = new W_accelerometer(_this);
w_accelerometer.setTitle("Accelerometer");
addWidget(w_accelerometer, w);
//
// w_networking = new W_networking(_this);
// w_networking.setTitle("Networking");
// addWidget(w_networking, w);
w_emg = new W_emg(_this);
w_emg.setTitle("EMG");
addWidget(w_emg, w);
w_template1 = new W_template(_this);
w_template1.setTitle("Widget Template 1");
addWidget(w_template1, w);
w_template2 = new W_template(_this);
w_template2.setTitle("Widget Template 2");
addWidget(w_template2, w);
// w_template2 = new W_template(_this);
// w_template2.setTitle("Widget Template 2");
// addWidget(w_template2, w);
// w_openbionics = new W_OpenBionics(_this);
// w_openbionics.setTitle("OpenBionics");
// addWidget(w_openbionics,w);
// w_template3 = new W_template(_this);
// w_template3.setTitle("LSL Stream");