Merge branch 'master' into development

Esse commit está contido em:
AJ Keller
2017-01-10 13:26:57 -05:00
commit de GitHub
4 arquivos alterados com 477 adições e 345 exclusões
+128 -127
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;
@@ -211,14 +211,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;
// }
}
//------------------------------------------------------------------------
@@ -697,40 +697,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()){
@@ -834,8 +834,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);
}
@@ -853,66 +853,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;
@@ -1693,34 +1693,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() {
@@ -1735,19 +1735,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()
@@ -1757,9 +1758,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;
}
+8 -7
Ver Arquivo
@@ -138,14 +138,15 @@ void serialEvent(Serial port){
board_message = new StringBuilder();
dollaBillz=0;
}
if (inByte != '$') board_message.append(char(inByte));
else dollaBillz++;
}
if (char(inByte) == 'S' || char(inByte) == 'F') {
if(inByte != '$'){
board_message.append(char(inByte));
} else { dollaBillz++; }
} else if(char(inByte) == 'S' || char(inByte) == 'F'){
isOpenBCI = true;
if (board_message == null) board_message = new StringBuilder();
board_message.append(char(inByte));
if(board_message == null){
board_message = new StringBuilder();
board_message.append(char(inByte));
}
}
}
}
+1 -1
Ver Arquivo
@@ -690,7 +690,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();
+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!");
// }
//
// }