Skip to content

Commit 81de40d

Browse files
authored
Merge pull request #1173 from OpenBCI/update-ganglion-decompression
Update Ganglion decompression
2 parents 5547183 + 1d7b589 commit 81de40d

10 files changed

Lines changed: 138 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ libDataHandler.so
2626
libGanglionLib.so
2727
libGanglionScan.so
2828
libunicorn.so
29+
OpenBCI_GUI/out/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v5.2.2
2+
3+
### Improvements
4+
- Update Ganglion decompression to support Ganglion firmware v3 and v2 #1173 Awesome work! @philippitts
5+
16
# v5.2.1
27

38
### Improvements

OpenBCI_GUI/BoardBrainflow.pde

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ abstract class BoardBrainFlow extends Board {
102102
time_last_datapoint = -1.0;
103103
}
104104
catch (BrainFlowError e) {
105-
println("ERROR: Exception when stoppping stream");
105+
outputError("ERROR: Exception when stopping stream. Please restart the Board and Session.");
106106
e.printStackTrace();
107-
streaming = true;
107+
//If no data was received in X seconds, there is a serious problem with communications. Go ahead and stop trying to collect data.
108+
//Prevents feedback loop of errors.
109+
if (data_popup_displayed) {
110+
streaming = false;
111+
}
108112
}
109113

110114
if (eegDataSource != DATASOURCE_PLAYBACKFILE && eegDataSource != DATASOURCE_STREAMING) {

OpenBCI_GUI/BoardGanglion.pde

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ class BoardGanglionNative extends BoardGanglion {
22

33
private PacketLossTrackerGanglionBLE packetLossTrackerGanglionNative;
44
private String boardName;
5+
private int firmwareVersion = 0;
56

67
public BoardGanglionNative() {
78
super();
89
}
910

10-
public BoardGanglionNative(String name) {
11+
public BoardGanglionNative(String name, boolean showUpgradePopup) {
1112
super();
1213
this.boardName = name;
14+
15+
if (name.indexOf("Ganglion 1.3") != -1) {
16+
this.firmwareVersion = 3;
17+
output("Detected Ganglion firmware version 3");
18+
}
19+
else {
20+
this.firmwareVersion = 2;
21+
output("Detected Ganglion firmware version 2");
22+
if (showUpgradePopup) {
23+
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");
24+
}
25+
}
1326
}
1427

1528
@Override
@@ -37,24 +50,43 @@ class BoardGanglionNative extends BoardGanglion {
3750

3851
@Override
3952
protected PacketLossTracker setupPacketLossTracker() {
40-
packetLossTrackerGanglionNative = new PacketLossTrackerGanglionBLE(getSampleIndexChannel(), getTimestampChannel());
53+
if (firmwareVersion == 2) {
54+
packetLossTrackerGanglionNative = new PacketLossTrackerGanglionBLE2(getSampleIndexChannel(), getTimestampChannel());
55+
}
56+
else if (firmwareVersion == 3) {
57+
packetLossTrackerGanglionNative = new PacketLossTrackerGanglionBLE3(getSampleIndexChannel(), getTimestampChannel());
58+
}
59+
4160
packetLossTrackerGanglionNative.setAccelerometerActive(isAccelerometerActive());
4261
return packetLossTrackerGanglionNative;
4362
}
4463
};
4564

4665
class BoardGanglionBLE extends BoardGanglion {
4766

67+
private int firmwareVersion = 0;
4868
private PacketLossTrackerGanglionBLE packetLossTrackerGanglionBLE;
4969

5070
public BoardGanglionBLE() {
5171
super();
5272
}
5373

54-
public BoardGanglionBLE(String serialPort, String macAddress) {
74+
public BoardGanglionBLE(String deviceName, String serialPort, String macAddress, boolean showUpgradePopup) {
5575
super();
5676
this.serialPort = serialPort;
5777
this.macAddress = macAddress;
78+
79+
if (deviceName.indexOf("Ganglion 1.3") != -1) {
80+
this.firmwareVersion = 3;
81+
output("Detected Ganglion firmware version 3");
82+
}
83+
else {
84+
this.firmwareVersion = 2;
85+
if (showUpgradePopup) {
86+
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");
87+
}
88+
output("Detected Ganglion firmware version 2");
89+
}
5890
}
5991

6092
@Override
@@ -75,7 +107,13 @@ class BoardGanglionBLE extends BoardGanglion {
75107

76108
@Override
77109
protected PacketLossTracker setupPacketLossTracker() {
78-
packetLossTrackerGanglionBLE = new PacketLossTrackerGanglionBLE(getSampleIndexChannel(), getTimestampChannel());
110+
if (firmwareVersion == 2) {
111+
packetLossTrackerGanglionBLE = new PacketLossTrackerGanglionBLE2(getSampleIndexChannel(), getTimestampChannel());
112+
}
113+
else if (firmwareVersion == 3) {
114+
packetLossTrackerGanglionBLE = new PacketLossTrackerGanglionBLE3(getSampleIndexChannel(), getTimestampChannel());
115+
}
116+
79117
packetLossTrackerGanglionBLE.setAccelerometerActive(isAccelerometerActive());
80118
return packetLossTrackerGanglionBLE;
81119
}
@@ -141,6 +179,7 @@ abstract class BoardGanglion extends BoardBrainFlow implements AccelerometerCapa
141179
protected String serialPort = "";
142180
protected String macAddress = "";
143181
protected String ipAddress = "";
182+
144183
private boolean isCheckingImpedance = false;
145184
private boolean isGettingAccel = false;
146185

OpenBCI_GUI/GuiSettings.pde

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum ExpertModeEnum implements GuiSettingsEnum {
3434
public class GuiSettingsValues {
3535
public ExpertModeEnum expertMode = ExpertModeEnum.OFF;
3636
public boolean showCytonSmoothingPopup = true;
37+
public boolean showGanglionUpgradePopup = true;
3738

3839
public GuiSettingsValues() {
3940
}
@@ -43,7 +44,7 @@ class GuiSettings {
4344

4445
private GuiSettingsValues values;
4546
private String filename;
46-
private List<String> valueKeys = Arrays.asList("expertMode", "showCytonSmoothingPopup");
47+
private List<String> valueKeys = Arrays.asList("expertMode", "showCytonSmoothingPopup", "showGanglionUpgradePopup");
4748

4849
GuiSettings(String settingsDirectory) {
4950

@@ -164,7 +165,16 @@ class GuiSettings {
164165
saveToFile();
165166
}
166167

168+
public void setShowGanglionUpgradePopup(boolean b) {
169+
values.showGanglionUpgradePopup = b;
170+
saveToFile();
171+
}
172+
167173
public boolean getShowCytonSmoothingPopup() {
168174
return values.showCytonSmoothingPopup;
169175
}
176+
177+
public boolean getShowGanglionUpgradePopup() {
178+
return values.showGanglionUpgradePopup;
179+
}
170180
}

OpenBCI_GUI/Info.plist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<key>CFBundleShortVersionString</key>
2424
<string>5</string>
2525
<key>CFBundleVersion</key>
26-
<string>5.2.1</string>
26+
<string>5.2.2</string>
2727
<key>CFBundleSignature</key>
2828
<string>????</string>
2929
<key>NSHumanReadableCopyright</key>

OpenBCI_GUI/OpenBCI_GUI.pde

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
6262
// Global Variables & Instances
6363
//------------------------------------------------------------------------
6464
//Used to check GUI version in TopNav.pde and displayed on the splash screen on startup
65-
String localGUIVersionString = "v5.2.1";
66-
String localGUIVersionDate = "July 2023";
65+
String localGUIVersionString = "v5.2.2";
66+
String localGUIVersionDate = "August 2023";
6767
String guiLatestVersionGithubAPI = "https://api.github.com/repos/OpenBCI/OpenBCI_GUI/releases/latest";
6868
String guiLatestReleaseLocation = "https://github.com/OpenBCI/OpenBCI_GUI/releases/latest";
6969
Boolean guiIsUpToDate;
@@ -606,19 +606,26 @@ void initSystem() {
606606
}
607607
break;
608608
case DATASOURCE_GANGLION:
609+
boolean showUpgradePopup = false;
610+
if (guiSettings.getShowGanglionUpgradePopup())
611+
{
612+
showUpgradePopup = true;
613+
guiSettings.setShowGanglionUpgradePopup(false);
614+
}
615+
609616
if (selectedProtocol == BoardProtocol.WIFI) {
610617
currentBoard = new BoardGanglionWifi(wifi_ipAddress, selectedSamplingRate);
611618
} else if (selectedProtocol == BoardProtocol.BLED112) {
612619
String ganglionName = (String)(controlPanel.bleBox.bleList.getItem(controlPanel.bleBox.bleList.activeItem).get("headline"));
613620
String ganglionPort = (String)(controlPanel.bleBox.bleList.getItem(controlPanel.bleBox.bleList.activeItem).get("subline"));
614621
String ganglionMac = controlPanel.bleBox.bleMACAddrMap.get(ganglionName);
615622
println("MAC address for Ganglion is " + ganglionMac);
616-
currentBoard = new BoardGanglionBLE(ganglionPort, ganglionMac);
623+
currentBoard = new BoardGanglionBLE(ganglionName, ganglionPort, ganglionMac, showUpgradePopup);
617624
} else if (selectedProtocol == BoardProtocol.NATIVE_BLE) {
618625
String ganglionName = (String)(controlPanel.bleBox.bleList.getItem(controlPanel.bleBox.bleList.activeItem).get("headline"));
619626
String ganglionMac = controlPanel.bleBox.bleMACAddrMap.get(ganglionName);
620-
println("MAC address for Ganglion is " + ganglionName);
621-
currentBoard = new BoardGanglionNative(ganglionName);
627+
println("MAC address for Ganglion is " + ganglionMac);
628+
currentBoard = new BoardGanglionNative(ganglionName, showUpgradePopup);
622629
}
623630
break;
624631
case DATASOURCE_STREAMING:
@@ -641,7 +648,7 @@ void initSystem() {
641648
println("OpenBCI_GUI: Configuring Cyton Channel Count...");
642649
if (currentBoard instanceof BoardCytonSerial) {
643650
Pair<Boolean, String> res = ((BoardBrainFlow)currentBoard).sendCommand("c");
644-
//println(res.getKey().booleanValue(), res.getValue());
651+
//println(res.getKey().booleanValue(), res.getValue());guiSettings
645652
if (res.getValue().startsWith("daisy removed")) {
646653
println("OpenBCI_GUI: Daisy is physically attached, using Cyton 8 Channels instead.");
647654
}

OpenBCI_GUI/PacketLossTracker.pde

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ class PacketLossTrackerCytonSerialDaisy extends PacketLossTracker {
211211
}
212212
}
213213

214-
// with accel: sample index range 0-100, all sample indexes are duplicated except for zero.
215-
// eg 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ... , 99, 99, 100, 100, 0, 1, 1, 2, 2, 3, 3, ...
216-
// without acceL: sample 0, then 101-200
217214
class PacketLossTrackerGanglionBLE extends PacketLossTracker {
218215

219216
ArrayList<Integer> sampleIndexArrayAccel = new ArrayList<Integer>();
@@ -225,32 +222,6 @@ class PacketLossTrackerGanglionBLE extends PacketLossTracker {
225222

226223
PacketLossTrackerGanglionBLE(int _sampleIndexChannel, int _timestampChannel, TTQTimeProvider _timeProvider) {
227224
super(_sampleIndexChannel, _timestampChannel, _timeProvider);
228-
229-
{
230-
// add indices to array of indices
231-
// With accel: 0-100, all sample indexes are duplicated except for zero
232-
sampleIndexArrayAccel.add(0);
233-
int firstIndex = 1;
234-
int lastIndex = 100;
235-
for (int i = firstIndex; i <= lastIndex; i++) {
236-
sampleIndexArrayAccel.add(i);
237-
sampleIndexArrayAccel.add(i);
238-
}
239-
}
240-
241-
{
242-
// add indices to array of indices
243-
// Without accel: 0, then 101 to 200, all sample indexes are duplicated except for zero
244-
sampleIndexArrayNoAccel.add(0);
245-
int firstIndex = 101;
246-
int lastIndex = 200;
247-
for (int i = firstIndex; i <= lastIndex; i++) {
248-
sampleIndexArrayNoAccel.add(i);
249-
sampleIndexArrayNoAccel.add(i);
250-
}
251-
}
252-
253-
setAccelerometerActive(true);
254225
}
255226

256227
public void setAccelerometerActive(boolean active) {
@@ -264,4 +235,60 @@ class PacketLossTrackerGanglionBLE extends PacketLossTracker {
264235

265236
reset();
266237
}
238+
}
239+
240+
// With acceleration: sample index range 0-100, all sample indexes are duplicated except for zero.
241+
// E.g. 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ... , 99, 99, 100, 100, 0, 1, 1, 2, 2, 3, 3, ...
242+
// Without acceleration: sample 0, then 101-200
243+
class PacketLossTrackerGanglionBLE2 extends PacketLossTrackerGanglionBLE {
244+
PacketLossTrackerGanglionBLE2(int _sampleIndexChannel, int _timestampChannel) {
245+
this(_sampleIndexChannel, _timestampChannel, new RealTimeProvider());
246+
}
247+
248+
PacketLossTrackerGanglionBLE2(int _sampleIndexChannel, int _timestampChannel, TTQTimeProvider _timeProvider) {
249+
super(_sampleIndexChannel, _timestampChannel, _timeProvider);
250+
251+
// Add indices to array of indices
252+
// With acceleration: 0-100, all sample indexes are duplicated except for zero
253+
sampleIndexArrayAccel.add(0);
254+
for (int i = 1; i <= 100; i++) {
255+
sampleIndexArrayAccel.add(i);
256+
sampleIndexArrayAccel.add(i);
257+
}
258+
259+
// Add indices to array of indices
260+
// Without acceleration: 0, then 101 to 200, all sample indexes are duplicated except for zero
261+
sampleIndexArrayNoAccel.add(0);
262+
for (int i = 101; i <= 200; i++) {
263+
sampleIndexArrayNoAccel.add(i);
264+
sampleIndexArrayNoAccel.add(i);
265+
}
266+
267+
setAccelerometerActive(true);
268+
}
269+
}
270+
271+
// With acceleration: sample index range 0-100, all sample indexes are duplicated (including zero).
272+
// E.g. 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, ... , 99, 99, 100, 100, 0, 0, 1, 1, 2, 2, 3, 3, ...
273+
// Without acceleration: 101-200
274+
class PacketLossTrackerGanglionBLE3 extends PacketLossTrackerGanglionBLE {
275+
PacketLossTrackerGanglionBLE3(int _sampleIndexChannel, int _timestampChannel) {
276+
this(_sampleIndexChannel, _timestampChannel, new RealTimeProvider());
277+
}
278+
279+
PacketLossTrackerGanglionBLE3(int _sampleIndexChannel, int _timestampChannel, TTQTimeProvider _timeProvider) {
280+
super(_sampleIndexChannel, _timestampChannel, _timeProvider);
281+
282+
for (int i = 0; i < 100; i++) {
283+
sampleIndexArrayAccel.add(i);
284+
sampleIndexArrayAccel.add(i);
285+
}
286+
287+
for (int i = 100; i < 200; i++) {
288+
sampleIndexArrayNoAccel.add(i);
289+
sampleIndexArrayNoAccel.add(i);
290+
}
291+
292+
setAccelerometerActive(true);
293+
}
267294
}
922 KB
Binary file not shown.

OpenBCI_GUI_unittests/PacketLossTrackerGanglion_UnitTests.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import org.junit.Before;
66

77
public static class PacketLossTrackerGanglionBLE_UnitTests{
88

9-
PacketLossTrackerGanglionBLE packetLossTracker;
9+
PacketLossTrackerGanglionBLE2 packetLossTracker;
1010
FakeTimeProvider fakeTimeProvider;
1111

1212
@Before
1313
public void setUp() {
1414
int sampleIndexChannel = 0;
1515
int timestampChannel = 1;
1616
fakeTimeProvider = currentApplet.new FakeTimeProvider();
17-
packetLossTracker = currentApplet.new PacketLossTrackerGanglionBLE(
17+
packetLossTracker = currentApplet.new PacketLossTrackerGanglionBLE2(
1818
sampleIndexChannel, timestampChannel, fakeTimeProvider);
1919
packetLossTracker.silent = true;
2020
}

0 commit comments

Comments
 (0)