diff --git a/ShimmerBLE/BLE.Client/BLE.Client/Pages/DeviceListPage.xaml b/ShimmerBLE/BLE.Client/BLE.Client/Pages/DeviceListPage.xaml
index ba6ce9bb..69bc0d20 100644
--- a/ShimmerBLE/BLE.Client/BLE.Client/Pages/DeviceListPage.xaml
+++ b/ShimmerBLE/BLE.Client/BLE.Client/Pages/DeviceListPage.xaml
@@ -610,6 +610,10 @@
+
+
+
+
_StepCountEnabled;
+
+ set
+ {
+ if (_StepCountEnabled == value)
+ return;
+
+ if (!_Accel2Enabled || !_GyroEnabled)
+ {
+ RaisePropertyChanged();
+ return;
+ }
+
+ _StepCountEnabled = value;
+ RaisePropertyChanged();
+ }
+ }
+
//bool _GyroHighPerformanceEnabled;
//public bool SensorGyroHighPerformance
//{
@@ -2384,6 +2417,7 @@ private void ShimmerDevice_BLEEvent(object sender, ShimmerBLEEventData e)
SensorAccel = ((SensorLIS2DW12)VerisenseBLEDevice.GetSensor(SensorLIS2DW12.SensorName)).IsAccelEnabled();
SensorAccel2 = ((SensorLSM6DS3)VerisenseBLEDevice.GetSensor(SensorLSM6DS3.SensorName)).IsAccelEnabled();
SensorGyro = ((SensorLSM6DS3)VerisenseBLEDevice.GetSensor(SensorLSM6DS3.SensorName)).IsGyroEnabled();
+ StepCount = ((SensorLSM6DS3)VerisenseBLEDevice.GetSensor(SensorLSM6DS3.SensorName)).IsStepCountEnabled();
if (((shimmer.Sensors.SensorGSR)VerisenseBLEDevice.GetSensor(shimmer.Sensors.SensorGSR.SensorName)).GetOversamplingRate() != null)
{
SelectedGSROversamplingRate = ((shimmer.Sensors.SensorGSR)VerisenseBLEDevice.GetSensor(shimmer.Sensors.SensorGSR.SensorName)).GetOversamplingRate().GetDisplayName();
@@ -2825,6 +2859,14 @@ protected async void ConfigureSensor()
{
((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetGyroEnabled(false);
}
+ if (StepCount)
+ {
+ ((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetStepCountEnabled(true);
+ }
+ else
+ {
+ ((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetStepCountEnabled(false);
+ }
((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetAccelRange(a2range);
((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetSamplingRate(a2gyrorate);
((SensorLSM6DS3)clone.GetSensor(SensorLSM6DS3.SensorName)).SetGyroRange(grange);
diff --git a/ShimmerBLE/ShimmerBLEAPI/App.xaml.cs b/ShimmerBLE/ShimmerBLEAPI/App.xaml.cs
index 33eb6df9..62b484cf 100644
--- a/ShimmerBLE/ShimmerBLEAPI/App.xaml.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/App.xaml.cs
@@ -19,6 +19,8 @@ public partial class App : Application
public static Guid ServiceID = Guid.Parse("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
public static Guid TxID = Guid.Parse("6E400002-B5A3-F393-E0A9-E50E24DCCA9E");
public static Guid RxID = Guid.Parse("6E400003-B5A3-F393-E0A9-E50E24DCCA9E");
+ public static Guid RSCServiceID = Guid.Parse("00001814-0000-1000-8000-00805f9b34fb");
+ public static Guid RSCMeasurementID = Guid.Parse("00002a53-0000-1000-8000-00805f9b34fb");
public static long RealmDBSizeLimitInMB = 500;
public static readonly long MinIntervalRealmDBSizeLimitInMB = 86400000;
//public static bool CompactDB = RealmService.CompactAndMigrateDatabase(); //first DB operation when you open the app
diff --git a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseByteCommunication.cs b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseByteCommunication.cs
index ea84bd2a..e43f653e 100644
--- a/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseByteCommunication.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/Communications/IVerisenseByteCommunication.cs
@@ -35,7 +35,8 @@ public class ByteLevelCommunicationEvent
public enum CommEvent
{
Disconnected = 1,
- NewBytes = 2
+ NewBytes = 2,
+ NewSteps = 3
}
}
}
diff --git a/ShimmerBLE/ShimmerBLEAPI/Communications/RadioPluginBLE.cs b/ShimmerBLE/ShimmerBLEAPI/Communications/RadioPluginBLE.cs
index 810761f7..f9028905 100644
--- a/ShimmerBLE/ShimmerBLEAPI/Communications/RadioPluginBLE.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/Communications/RadioPluginBLE.cs
@@ -25,6 +25,9 @@ public class RadioPluginBLE : IVerisenseByteCommunication
ICharacteristic UartRX { get; set; }
ICharacteristic UartTX { get; set; }
IService ServiceTXRX { get; set; }
+ IService ServiceRSC { get; set; }
+ ICharacteristic RSCMeasure { get; set; }
+
ConnectivityState StateOfConnectivity = ConnectivityState.Unknown;
///
@@ -87,7 +90,17 @@ public async Task Connect()
AdvanceLog(nameof(RadioPluginBLE), "Connect ASM Hash", ConnectedASM.GetHashCode(), Asm_uuid.ToString());
await Task.Delay(500);
- System.Console.WriteLine("Getting Service");
+ System.Console.WriteLine("Getting Services");
+
+ ServiceRSC = await ConnectedASM.GetServiceAsync(App.RSCServiceID);
+
+ if (ServiceRSC != null)
+ {
+ RSCMeasure = await ServiceRSC.GetCharacteristicAsync(App.RSCMeasurementID);
+ RSCMeasure.ValueUpdated += RSCMeasurement_ValueUpdated;
+ await RSCMeasure.StartUpdatesAsync();
+ }
+
ServiceTXRX = await ConnectedASM.GetServiceAsync(App.ServiceID);
if (ServiceTXRX != null)
@@ -99,7 +112,7 @@ public async Task Connect()
System.Console.WriteLine("Getting RX Characteristics Completed");
UartRX.ValueUpdated += UartRX_ValueUpdated;
await UartRX.StartUpdatesAsync();
-
+
AdvanceLog(nameof(RadioPluginBLE), "GetKnownDevice", "Success", Asm_uuid.ToString());
//StateChange(ShimmerDeviceBluetoothState.Connected);
localTask.TrySetResult(true);
@@ -203,6 +216,12 @@ public async Task Disconnect()
UartRX.Service.Dispose();
UartRX = null;
}
+ if (RSCMeasure != null)
+ {
+ RSCMeasure.ValueUpdated -= RSCMeasurement_ValueUpdated;
+ RSCMeasure.Service.Dispose();
+ RSCMeasure = null;
+ }
if (UartTX != null)
{
UartTX.Service.Dispose();
@@ -214,6 +233,12 @@ public async Task Disconnect()
ServiceTXRX = null;
}
+ if (ServiceRSC != null)
+ {
+ ServiceRSC.Dispose();
+ ServiceRSC = null;
+ }
+
//ResponseBuffer = null;
if (ConnectedASM != null)
@@ -291,6 +316,14 @@ private void UartRX_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArg
}
}
+ private void RSCMeasurement_ValueUpdated(object sender, Plugin.BLE.Abstractions.EventArgs.CharacteristicUpdatedEventArgs e)
+ {
+ if (CommunicationEvent != null)
+ {
+ CommunicationEvent.Invoke(null, new ByteLevelCommunicationEvent { Bytes = e.Characteristic.Value, Event = Communications.ByteLevelCommunicationEvent.CommEvent.NewSteps });
+ }
+ }
+
private bool disposedValue = false;
///
/// Disconnect and Dispose Veriense BLE Device
@@ -311,6 +344,12 @@ public void Dispose(bool disposing)
UartRX = null;
}
+ if (RSCMeasure != null)
+ {
+ RSCMeasure.ValueUpdated -= RSCMeasurement_ValueUpdated;
+ RSCMeasure = null;
+ }
+
UartTX = null;
//ResponseBuffer = null;
diff --git a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs
index 2e174e0e..4655ed52 100644
--- a/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs
@@ -288,6 +288,17 @@ protected void UartRX_ValueUpdated(object sender, ByteLevelCommunicationEvent co
DataRequestTimer.Dispose(); //there is no point having the timer, if the connection is disconnected
}
StateChange(ShimmerDeviceBluetoothState.Disconnected);
+ }
+ else if (comEvent.Event == ByteLevelCommunicationEvent.CommEvent.NewSteps)
+ {
+ byte[] bytes = comEvent.Bytes;
+
+ int strideLength = int.Parse(bytes[4].ToString(), System.Globalization.NumberStyles.HexNumber);
+ int totalDistance = int.Parse(bytes[6].ToString(), System.Globalization.NumberStyles.HexNumber);
+ int stepsCount = totalDistance / strideLength;
+
+ if (ShimmerBLEEvent != null)
+ ShimmerBLEEvent.Invoke(null, new ShimmerBLEEventData { ASMID = Asm_uuid.ToString(), CurrentEvent = VerisenseBLEEvent.NewStepsData, ObjMsg = stepsCount });
}
}
@@ -1298,6 +1309,7 @@ void HandleCompletePayload()
{
DataBuffer.Finish = DateTime.Now;
DataBuffer.Transfer = DataBuffer.CurrentLength / (DataBuffer.Finish - DataBuffer.Start).TotalSeconds;
+ Console.WriteLine("Current Length Complete Payload = " + DataBuffer.CurrentLength);
string syncProgress = string.Format("{0:.##} KB/s", DataBuffer.Transfer / 1024.0) + "(" + ShimmerBLEAPI.Resources.AppResources.PayloadIndex + ": " + PayloadIndex + ")";
AdvanceLog(LogObject, "Payload transfer rate", syncProgress, ASMName);
//InvokeSyncEvent(Asm_uuid.ToString(), new SyncEventData { ASMID = Asm_uuid.ToString(), CurrentEvent = SyncEvent.DataSync, SyncProgress = syncProgress });
diff --git a/ShimmerBLE/ShimmerBLEAPI/Models/ShimmerBLEEventData.cs b/ShimmerBLE/ShimmerBLEAPI/Models/ShimmerBLEEventData.cs
index 85cec28f..794df6f9 100644
--- a/ShimmerBLE/ShimmerBLEAPI/Models/ShimmerBLEEventData.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/Models/ShimmerBLEEventData.cs
@@ -23,7 +23,8 @@ public enum VerisenseBLEEvent
RequestResponse = 5,
WriteResponse = 6,
RequestResponseFail = 7,
- DataStreamCRCFail = 8
+ DataStreamCRCFail = 8,
+ NewStepsData = 9
}
}
diff --git a/ShimmerBLE/ShimmerBLEAPI/Sensors/SensorLSM6DS3.cs b/ShimmerBLE/ShimmerBLEAPI/Sensors/SensorLSM6DS3.cs
index 8be981ee..3eab4c85 100644
--- a/ShimmerBLE/ShimmerBLEAPI/Sensors/SensorLSM6DS3.cs
+++ b/ShimmerBLE/ShimmerBLEAPI/Sensors/SensorLSM6DS3.cs
@@ -24,6 +24,8 @@ public SensorLSM6DS3()
//GEN_CFG_0
protected bool Accel2_Enabled = false;
protected bool Gyro_Enabled = false;
+ //GEN_CFG_2
+ protected bool StepCountEnabled;
//GYRO_ACCEL2_CFG_0
protected SensorSetting FIFOThresholdSetting = Sensor.UnknownSetting;
//GYRO_ACCEL2_CFG_1
@@ -268,6 +270,7 @@ public void SetAccelEnabled(bool enable)
{
Accel2_Enabled = enable;
}
+
///
/// Turns on/off data collection from the gyroscope
///
@@ -276,6 +279,28 @@ public void SetGyroEnabled(bool enable)
{
Gyro_Enabled = enable;
}
+
+ ///
+ /// Returns true if step count is enabled
+ ///
+ public bool IsStepCountEnabled()
+ {
+ return StepCountEnabled;
+ }
+
+ ///
+ /// Enable or disable step count
+ ///
+ ///
+ public void SetStepCountEnabled(bool enabled)
+ {
+ if(enabled && (!Accel2_Enabled || !Gyro_Enabled))
+ {
+ throw new Exception("Unable to enable step count when Accel2 or Gyro is not enabled. ");
+ }
+ StepCountEnabled = enabled;
+ }
+
///
/// Returns true if the data collection from the secondary accelerometer is enabled
///
@@ -284,6 +309,7 @@ public bool IsAccelEnabled()
{
return Accel2_Enabled;
}
+
///
/// Returns true if the data collection from the gyroscope is enabled
///
@@ -660,6 +686,15 @@ public override byte[] GenerateOperationConfig(byte[] operationalConfigBytes)
operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_0] = (byte)(operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_0] & 0b11011111);
}
+ if (StepCountEnabled)
+ {
+ operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_2] = (byte)(operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_2] | 0b00100000);
+ }
+ else
+ {
+ operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_2] = (byte)(operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_2] & 0b11011111);
+ }
+
//temp
operationalConfigBytes[(int)ConfigurationBytesIndexName.GYRO_ACCEL2_CFG_5] = (byte)((operationalConfigBytes[(int)ConfigurationBytesIndexName.GYRO_ACCEL2_CFG_5] & 0b0001111) | (SamplingRateSetting.GetConfigurationValue() << 4));
operationalConfigBytes[(int)ConfigurationBytesIndexName.GYRO_ACCEL2_CFG_5] = (byte)((operationalConfigBytes[(int)ConfigurationBytesIndexName.GYRO_ACCEL2_CFG_5] & 0b11110011) | (GyroRangeSetting.GetConfigurationValue() << 2));
@@ -902,6 +937,14 @@ public override void InitializeUsingOperationConfig(byte[] operationalConfigByte
{
Gyro_Enabled = false;
}
+ if ((operationalConfigBytes[(int)ConfigurationBytesIndexName.GEN_CFG_2] & 0b00100000) > 5)
+ {
+ StepCountEnabled = true;
+ }
+ else
+ {
+ StepCountEnabled = false;
+ }
if (((operationalConfigBytes[(int)ConfigurationBytesIndexName.GYRO_ACCEL2_CFG_1] >> 7) & 0b00000001) == 1)
{
StepCounterAndTimestampEnabled = true;