Skip to content

Commit

Permalink
Add toggle for Ganglion v3 and MacOS to Control Panel - Temp fix for #…
Browse files Browse the repository at this point in the history
  • Loading branch information
retiutut committed Sep 20, 2023
1 parent 60455d9 commit a590c3b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
37 changes: 37 additions & 0 deletions OpenBCI_GUI/BoardGanglion.pde
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ class BoardGanglionNative extends BoardGanglion {
}
}
}

//Temporary fix for Ganglion firmware on Mac
public BoardGanglionNative(String name, boolean showUpgradePopup, boolean usingV3Firmware) {
super();
this.boardName = name;

if (usingV3Firmware) {
this.firmwareVersion = 3;
output("Detected Ganglion firmware version 3");
}
else {
this.firmwareVersion = 2;
output("Detected Ganglion firmware version 2");
if (showUpgradePopup) {
PopupMessage msg = new PopupMessage("Warning", "Ganglion firmware version 2 detected. Please update to version 3 for better performance. \n\nhttps://docs.openbci.com/Ganglion/GanglionProgram");
}
}
}

@Override
protected BrainFlowInputParams getParams() {
Expand Down Expand Up @@ -89,6 +107,25 @@ class BoardGanglionBLE extends BoardGanglion {
}
}

//Temporary fix for Ganglion firmware on Mac
public BoardGanglionBLE(String deviceName, String serialPort, String macAddress, boolean showUpgradePopup, boolean usingV3Firmware) {
super();
this.serialPort = serialPort;
this.macAddress = macAddress;

if (usingV3Firmware) {
this.firmwareVersion = 3;
output("Detected Ganglion firmware version 3");
}
else {
this.firmwareVersion = 2;
if (showUpgradePopup) {
PopupMessage msg = new PopupMessage("Warning", "Ganglion firmware version 2 detected. Please update to version 3 for better performance. \n\nhttps://docs.openbci.com/Ganglion/GanglionProgram");
}
output("Detected Ganglion firmware version 2");
}
}

@Override
public BoardIds getBoardId() {
return BoardIds.GANGLION_BOARD;
Expand Down
50 changes: 50 additions & 0 deletions OpenBCI_GUI/ControlPanel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ class BLEBox {
private MenuList bleList;
private Button refreshBLE;
Map<String, String> bleMACAddrMap = new HashMap<String, String>();
private final int BUTTON_HEIGHT = 24;

private Button v2FirmwareButton;
private Button v3FirmwareButton;

BLEBox(int _x, int _y, int _w, int _h, int _padding) {
x = _x;
Expand All @@ -691,6 +695,17 @@ class BLEBox {

createRefreshBLEButton("refreshGanglionBLEButton", "START SEARCH", x + padding, y + padding*4 + 72 + 8, w - padding*5, 24);
createGanglionBLEMenuList(bleBox_cp5, "bleList", x + padding, y + padding*3 + 8, w - padding*2, 72, p3);

//Temporary fix for Mac OS X and Ganglion BLE
if (isMac()) {
h = 140 + _padding * 2 + BUTTON_HEIGHT;
int buttonWidth = (w-padding*3)/2;
int buttonY = y + h - padding - BUTTON_HEIGHT;
createV2FirmwareButton("v2FirmwareButton", "V2 FIRMWARE", x + padding, buttonY, buttonWidth, BUTTON_HEIGHT);
createV3FirmwareButton("v3FirmwareButton", "V3 FIRMWARE", x + padding + buttonWidth + padding, buttonY, buttonWidth, BUTTON_HEIGHT);
}


}

public void update() {
Expand Down Expand Up @@ -835,6 +850,41 @@ class BLEBox {
}
});
}

//Temporary fix for Ganglion firmware on Mac
private void createV2FirmwareButton(String name, String text, int _x, int _y, int _w, int _h) {
v2FirmwareButton = createButton(bleBox_cp5, name, text, _x, _y, _w, _h);
v2FirmwareButton.setSwitch(true);
if (usingGanglionV3andMacOS) {
v2FirmwareButton.setOff();
} else {
v2FirmwareButton.setOn();
}
v2FirmwareButton.setOn();
v2FirmwareButton.onRelease(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
v3FirmwareButton.setOff();
usingGanglionV3andMacOS = false;
}
});
}

//Temporary fix for Ganglion firmware on Mac
private void createV3FirmwareButton(String name, String text, int _x, int _y, int _w, int _h) {
v3FirmwareButton = createButton(bleBox_cp5, name, text, _x, _y, _w, _h);
v3FirmwareButton.setSwitch(true);
if (usingGanglionV3andMacOS) {
v3FirmwareButton.setOn();
} else {
v3FirmwareButton.setOff();
}
v3FirmwareButton.onRelease(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
v2FirmwareButton.setOff();
usingGanglionV3andMacOS = true;
}
});
}
};

class WifiBox {
Expand Down
14 changes: 12 additions & 2 deletions OpenBCI_GUI/OpenBCI_GUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ boolean isFFTFiltered = true; //yes by default ... this is used in dataProcessin
StringBuilder globalScreenResolution;
StringBuilder globalScreenDPI;

boolean usingGanglionV3andMacOS = false;

//------------------------------------------------------------------------
// Global Functions
//------------------------------------------------------------------------
Expand Down Expand Up @@ -621,12 +623,20 @@ void initSystem() {
String ganglionPort = (String)(controlPanel.bleBox.bleList.getItem(controlPanel.bleBox.bleList.activeItem).get("subline"));
String ganglionMac = controlPanel.bleBox.bleMACAddrMap.get(ganglionName);
println("MAC address for Ganglion is " + ganglionMac);
currentBoard = new BoardGanglionBLE(ganglionName, ganglionPort, ganglionMac, showUpgradePopup);
if (isMac()) {
currentBoard = new BoardGanglionBLE(ganglionName, ganglionPort, ganglionMac, showUpgradePopup, usingGanglionV3andMacOS);
} else {
currentBoard = new BoardGanglionBLE(ganglionName, ganglionPort, ganglionMac, showUpgradePopup);
}
} else if (selectedProtocol == BoardProtocol.NATIVE_BLE) {
String ganglionName = (String)(controlPanel.bleBox.bleList.getItem(controlPanel.bleBox.bleList.activeItem).get("headline"));
String ganglionMac = controlPanel.bleBox.bleMACAddrMap.get(ganglionName);
println("MAC address for Ganglion is " + ganglionMac);
currentBoard = new BoardGanglionNative(ganglionName, showUpgradePopup);
if (isMac()) {
currentBoard = new BoardGanglionNative(ganglionName, showUpgradePopup, usingGanglionV3andMacOS);
} else {
currentBoard = new BoardGanglionNative(ganglionName, showUpgradePopup);
}
}
break;
case DATASOURCE_STREAMING:
Expand Down

0 comments on commit a590c3b

Please sign in to comment.