Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Software Marker Widget #1174

Merged
merged 19 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4303a75
Add W_Marker widget and a few base methods
retiutut Aug 2, 2023
13de3f7
Add insertMarker and getMarkerChannel methods to all relevant boards
retiutut Aug 3, 2023
482195f
Add time series to Marker Widget
retiutut Aug 4, 2023
0de3b4d
Fix non final variable due to scope in Marker widget
retiutut Aug 4, 2023
2c034cd
Add ability to playback marker data in Marker Widget
retiutut Aug 4, 2023
9e96344
Add more Marker keyboard shortcuts and remove s, b, and d shortcuts
retiutut Aug 4, 2023
bc8e2c9
Add Marker data type to networking output
retiutut Aug 4, 2023
08e9ef5
Update marker widget button positions using Grid class
retiutut Aug 10, 2023
f42f970
Add test for receiving Markers over UDP
retiutut Aug 14, 2023
690c0d8
Remove sampling rate check in sendMarkerData in Networking
retiutut Aug 14, 2023
05371a9
Add Marker Widget to Session settings and account for UI overlapping
retiutut Aug 14, 2023
3deb1a3
Add udp marker receiver to Marker widget
retiutut Aug 14, 2023
9eaf884
Update Marker Widget UI to improve UDP receiver textfield appearance
retiutut Aug 15, 2023
ac27e49
Update Marker Widget Vert Scale UI and show all 8 buttons always
retiutut Aug 15, 2023
254a705
Fix non-final variable in local scope in Marker Widget createTextfield
retiutut Aug 15, 2023
78eff9d
Update version to v6.0.0-alpha.1 and update changelog
retiutut Aug 15, 2023
d9b1221
Update line endings for certain files
retiutut Aug 16, 2023
2e7492e
Remove unnecessary comments left in from debugging
retiutut Aug 16, 2023
7987509
Add autoscale option to marker widget
retiutut Aug 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Improvements
- Update repository to Processing 4.2 #1111
- Add Software Marker Widget #1091

# v5.2.1

Expand Down
4 changes: 3 additions & 1 deletion Networking-Test-Kit/LSL/lslStreamTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def testLSLSamplingRate():
# print( len(chunk) )
totalNumSamples += len(chunk)
# print(chunk)
i = 0
for sample in chunk:
print(sample)
print(sample, timestamp[i])
validSamples += 1
i += 1

print( "Number of Chunks and Samples == {} , {}".format(numChunks, totalNumSamples) )
print( "Valid Samples and Duration == {} / {}".format(validSamples, duration) )
Expand Down
106 changes: 106 additions & 0 deletions Networking-Test-Kit/UDP/udp_receive_marker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import socket
import sys
import time
import argparse
import signal
import struct
import os
import json

numSamples = 0

# Print received message to console
def print_message(*args):
try:
#print(args[0]) #added to see raw data
obj = json.loads(args[0].decode())
print(obj.get('data'))
num_samples_packet = len(obj.get('data'))
global numSamples
print("NumSamplesInPacket_Marker == " + str(num_samples_packet))
numSamples += num_samples_packet
if obj:
return True
else:
return False
except BaseException as e:
print(e)
return False

# Clean exit from print mode
def exit_print(signal, frame):
print("Closing listener")
sys.exit(0)

# Record received message in text file
def record_to_file(*args):
textfile.write(str(time.time()) + ",")
obj = json.loads(args[0].decode())
#print(obj.get('data'))
textfile.write(json.dumps(obj))
textfile.write("\n")

# Save recording, clean exit from record mode
def close_file(*args):
print("\nFILE SAVED")
textfile.close()
sys.exit(0)

if __name__ == "__main__":
# Collect command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=12345, help="The port to listen on")
parser.add_argument("--address",default="/openbci", help="address to listen to")
parser.add_argument("--option",default="print",help="Debugger option")
parser.add_argument("--len",default=9,help="Debugger option")
args = parser.parse_args()

# Set up necessary parameters from command line
length = int(args.len)
if args.option=="print":
signal.signal(signal.SIGINT, exit_print)
elif args.option=="record":
i = 0
while os.path.exists("udp_test%s.txt" % i):
i += 1
filename = "udp_test%i.txt" % i
textfile = open(filename, "w")
textfile.write("time,address,messages\n")
textfile.write("-------------------------\n")
print("Recording to %s" % filename)
signal.signal(signal.SIGINT, close_file)

# Connect to socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = (args.ip, args.port)
sock.bind(server_address)

# Display socket attributes
print('--------------------')
print("-- UDP LISTENER -- ")
print('--------------------')
print("IP:", args.ip)
print("PORT:", args.port)
print('--------------------')
print("%s option selected" % args.option)

# Receive messages
print("Listening...")
start = time.time()

duration = 10
while time.time() <= start + duration:
data, addr = sock.recvfrom(20000) # buffer size is 20000 bytes
if args.option=="print":
print_message(data)
elif args.option=="record":
record_to_file(data)
numSamples += 1

print( "Samples == {}".format(numSamples) )
print( "Duration == {}".format(duration) )
print( "Avg Sampling Rate == {}".format(numSamples / duration) )
42 changes: 42 additions & 0 deletions Networking-Test-Kit/UDP/udp_send_marker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import socket
import random
import struct
import time
import argparse

if __name__ == "__main__":

test_duration = 10

# Collect command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The IP of the UDP server")
parser.add_argument("--port", type=int, default=12350,
help="The port the UDP server is sending to")
args = parser.parse_args()

# Establish UDP socket
UDP_IP = args.ip
UDP_PORT = args.port
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP

# Display socket attributes
print('---------------------')
print("-- UDP MARKER SEND -- ")
print('---------------------')
print("IP:", args.ip)
print("PORT:", args.port)
print('--------------------=')

# Send test data
start = time.time()
while time.time() <= start + test_duration:
# generate random float
marker = random.uniform(0, 4)
# package as byte array
msg = struct.pack('!d', marker)
# send through socket
sock.sendto(msg, (UDP_IP, UDP_PORT))
time.sleep(.25)
4 changes: 4 additions & 0 deletions OpenBCI_GUI/Board.pde
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ abstract class Board implements DataSource {

public abstract Pair <Boolean, String> sendCommand(String command);

public abstract void insertMarker(int value);

public abstract void insertMarker(double value);

// ***************************************
// protected methods implemented by board

Expand Down
3 changes: 2 additions & 1 deletion OpenBCI_GUI/BoardBrainFlowSynthetic.pde
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ class BoardBrainFlowSynthetic extends BoardBrainFlow implements AccelerometerCap

@Override
protected void addChannelNamesInternal(String[] channelNames) {
for (int i=0; i<getAccelerometerChannels().length; i++) {
for (int i = 0; i < getAccelerometerChannels().length; i++) {
channelNames[getAccelerometerChannels()[i]] = "Accel Channel " + i;
}
channelNames[getMarkerChannel()] = "Marker Channel";
}

@Override
Expand Down
38 changes: 38 additions & 0 deletions OpenBCI_GUI/BoardBrainflow.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ abstract class BoardBrainFlow extends Board {
protected int sampleIndexChannelCache = -1;
protected int timeStampChannelCache = -1;
protected int totalChannelsCache = -1;
protected int markerChannelCache = -1;
protected int[] exgChannelsCache = null;
protected int[] otherChannelsCache = null;

protected boolean streaming = false;
protected double time_last_datapoint = -1.0;
protected boolean data_popup_displayed = false;

private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

/* Abstract Functions.
* Implement these in your board.
*/
Expand Down Expand Up @@ -300,4 +303,39 @@ abstract class BoardBrainFlow extends Board {

return otherChannelsCache;
}

@Override
public int getMarkerChannel() {
if (markerChannelCache < 0) {
try {
markerChannelCache = BoardShim.get_marker_channel(getBoardIdInt());
} catch (BrainFlowError e) {
e.printStackTrace();
}
}

return markerChannelCache;
}

@Override
public void insertMarker(double value) {
if (isConnected() && streaming) {
try {
boardShim.insert_marker(value);
String currentTimeString = dateFormat.format(new Date());
StringBuilder markerNotification = new StringBuilder("Inserted marker ");
markerNotification.append(value);
markerNotification.append(" at approximately: ");
markerNotification.append(currentTimeString);
println(markerNotification.toString());
} catch (BrainFlowError e) {
e.printStackTrace();
}
}
}

@Override
public void insertMarker(int value) {
insertMarker((double) value);
}
};
1 change: 1 addition & 0 deletions OpenBCI_GUI/BoardCyton.pde
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ implements ImpedanceSettingsBoard, AccelerometerCapableBoard, AnalogCapableBoard
for (int i=0; i<getAnalogChannels().length; i++) {
channelNames[getAnalogChannels()[i]] = "Analog Channel " + i;
}
channelNames[getMarkerChannel()] = "Marker Channel";
}

@Override
Expand Down
1 change: 1 addition & 0 deletions OpenBCI_GUI/BoardGanglion.pde
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ abstract class BoardGanglion extends BoardBrainFlow implements AccelerometerCapa
for (int i=0; i<getAccelerometerChannels().length; i++) {
channelNames[getAccelerometerChannels()[i]] = "Accel Channel " + i;
}
channelNames[getMarkerChannel()] = "Marker Channel";
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions OpenBCI_GUI/BoardNull.pde
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ class BoardNull extends Board {
return 0;
}

@Override
public int getMarkerChannel() {
return 0;
}

@Override
public void insertMarker(int marker) {
// empty
}

@Override
public void insertMarker(double value) {
// empty
}

@Override
public void setEXGChannelActive(int channelIndex, boolean active) {
// empty
Expand Down
2 changes: 2 additions & 0 deletions OpenBCI_GUI/DataSource.pde
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface DataSource {
public int getTotalChannelCount();

public boolean isStreaming();

public int getMarkerChannel();
};
5 changes: 5 additions & 0 deletions OpenBCI_GUI/DataSourcePlayback.pde
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ abstract class DataSourcePlayback implements DataSource, FileBoard {
return float(getCurrentSample()) / float(getSampleRate());
}

@Override
public int getMarkerChannel() {
return underlyingBoard.getMarkerChannel();
}

public void goToIndex(int index) {
currentSampleExg = index;
}
Expand Down
6 changes: 6 additions & 0 deletions OpenBCI_GUI/DataSourceSDCard.pde
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class DataSourceSDCard implements DataSource, FileBoard, AccelerometerCapableBoa
return totalChannels;
}

@Override
public int getMarkerChannel() {
//There is no software marker channel for SD card playback
return -1;
}

@Override
public double[][] getFrameData() {
double[][] array = new double[getTotalChannelCount()][numNewSamplesThisFrame];
Expand Down
10 changes: 7 additions & 3 deletions OpenBCI_GUI/DataWriterODF.pde
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DataWriterODF {

String[] colNames = getChannelNames();

for (int i=0; i<colNames.length; i++) {
for (int i = 0; i < colNames.length; i++) {
output.print(colNames[i]);
output.print(", ");
}
Expand All @@ -37,8 +37,8 @@ public class DataWriterODF {

public void append(double[][] data) {
//get current date time with Date()
for (int iSample=0; iSample<data[0].length; iSample++) {
for (int iChan=0; iChan<data.length; iChan++) {
for (int iSample = 0; iSample < data[0].length; iSample++) {
for (int iChan = 0; iChan < data.length; iChan++) {
output.print(data[iChan][iSample]);
output.print(", ");
}
Expand Down Expand Up @@ -81,5 +81,9 @@ public class DataWriterODF {
protected int getTimestampChannel() {
return ((Board)currentBoard).getTimestampChannel();
}

protected int getMarkerChannel() {
return ((Board)currentBoard).getMarkerChannel();
}

};
9 changes: 6 additions & 3 deletions OpenBCI_GUI/Extras.pde
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,14 @@ String getIpAddrFromStr(String strWithIP) {
}
}

float getFontStringHeight(PFont _font, String string) {
float getFontStringHeight(PFont font, String text) {
if (text == null) {
return 0;
}
float minY = Float.MAX_VALUE;
float maxY = Float.NEGATIVE_INFINITY;
for (Character c : string.toCharArray()) {
PShape character = _font.getShape(c); // create character vector
for (Character c : text.toCharArray()) {
PShape character = font.getShape(c); // create character vector
for (int i = 0; i < character.getVertexCount(); i++) {
minY = min(character.getVertex(i).y, minY);
maxY = max(character.getVertex(i).y, maxY);
Expand Down
6 changes: 5 additions & 1 deletion OpenBCI_GUI/Grid.pde
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Grid {
pushStyle();
textAlign(LEFT);
stroke(OPENBCI_DARKBLUE);
textFont(p5, 12);
textFont(tableFont, tableFontSize);

if (drawTableInnerLines) {
// draw row lines
Expand Down Expand Up @@ -145,4 +145,8 @@ class Grid {
public void setDrawTableInnerLines(boolean b) {
drawTableInnerLines = b;
}

public int getHeight() {
return rowHeight * numRows;
}
}
2 changes: 1 addition & 1 deletion OpenBCI_GUI/Info.plist.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Copyright © 2023 OpenBCI
</string>
<key>CFBundleGetInfoString</key>
<string>July 2023</string>
<string>August 2023</string>
<!-- End of the set that can be customized -->

<key>JVMRuntime</key>
Expand Down
Loading