From 3ec19c76a3abd06005ef425805e9fddf900b2a92 Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 4 Apr 2024 13:54:49 +0800 Subject: [PATCH 01/11] shimmer grpc now working --- .../BasicShimmerBluetoothManagerPc.java | 2 +- .../simpleexamples/SensorMapsExample.java | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java index 97a0eb559..9f75b7f1a 100644 --- a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java +++ b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java @@ -178,7 +178,7 @@ protected void connectVerisenseDevice(BluetoothDeviceDetails bdd) { } @Override - protected void connectShimmer3BleGrpc(BluetoothDeviceDetails bdd) { + public void connectShimmer3BleGrpc(BluetoothDeviceDetails bdd) { ShimmerGRPC shimmer; if(!shimmer3BleMacIdList.contains(bdd.mShimmerMacId)) { diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index b1c004b23..d3241176c 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -9,14 +9,16 @@ import com.shimmerresearch.driver.ObjectCluster; import com.shimmerresearch.driver.ShimmerDevice; import com.shimmerresearch.driver.ShimmerMsg; +import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails; import com.shimmerresearch.exceptions.ShimmerException; +import com.shimmerresearch.grpc.ShimmerGRPC; import com.shimmerresearch.guiUtilities.configuration.EnableSensorsDialog; import com.shimmerresearch.guiUtilities.configuration.SensorConfigDialog; import com.shimmerresearch.guiUtilities.configuration.SignalsToPlotDialog; import com.shimmerresearch.guiUtilities.plot.BasicPlotManagerPC; import com.shimmerresearch.pcDriver.ShimmerPC; import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; - +import com.shimmerresearch.bluetooth.ShimmerBluetooth; import info.monitorenter.gui.chart.Chart2D; import javax.swing.JLabel; @@ -49,12 +51,13 @@ public class SensorMapsExample extends BasicProcessWithCallBack { private JFrame frame; private JTextField textField; JTextPane textPaneStatus; - static ShimmerPC shimmer = new ShimmerPC("ShimmerDevice"); static ShimmerDevice shimmerDevice; static BasicShimmerBluetoothManagerPc btManager = new BasicShimmerBluetoothManagerPc(); BasicPlotManagerPC plotManager = new BasicPlotManagerPC(); String btComport; final Chart2D mChart = new Chart2D(); + + /** * Initialize the contents of the frame * @wbp.parser.entryPoint @@ -80,7 +83,12 @@ public void initialize() { public void actionPerformed(ActionEvent arg0) { btComport = textField.getText(); - btManager.connectShimmerThroughCommPort(btComport); + if (btComport.length()==17) { + BluetoothDeviceDetails bdd = new BluetoothDeviceDetails("", btComport, "ShimmerGRPC"); + btManager.connectShimmer3BleGrpc(bdd); + } else { + btManager.connectShimmerThroughCommPort(btComport); + } } }); @@ -92,7 +100,7 @@ public void actionPerformed(ActionEvent arg0) { btnDisconnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - btManager.disconnectShimmer(shimmer); + btManager.disconnectShimmer(btComport); } }); @@ -107,9 +115,9 @@ public void actionPerformed(ActionEvent arg0) { Random random = new Random(); int ledvalue = random.nextInt(3-0)+0; System.out.println("LED Value to Write: " + ledvalue); - shimmer.writeLEDCommand(ledvalue); + ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).writeLEDCommand(ledvalue); Thread.sleep(400);//make sure to wait for the cmd to be written. - int currentledvalue = shimmer.getCurrentLEDStatus(); + int currentledvalue = ((ShimmerPC)btManager.getShimmerDeviceBtConnected(btComport)).getCurrentLEDStatus(); System.out.println("Current ED Value: " + currentledvalue); } catch (Exception e) { @@ -140,9 +148,9 @@ public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) { //Ensure the Shimmer is not streaming or SD logging before configuring it - if(shimmer.isConnected()) { - if(!shimmer.isStreaming() && !shimmer.isSDLogging()) { - EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(shimmer,btManager); + if(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isConnected()) { + if(!((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isStreaming() && !((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isSDLogging()) { + EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)),btManager); sensorsDialog.showDialog(); } else { JOptionPane.showMessageDialog(frame, "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", JOptionPane.WARNING_MESSAGE); @@ -161,9 +169,9 @@ public void actionPerformed(ActionEvent arg0) { mntmDeviceConfiguration.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if(shimmer.isConnected()) { - if(!shimmer.isStreaming() && !shimmer.isSDLogging()) { - SensorConfigDialog configDialog = new SensorConfigDialog(shimmer,btManager); + if(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isConnected()) { + if(!((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isStreaming() && !((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isSDLogging()) { + SensorConfigDialog configDialog = new SensorConfigDialog(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)),btManager); configDialog.showDialog(); } else { JOptionPane.showMessageDialog(frame, "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", JOptionPane.WARNING_MESSAGE); @@ -176,7 +184,6 @@ public void actionPerformed(ActionEvent e) { }); mnTools.add(mntmDeviceConfiguration); - JPanel plotPanel = new JPanel(); plotPanel.setBounds(10, 236, 611, 272); frame.getContentPane().add(plotPanel); @@ -192,7 +199,7 @@ public void actionPerformed(ActionEvent e) { mntmSignalsToPlot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SignalsToPlotDialog signalsToPlotDialog = new SignalsToPlotDialog(); - signalsToPlotDialog.initialize(shimmer, plotManager, mChart); + signalsToPlotDialog.initialize(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)), plotManager, mChart); } }); mnTools.add(mntmSignalsToPlot); @@ -202,7 +209,7 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent arg0) { try { - shimmer.startStreaming(); + ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).startStreaming(); } catch (ShimmerException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -217,7 +224,7 @@ public void actionPerformed(ActionEvent arg0) { btnStopStreaming.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - shimmer.stopStreaming(); + ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).stopStreaming(); } }); @@ -267,7 +274,7 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { textPaneStatus.setText("connecting..."); } else if (callbackObject.mState == BT_STATE.CONNECTED) { textPaneStatus.setText("connected"); - shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport); + //shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport); // shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport); //shimmer.startStreaming(); } else if (callbackObject.mState == BT_STATE.DISCONNECTED From 7eb3e5aeb3f08456fc940fae41d3e822289e2fb1 Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 4 Apr 2024 14:56:11 +0800 Subject: [PATCH 02/11] Update SensorMapsExample.java PRR included --- .../simpleexamples/SensorMapsExample.java | 82 ++++++++++++++++--- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index d3241176c..368644a01 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -6,9 +6,11 @@ import com.shimmerresearch.driver.BasicProcessWithCallBack; import com.shimmerresearch.driver.CallbackObject; import com.shimmerresearch.driver.Configuration; +import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE; import com.shimmerresearch.driver.ObjectCluster; import com.shimmerresearch.driver.ShimmerDevice; import com.shimmerresearch.driver.ShimmerMsg; +import com.shimmerresearch.driverUtilities.AssembleShimmerConfig; import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails; import com.shimmerresearch.exceptions.ShimmerException; import com.shimmerresearch.grpc.ShimmerGRPC; @@ -42,6 +44,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.Timer; +import java.util.TimerTask; import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Image; @@ -54,9 +58,10 @@ public class SensorMapsExample extends BasicProcessWithCallBack { static ShimmerDevice shimmerDevice; static BasicShimmerBluetoothManagerPc btManager = new BasicShimmerBluetoothManagerPc(); BasicPlotManagerPC plotManager = new BasicPlotManagerPC(); - String btComport; + static String btComport; final Chart2D mChart = new Chart2D(); - + private JTextField textFieldSamplingRate; + static JLabel lblPRR; /** * Initialize the contents of the frame @@ -64,17 +69,17 @@ public class SensorMapsExample extends BasicProcessWithCallBack { */ public void initialize() { frame = new JFrame("Shimmer SensorMaps Example"); - frame.setBounds(100, 100, 842, 591); + frame.setBounds(100, 100, 1000, 591); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); - JLabel lblSetComPort = new JLabel("Set COM Port"); - lblSetComPort.setBounds(10, 60, 119, 23); + JLabel lblSetComPort = new JLabel("Set COM Port (e.g. COMX) or Mac Address (e.g. XX:XX:XX:XX:XX:XX)"); + lblSetComPort.setBounds(10, 25, 611, 23); frame.getContentPane().add(lblSetComPort); textField = new JTextField(); textField.setToolTipText("for example COM1, COM2, etc"); - textField.setBounds(10, 91, 144, 29); + textField.setBounds(10, 56, 144, 29); frame.getContentPane().add(textField); textField.setColumns(10); @@ -93,7 +98,7 @@ public void actionPerformed(ActionEvent arg0) { } }); btnConnect.setToolTipText("attempt connection to Shimmer device"); - btnConnect.setBounds(185, 90, 199, 31); + btnConnect.setBounds(185, 55, 199, 31); frame.getContentPane().add(btnConnect); JButton btnDisconnect = new JButton("DISCONNECT"); @@ -105,7 +110,7 @@ public void actionPerformed(ActionEvent e) { } }); btnDisconnect.setToolTipText("disconnect from Shimmer device"); - btnDisconnect.setBounds(415, 90, 187, 31); + btnDisconnect.setBounds(415, 55, 187, 31); frame.getContentPane().add(btnDisconnect); JButton btnSetBlinkLED = new JButton("Set Blink LED (Random)"); @@ -124,7 +129,7 @@ public void actionPerformed(ActionEvent arg0) { } } }); - btnSetBlinkLED.setBounds(625, 90, 187, 31); + btnSetBlinkLED.setBounds(625, 55, 187, 31); frame.getContentPane().add(btnSetBlinkLED); @@ -137,7 +142,7 @@ public void actionPerformed(ActionEvent arg0) { frame.getContentPane().add(textPaneStatus); JMenuBar menuBar = new JMenuBar(); - menuBar.setBounds(0, 0, 638, 23); + menuBar.setBounds(0, 0, 984, 23); frame.getContentPane().add(menuBar); JMenu mnTools = new JMenu("Tools"); @@ -185,7 +190,7 @@ public void actionPerformed(ActionEvent e) { mnTools.add(mntmDeviceConfiguration); JPanel plotPanel = new JPanel(); - plotPanel.setBounds(10, 236, 611, 272); + plotPanel.setBounds(10, 250, 611, 272); frame.getContentPane().add(plotPanel); plotPanel.setLayout(null); @@ -247,6 +252,30 @@ public void actionPerformed(ActionEvent arg0) { btnTakeSnapshot.setBounds(625, 181, 187, 31); frame.getContentPane().add(btnTakeSnapshot); + textFieldSamplingRate = new JTextField(); + textFieldSamplingRate.setToolTipText("for example COM1, COM2, etc"); + textFieldSamplingRate.setColumns(10); + textFieldSamplingRate.setBounds(10, 99, 144, 29); + frame.getContentPane().add(textFieldSamplingRate); + + JButton btnWriteSamplingRate = new JButton("Write Sampling Rate"); + btnWriteSamplingRate.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + ShimmerDevice sd = ((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)); + ShimmerDevice cloned = sd.deepClone(); + cloned.setSamplingRateShimmer(Double.parseDouble(textFieldSamplingRate.getText())); + AssembleShimmerConfig.generateSingleShimmerConfig(cloned, COMMUNICATION_TYPE.BLUETOOTH); + btManager.configureShimmer(cloned); + } + }); + btnWriteSamplingRate.setToolTipText("attempt connection to Shimmer device"); + btnWriteSamplingRate.setBounds(185, 97, 199, 31); + frame.getContentPane().add(btnWriteSamplingRate); + + lblPRR = new JLabel("Packet Reception Rate: "); + lblPRR.setBounds(10, 228, 372, 14); + frame.getContentPane().add(lblPRR); + plotManager.setTitle("Plot"); } @@ -258,6 +287,18 @@ public static void main(String args[]) { //s.setWaitForData(shimmer); } + static Timer timer = null; + static class PRRTask extends TimerTask { + @Override + public void run() { + ShimmerDevice sd = ((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)); + if (sd!=null) { + lblPRR.setText("Packet Reception Rate: " +Double.toString(sd.getPacketReceptionRateOverall())); + } + } + } + + @Override protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { // TODO Auto-generated method stub @@ -273,6 +314,10 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { if (callbackObject.mState == BT_STATE.CONNECTING) { textPaneStatus.setText("connecting..."); } else if (callbackObject.mState == BT_STATE.CONNECTED) { + if (timer!=null){ + timer.cancel(); + timer = new Timer(); + } textPaneStatus.setText("connected"); //shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport); // shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport); @@ -280,13 +325,28 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { } else if (callbackObject.mState == BT_STATE.DISCONNECTED // || callbackObject.mState == BT_STATE.NONE || callbackObject.mState == BT_STATE.CONNECTION_LOST){ + if (timer!=null) { + timer.cancel(); + timer = null; + } textPaneStatus.setText("disconnected"); + }else if (callbackObject.mState == BT_STATE.STREAMING) { + if (timer!=null){ + timer.cancel(); + timer = new Timer(); + } else { + timer = new Timer(); + } + // Schedule a task to be executed after a delay of 2 seconds + timer.schedule(new PRRTask(), 0 , 2000); + } } else if (ind == ShimmerPC.MSG_IDENTIFIER_NOTIFICATION_MESSAGE) { CallbackObject callbackObject = (CallbackObject)object; int msg = callbackObject.mIndicator; if (msg== ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED){ textPaneStatus.setText("device fully initialized"); + textFieldSamplingRate.setText(Double.toString(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).getSamplingRateShimmer())); } if (msg == ShimmerPC.NOTIFICATION_SHIMMER_STOP_STREAMING) { textPaneStatus.setText("device stopped streaming"); From d1b972e36add63b1f38039c30a9d76ba55aed5db Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 4 Apr 2024 21:40:21 +0800 Subject: [PATCH 03/11] update sensor maps for verisense --- ShimmerDriverPC/build.gradle | 1 + .../BasicShimmerBluetoothManagerPc.java | 2 +- ShimmerPCBasicExamples/build.gradle | 2 +- .../simpleexamples/SensorMapsExample.java | 46 +++++++++++++++---- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ShimmerDriverPC/build.gradle b/ShimmerDriverPC/build.gradle index 0f2ebe6d3..1de1846a7 100644 --- a/ShimmerDriverPC/build.gradle +++ b/ShimmerDriverPC/build.gradle @@ -90,4 +90,5 @@ dependencies { // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add // 'test.useTestNG()' to your build script. testCompile 'junit:junit:4.12' + compile 'com.parse.bolts:bolts-tasks:1.4.0' } diff --git a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java index 9f75b7f1a..a75a4be46 100644 --- a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java +++ b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java @@ -146,7 +146,7 @@ protected Shimmer4sdk createNewShimmer4(ShimmerRadioInitializer radioInitializer } @Override - protected void connectVerisenseDevice(BluetoothDeviceDetails bdd) { + public void connectVerisenseDevice(BluetoothDeviceDetails bdd) { VerisenseDevice verisenseDevice; if(!verisenseMacIdList.contains(bdd.mShimmerMacId)) { diff --git a/ShimmerPCBasicExamples/build.gradle b/ShimmerPCBasicExamples/build.gradle index e31a2c9c2..7ed9208dc 100644 --- a/ShimmerPCBasicExamples/build.gradle +++ b/ShimmerPCBasicExamples/build.gradle @@ -54,5 +54,5 @@ dependencies { // compile(group: 'com.shimmerresearch', name: 'shimmerdriverpc', version: '0.10.0_alpha') compile name: 'ShimmerBiophysicalProcessingLibrary_Rev_0_11' - + compile 'com.parse.bolts:bolts-tasks:1.4.0' } diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 368644a01..1ca37cefa 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -20,6 +20,7 @@ import com.shimmerresearch.guiUtilities.plot.BasicPlotManagerPC; import com.shimmerresearch.pcDriver.ShimmerPC; import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; +import com.shimmerresearch.verisense.VerisenseDevice; import com.shimmerresearch.bluetooth.ShimmerBluetooth; import info.monitorenter.gui.chart.Chart2D; @@ -30,6 +31,7 @@ import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.imageio.ImageIO; +import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JTextPane; @@ -49,6 +51,7 @@ import java.awt.Canvas; import java.awt.Graphics2D; import java.awt.Image; +import javax.swing.JComboBox; public class SensorMapsExample extends BasicProcessWithCallBack { @@ -62,7 +65,7 @@ public class SensorMapsExample extends BasicProcessWithCallBack { final Chart2D mChart = new Chart2D(); private JTextField textFieldSamplingRate; static JLabel lblPRR; - + JComboBox comboBox; /** * Initialize the contents of the frame * @wbp.parser.entryPoint @@ -89,8 +92,13 @@ public void actionPerformed(ActionEvent arg0) { btComport = textField.getText(); if (btComport.length()==17) { - BluetoothDeviceDetails bdd = new BluetoothDeviceDetails("", btComport, "ShimmerGRPC"); - btManager.connectShimmer3BleGrpc(bdd); + if (comboBox.getSelectedItem().equals("Shimmer3")) { + BluetoothDeviceDetails bdd = new BluetoothDeviceDetails("", btComport, "Shimmer3BLE"); + btManager.connectShimmer3BleGrpc(bdd); + } else if (comboBox.getSelectedItem().equals("Verisense")) { + BluetoothDeviceDetails bdd = new BluetoothDeviceDetails(btComport, btComport, "ShimmerGRPC"); + btManager.connectVerisenseDevice(bdd); + } } else { btManager.connectShimmerThroughCommPort(btComport); } @@ -98,7 +106,7 @@ public void actionPerformed(ActionEvent arg0) { } }); btnConnect.setToolTipText("attempt connection to Shimmer device"); - btnConnect.setBounds(185, 55, 199, 31); + btnConnect.setBounds(245, 55, 199, 31); frame.getContentPane().add(btnConnect); JButton btnDisconnect = new JButton("DISCONNECT"); @@ -110,7 +118,7 @@ public void actionPerformed(ActionEvent e) { } }); btnDisconnect.setToolTipText("disconnect from Shimmer device"); - btnDisconnect.setBounds(415, 55, 187, 31); + btnDisconnect.setBounds(475, 55, 187, 31); frame.getContentPane().add(btnDisconnect); JButton btnSetBlinkLED = new JButton("Set Blink LED (Random)"); @@ -129,7 +137,7 @@ public void actionPerformed(ActionEvent arg0) { } } }); - btnSetBlinkLED.setBounds(625, 55, 187, 31); + btnSetBlinkLED.setBounds(685, 55, 187, 31); frame.getContentPane().add(btnSetBlinkLED); @@ -214,7 +222,13 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent arg0) { try { - ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).startStreaming(); + ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); + if (device instanceof VerisenseDevice) { + ((VerisenseDevice)device).startStreaming(); + }else{ + ((ShimmerBluetooth)device).startStreaming(); + } + } catch (ShimmerException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -269,12 +283,19 @@ public void actionPerformed(ActionEvent e) { } }); btnWriteSamplingRate.setToolTipText("attempt connection to Shimmer device"); - btnWriteSamplingRate.setBounds(185, 97, 199, 31); + btnWriteSamplingRate.setBounds(245, 97, 199, 31); frame.getContentPane().add(btnWriteSamplingRate); lblPRR = new JLabel("Packet Reception Rate: "); lblPRR.setBounds(10, 228, 372, 14); frame.getContentPane().add(lblPRR); + String[] options = {"Shimmer3", "Verisense"}; + + DefaultComboBoxModel model = new DefaultComboBoxModel<>(options); + comboBox = new JComboBox<>(options); + comboBox.setModel(model); + comboBox.setBounds(164, 59, 71, 22); + frame.getContentPane().add(comboBox); plotManager.setTitle("Plot"); } @@ -298,6 +319,7 @@ public void run() { } } + @Override protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { @@ -346,7 +368,13 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { int msg = callbackObject.mIndicator; if (msg== ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED){ textPaneStatus.setText("device fully initialized"); - textFieldSamplingRate.setText(Double.toString(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).getSamplingRateShimmer())); + ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); + if (device instanceof VerisenseDevice) { + + textFieldSamplingRate.setText(Double.toString(((VerisenseDevice)device).getSamplingRateShimmer())); + }else{ + textFieldSamplingRate.setText(Double.toString(((ShimmerBluetooth)device).getSamplingRateShimmer())); + } } if (msg == ShimmerPC.NOTIFICATION_SHIMMER_STOP_STREAMING) { textPaneStatus.setText("device stopped streaming"); From 759c20eb237d2f131053696a79b13983b8e0a72a Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 5 Apr 2024 12:53:51 +0800 Subject: [PATCH 04/11] consolidating examples now verisense works in sensormapsexample --- .../driver/ble/SensorMapsExample.java | 514 ------------------ .../driver/ble/SensorMapsExample2.java | 434 --------------- .../simpleexamples/SensorMapsExample.java | 121 +++-- 3 files changed, 80 insertions(+), 989 deletions(-) delete mode 100644 ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample.java delete mode 100644 ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample2.java diff --git a/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample.java b/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample.java deleted file mode 100644 index 605ee425f..000000000 --- a/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample.java +++ /dev/null @@ -1,514 +0,0 @@ -package com.shimmerresearch.driver.ble; - -import javax.swing.JFrame; - -import com.shimmerresearch.bluetooth.ShimmerBluetooth; -import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE; -import com.shimmerresearch.driver.BasicProcessWithCallBack; -import com.shimmerresearch.driver.CallbackObject; -import com.shimmerresearch.driver.Configuration; -import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE; -import com.shimmerresearch.driver.ObjectCluster; -import com.shimmerresearch.driver.ShimmerDevice; -import com.shimmerresearch.driver.ShimmerMsg; -import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails; -import com.shimmerresearch.driverUtilities.HwDriverShimmerDeviceDetails.DEVICE_TYPE; -import com.shimmerresearch.exceptions.ShimmerException; -import com.shimmerresearch.guiUtilities.configuration.EnableSensorsDialog; -import com.shimmerresearch.guiUtilities.configuration.SensorConfigDialog; -import com.shimmerresearch.guiUtilities.configuration.SignalsToPlotDialog; -import com.shimmerresearch.guiUtilities.plot.BasicPlotManagerPC; -import com.shimmerresearch.pcDriver.ShimmerPC; -import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; -import com.shimmerresearch.verisense.VerisenseDevice; -import com.shimmerresearch.verisense.communication.SyncProgressDetails; -import com.shimmerresearch.verisense.communication.VerisenseMessage; - -import bolts.Continuation; -import bolts.Task; -import info.monitorenter.gui.chart.Chart2D; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JTextField; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JTextPane; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import javax.swing.JMenu; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.awt.Canvas; -import javax.swing.SwingConstants; -import javax.swing.JTextArea; -import java.awt.Font; - -public class SensorMapsExample extends BasicProcessWithCallBack { - - private JFrame frame; - private JTextField textField; - private JTextField btFriendlyNameTextField; - private JTextField ParticipantNameTextField; - private JTextField TrialNameTextField; - private JLabel lblParticipantName; - private JLabel lblTrialName; - private JTextArea lblBinFileDirectory; - private JButton btnSync; - private JButton btnEraseData; - private JButton btnDisableLogging; - private JLabel lblPayloadIndex; - JTextPane textPaneStatus; - static ShimmerDevice shimmerDevice; - static BasicShimmerBluetoothManagerPc btManager = new BasicShimmerBluetoothManagerPc(); - BasicPlotManagerPC plotManager = new BasicPlotManagerPC(); - String btComport; - String macAddress; - String btFriendlyName; - String previousStatus; - - /** - * Initialize the contents of the frame - * - * @wbp.parser.entryPoint - */ - public void initialize() { - frame = new JFrame("Shimmer SensorMaps Example"); - frame.setBounds(100, 100, 868, 596); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.getContentPane().setLayout(null); - - JLabel lblSetComPort = new JLabel("Set COM Port or Mac Id"); - lblSetComPort.setBounds(10, 85, 154, 23); - frame.getContentPane().add(lblSetComPort); - - textField = new JTextField(); - textField.setToolTipText("for example COM1, COM2, d0:2b:46:3d:a2:bb, etc"); - textField.setBounds(10, 106, 154, 29); - frame.getContentPane().add(textField); - textField.setColumns(10); - - JLabel lblSetFriendlyName = new JLabel("Set Friendly Name"); - lblSetFriendlyName.setBounds(10, 30, 154, 23); - frame.getContentPane().add(lblSetFriendlyName); - - btFriendlyNameTextField = new JTextField(); - btFriendlyNameTextField.setToolTipText("for example Verisense-19092501A2BB, Shimmer3-1E59, etc"); - btFriendlyNameTextField.setBounds(10, 51, 154, 29); - frame.getContentPane().add(btFriendlyNameTextField); - btFriendlyNameTextField.setColumns(10); - - textField.setText("e7:45:2c:6d:6f:14"); -// textField.setText("d0:2b:46:3d:a2:bb"); -// textField.setText("e7:ec:37:a0:d2:34"); -// textField.setText("Com5"); -// btFriendlyNameTextField.setText("Shimmer-E6C8"); - btFriendlyNameTextField.setText("Verisense-19092501A2BB"); - - JButton btnConnect = new JButton("CONNECT"); - btnConnect.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - btFriendlyName = btFriendlyNameTextField.getText(); - if (btFriendlyName.contains("Shimmer")) { - btComport = textField.getText(); - btManager.connectShimmerThroughCommPort(btComport); - } else if (btFriendlyName.contains("Verisense")) { - macAddress = textField.getText(); - btManager.setPathToVeriBLEApp("bleconsoleapp\\BLEConsoleApp1.exe"); - BluetoothDeviceDetails devDetails = new BluetoothDeviceDetails("", macAddress, "Verisense"); - btManager.connectShimmerThroughBTAddress(devDetails); - } - } - }); - btnConnect.setToolTipText("attempt connection to Shimmer device"); - btnConnect.setBounds(210, 35, 175, 25); - frame.getContentPane().add(btnConnect); - - lblParticipantName = new JLabel("Participant Name"); - lblParticipantName.setBounds(415, 30, 175, 23); - frame.getContentPane().add(lblParticipantName); - - ParticipantNameTextField = new JTextField(); - ParticipantNameTextField.setToolTipText("enter your participant name"); - ParticipantNameTextField.setText("ExampleParticipant"); - ParticipantNameTextField.setBounds(415, 51, 175, 29); - frame.getContentPane().add(ParticipantNameTextField); - ParticipantNameTextField.setColumns(10); - - lblTrialName = new JLabel("Trial Name"); - lblTrialName.setBounds(415, 85, 175, 23); - frame.getContentPane().add(lblTrialName); - - TrialNameTextField = new JTextField(); - TrialNameTextField.setToolTipText("enter the trial name"); - TrialNameTextField.setText("ExampleTrial"); - TrialNameTextField.setBounds(415, 106, 175, 29); - frame.getContentPane().add(TrialNameTextField); - TrialNameTextField.setColumns(10); - - lblPayloadIndex = new JLabel("Current payload index : "); - lblPayloadIndex.setVerticalAlignment(SwingConstants.TOP); - lblPayloadIndex.setBounds(415, 166, 408, 35); - frame.getContentPane().add(lblPayloadIndex); - - lblBinFileDirectory = new JTextArea(""); - lblBinFileDirectory.setFont(lblPayloadIndex.getFont()); - lblBinFileDirectory.setBounds(415, 203, 408, 61); - frame.getContentPane().add(lblBinFileDirectory); - lblBinFileDirectory.setEditable(false); - lblBinFileDirectory.setOpaque(false); - lblBinFileDirectory.setWrapStyleWord(true); - lblBinFileDirectory.setLineWrap(true); - lblBinFileDirectory.setText("Bin file path :"); - - btnSync = new JButton("DATA SYNC"); - btnSync.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - previousStatus = textPaneStatus.getText(); - VerisenseDevice verisenseDevice = (VerisenseDevice) shimmerDevice; - verisenseDevice.setTrialName(TrialNameTextField.getText()); - verisenseDevice.setParticipantID(ParticipantNameTextField.getText()); - try { - verisenseDevice.readLoggedData(); - } catch (ShimmerException e) { - if(e.getMessage() == "A task is still ongoing") { - textPaneStatus.setText(previousStatus); - JOptionPane.showMessageDialog(frame, - "Please wait until current task is finished", "Warning", - JOptionPane.WARNING_MESSAGE); - return; - } - e.printStackTrace(); - } - } - }); - btnSync.setToolTipText("Data Sync"); - btnSync.setBounds(210, 179, 175, 25); - frame.getContentPane().add(btnSync); - - btnEraseData = new JButton("ERASE DATA"); - btnEraseData.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - try { - previousStatus = textPaneStatus.getText(); - textPaneStatus.setText("erasing data..."); - VerisenseDevice verisenseDevice = (VerisenseDevice) shimmerDevice; - verisenseDevice.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH).eraseDataTask().continueWith(new Continuation() { - @Override - public Void then(Task completed) throws Exception { - System.out.println("erased data completed"); - return null; - } - }); - //verisenseDevice.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH).eraseData().waitForCompletion(60, TimeUnit.SECONDS); - } catch (ShimmerException e) { - if(e.getMessage() == "A task is still ongoing") { - textPaneStatus.setText(previousStatus); - JOptionPane.showMessageDialog(frame, - "Please wait until current task is finished", "Warning", - JOptionPane.WARNING_MESSAGE); - return; - } - e.printStackTrace(); - } - } - }); - btnEraseData.setToolTipText("erase logged data"); - btnEraseData.setBounds(210, 215, 175, 25); - frame.getContentPane().add(btnEraseData); - - btnDisableLogging = new JButton("DISABLE LOGGING"); - btnDisableLogging.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - try { - previousStatus = textPaneStatus.getText(); - textPaneStatus.setText("writing op config..."); - VerisenseDevice verisenseDevice = ((VerisenseDevice)shimmerDevice).deepClone(); - verisenseDevice.setRecordingEnabled(!verisenseDevice.isRecordingEnabled()); - byte[] opConfig = verisenseDevice.configBytesGenerate(true, COMMUNICATION_TYPE.BLUETOOTH); - ((VerisenseDevice)shimmerDevice).getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH).writeOperationalConfig(opConfig); - btnDisableLogging.setText(verisenseDevice.isRecordingEnabled()?"DISABLE LOGGING":"ENABLE LOGGING"); - } catch (ShimmerException e) { - if(e.getMessage() == "A task is still ongoing") { - textPaneStatus.setText(previousStatus); - JOptionPane.showMessageDialog(frame, - "Please wait until current task is finished", "Warning", - JOptionPane.WARNING_MESSAGE); - return; - } - e.printStackTrace(); - } - } - }); - btnDisableLogging.setToolTipText("disable logging"); - btnDisableLogging.setBounds(210, 251, 175, 25); - frame.getContentPane().add(btnDisableLogging); - - ParticipantNameTextField.setVisible(false); - lblParticipantName.setVisible(false); - TrialNameTextField.setVisible(false); - lblTrialName.setVisible(false); - btnSync.setVisible(false); - btnEraseData.setVisible(false); - btnDisableLogging.setVisible(false); - lblPayloadIndex.setVisible(false); - lblBinFileDirectory.setVisible(false); - JButton btnDisconnect = new JButton("DISCONNECT"); - btnDisconnect.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - btManager.disconnectShimmer(shimmerDevice); - } - }); - btnDisconnect.setToolTipText("disconnect from Shimmer device"); - btnDisconnect.setBounds(210, 71, 175, 25); - frame.getContentPane().add(btnDisconnect); - - JLabel lblShimmerStatus = new JLabel("Shimmer Status"); - lblShimmerStatus.setBounds(10, 145, 154, 23); - frame.getContentPane().add(lblShimmerStatus); - - textPaneStatus = new JTextPane(); - textPaneStatus.setBounds(10, 166, 154, 35); - frame.getContentPane().add(textPaneStatus); - - JMenuBar menuBar = new JMenuBar(); - menuBar.setBounds(0, 0, 638, 23); - frame.getContentPane().add(menuBar); - - JMenu mnTools = new JMenu("Tools"); - menuBar.add(mnTools); - - JMenuItem mntmSelectSensors = new JMenuItem("Select sensors"); - mntmSelectSensors.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - - // Ensure the Shimmer is not streaming or SD logging before configuring it - if (shimmerDevice.isConnected()) { - if (!shimmerDevice.isStreaming() && !shimmerDevice.isSDLogging()) { - EnableSensorsDialog sensorsDialog; - sensorsDialog = new EnableSensorsDialog(shimmerDevice, btManager); - sensorsDialog.showDialog(); - } else { - JOptionPane.showMessageDialog(frame, - "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", - JOptionPane.WARNING_MESSAGE); - } - } else { - JOptionPane.showMessageDialog(frame, "No device connected!", "Info", JOptionPane.WARNING_MESSAGE); - } - -// EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(shimmerDevice); -// sensorsDialog.initialize(); - - } - }); - mnTools.add(mntmSelectSensors); - - JMenuItem mntmDeviceConfiguration = new JMenuItem("Sensor configuration"); - mntmDeviceConfiguration.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - - if (shimmerDevice.isConnected()) { - if (!shimmerDevice.isStreaming() && !shimmerDevice.isSDLogging()) { - SensorConfigDialog configDialog; - configDialog = new SensorConfigDialog(shimmerDevice, btManager); - configDialog.showDialog(); - } else { - JOptionPane.showMessageDialog(frame, - "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", - JOptionPane.WARNING_MESSAGE); - } - } else { - JOptionPane.showMessageDialog(frame, "No device connected!", "Info", JOptionPane.WARNING_MESSAGE); - } - } - }); - mnTools.add(mntmDeviceConfiguration); - - JPanel plotPanel = new JPanel(); - plotPanel.setBounds(12, 274, 828, 272); - frame.getContentPane().add(plotPanel); - plotPanel.setLayout(null); - - final Chart2D mChart = new Chart2D(); - mChart.setLocation(12, 13); - mChart.setSize(801, 246); - plotPanel.add(mChart); - plotManager.addChart(mChart); - - JMenuItem mntmSignalsToPlot = new JMenuItem("Signals to plot"); - mntmSignalsToPlot.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - SignalsToPlotDialog signalsToPlotDialog; - if (btFriendlyName.contains("Verisense")) { - signalsToPlotDialog = new SignalsToPlotDialog(true); - } else { - signalsToPlotDialog = new SignalsToPlotDialog(); - } - - signalsToPlotDialog.initialize(shimmerDevice, plotManager, mChart); - } - }); - - mnTools.add(mntmSignalsToPlot); - - JButton btnStartStreaming = new JButton("START STREAMING"); - btnStartStreaming.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - - try { - shimmerDevice.startStreaming(); - } catch (ShimmerException e) { - if(e.getMessage() == "A task is still ongoing") { - JOptionPane.showMessageDialog(frame, - "Please wait until current task is finished", "Warning", - JOptionPane.WARNING_MESSAGE); - return; - } - textPaneStatus.setText(e.getMessage()); - e.printStackTrace(); - } - - } - }); - btnStartStreaming.setBounds(210, 107, 175, 25); - frame.getContentPane().add(btnStartStreaming); - - JButton btnStopStreaming = new JButton("STOP STREAMING"); - btnStopStreaming.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - shimmerDevice.stopStreaming(); - } catch (ShimmerException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - btnStopStreaming.setBounds(210, 143, 175, 25); - frame.getContentPane().add(btnStopStreaming); - - plotManager.setTitle("Plot"); - } - - public static void main(String args[]) { - // shimmer - SensorMapsExample s = new SensorMapsExample(); - - s.initialize(); - s.frame.setVisible(true); - s.setWaitForData(btManager.callBackObject); - s.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - s.frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - if (shimmerDevice instanceof VerisenseDevice) { - ((VerisenseDevice) shimmerDevice).stopCommunicationProcess(COMMUNICATION_TYPE.BLUETOOTH); - } - } - }); - // s.setWaitForData(shimmer); - } - - @Override - protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { - // TODO Auto-generated method stub - - // TODO Auto-generated method stub - int ind = shimmerMSG.mIdentifier; - - Object object = (Object) shimmerMSG.mB; - - if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) { - CallbackObject callbackObject = (CallbackObject) object; - - if (callbackObject.mState == BT_STATE.CONNECTING) { - textPaneStatus.setText("connecting..."); - } else if (callbackObject.mState == BT_STATE.CONNECTED) { - textPaneStatus.setText("connected"); - - if (btFriendlyName.contains("Verisense")) { - ParticipantNameTextField.setVisible(true); - lblParticipantName.setVisible(true); - TrialNameTextField.setVisible(true); - lblTrialName.setVisible(true); - btnSync.setVisible(true); - btnEraseData.setVisible(true); - btnDisableLogging.setVisible(true); - lblPayloadIndex.setVisible(true); - lblBinFileDirectory.setVisible(true); - shimmerDevice = btManager.getShimmerDeviceBtConnected(macAddress.toUpperCase()); - if(((VerisenseDevice)shimmerDevice).isRecordingEnabled()) { - btnDisableLogging.setText("DISABLE LOGGING"); - } - else { - btnDisableLogging.setText("ENABLE LOGGING"); - } - } else { - shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport); - } - - // shimmer.startStreaming(); - } else if (callbackObject.mState == BT_STATE.DISCONNECTED -// || callbackObject.mState == BT_STATE.NONE - || callbackObject.mState == BT_STATE.CONNECTION_LOST) { - textPaneStatus.setText("disconnected"); - - ParticipantNameTextField.setVisible(false); - lblParticipantName.setVisible(false); - TrialNameTextField.setVisible(false); - lblTrialName.setVisible(false); - btnSync.setVisible(false); - btnEraseData.setVisible(false); - btnDisableLogging.setVisible(false); - lblPayloadIndex.setVisible(false); - lblBinFileDirectory.setVisible(false); - } else if (callbackObject.mState == BT_STATE.STREAMING) { - textPaneStatus.setText("device streaming"); - }else if (callbackObject.mState == BT_STATE.STREAMING_LOGGED_DATA) { - textPaneStatus.setText("synchronizing data"); - } - } else if (ind == ShimmerPC.MSG_IDENTIFIER_NOTIFICATION_MESSAGE) { - CallbackObject callbackObject = (CallbackObject) object; - int msg = callbackObject.mIndicator; - if (msg == ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED) { - textPaneStatus.setText("device fully initialized"); - } - if (msg == ShimmerPC.NOTIFICATION_SHIMMER_STOP_STREAMING) { - textPaneStatus.setText("device stopped streaming"); - } else if (msg == ShimmerPC.NOTIFICATION_SHIMMER_START_STREAMING) { - textPaneStatus.setText("device streaming"); - } else { - } - } else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) { - System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET"); - ObjectCluster objc = (ObjectCluster) shimmerMSG.mB; - - try { - plotManager.filterDataAndPlot(objc); - } catch (Exception e) { - e.printStackTrace(); - } - - } else if (ind == ShimmerPC.MSG_IDENTIFIER_PACKET_RECEPTION_RATE_OVERALL) { - - } else if (ind == ShimmerBluetooth.MSG_IDENTIFIER_SYNC_PROGRESS) { - CallbackObject callbackObject = (CallbackObject) object; - lblPayloadIndex.setText("Current Payload Index : " + ((SyncProgressDetails)callbackObject.mMyObject).mPayloadIndex + " ; Speed(KBps) : " + ((SyncProgressDetails)callbackObject.mMyObject).mTransferRateBytes/1000 ); - String path = Paths.get(((SyncProgressDetails)callbackObject.mMyObject).mBinFilePath).toAbsolutePath().toString(); - lblBinFileDirectory.setText("Bin file path : " + path); - } else if (ind == ShimmerBluetooth.MSG_IDENTIFIER_VERISENSE_ERASE_DATA_COMPLETED) { - textPaneStatus.setText("connected"); - } else if (ind == ShimmerBluetooth.MSG_IDENTIFIER_VERISENSE_WRITE_OPCONFIG_COMPLETED) { - textPaneStatus.setText("connected"); - } - } -} diff --git a/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample2.java b/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample2.java deleted file mode 100644 index 20e37177d..000000000 --- a/ShimmerDriverPC/src/test/java/com/shimmerresearch/driver/ble/SensorMapsExample2.java +++ /dev/null @@ -1,434 +0,0 @@ -package com.shimmerresearch.driver.ble; - -import javax.swing.JFrame; - -import com.shimmerresearch.bluetooth.ShimmerBluetooth; -import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE; -import com.shimmerresearch.driver.BasicProcessWithCallBack; -import com.shimmerresearch.driver.CallbackObject; -import com.shimmerresearch.driver.Configuration; -import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE; -import com.shimmerresearch.driver.ObjectCluster; -import com.shimmerresearch.driver.ShimmerDevice; -import com.shimmerresearch.driver.ShimmerMsg; -import com.shimmerresearch.driverUtilities.BluetoothDeviceDetails; -import com.shimmerresearch.driverUtilities.ChannelDetails.CHANNEL_TYPE; -import com.shimmerresearch.driverUtilities.HwDriverShimmerDeviceDetails.DEVICE_TYPE; -import com.shimmerresearch.exceptions.ShimmerException; -import com.shimmerresearch.guiUtilities.configuration.EnableSensorsDialog; -import com.shimmerresearch.guiUtilities.configuration.SensorConfigDialog; -import com.shimmerresearch.guiUtilities.configuration.SignalsToPlotDialog; -import com.shimmerresearch.guiUtilities.plot.BasicPlotManagerPC; -import com.shimmerresearch.pcDriver.ShimmerPC; -import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; -import com.shimmerresearch.verisense.VerisenseDevice; -import com.shimmerresearch.verisense.communication.SyncProgressDetails; - -import info.monitorenter.gui.chart.Chart2D; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JTextField; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JTextPane; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import javax.swing.JMenu; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.awt.Canvas; -import javax.swing.SwingConstants; -import javax.swing.JTextArea; -import java.awt.Font; - -public class SensorMapsExample2 extends BasicProcessWithCallBack { - - private JFrame frame; - private JTextField[] macAddressTextField = new JTextField[2]; - private JTextField[] btFriendlyNameTextField = new JTextField[2]; - private JTextField[] ParticipantNameTextField = new JTextField[2]; - private JTextField[] TrialNameTextField = new JTextField[2]; - private JTextArea[] lblBinFileDirectory = new JTextArea[2]; - private JLabel[] lblPayloadIndex = new JLabel[2]; - private JLabel[] lblObjCluster = new JLabel[2]; - JTextPane[] textPaneStatus = new JTextPane[2]; - static BasicShimmerBluetoothManagerPc btManager = new BasicShimmerBluetoothManagerPc(); - String btComport; - String btFriendlyName; - - String[] macAddress = new String[2]; - static ShimmerDevice[] shimmerDevice = new ShimmerDevice[2]; - - /** - * Initialize the contents of the frame - * - * @wbp.parser.entryPoint - */ - private JLabel addLabel(String text, int x, int y, int width, int height) { - JLabel lbl = new JLabel(text); - lbl.setBounds(x, y, width, height); - frame.getContentPane().add(lbl); - - return lbl; - } - - private JTextField addTextField(String tooltip, int x, int y, int width, int height, int column) { - JTextField textField = new JTextField(); - textField.setToolTipText(tooltip); - textField.setBounds(x, y, width, height); - textField.setColumns(column); - frame.getContentPane().add(textField); - - return textField; - } - - public void initialize() { - frame = new JFrame("Shimmer SensorMaps Example"); - frame.setBounds(100, 100, 868, 596); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.getContentPane().setLayout(null); - - addLabel("Set Friendly Name", 10, 30, 154, 23); - - btFriendlyNameTextField[0] = addTextField("for example Verisense-19092501A2BB, Shimmer3-1E59, etc", 10, 51, 154, 29, 10); - - addLabel("Set COM Port or Mac Id", 10, 85, 154, 23); - - macAddressTextField[0] = addTextField("for example COM1, COM2, d0:2b:46:3d:a2:bb, etc", 10, 106, 154, 29, 10); - - addLabel("Shimmer Status", 10, 145, 154, 23); - - textPaneStatus[0] = new JTextPane(); - textPaneStatus[0].setBounds(10, 166, 154, 35); - frame.getContentPane().add(textPaneStatus[0]); - - addLabel("Participant Name", 415, 30, 175, 23); - - ParticipantNameTextField[0] = addTextField("enter your participant name", 415, 51, 175, 29, 10); - - addLabel("Trial Name", 415, 85, 175, 23); - - TrialNameTextField[0] = addTextField("enter your trial name", 415, 106, 175, 29, 10); - - lblPayloadIndex[0] = addLabel("Current payload index : ", 415, 166, 408, 35); - lblPayloadIndex[0].setVerticalAlignment(SwingConstants.TOP); - - lblBinFileDirectory[0] = new JTextArea(""); - lblBinFileDirectory[0].setFont(lblPayloadIndex[0].getFont()); - lblBinFileDirectory[0].setBounds(415, 203, 408, 61); - frame.getContentPane().add(lblBinFileDirectory[0]); - lblBinFileDirectory[0].setEditable(false); - lblBinFileDirectory[0].setOpaque(false); - lblBinFileDirectory[0].setWrapStyleWord(true); - lblBinFileDirectory[0].setLineWrap(true); - lblBinFileDirectory[0].setText("Bin file path :"); - - lblObjCluster[0] = addLabel("Object Cluster", 415, 135, 175, 23); - - JButton btnConnect = new JButton("CONNECT"); - btnConnect.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - btFriendlyName = btFriendlyNameTextField[0].getText(); - if (btFriendlyName.contains("Shimmer")) { - btComport = macAddressTextField[0].getText(); - btManager.connectShimmerThroughCommPort(btComport); - } else if (btFriendlyName.contains("Verisense")) { - macAddress[0] = macAddressTextField[0].getText().toUpperCase(); - btManager.setPathToVeriBLEApp("bleconsoleapp\\BLEConsoleApp1.exe"); - BluetoothDeviceDetails devDetails = new BluetoothDeviceDetails("", macAddress[0], "Verisense"); - btManager.connectShimmerThroughBTAddress(devDetails); - } - } - }); - btnConnect.setToolTipText("attempt connection to Shimmer device"); - btnConnect.setBounds(210, 35, 175, 31); - frame.getContentPane().add(btnConnect); - - JButton btnDisconnect = new JButton("DISCONNECT"); - btnDisconnect.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - btManager.disconnectShimmer(shimmerDevice[0]); - } - }); - btnDisconnect.setToolTipText("disconnect from Shimmer device"); - btnDisconnect.setBounds(210, 76, 175, 31); - frame.getContentPane().add(btnDisconnect); - - JButton btnStartStreaming = new JButton("START STREAMING"); - btnStartStreaming.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - try { - shimmerDevice[0].startStreaming(); - } catch (ShimmerException e) { - e.printStackTrace(); - textPaneStatus[0].setText(e.getMessage()); - } - } - }); - btnStartStreaming.setBounds(210, 117, 175, 31); - frame.getContentPane().add(btnStartStreaming); - - JButton btnStopStreaming = new JButton("STOP STREAMING"); - btnStopStreaming.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - shimmerDevice[0].stopStreaming(); - } catch (ShimmerException e1) { - e1.printStackTrace(); - } - } - }); - btnStopStreaming.setBounds(210, 158, 175, 31); - frame.getContentPane().add(btnStopStreaming); - - JButton btnSync = new JButton("DATA SYNC"); - btnSync.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - VerisenseDevice verisenseDevice = (VerisenseDevice) shimmerDevice[0]; - verisenseDevice.setTrialName(TrialNameTextField[0].getText()); - verisenseDevice.setParticipantID(ParticipantNameTextField[0].getText()); - try { - verisenseDevice.readLoggedData(); - } catch (ShimmerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }); - btnSync.setToolTipText("Data Sync"); - btnSync.setBounds(210, 199, 175, 31); - frame.getContentPane().add(btnSync); - - //sensor2 - - addLabel("Set Friendly Name", 10, 250, 154, 23); - - btFriendlyNameTextField[1] = addTextField("for example Verisense-19092501A2BB, Shimmer3-1E59, etc", 10, 271, 154, 29, 10); - - addLabel("Set COM Port or Mac Id", 10, 305, 154, 23); - - macAddressTextField[1] = addTextField("for example COM1, COM2, d0:2b:46:3d:a2:bb, etc", 10, 326, 154, 29, 10); - - addLabel("Shimmer Status", 10, 365, 154, 23); - - textPaneStatus[1] = new JTextPane(); - textPaneStatus[1].setBounds(10, 386, 154, 35); - frame.getContentPane().add(textPaneStatus[1]); - - addLabel("Participant Name", 415, 250, 175, 23); - - ParticipantNameTextField[1] = new JTextField(); - ParticipantNameTextField[1].setToolTipText("enter your participant name"); - ParticipantNameTextField[1].setBounds(415, 271, 175, 29); - frame.getContentPane().add(ParticipantNameTextField[1]); - ParticipantNameTextField[1].setColumns(10); - - addLabel("Trial Name", 415, 305, 175, 23); - - TrialNameTextField[1] = new JTextField(); - TrialNameTextField[1].setToolTipText("enter the trial name"); - TrialNameTextField[1].setBounds(415, 326, 175, 29); - frame.getContentPane().add(TrialNameTextField[1]); - TrialNameTextField[1].setColumns(10); - - lblPayloadIndex[1] = new JLabel("Current payload index : "); - lblPayloadIndex[1].setVerticalAlignment(SwingConstants.TOP); - lblPayloadIndex[1].setBounds(415, 386, 408, 35); - frame.getContentPane().add(lblPayloadIndex[1]); - - lblBinFileDirectory[1] = new JTextArea(""); - lblBinFileDirectory[1].setFont(lblPayloadIndex[1].getFont()); - lblBinFileDirectory[1].setBounds(415, 423, 408, 61); - frame.getContentPane().add(lblBinFileDirectory[1]); - lblBinFileDirectory[1].setEditable(false); - lblBinFileDirectory[1].setOpaque(false); - lblBinFileDirectory[1].setWrapStyleWord(true); - lblBinFileDirectory[1].setLineWrap(true); - lblBinFileDirectory[1].setText("Bin file path :"); - - lblObjCluster[1] = addLabel("Object Cluster", 415, 355, 175, 23); - - JButton btnConnect2 = new JButton("CONNECT"); - btnConnect2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - btFriendlyName = btFriendlyNameTextField[1].getText(); - if (btFriendlyName.contains("Shimmer")) { - btComport = macAddressTextField[1].getText(); - btManager.connectShimmerThroughCommPort(btComport); - } else if (btFriendlyName.contains("Verisense")) { - macAddress[1] = macAddressTextField[1].getText().toUpperCase(); - btManager.setPathToVeriBLEApp("bleconsoleapp\\BLEConsoleApp1.exe"); - BluetoothDeviceDetails devDetails = new BluetoothDeviceDetails("", macAddress[1], "Verisense"); - btManager.connectShimmerThroughBTAddress(devDetails); - } - } - }); - - btnConnect2.setToolTipText("attempt connection to Shimmer device"); - btnConnect2.setBounds(210, 255, 175, 31); - frame.getContentPane().add(btnConnect2); - - JButton btnDisconnect2 = new JButton("DISCONNECT"); - btnDisconnect2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - btManager.disconnectShimmer(shimmerDevice[1]); - } - }); - btnDisconnect2.setToolTipText("disconnect from Shimmer device"); - btnDisconnect2.setBounds(210, 296, 175, 31); - frame.getContentPane().add(btnDisconnect2); - - JButton btnStartStreaming2 = new JButton("START STREAMING"); - btnStartStreaming2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - try { - shimmerDevice[1].startStreaming(); - } catch (ShimmerException e) { - e.printStackTrace(); - textPaneStatus[1].setText(e.getMessage()); - } - } - }); - btnStartStreaming2.setBounds(210, 337, 175, 31); - frame.getContentPane().add(btnStartStreaming2); - - JButton btnStopStreaming2 = new JButton("STOP STREAMING"); - btnStopStreaming2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - shimmerDevice[1].stopStreaming(); - } catch (ShimmerException e1) { - e1.printStackTrace(); - } - } - }); - btnStopStreaming2.setBounds(210, 378, 175, 31); - frame.getContentPane().add(btnStopStreaming2); - - JButton btnSync2 = new JButton("DATA SYNC"); - btnSync2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - VerisenseDevice verisenseDevice = (VerisenseDevice) shimmerDevice[1]; - verisenseDevice.setTrialName(TrialNameTextField[1].getText()); - verisenseDevice.setParticipantID(ParticipantNameTextField[1].getText()); - try { - verisenseDevice.readLoggedData(); - } catch (ShimmerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }); - btnSync2.setToolTipText("Data Sync"); - btnSync2.setBounds(210, 419, 175, 31); - frame.getContentPane().add(btnSync2); - - macAddressTextField[1].setText("d0:2b:46:3d:a2:bb"); - //macAddressTextField[1].setText("e7:ec:37:a0:d2:34"); - btFriendlyNameTextField[1].setText("Verisense-19092501A2BB"); - - //macAddressTextField[0].setText("d0:2b:46:3d:a2:bb"); - macAddressTextField[0].setText("e7:ec:37:a0:d2:34"); - btFriendlyNameTextField[0].setText("Verisense-19092501D234"); - } - - public static void main(String args[]) { - // shimmer - SensorMapsExample2 s = new SensorMapsExample2(); - - s.initialize(); - s.frame.setVisible(true); - s.setWaitForData(btManager.callBackObject); - s.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - s.frame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - if (shimmerDevice[0] instanceof VerisenseDevice) { - ((VerisenseDevice) shimmerDevice[0]).stopCommunicationProcess(COMMUNICATION_TYPE.BLUETOOTH); - } - - if (shimmerDevice[1] instanceof VerisenseDevice) { - ((VerisenseDevice) shimmerDevice[1]).stopCommunicationProcess(COMMUNICATION_TYPE.BLUETOOTH); - } - } - }); - // s.setWaitForData(shimmer); - } - - @Override - protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { - - int ind = shimmerMSG.mIdentifier; - //callbackObject.mBluetoothAddress (all upper case) - Object object = (Object) shimmerMSG.mB; - - if (ind == ShimmerPC.MSG_IDENTIFIER_STATE_CHANGE) { - CallbackObject callbackObject = (CallbackObject) object; - int index = Arrays.asList(macAddress).indexOf(callbackObject.mBluetoothAddress); - - if (callbackObject.mState == BT_STATE.CONNECTING) { - textPaneStatus[index].setText("connecting..."); - } else if (callbackObject.mState == BT_STATE.CONNECTED) { - textPaneStatus[index].setText("connected"); - - if (btFriendlyName.contains("Verisense")) { - shimmerDevice[index] = (btManager.getShimmerDeviceBtConnected(macAddress[index])); - } else { - shimmerDevice[index] = (btManager.getShimmerDeviceBtConnected(btComport)); - } - - // shimmer.startStreaming(); - } else if (callbackObject.mState == BT_STATE.DISCONNECTED -// || callbackObject.mState == BT_STATE.NONE - || callbackObject.mState == BT_STATE.CONNECTION_LOST) { - textPaneStatus[index].setText("disconnected"); - } else if (callbackObject.mState == BT_STATE.STREAMING) { - textPaneStatus[index].setText("device streaming"); - }else if (callbackObject.mState == BT_STATE.STREAMING_LOGGED_DATA) { - textPaneStatus[index].setText("synchronizing data"); - } - } else if (ind == ShimmerPC.MSG_IDENTIFIER_NOTIFICATION_MESSAGE) { - CallbackObject callbackObject = (CallbackObject) object; - int index = Arrays.asList(macAddress).indexOf(callbackObject.mBluetoothAddress); - int msg = callbackObject.mIndicator; - if (msg == ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED) { - textPaneStatus[index].setText("device fully initialized"); - } - if (msg == ShimmerPC.NOTIFICATION_SHIMMER_STOP_STREAMING) { - textPaneStatus[index].setText("device stopped streaming"); - } else if (msg == ShimmerPC.NOTIFICATION_SHIMMER_START_STREAMING) { - textPaneStatus[index].setText("device streaming"); - } else { - } - } else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) { - System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET"); - ObjectCluster objc = (ObjectCluster) shimmerMSG.mB; - int index = Arrays.asList(macAddress).indexOf(objc.getMacAddress()); - - try { - lblObjCluster[index].setText("Object Cluster : " + objc.getFormatClusterValue(objc.getChannelNamesByInsertionOrder().get(0), CHANNEL_TYPE.UNCAL.toString())); - } catch (Exception e) { - e.printStackTrace(); - } - - } else if (ind == ShimmerPC.MSG_IDENTIFIER_PACKET_RECEPTION_RATE_OVERALL) { - - } else if (ind == ShimmerBluetooth.MSG_IDENTIFIER_SYNC_PROGRESS) { - CallbackObject callbackObject = (CallbackObject) object; - int index = Arrays.asList(macAddress).indexOf(callbackObject.mBluetoothAddress); - lblPayloadIndex[index].setText("Current Payload Index : " + ((SyncProgressDetails)callbackObject.mMyObject).mPayloadIndex + " ; Speed(KBps) : " + ((SyncProgressDetails)callbackObject.mMyObject).mTransferRateBytes/1000 ); - String path = Paths.get(((SyncProgressDetails)callbackObject.mMyObject).mBinFilePath).toAbsolutePath().toString(); - lblBinFileDirectory[index].setText("Bin file path : " + path); - } - } -} diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 1ca37cefa..46160891a 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -21,6 +21,7 @@ import com.shimmerresearch.pcDriver.ShimmerPC; import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; import com.shimmerresearch.verisense.VerisenseDevice; +import com.shimmerresearch.verisense.communication.VerisenseProtocolByteCommunication; import com.shimmerresearch.bluetooth.ShimmerBluetooth; import info.monitorenter.gui.chart.Chart2D; @@ -121,25 +122,6 @@ public void actionPerformed(ActionEvent e) { btnDisconnect.setBounds(475, 55, 187, 31); frame.getContentPane().add(btnDisconnect); - JButton btnSetBlinkLED = new JButton("Set Blink LED (Random)"); - btnSetBlinkLED.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - try { - Random random = new Random(); - int ledvalue = random.nextInt(3-0)+0; - System.out.println("LED Value to Write: " + ledvalue); - ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).writeLEDCommand(ledvalue); - Thread.sleep(400);//make sure to wait for the cmd to be written. - int currentledvalue = ((ShimmerPC)btManager.getShimmerDeviceBtConnected(btComport)).getCurrentLEDStatus(); - System.out.println("Current ED Value: " + currentledvalue); - } catch (Exception e) { - - } - } - }); - btnSetBlinkLED.setBounds(685, 55, 187, 31); - frame.getContentPane().add(btnSetBlinkLED); - JLabel lblShimmerStatus = new JLabel("Shimmer Status"); lblShimmerStatus.setBounds(10, 139, 144, 23); @@ -159,17 +141,31 @@ public void actionPerformed(ActionEvent arg0) { JMenuItem mntmSelectSensors = new JMenuItem("Select sensors"); mntmSelectSensors.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { + ShimmerDevice SD = btManager.getShimmerDeviceBtConnected(btComport); + boolean connected = false; + if (SD!=null) { + if (SD instanceof VerisenseDevice) { + VerisenseDevice vd = (VerisenseDevice) SD; + if (vd.getBluetoothRadioState().equals(BT_STATE.CONNECTED)){ + connected = true; + } + + + } else { + ShimmerBluetooth sb = (ShimmerBluetooth) SD; + if (sb.getBluetoothRadioState().equals(BT_STATE.CONNECTED)){ + connected = true; + } + } + } //Ensure the Shimmer is not streaming or SD logging before configuring it - if(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isConnected()) { - if(!((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isStreaming() && !((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isSDLogging()) { - EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)),btManager); + if(connected) { + EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)),btManager); sensorsDialog.showDialog(); - } else { - JOptionPane.showMessageDialog(frame, "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", JOptionPane.WARNING_MESSAGE); - } + } else { - JOptionPane.showMessageDialog(frame, "No device connected!", "Info", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(frame, "Device not in a connected state!", "Info", JOptionPane.WARNING_MESSAGE); } // EnableSensorsDialog sensorsDialog = new EnableSensorsDialog(shimmerDevice); @@ -182,16 +178,30 @@ public void actionPerformed(ActionEvent arg0) { mntmDeviceConfiguration.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isConnected()) { - if(!((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isStreaming() && !((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).isSDLogging()) { - SensorConfigDialog configDialog = new SensorConfigDialog(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)),btManager); - configDialog.showDialog(); + ShimmerDevice SD = btManager.getShimmerDeviceBtConnected(btComport); + boolean connected = false; + if (SD!=null) { + if (SD instanceof VerisenseDevice) { + VerisenseDevice vd = (VerisenseDevice) SD; + if (vd.getBluetoothRadioState().equals(BT_STATE.CONNECTED)){ + connected = true; + } + + } else { - JOptionPane.showMessageDialog(frame, "Cannot configure sensors!\nDevice is streaming or SDLogging", "Warning", JOptionPane.WARNING_MESSAGE); + ShimmerBluetooth sb = (ShimmerBluetooth) SD; + if (sb.getBluetoothRadioState().equals(BT_STATE.CONNECTED)){ + connected = true; + } } - } else { - JOptionPane.showMessageDialog(frame, "No device connected!", "Info", JOptionPane.WARNING_MESSAGE); } + if(connected) { + SensorConfigDialog configDialog = new SensorConfigDialog(((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)),btManager); + configDialog.showDialog(); + + } else { + JOptionPane.showMessageDialog(frame, "Device not in a connected state!", "Info", JOptionPane.WARNING_MESSAGE); + } } }); @@ -212,7 +222,7 @@ public void actionPerformed(ActionEvent e) { mntmSignalsToPlot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SignalsToPlotDialog signalsToPlotDialog = new SignalsToPlotDialog(); - signalsToPlotDialog.initialize(((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)), plotManager, mChart); + signalsToPlotDialog.initialize(((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)), plotManager, mChart); } }); mnTools.add(mntmSignalsToPlot); @@ -242,9 +252,20 @@ public void actionPerformed(ActionEvent arg0) { JButton btnStopStreaming = new JButton("STOP STREAMING"); btnStopStreaming.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); + try { + if (device instanceof VerisenseDevice) { + + ((VerisenseDevice)device).stopStreaming(); + + }else{ + ((ShimmerBluetooth)device).stopStreaming(); + } - ((ShimmerBluetooth)btManager.getShimmerDeviceBtConnected(btComport)).stopStreaming(); - + } catch (ShimmerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } } }); btnStopStreaming.setBounds(415, 181, 187, 31); @@ -272,7 +293,7 @@ public void actionPerformed(ActionEvent arg0) { textFieldSamplingRate.setBounds(10, 99, 144, 29); frame.getContentPane().add(textFieldSamplingRate); - JButton btnWriteSamplingRate = new JButton("Write Sampling Rate"); + JButton btnWriteSamplingRate = new JButton("Write Sampling Rate (Shimmer3)"); btnWriteSamplingRate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ShimmerDevice sd = ((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)); @@ -291,12 +312,30 @@ public void actionPerformed(ActionEvent e) { frame.getContentPane().add(lblPRR); String[] options = {"Shimmer3", "Verisense"}; - DefaultComboBoxModel model = new DefaultComboBoxModel<>(options); comboBox = new JComboBox<>(options); - comboBox.setModel(model); - comboBox.setBounds(164, 59, 71, 22); + comboBox.setBounds(164, 59, 71, 22); frame.getContentPane().add(comboBox); + JButton btnNewButton = new JButton("Sync (Verisense)"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + VerisenseDevice device = (VerisenseDevice)btManager.getShimmerDeviceBtConnected(btComport); + try { + + ((VerisenseProtocolByteCommunication)device.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH)).readLoggedData(); + + + + + } catch (ShimmerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + btnNewButton.setBounds(475, 97, 187, 31); + frame.getContentPane().add(btnNewButton); + plotManager.setTitle("Plot"); } @@ -368,7 +407,7 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { int msg = callbackObject.mIndicator; if (msg== ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED){ textPaneStatus.setText("device fully initialized"); - ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); + ShimmerDevice device = btManager.getShimmerDeviceBtConnectedFromMac(btComport); if (device instanceof VerisenseDevice) { textFieldSamplingRate.setText(Double.toString(((VerisenseDevice)device).getSamplingRateShimmer())); From b91e47acd7b67fdce7ba9036f77d0af4abd54739 Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 5 Apr 2024 14:38:44 +0800 Subject: [PATCH 05/11] more updates for verisense --- .../simpleexamples/SensorMapsExample.java | 66 +++++++++++++++---- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 46160891a..b68b604b8 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -21,6 +21,7 @@ import com.shimmerresearch.pcDriver.ShimmerPC; import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; import com.shimmerresearch.verisense.VerisenseDevice; +import com.shimmerresearch.verisense.communication.SyncProgressDetails; import com.shimmerresearch.verisense.communication.VerisenseProtocolByteCommunication; import com.shimmerresearch.bluetooth.ShimmerBluetooth; import info.monitorenter.gui.chart.Chart2D; @@ -67,13 +68,16 @@ public class SensorMapsExample extends BasicProcessWithCallBack { private JTextField textFieldSamplingRate; static JLabel lblPRR; JComboBox comboBox; + JLabel lblFilePath; + + String[] options = {"Shimmer3", "Verisense"}; /** * Initialize the contents of the frame * @wbp.parser.entryPoint */ public void initialize() { frame = new JFrame("Shimmer SensorMaps Example"); - frame.setBounds(100, 100, 1000, 591); + frame.setBounds(100, 100, 1200, 591); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); @@ -107,7 +111,7 @@ public void actionPerformed(ActionEvent arg0) { } }); btnConnect.setToolTipText("attempt connection to Shimmer device"); - btnConnect.setBounds(245, 55, 199, 31); + btnConnect.setBounds(290, 56, 199, 31); frame.getContentPane().add(btnConnect); JButton btnDisconnect = new JButton("DISCONNECT"); @@ -119,7 +123,7 @@ public void actionPerformed(ActionEvent e) { } }); btnDisconnect.setToolTipText("disconnect from Shimmer device"); - btnDisconnect.setBounds(475, 55, 187, 31); + btnDisconnect.setBounds(520, 56, 187, 31); frame.getContentPane().add(btnDisconnect); @@ -132,7 +136,7 @@ public void actionPerformed(ActionEvent e) { frame.getContentPane().add(textPaneStatus); JMenuBar menuBar = new JMenuBar(); - menuBar.setBounds(0, 0, 984, 23); + menuBar.setBounds(0, 0, 1184, 23); frame.getContentPane().add(menuBar); JMenu mnTools = new JMenu("Tools"); @@ -208,13 +212,13 @@ public void actionPerformed(ActionEvent e) { mnTools.add(mntmDeviceConfiguration); JPanel plotPanel = new JPanel(); - plotPanel.setBounds(10, 250, 611, 272); + plotPanel.setBounds(10, 269, 1164, 272); frame.getContentPane().add(plotPanel); plotPanel.setLayout(null); mChart.setLocation(12, 13); - mChart.setSize(587, 246); + mChart.setSize(1142, 246); plotPanel.add(mChart); plotManager.addChart(mChart); @@ -304,16 +308,16 @@ public void actionPerformed(ActionEvent e) { } }); btnWriteSamplingRate.setToolTipText("attempt connection to Shimmer device"); - btnWriteSamplingRate.setBounds(245, 97, 199, 31); + btnWriteSamplingRate.setBounds(164, 98, 220, 31); frame.getContentPane().add(btnWriteSamplingRate); lblPRR = new JLabel("Packet Reception Rate: "); lblPRR.setBounds(10, 228, 372, 14); frame.getContentPane().add(lblPRR); - String[] options = {"Shimmer3", "Verisense"}; - comboBox = new JComboBox<>(options); - comboBox.setBounds(164, 59, 71, 22); + DefaultComboBoxModel comboModel = new DefaultComboBoxModel(options); + comboBox = new JComboBox<>(comboModel); + comboBox.setBounds(164, 59, 116, 22); frame.getContentPane().add(comboBox); JButton btnNewButton = new JButton("Sync (Verisense)"); @@ -333,9 +337,33 @@ public void actionPerformed(ActionEvent e) { } } }); - btnNewButton.setBounds(475, 97, 187, 31); + btnNewButton.setBounds(415, 97, 187, 31); frame.getContentPane().add(btnNewButton); + JButton btnEraseDataverisense = new JButton("Erase Data (Verisense)"); + btnEraseDataverisense.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + VerisenseDevice device = (VerisenseDevice)btManager.getShimmerDeviceBtConnected(btComport); + try { + + ((VerisenseProtocolByteCommunication)device.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH)).eraseDataTask().wait(); + lblFilePath.setText("Erased Data"); + } catch (ShimmerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + btnEraseDataverisense.setBounds(632, 97, 187, 31); + frame.getContentPane().add(btnEraseDataverisense); + + lblFilePath = new JLabel(" "); + lblFilePath.setBounds(12, 253, 611, 14); + frame.getContentPane().add(lblFilePath); + plotManager.setTitle("Plot"); } @@ -381,6 +409,15 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { } textPaneStatus.setText("connected"); //shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport); +// shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport); + //shimmer.startStreaming(); + } else if (callbackObject.mState == BT_STATE.STREAMING_LOGGED_DATA) { + if (timer!=null){ + timer.cancel(); + timer = new Timer(); + } + textPaneStatus.setText("Syncing"); + //shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport); // shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport); //shimmer.startStreaming(); } else if (callbackObject.mState == BT_STATE.DISCONNECTED @@ -432,7 +469,12 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { } else if (ind == ShimmerPC.MSG_IDENTIFIER_PACKET_RECEPTION_RATE_OVERALL) { - } + } else if(ind == ShimmerPC.MSG_IDENTIFIER_SYNC_PROGRESS){ + SyncProgressDetails mDetails = (SyncProgressDetails)((CallbackObject)shimmerMSG.mB).mMyObject; + String progress = "Payload Index : " + Double.toString(mDetails.mPayloadIndex) + ", Transfer Rate (bytes/s) : " + Double.toString(mDetails.mTransferRateBytes) ; + lblPRR.setText(progress); + lblFilePath.setText(mDetails.mBinFilePath); + } From d5f18fc8338856cb99cbfb88b902be7f81f6f64b Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 5 Apr 2024 15:01:15 +0800 Subject: [PATCH 06/11] write to file now functional --- .../simpleexamples/SensorMapsExample.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index b68b604b8..a38d80470 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -19,6 +19,7 @@ import com.shimmerresearch.guiUtilities.configuration.SignalsToPlotDialog; import com.shimmerresearch.guiUtilities.plot.BasicPlotManagerPC; import com.shimmerresearch.pcDriver.ShimmerPC; +import com.shimmerresearch.tools.LoggingPC; import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc; import com.shimmerresearch.verisense.VerisenseDevice; import com.shimmerresearch.verisense.communication.SyncProgressDetails; @@ -38,6 +39,8 @@ import javax.swing.JCheckBox; import javax.swing.JTextPane; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.ActionEvent; import javax.swing.JMenu; import java.awt.event.KeyAdapter; @@ -69,6 +72,8 @@ public class SensorMapsExample extends BasicProcessWithCallBack { static JLabel lblPRR; JComboBox comboBox; JLabel lblFilePath; + LoggingPC lpc; + JCheckBox chckbxWriteDataToFile; String[] options = {"Shimmer3", "Verisense"}; /** @@ -235,6 +240,11 @@ public void actionPerformed(ActionEvent e) { btnStartStreaming.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { + if (chckbxWriteDataToFile.isSelected()) { + String ts = Long.toString(System.currentTimeMillis()); + lpc = new LoggingPC(ts+"_test.csv"); + } + try { ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); if (device instanceof VerisenseDevice) { @@ -256,6 +266,12 @@ public void actionPerformed(ActionEvent arg0) { JButton btnStopStreaming = new JButton("STOP STREAMING"); btnStopStreaming.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + + if (lpc!=null) { + lpc.closeFile(); + lpc=null; + } + ShimmerDevice device = btManager.getShimmerDeviceBtConnected(btComport); try { if (device instanceof VerisenseDevice) { @@ -346,15 +362,12 @@ public void actionPerformed(ActionEvent e) { VerisenseDevice device = (VerisenseDevice)btManager.getShimmerDeviceBtConnected(btComport); try { - ((VerisenseProtocolByteCommunication)device.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH)).eraseDataTask().wait(); - lblFilePath.setText("Erased Data"); + ((VerisenseProtocolByteCommunication)device.getMapOfVerisenseProtocolByteCommunication().get(COMMUNICATION_TYPE.BLUETOOTH)).eraseDataTask(); + } catch (ShimmerException e1) { // TODO Auto-generated catch block e1.printStackTrace(); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + } } }); btnEraseDataverisense.setBounds(632, 97, 187, 31); @@ -364,6 +377,19 @@ public void actionPerformed(ActionEvent e) { lblFilePath.setBounds(12, 253, 611, 14); frame.getContentPane().add(lblFilePath); + chckbxWriteDataToFile = new JCheckBox("Write Data to File"); + chckbxWriteDataToFile.setBounds(829, 185, 242, 23); + chckbxWriteDataToFile.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + if(e.getStateChange() == ItemEvent.SELECTED) { + + } else { + + } + } + }); + frame.getContentPane().add(chckbxWriteDataToFile); + plotManager.setTitle("Plot"); } @@ -460,7 +486,9 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { } else if (ind == ShimmerPC.MSG_IDENTIFIER_DATA_PACKET) { System.out.println("Shimmer MSG_IDENTIFIER_DATA_PACKET"); ObjectCluster objc = (ObjectCluster) shimmerMSG.mB; - + if (lpc!=null) { + lpc.logData(objc); + } try { plotManager.filterDataAndPlot(objc); } catch (Exception e) { From 44617e3e157fab850b15b02938f96bedbc9e4ce3 Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 5 Apr 2024 15:57:09 +0800 Subject: [PATCH 07/11] fix sensormaps example --- .../com/shimmerresearch/simpleexamples/SensorMapsExample.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index a38d80470..780b0a1fb 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -471,6 +471,10 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { if (msg== ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED){ textPaneStatus.setText("device fully initialized"); ShimmerDevice device = btManager.getShimmerDeviceBtConnectedFromMac(btComport); + if (btComport.contains("COM")) { + device = btManager.getShimmerDeviceBtConnected(btComport); + } + if (device instanceof VerisenseDevice) { textFieldSamplingRate.setText(Double.toString(((VerisenseDevice)device).getSamplingRateShimmer())); From 2673151d7efea066dcdbf6d281c2f5d1d6d8e5cf Mon Sep 17 00:00:00 2001 From: JongChern Date: Mon, 8 Apr 2024 11:01:23 +0800 Subject: [PATCH 08/11] update sensormapsexample --- .../com/shimmerresearch/simpleexamples/SensorMapsExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 780b0a1fb..910f91b70 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -70,6 +70,7 @@ public class SensorMapsExample extends BasicProcessWithCallBack { final Chart2D mChart = new Chart2D(); private JTextField textFieldSamplingRate; static JLabel lblPRR; + static final String PREFIX_COM = "COM"; JComboBox comboBox; JLabel lblFilePath; LoggingPC lpc; @@ -471,7 +472,7 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) { if (msg== ShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED){ textPaneStatus.setText("device fully initialized"); ShimmerDevice device = btManager.getShimmerDeviceBtConnectedFromMac(btComport); - if (btComport.contains("COM")) { + if (btComport.contains(PREFIX_COM)) { device = btManager.getShimmerDeviceBtConnected(btComport); } From 5223926a4ff90a43adfc6818dcc7c54b5d6f9770 Mon Sep 17 00:00:00 2001 From: JongChern Date: Mon, 8 Apr 2024 11:47:52 +0800 Subject: [PATCH 09/11] minor update to make sure the device is removed from the map --- .../managers/bluetoothManager/ShimmerBluetoothManager.java | 3 +++ .../com/shimmerresearch/simpleexamples/SensorMapsExample.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ShimmerBluetoothManager/src/main/java/com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.java b/ShimmerBluetoothManager/src/main/java/com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.java index 046720275..c36cd25e6 100644 --- a/ShimmerBluetoothManager/src/main/java/com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.java +++ b/ShimmerBluetoothManager/src/main/java/com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.java @@ -137,6 +137,9 @@ public void connectShimmerThroughBTAddress(BluetoothDeviceDetails deviceDetails) connectThread.start(); } + /** + * @param connectionHandle comport or mac address, note that this does not remove the device from the map + */ public void disconnectShimmer(String connectionHandle){ printMessage("Attempting to disconnect from connection handle = " + connectionHandle); ShimmerDevice shimmerDevice = getShimmerDeviceBtConnected(connectionHandle); diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 910f91b70..8927c3e2d 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -124,7 +124,7 @@ public void actionPerformed(ActionEvent arg0) { btnDisconnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - btManager.disconnectShimmer(btComport); + btManager.disconnectAllDevices(); //using disconnect all as this removes the device from the map as well } }); From 55adbbb51aa0d6e885168f72dba2eb57c644d2e3 Mon Sep 17 00:00:00 2001 From: JongChern Date: Mon, 8 Apr 2024 12:53:54 +0800 Subject: [PATCH 10/11] more fixes --- .../guiUtilities/configuration/EnableSensorsDialog.java | 1 + .../com/shimmerresearch/simpleexamples/SensorMapsExample.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ShimmerDriverPC/src/main/java/com/shimmerresearch/guiUtilities/configuration/EnableSensorsDialog.java b/ShimmerDriverPC/src/main/java/com/shimmerresearch/guiUtilities/configuration/EnableSensorsDialog.java index 9c1e875f5..07e42ec5e 100644 --- a/ShimmerDriverPC/src/main/java/com/shimmerresearch/guiUtilities/configuration/EnableSensorsDialog.java +++ b/ShimmerDriverPC/src/main/java/com/shimmerresearch/guiUtilities/configuration/EnableSensorsDialog.java @@ -88,6 +88,7 @@ public void actionPerformed(ActionEvent e) { @Override protected void createFrame() { + dialog = new JDialog(); dialog.setModal(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setTitle("Enable Sensors"); diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 8927c3e2d..2760704c0 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -231,6 +231,8 @@ public void actionPerformed(ActionEvent e) { JMenuItem mntmSignalsToPlot = new JMenuItem("Signals to plot"); mntmSignalsToPlot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + mChart.removeAll(); + plotManager.removeAllSignals(); SignalsToPlotDialog signalsToPlotDialog = new SignalsToPlotDialog(); signalsToPlotDialog.initialize(((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)), plotManager, mChart); } @@ -240,7 +242,6 @@ public void actionPerformed(ActionEvent e) { JButton btnStartStreaming = new JButton("START STREAMING"); btnStartStreaming.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - if (chckbxWriteDataToFile.isSelected()) { String ts = Long.toString(System.currentTimeMillis()); lpc = new LoggingPC(ts+"_test.csv"); From 677933cda0f22e0c916bd6d8556deeebe188343c Mon Sep 17 00:00:00 2001 From: JongChern Date: Mon, 8 Apr 2024 15:57:58 +0800 Subject: [PATCH 11/11] fix to checkifalive timer --- .../tools/bluetooth/BasicShimmerBluetoothManagerPc.java | 7 +++++++ .../shimmerresearch/simpleexamples/SensorMapsExample.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java index a75a4be46..b045c75cf 100644 --- a/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java +++ b/ShimmerDriverPC/src/main/java/com/shimmerresearch/tools/bluetooth/BasicShimmerBluetoothManagerPc.java @@ -207,6 +207,12 @@ public void connectShimmer3BleGrpc(BluetoothDeviceDetails bdd) { @Override public void connectShimmerThroughCommPort(String comPort){ directConnectUnknownShimmer=true; + + if (mMapOfBtConnectedShimmers.containsKey(comPort)){ + if(!mMapOfBtConnectedShimmers.get(comPort).isConnected()) { + mMapOfBtConnectedShimmers.remove(comPort); + } + } super.setConnectionExceptionListener(new ConnectionExceptionListener() { @@ -243,6 +249,7 @@ public void putShimmerGlobalMap(String bluetoothAddress, ShimmerDevice shimmerDe protected void setupShimmer3BluetoothForBtManager(ShimmerDevice shimmerDevice) { ((ShimmerPC)shimmerDevice).setUseInfoMemConfigMethod(USE_INFOMEM_CONFIG_METHOD); + ((ShimmerPC)shimmerDevice).enableCheckifAlive(true); } diff --git a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java index 2760704c0..1866a0035 100644 --- a/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java +++ b/ShimmerPCBasicExamples/src/main/java/com/shimmerresearch/simpleexamples/SensorMapsExample.java @@ -124,7 +124,7 @@ public void actionPerformed(ActionEvent arg0) { btnDisconnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - btManager.disconnectAllDevices(); //using disconnect all as this removes the device from the map as well + btManager.disconnectShimmer(btComport); } });