Skip to content

Commit

Permalink
Merge pull request #382 from andrewjaykeller/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
AJ Keller authored Sep 22, 2018
2 parents 2421fcf + 0286e08 commit 1c47a16
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 40 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# v3.5.0
# v4.0.0

Use OpenBCIHub v1.5.0 please.
Use OpenBCIHub v2.0.0 please.

### New Features

* Timestamps in CSV now come from the OpenBCIHub

### Breaking Changes

* Now sending and receiving from the hub in JSON!

### Alpha 0

* Initial Release

# v3.4.0

Use OpenBCIHub v1.4.5 please.
Expand Down
43 changes: 19 additions & 24 deletions OpenBCI_GUI/BoardCyton.pde
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,6 @@ class Cyton {
isWritingChannel = true;
}

public void syncChannelSettings() {
write("r,start" + TCP_STOP);
}

/**
* Used to convert a gain from the hub back into local codes.
*/
Expand Down Expand Up @@ -659,16 +655,18 @@ class Cyton {

// FULL DISCLAIMER: this method is messy....... very messy... we had to brute force a firmware miscue
public void writeChannelSettings(int _numChannel, char[][] channelSettingValues) { //numChannel counts from zero
String output = "r,set,";
output += Integer.toString(_numChannel) + ","; // 0 indexed channel number
output += channelSettingValues[_numChannel][0] + ","; // power down
output += getGainForCommand(channelSettingValues[_numChannel][1]) + ","; // gain
output += getInputTypeForCommand(channelSettingValues[_numChannel][2]) + ",";
output += channelSettingValues[_numChannel][3] + ",";
output += channelSettingValues[_numChannel][4] + ",";
output += channelSettingValues[_numChannel][5] + TCP_STOP;
write(output);
verbosePrint("done writing channel." + output); //debugging
JSONObject json = new JSONObject();
json.setString(TCP_JSON_KEY_TYPE, TCP_TYPE_CHANNEL_SETTINGS);
json.setString(TCP_JSON_KEY_ACTION, TCP_ACTION_SET);
json.setInt(TCP_JSON_KEY_CHANNEL_NUMBER, _numChannel);
json.setBoolean(TCP_JSON_KEY_CHANNEL_SET_POWER_DOWN, channelSettingValues[_numChannel][0] == '1');
json.setInt(TCP_JSON_KEY_CHANNEL_SET_GAIN, getGainForCommand(channelSettingValues[_numChannel][1]));
json.setString(TCP_JSON_KEY_CHANNEL_SET_INPUT_TYPE, getInputTypeForCommand(channelSettingValues[_numChannel][2]));
json.setBoolean(TCP_JSON_KEY_CHANNEL_SET_BIAS, channelSettingValues[_numChannel][3] == '1');
json.setBoolean(TCP_JSON_KEY_CHANNEL_SET_SRB2, channelSettingValues[_numChannel][4] == '1');
json.setBoolean(TCP_JSON_KEY_CHANNEL_SET_SRB1, channelSettingValues[_numChannel][5] == '1');
hub.writeJSON(json);
verbosePrint("done writing channel." + json); //debugging
isWritingChannel = false;
}

Expand All @@ -685,16 +683,13 @@ class Cyton {
// }

public void writeImpedanceSettings(int _numChannel, char[][] impedanceCheckValues) { //numChannel counts from zero
String output = "i,set,";
if (_numChannel < 8) {
output += (char)('0'+(_numChannel+1)) + ",";
} else { //(_numChannel >= 8) {
//command_activate_channel holds non-daisy and daisy values
output += command_activate_channel[_numChannel] + ",";
}
output += impedanceCheckValues[_numChannel][0] + ",";
output += impedanceCheckValues[_numChannel][1] + TCP_STOP;
write(output);
JSONObject json = new JSONObject();
json.setString(TCP_JSON_KEY_TYPE, TCP_TYPE_IMPEDANCE);
json.setString(TCP_JSON_KEY_ACTION, TCP_ACTION_SET);
json.setInt(TCP_JSON_KEY_CHANNEL_NUMBER, _numChannel);
json.setBoolean(TCP_JSON_KEY_IMPEDANCE_SET_P_INPUT, impedanceCheckValues[_numChannel][0] == '1');
json.setBoolean(TCP_JSON_KEY_IMPEDANCE_SET_N_INPUT, impedanceCheckValues[_numChannel][1] == '1');
hub.writeJSON(json);
isWritingImp = false;
}
};
7 changes: 3 additions & 4 deletions OpenBCI_GUI/HardwareSettingsController.pde
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void activateChannel(int Ichan) {
println("OpenBCI_GUI: activating channel " + (Ichan+1));
if (eegDataSource == DATASOURCE_CYTON) {
if (cyton.isPortOpen()) {
verbosePrint("**");
cyton.changeChannelState(Ichan, true); //activate
}
} else if (eegDataSource == DATASOURCE_GANGLION) {
Expand Down Expand Up @@ -69,15 +68,15 @@ class HardwareSettingsController{
//char[][] impedanceCheckValues = new char [nchan][2];

int spaceBetweenButtons = 5; //space between buttons

// [Number of Channels] x 6 array of buttons for channel settings
Button[][] channelSettingButtons = new Button [nchan][numSettingsPerChannel]; // [channel#][Button#]

// Array for storing SRB2 history settings of channels prior to shutting off .. so you can return to previous state when reactivating channel
char[] previousSRB2 = new char [nchan];
// Array for storing SRB2 history settings of channels prior to shutting off .. so you can return to previous state when reactivating channel
char[] previousBIAS = new char [nchan];

//maximum different values for the different settings (Power Down, Gain, Input Type, BIAS, SRB2, SRB1) of
//refer to page 44 of ADS1299 Datasheet: http://www.ti.com/lit/ds/symlink/ads1299.pdf
char[] maxValuesPerSetting = {
Expand All @@ -89,7 +88,7 @@ class HardwareSettingsController{
'1'
}; // SRB1 :: (0) Yes, (1) No ... this setting affects all channels ... either all on or all off
//

//variables used for channel write timing in writeChannelSettings()
int channelToWrite = -1;

Expand Down
2 changes: 1 addition & 1 deletion OpenBCI_GUI/Info.plist.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<key>CFBundleShortVersionString</key>
<string>3</string>
<key>CFBundleVersion</key>
<string>3.4.0</string>
<string>4.0.0-alpha.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
Expand Down
9 changes: 8 additions & 1 deletion OpenBCI_GUI/InterfaceHub.pde
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ final static String TCP_JSON_KEY_CODE = "code";
final static String TCP_JSON_KEY_COMMAND = "command";
final static String TCP_JSON_KEY_FIRMWARE = "firmware";
final static String TCP_JSON_KEY_IMPEDANCE_VALUE = "impedanceValue";
final static String TCP_JSON_KEY_IMPEDANCE_SET_P_INPUT = "pInputApplied";
final static String TCP_JSON_KEY_IMPEDANCE_SET_N_INPUT = "nInputApplied";
final static String TCP_JSON_KEY_LATENCY = "latency";
final static String TCP_JSON_KEY_MESSAGE = "message";
final static String TCP_JSON_KEY_NAME = "name";
Expand Down Expand Up @@ -120,10 +122,12 @@ final static String TCP_TYPE_STATUS = "status";
final static String TCP_TYPE_WIFI = "wifi";
final static String TCP_STOP = "\r\n";

final static String TCP_ACTION_SET = "set";
final static String TCP_ACTION_START = "start";
final static String TCP_ACTION_STATUS = "status";
final static String TCP_ACTION_STOP = "stop";


final static String TCP_WIFI_ERASE_CREDENTIALS = "eraseCredentials";
final static String TCP_WIFI_GET_FIRMWARE_VERSION = "getFirmwareVersion";
final static String TCP_WIFI_GET_IP_ADDRESS = "getIpAddress";
Expand Down Expand Up @@ -363,7 +367,6 @@ class Hub {
processBoardType(json);
} else if (type.equals(TCP_TYPE_CHANNEL_SETTINGS)) {
processRegisterQuery(json);
checkForSuccessTS = json.getInt(TCP_JSON_KEY_CODE);
} else if (type.equals(TCP_TYPE_COMMAND)) {
processCommand(json);
} else if (type.equals(TCP_TYPE_CONNECT)) {
Expand Down Expand Up @@ -856,6 +859,10 @@ class Hub {
action = json.getString(TCP_JSON_KEY_ACTION);
if (action.equals(TCP_ACTION_START)) {
println("Query registers for cyton channel settings");
} else if (action.equals(TCP_ACTION_SET)) {
checkForSuccessTS = json.getInt(TCP_JSON_KEY_CODE);
println("Success writing channel " + json.getInt(TCP_JSON_KEY_CHANNEL_NUMBER));

}
break;
case RESP_SUCCESS_CHANNEL_SETTING:
Expand Down
4 changes: 2 additions & 2 deletions OpenBCI_GUI/OpenBCI_GUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ String loadSettingsDialogName; //Used when Load button is pressed
String controlEventDataSource; //Used for output message on system start
Boolean errorUserSettingsNotFound = false; //For error catching
int loadErrorTimerStart;
int loadErrorTimeWindow = 3800; //Time window in milliseconds to apply channel settings to Cyton board. This is to avoid a GUI crash at ~ 4500-5000 milliseconds.
int loadErrorTimeWindow = 5000; //Time window in milliseconds to apply channel settings to Cyton board. This is to avoid a GUI crash at ~ 4500-5000 milliseconds.
Boolean loadErrorCytonEvent = false;

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1442,7 +1442,7 @@ void introAnimation() {
textLeading(24);
fill(31, 69, 110, transparency);
textAlign(CENTER, CENTER);
text("OpenBCI GUI v3.4.0\nAugust 2018", width/2, height/2 + width/9);
text("OpenBCI GUI v4.0.0-alpha.0\nSeptember 2018", width/2, height/2 + width/9);
}

//exit intro animation at t2
Expand Down
16 changes: 10 additions & 6 deletions OpenBCI_GUI/SoftwareSettings.pde
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,15 @@ void loadApplyTimeSeriesSettings() {
//Use channelSettingValues variable to store these settings once they are loaded from JSON file. Update occurs in hwSettingsController
channelSettingValues[i][0] = (char)(active + '0');
if (active == 0) {
activateChannel(channel);// power down == false, set color to vibrant
if (eegDataSource == DATASOURCE_GANGLION) {
activateChannel(channel);// power down == false, set color to vibrant
}
w_timeSeries.channelBars[i].isOn = true;
w_timeSeries.channelBars[i].onOffButton.setColorNotPressed(channelColors[(channel)%8]);
} else {
deactivateChannel(channel); // power down == true, set color to dark gray, indicating power down
if (eegDataSource == DATASOURCE_GANGLION) {
deactivateChannel(channel); // power down == true, set color to dark gray, indicating power down
}
w_timeSeries.channelBars[i].isOn = false; // deactivate it
w_timeSeries.channelBars[i].onOffButton.setColorNotPressed(color(50));
}
Expand All @@ -1022,17 +1026,17 @@ void loadApplyTimeSeriesSettings() {
channelSettingValues[i][5] = (char)(srb1Setting + '0');
} //end case for all channels

for (int i = 0; i < slnchan;) { //For all time series channels...
for (int i = 0; i < slnchan; i++) { //For all time series channels...
try {
cyton.writeChannelSettings(i, channelSettingValues); //Write the channel settings to the board!
} catch (RuntimeException e) {
verbosePrint("Runtime Error when trying to write channel settings to cyton...");
}
if (checkForSuccessTS > 0) { // If we receive a return code...
println("Return code:" + checkForSuccessTS);
println("Return code: " + checkForSuccessTS);
//when successful, iterate to next channel(i++) and set Check to null
if (checkForSuccessTS == RESP_SUCCESS) {
i++;
// i++;
checkForSuccessTS = 0;
}

Expand All @@ -1046,7 +1050,7 @@ void loadApplyTimeSeriesSettings() {
}
}
//delay(10);// Works on 8 chan sometimes
delay(100); // Works on 8 and 16 channels 3/3 trials applying settings to all channels.
delay(250); // Works on 8 and 16 channels 3/3 trials applying settings to all channels.
//Tested by setting gain 1x and loading 24x.
}
loadErrorCytonEvent = false;
Expand Down

0 comments on commit 1c47a16

Please sign in to comment.