@@ -65,8 +65,8 @@ class W_Networking extends Widget {
6565 private String defaultBaud;
6666
6767 public LinkedList<String > protocols = new LinkedList<String > (Arrays . asList(" UDP" , " LSL" , " OSC" , " Serial" ));
68- public LinkedList<String > dataTypes = new LinkedList<String > (Arrays . asList(" None" , " Focus" , " EMG " , " AvgBandPower" ,
69- " TimeSeriesFilt" , " TimeSeriesRaw" , " Accel/Aux" , " Pulse" , " BandPower" , " FFT" ));
68+ public LinkedList<String > dataTypes = new LinkedList<String > (Arrays . asList(" None" , " Focus" , " EMGJoystick " , " AvgBandPower" ,
69+ " TimeSeriesFilt" , " TimeSeriesRaw" , " EMG " , " Accel/Aux" , " Pulse" , " BandPower" , " FFT" ));
7070 public LinkedList<String > baudRates = new LinkedList<String > (Arrays . asList(" 57600" , " 115200" , " 250000" , " 500000" ));
7171 public LinkedList<String > dataTypeNames = new LinkedList<String > (
7272 Arrays . asList(" dataType1" , " dataType2" , " dataType3" , " dataType4" ));
@@ -516,12 +516,14 @@ class W_Networking extends Widget {
516516 startNetwork(); // Begin streaming
517517 output(" Network Stream Started" );
518518 } catch (Exception e) {
519- // e.printStackTrace();
519+ e. printStackTrace();
520520 String exception = e. toString();
521521 String [] nwError = split (exception, ' :' );
522522 outputError(" Networking Error - Port: " + nwError[2 ]);
523523 shutDown();
524524 networkActive = false ;
525+ startButton. setColorBackground(TURN_ON_GREEN );
526+ startButton. getCaptionLabel(). setText(" Start " + protocolMode + " Stream" );
525527 return ;
526528 }
527529 } else {
@@ -990,9 +992,10 @@ class W_Networking extends Widget {
990992 return digitalBoard. getDigitalChannels(). length;
991993 }
992994 }
995+ } else if (dataType. equals(" EMGJoystick" )) {
996+ return 2 ;
993997 }
994- outputError(" Error detecting number of channels for LSL stream data... please fix!" );
995- return 0 ;
998+ throw new IllegalArgumentException (" IllegalArgumentException: Error detecting number of channels for LSL stream data... please fix!" );
996999 }
9971000
9981001 private void checkOverlappingSerialDropdown () {
@@ -1303,6 +1306,8 @@ class Stream extends Thread {
13031306 }
13041307 } else if (this . dataType. equals(" Pulse" )) {
13051308 sendPulseData();
1309+ } else if (this . dataType. equals(" EMGJoystick" )) {
1310+ sendEMGJoystickData();
13061311 }
13071312 }
13081313
@@ -1965,6 +1970,72 @@ class Stream extends Thread {
19651970 }
19661971 }// End sendPulseData
19671972
1973+ private void sendEMGJoystickData () {
1974+
1975+ final float [] emgJoystickXY = w_emgJoystick. getJoystickXY();
1976+
1977+ if (this . protocol. equals(" OSC" )) {
1978+ for (int i = 0 ; i < emgJoystickXY. length; i++ ) {
1979+ msg. clearArguments();
1980+ if (i == 0 ) {
1981+ msg. setAddrPattern(baseOscAddress + " /emg-joystick/x" );
1982+ } else if (i == 1 ) {
1983+ msg. setAddrPattern(baseOscAddress + " /emg-joystick/y" );
1984+ }
1985+ msg. add(emgJoystickXY[i]);
1986+ try {
1987+ this . osc. send(msg, this . oscNetAddress);
1988+ } catch (Exception e) {
1989+ println (e. getMessage());
1990+ }
1991+ }
1992+ } else if (this . protocol. equals(" UDP" )) {
1993+ StringBuilder output = new StringBuilder (" {\" type\" :\" emgJoystick\" ,\" data\" :[" );
1994+ for (int i = 0 ; i < emgJoystickXY. length; i++ ) {
1995+ // Formatting in this way is resilient to internationalization
1996+ String dataFormatted = threeDecimalPlaces. format(emgJoystickXY[i]);
1997+ output. append(dataFormatted);
1998+ if (i != emgJoystickXY. length - 1 ) {
1999+ output. append(" ," );
2000+ } else {
2001+ output. append(" ]}\r\n " );
2002+ }
2003+ }
2004+ try {
2005+ this . udp. send(output. toString(), this . ip, this . port);
2006+ } catch (Exception e) {
2007+ println (e. getMessage());
2008+ }
2009+ } else if (this . protocol. equals(" LSL" )) {
2010+ for (int i = 0 ; i < emgJoystickXY. length; i++ ) {
2011+ dataToSend[i] = emgJoystickXY[i];
2012+ }
2013+ outlet_data. push_sample(dataToSend);
2014+ } else if (this . protocol. equals(" Serial" )) {
2015+ // Data Format: +0.900,-0.042\n
2016+ // 7 chars per axis, including \n char
2017+ StringBuilder output = new StringBuilder ();
2018+ for (int i = 0 ; i < emgJoystickXY. length; i++ ) {
2019+ float data = emgJoystickXY[i];
2020+ String dataFormatted = threeDecimalPlaces. format(data);
2021+ if (data >= 0 )
2022+ output. append(" +" );
2023+ output. append(dataFormatted);
2024+ if (i != emgJoystickXY. length - 1 ) {
2025+ output. append(" ," );
2026+ } else {
2027+ output. append(" \n " );
2028+ }
2029+ }
2030+ try {
2031+ // println(serialMessage);
2032+ this . serial_networking. write(output. toString());
2033+ } catch (Exception e) {
2034+ println (e. getMessage());
2035+ }
2036+ }
2037+ }
2038+
19682039 // // Add new stream function here (ex. sendWidgetData) in the same format as
19692040 // // above
19702041
0 commit comments