Merge branch 'development' of https://github.com/conorrussomanno/OpenBCI_GUI_v2.0 into development
Esse commit está contido em:
@@ -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();
|
||||
|
||||
@@ -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
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -63,6 +63,8 @@ class OpenBCI_Ganglion {
|
||||
final static String TCP_ACTION_STATUS = "status";
|
||||
final static String TCP_ACTION_STOP = "stop";
|
||||
|
||||
final static String GANGLION_BOOTLOADER_MODE = ">";
|
||||
|
||||
final static byte BYTE_START = (byte)0xA0;
|
||||
final static byte BYTE_END = (byte)0xC0;
|
||||
|
||||
@@ -91,6 +93,9 @@ class OpenBCI_Ganglion {
|
||||
final static int RESP_ERROR_SCAN_COULD_NOT_STOP = 411;
|
||||
final static int RESP_GANGLION_FOUND = 201;
|
||||
final static int RESP_SUCCESS = 200;
|
||||
final static int RESP_SUCCESS_DATA_ACCEL = 202;
|
||||
final static int RESP_SUCCESS_DATA_IMPEDANCE = 203;
|
||||
final static int RESP_SUCCESS_DATA_SAMPLE = 204;
|
||||
final static int RESP_STATUS_CONNECTED = 300;
|
||||
final static int RESP_STATUS_DISCONNECTED = 301;
|
||||
final static int RESP_STATUS_SCANNING = 302;
|
||||
@@ -273,12 +278,13 @@ class OpenBCI_Ganglion {
|
||||
}
|
||||
|
||||
private void processAccel(String msg) {
|
||||
// println(msg);
|
||||
String[] list = split(msg, ',');
|
||||
for (int i = 0; i < NUM_ACCEL_DIMS; i++) {
|
||||
accelArray[i] = Integer.parseInt(list[i + 1]);
|
||||
if (Integer.parseInt(list[1]) == RESP_SUCCESS_DATA_ACCEL) {
|
||||
for (int i = 0; i < NUM_ACCEL_DIMS; i++) {
|
||||
accelArray[i] = Integer.parseInt(list[i + 2]);
|
||||
}
|
||||
newAccelData = true;
|
||||
}
|
||||
newAccelData = true;
|
||||
}
|
||||
|
||||
private void processConnect(String msg) {
|
||||
@@ -304,7 +310,7 @@ class OpenBCI_Ganglion {
|
||||
String[] list = split(msg, ',');
|
||||
int code = Integer.parseInt(list[1]);
|
||||
if (eegDataSource == DATASOURCE_GANGLION && systemMode == 10 && isRunning) { //<>//
|
||||
if (isSuccessCode(Integer.parseInt(list[1]))) { //<>//
|
||||
if (Integer.parseInt(list[1]) == RESP_SUCCESS_DATA_SAMPLE) { //<>//
|
||||
// Sample number stuff
|
||||
dataPacket.sampleIndex = int(Integer.parseInt(list[2]));
|
||||
if ((dataPacket.sampleIndex - prevSampleIndex) != 1) {
|
||||
@@ -370,26 +376,19 @@ class OpenBCI_Ganglion {
|
||||
|
||||
private void processImpedance(String msg) {
|
||||
String[] list = split(msg, ',');
|
||||
println("Length = " + list.length);
|
||||
for(int i = 0; i < list.length; i++){
|
||||
println(i + " " + list[i]);
|
||||
}
|
||||
int channel = Integer.parseInt(list[1]);
|
||||
if (channel < 5) { //<>//
|
||||
println("channel - " + channel);
|
||||
int value = Integer.parseInt(list[2]);
|
||||
impedanceArray[channel] = value;
|
||||
|
||||
if (channel == 0) {
|
||||
impedanceUpdated = true;
|
||||
println("Impedance for channel reference is " + value + " ohms.");
|
||||
} else {
|
||||
println("? for channel " + channel + " is " + value + " ohms.");
|
||||
if (Integer.parseInt(list[1]) == RESP_SUCCESS_DATA_IMPEDANCE) {
|
||||
int channel = Integer.parseInt(list[2]);
|
||||
if (channel < 5) { //<>//
|
||||
int value = Integer.parseInt(list[3]);
|
||||
impedanceArray[channel] = value;
|
||||
if (channel == 0) {
|
||||
impedanceUpdated = true;
|
||||
println("Impedance for channel reference is " + value + " ohms.");
|
||||
} else {
|
||||
println("? for channel " + channel + " is " + value + " ohms.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//println("Impedance " + list[2]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processScan(String msg) {
|
||||
@@ -618,7 +617,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -661,4 +660,18 @@ class OpenBCI_Ganglion {
|
||||
safeTCPWrite(TCP_CMD_IMPEDANCE + "," + TCP_ACTION_STOP + TCP_STOP);
|
||||
checkingImpedance = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the ganglion in bootloader mode.
|
||||
*/
|
||||
public void enterBootloaderMode() {
|
||||
println("OpenBCI_Ganglion: Entering Bootloader Mode");
|
||||
safeTCPWrite(TCP_CMD_COMMAND + "," + GANGLION_BOOTLOADER_MODE + TCP_STOP);
|
||||
delay(500);
|
||||
disconnectBLE();
|
||||
haltSystem();
|
||||
initSystemButton.setString("START SYSTEM");
|
||||
controlPanel.open();
|
||||
output("Ganglion now in bootloader mode! Enjoy!");
|
||||
}
|
||||
};
|
||||
|
||||
+537
-489
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -77,18 +77,9 @@ void parseKey(char val) {
|
||||
// drawTimeSeries = !drawTimeSeries;
|
||||
break;
|
||||
case '>':
|
||||
wm.setVisible(!wm.isVisible());
|
||||
// wmVisible = !wmVisible;
|
||||
break;
|
||||
case ':':
|
||||
// if(isGanglion && eegDataSource == DATASOURCE_GANGLION){
|
||||
// println("Start/stop impedance check...");
|
||||
// if(ganglion.isCheckingImpedance()){
|
||||
// ganglion.impedanceStop();
|
||||
// } else {
|
||||
// ganglion.impedanceStart();
|
||||
// }
|
||||
// }
|
||||
if(eegDataSource == DATASOURCE_GANGLION){
|
||||
ganglion.enterBootloaderMode();
|
||||
}
|
||||
break;
|
||||
case '{':
|
||||
if(colorScheme == COLOR_SCHEME_DEFAULT){
|
||||
|
||||
+188
-177
@@ -1,11 +1,11 @@
|
||||
|
||||
//<>//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GUI for controlling the ADS1299-based OpenBCI
|
||||
//
|
||||
// Created: Chip Audette, Oct 2013 - May 2014
|
||||
// Modified: Conor Russomanno & Joel Murphy, August 2014 - Dec 2014
|
||||
// Modified (v2.0): Conor Russomanno & Joel Murphy, June 2016
|
||||
// Modified (v2.0): Conor Russomanno & Joel Murphy (AJ Keller helped too), June 2016
|
||||
//
|
||||
// Requires gwoptics graphing library for processing. Built on V0.5.0
|
||||
// http://www.gwoptics.org/processing/gwoptics_p5lib/
|
||||
@@ -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;
|
||||
@@ -333,12 +333,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 +373,22 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,12 +401,16 @@ void hubStart() {
|
||||
if (isWindows()) {
|
||||
println("OpenBCI_GUI: hubStart: OS Detected: Windows");
|
||||
nodeHubby = launch(dataPath("Ganglion Hub.exe"));
|
||||
} else if (isLinux()) {
|
||||
println("OpenBCI_GUI: hubStart: OS Detected: Linux");
|
||||
nodeHubby = exec(dataPath("Ganglion Hub"));
|
||||
} else {
|
||||
println("OpenBCI_GUI: hubStart: OS Detected: Mac");
|
||||
nodeHubby = launch(dataPath("Ganglion Hub.app"));
|
||||
}
|
||||
// hubRunning = true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
println("hubStart: " + e);
|
||||
}
|
||||
}
|
||||
@@ -421,6 +427,14 @@ boolean hubStop() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Helper function to determine if the system is linux or not.
|
||||
* @return {boolean} true if os is linux, false otherwise.
|
||||
*/
|
||||
private boolean isLinux() {
|
||||
return System.getProperty("os.name").toLowerCase().indexOf("linux") > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Helper function to determine if the system is windows or not.
|
||||
* @return {boolean} true if os is windows, false otherwise.
|
||||
@@ -438,20 +452,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();
|
||||
}
|
||||
}
|
||||
@@ -464,7 +480,8 @@ boolean killRunningprocessWin() {
|
||||
try {
|
||||
Runtime.getRuntime().exec("taskkill /F /IM Ganglion Hub.exe");
|
||||
return true;
|
||||
} catch (Exception err) {
|
||||
}
|
||||
catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -484,7 +501,8 @@ void endProcess(int pid) {
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
try {
|
||||
rt.exec("kill -9 " + pid);
|
||||
} catch (IOException err) {
|
||||
}
|
||||
catch (IOException err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -496,144 +514,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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,7 +672,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
|
||||
@@ -688,14 +709,14 @@ void haltSystem() {
|
||||
|
||||
void systemUpdate() { // for updating data values and variables
|
||||
|
||||
if(millis() - timeOfSetup >= 1000 && isGanglion == false){
|
||||
if (millis() - timeOfSetup >= 1000 && isGanglion == false) {
|
||||
ganglion = new OpenBCI_Ganglion(this);
|
||||
println("Instantiating Ganglion object...");
|
||||
isGanglion = 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);
|
||||
}
|
||||
|
||||
@@ -712,8 +733,6 @@ void systemUpdate() { // for updating data values and variables
|
||||
if (widthOfLastScreen != width || heightOfLastScreen != height) {
|
||||
topNav.screenHasBeenResized(width, height);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (systemMode == SYSTEMMODE_POSTINIT) {
|
||||
if (isRunning) {
|
||||
@@ -748,12 +767,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 {
|
||||
@@ -793,7 +810,6 @@ void systemUpdate() { // for updating data values and variables
|
||||
|
||||
wm.update();
|
||||
playground.update();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -815,16 +831,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:
|
||||
@@ -870,9 +886,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");
|
||||
@@ -923,7 +936,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();
|
||||
}
|
||||
|
||||
@@ -949,11 +962,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.0\nJanuary 2017", width/2, height/2 + width/9);
|
||||
}
|
||||
|
||||
//exit intro animation at t2
|
||||
@@ -988,7 +1001,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);
|
||||
@@ -996,7 +1008,6 @@ void mouseOutOfBounds() {
|
||||
appletOriginY = (int)loc.y;
|
||||
windowOriginSet = true;
|
||||
mouseInFrame = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
+13
-1
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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,30 @@ void setupWidgets(PApplet _this, ArrayList<Widget> w){
|
||||
w_accelerometer = new W_accelerometer(_this);
|
||||
w_accelerometer.setTitle("Accelerometer");
|
||||
addWidget(w_accelerometer, w);
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
//
|
||||
>>>>>>> e9b30d1441fde495039667b13c4215370dea102e
|
||||
// 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");
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário