Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package com.shimmerresearch.guiUtilities.configuration;

import java.awt.BorderLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.shimmerresearch.bluetooth.ShimmerBluetooth;
import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE;
import com.shimmerresearch.driver.Configuration;
import com.shimmerresearch.driver.ShimmerDevice;
import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE;
import com.shimmerresearch.driverUtilities.AssembleShimmerConfig;
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
import com.shimmerresearch.managers.bluetoothManager.ShimmerBluetoothManager;
import com.shimmerresearch.sensors.lis2dw12.SensorLIS2DW12;
import com.shimmerresearch.sensors.lisxmdl.SensorLIS3MDL;
import com.shimmerresearch.sensors.lsm6dsv.SensorLSM6DSV;
import com.shimmerresearch.tools.bluetooth.BasicShimmerBluetoothManagerPc;
import com.shimmerresearch.verisense.VerisenseDevice;

public class EnableLowPowerModeDialog {
private static JDialog dialog = new JDialog();
JPanel panel = new JPanel();
protected ShimmerDevice shimmerDevice;
protected ShimmerDevice clone;
ShimmerBluetoothManager bluetoothManager;
JCheckBox cbEnableMagLP;
JCheckBox cbEnableGyroLP;
JCheckBox cbEnableWRAccelLP;

public EnableLowPowerModeDialog(ShimmerDevice shimmerPC, BasicShimmerBluetoothManagerPc btManager) {
this.shimmerDevice = shimmerPC;
this.bluetoothManager = btManager;
this.clone = this.shimmerDevice.deepClone();

}

public static void main(String[] args) {

// dialog.setVisible(true);

}

/**
* Call this to initialize and display the dialog.
*
* @wbp.parser.entryPoint
*/
public void showDialog() {
createFrame();
createWriteButton();
initialize();
showFrame();
}

protected void createWriteButton() {
// TODO Auto-generated method stub
JButton btnWriteConfig = new JButton("Save");
btnWriteConfig.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

boolean connected = false;
if (shimmerDevice != null) {
if (shimmerDevice instanceof VerisenseDevice) {
VerisenseDevice vd = (VerisenseDevice) shimmerDevice;
if (vd.getBluetoothRadioState().equals(BT_STATE.CONNECTED)) {
connected = true;
}

} else {
ShimmerBluetooth sb = (ShimmerBluetooth) shimmerDevice;
if (sb.getBluetoothRadioState().equals(BT_STATE.CONNECTED)) {
connected = true;
}
}
}
if (connected) {
clone.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS3MDL_MAG,
SensorLIS3MDL.GuiLabelConfig.LIS3MDL_MAG_LP, cbEnableMagLP.isSelected());
clone.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LSM6DSV_GYRO,
SensorLSM6DSV.GuiLabelConfig.LSM6DSV_GYRO_LPM, cbEnableGyroLP.isSelected());
clone.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS2DW12_ACCEL_WR,
SensorLIS2DW12.GuiLabelConfig.LIS2DW12_ACCEL_LPM, cbEnableWRAccelLP.isSelected());

AssembleShimmerConfig.generateSingleShimmerConfig(clone, COMMUNICATION_TYPE.BLUETOOTH);
bluetoothManager.configureShimmer(clone);

} else {
JOptionPane.showMessageDialog(dialog, "Device not in a connected state!", "Info",
JOptionPane.WARNING_MESSAGE);
}

}
});
btnWriteConfig.setToolTipText("Write the current sensors low power mode to the Shimmer device");
dialog.getContentPane().add(btnWriteConfig, BorderLayout.SOUTH);
}

protected void createFrame() {
dialog = new JDialog();
dialog.setModal(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setTitle("Low Power Mode");

panel.setLayout((LayoutManager) new BoxLayout(panel, BoxLayout.Y_AXIS));

dialog.getContentPane().add(panel, BorderLayout.CENTER);
}

protected void initialize() {
createCheckBox();

if (clone.getHardwareVersion() == HW_ID.SHIMMER_3R) {
cbEnableGyroLP.setText("Enable LN Accel and Gyro LP Mode");
}
boolean isLowPowerMagEnabled = Boolean.valueOf(clone.getConfigGuiValueUsingConfigLabel(
Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS3MDL_MAG, SensorLIS3MDL.GuiLabelConfig.LIS3MDL_MAG_LP));
cbEnableMagLP.setSelected(isLowPowerMagEnabled);

boolean isLowPowerGyroEnabled = Boolean.valueOf(clone.getConfigGuiValueUsingConfigLabel(
Configuration.Shimmer3.SENSOR_ID.SHIMMER_LSM6DSV_GYRO, SensorLSM6DSV.GuiLabelConfig.LSM6DSV_GYRO_LPM));
cbEnableGyroLP.setSelected(isLowPowerGyroEnabled);

boolean isLowPowerWRAccelEnabled = Boolean.valueOf(
clone.getConfigGuiValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS2DW12_ACCEL_WR,
SensorLIS2DW12.GuiLabelConfig.LIS2DW12_ACCEL_LPM));
cbEnableWRAccelLP.setSelected(isLowPowerWRAccelEnabled);

}

protected void createCheckBox() {
cbEnableMagLP = new JCheckBox("Enable Mag LP Mode");
cbEnableMagLP.setSelected(false);
panel.add(cbEnableMagLP);

cbEnableWRAccelLP = new JCheckBox("Enable WR Accel LP Mode", true);
cbEnableWRAccelLP.setSelected(false);
panel.add(cbEnableWRAccelLP);

cbEnableGyroLP = new JCheckBox("Enable Gyro LP Mode", true);
cbEnableGyroLP.setSelected(false);
panel.add(cbEnableGyroLP);

}

protected void showFrame() {
// TODO Auto-generated method stub
// maybe should be in a different abstract method? lets see how android needs to
// handles this
dialog.setSize(300, 200);
dialog.setVisible(true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
import com.shimmerresearch.exceptions.ShimmerException;
import com.shimmerresearch.grpc.ShimmerGRPC;
import com.shimmerresearch.guiUtilities.configuration.EnableLowPowerModeDialog;
import com.shimmerresearch.guiUtilities.configuration.EnableSensorsDialog;
import com.shimmerresearch.guiUtilities.configuration.SensorConfigDialog;
import com.shimmerresearch.guiUtilities.configuration.SignalsToPlotDialog;
Expand Down Expand Up @@ -81,11 +82,7 @@ public class SensorMapsExample extends BasicProcessWithCallBack {
JLabel lblFilePath;
LoggingPC lpc;
JCheckBox chckbxWriteDataToFile;
JCheckBox cbEnableMagLP;
JCheckBox cbEnableGyroLP;
JCheckBox cbEnableWRAccelLP;
String[] options = {"Shimmer3", "Verisense"};
boolean isLPModeCBUpdated = false;
/**
* Initialize the contents of the frame
* @wbp.parser.entryPoint
Expand Down Expand Up @@ -132,7 +129,6 @@ public void actionPerformed(ActionEvent arg0) {
JButton btnDisconnect = new JButton("DISCONNECT");
btnDisconnect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isLPModeCBUpdated = false;
btManager.disconnectShimmer(btComport);

}
Expand All @@ -141,62 +137,6 @@ public void actionPerformed(ActionEvent e) {
btnDisconnect.setBounds(520, 56, 187, 31);
frame.getContentPane().add(btnDisconnect);

cbEnableMagLP = new JCheckBox("Enable Mag LP Mode");
cbEnableMagLP.setBounds(900,30, 300,50);
cbEnableMagLP.setSelected(false);
frame.getContentPane().add(cbEnableMagLP);

cbEnableWRAccelLP = new JCheckBox("Enable WR Accel LP Mode", true);
cbEnableWRAccelLP.setBounds(900,65, 300,50);
cbEnableWRAccelLP.setSelected(false);
frame.getContentPane().add(cbEnableWRAccelLP);

cbEnableGyroLP = new JCheckBox("Enable Gyro LP Mode", true);
cbEnableGyroLP.setBounds(900,100, 300,50);
cbEnableGyroLP.setSelected(false);
frame.getContentPane().add(cbEnableGyroLP);

JButton btnSaveLPMode = new JButton("Save LP Mode");
btnSaveLPMode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {


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;
}
}
}
if(connected) {
ShimmerDevice cloneDevice = SD.deepClone();

cloneDevice.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS3MDL_MAG, SensorLIS3MDL.GuiLabelConfig.LIS3MDL_MAG_LP, cbEnableMagLP.isSelected());
cloneDevice.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LSM6DSV_GYRO, SensorLSM6DSV.GuiLabelConfig.LSM6DSV_GYRO_LPM, cbEnableGyroLP.isSelected());
cloneDevice.setConfigValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS2DW12_ACCEL_WR, SensorLIS2DW12.GuiLabelConfig.LIS2DW12_ACCEL_LPM, cbEnableWRAccelLP.isSelected());

AssembleShimmerConfig.generateSingleShimmerConfig(cloneDevice, COMMUNICATION_TYPE.BLUETOOTH);
btManager.configureShimmer(cloneDevice);

} else {
JOptionPane.showMessageDialog(frame, "Device not in a connected state!", "Info", JOptionPane.WARNING_MESSAGE);
}

}
});
btnSaveLPMode.setBounds(900, 150, 150, 25);
frame.getContentPane().add(btnSaveLPMode);

JLabel lblShimmerStatus = new JLabel("Shimmer Status");
lblShimmerStatus.setBounds(10, 139, 144, 23);
frame.getContentPane().add(lblShimmerStatus);
Expand Down Expand Up @@ -302,6 +242,40 @@ public void actionPerformed(ActionEvent e) {
}
});
mnTools.add(mntmSignalsToPlot);


JMenuItem mntmLowPowerMode = new JMenuItem("Low Power Mode");
mntmLowPowerMode.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

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;
}
}
}
if(connected) {
EnableLowPowerModeDialog lpModeDialog = new EnableLowPowerModeDialog(((ShimmerDevice)btManager.getShimmerDeviceBtConnected(btComport)),btManager);
lpModeDialog.showDialog();

} else {
JOptionPane.showMessageDialog(frame, "Device not in a connected state!", "Info", JOptionPane.WARNING_MESSAGE);
}

}
});
mnTools.add(mntmLowPowerMode);

JButton btnStartStreaming = new JButton("START STREAMING");
btnStartStreaming.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -500,22 +474,6 @@ protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
timer = new Timer();
}
textPaneStatus.setText("connected");
if(!isLPModeCBUpdated) {
ShimmerDevice cloneDevice = btManager.getShimmerDeviceBtConnected(btComport).deepClone();
if(cloneDevice.getHardwareVersion()==HW_ID.SHIMMER_3R) {
cbEnableGyroLP.setText("Enable LN Accel and Gyro LP Mode");
}
boolean isLowPowerMagEnabled = Boolean.valueOf(cloneDevice.getConfigGuiValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS3MDL_MAG, SensorLIS3MDL.GuiLabelConfig.LIS3MDL_MAG_LP));
cbEnableMagLP.setSelected(isLowPowerMagEnabled);

boolean isLowPowerGyroEnabled = Boolean.valueOf(cloneDevice.getConfigGuiValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LSM6DSV_GYRO, SensorLSM6DSV.GuiLabelConfig.LSM6DSV_GYRO_LPM));
cbEnableGyroLP.setSelected(isLowPowerGyroEnabled);

boolean isLowPowerWRAccelEnabled = Boolean.valueOf(cloneDevice.getConfigGuiValueUsingConfigLabel(Configuration.Shimmer3.SENSOR_ID.SHIMMER_LIS2DW12_ACCEL_WR, SensorLIS2DW12.GuiLabelConfig.LIS2DW12_ACCEL_LPM));
cbEnableWRAccelLP.setSelected(isLowPowerWRAccelEnabled);

isLPModeCBUpdated = true;
}

//shimmer = (ShimmerPC) btManager.getShimmerDeviceBtConnected(btComport);
// shimmerDevice = btManager.getShimmerDeviceBtConnected(btComport);
Expand Down