Skip to content
Open
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
4 changes: 4 additions & 0 deletions ShimmerBLE/BLE.Client/BLE.Client/Pages/DeviceListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@
<Label Text="SensorGyro : " WidthRequest="200"/>
<CheckBox IsChecked="{Binding SensorGyro}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Step Count : " WidthRequest="200"/>
<CheckBox IsChecked="{Binding StepCount}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Sampling Rate : " WidthRequest="200"/>
<Picker ItemsSource="{Binding Accel2GyroRates}"
Expand Down
42 changes: 42 additions & 0 deletions ShimmerBLE/BLE.Client/BLE.Client/ViewModels/DeviceListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public bool SensorAccel2
if (_Accel2Enabled == value)
return;

if (_Accel2Enabled && _StepCountEnabled)
{
RaisePropertyChanged();
return;
}

_Accel2Enabled = value;
RaisePropertyChanged();
}
Expand All @@ -322,11 +328,38 @@ public bool SensorGyro
if (_GyroEnabled == value)
return;

if(_GyroEnabled && _StepCountEnabled)
{
RaisePropertyChanged();
return;
}

_GyroEnabled = value;
RaisePropertyChanged();
}
}

bool _StepCountEnabled;
public bool StepCount
{
get => _StepCountEnabled;

set
{
if (_StepCountEnabled == value)
return;

if (!_Accel2Enabled || !_GyroEnabled)
{
RaisePropertyChanged();
return;
}

_StepCountEnabled = value;
RaisePropertyChanged();
}
}

//bool _GyroHighPerformanceEnabled;
//public bool SensorGyroHighPerformance
//{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ShimmerBLE/ShimmerBLEAPI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class ByteLevelCommunicationEvent
public enum CommEvent
{
Disconnected = 1,
NewBytes = 2
NewBytes = 2,
NewSteps = 3
}
}
}
43 changes: 41 additions & 2 deletions ShimmerBLE/ShimmerBLEAPI/Communications/RadioPluginBLE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -87,7 +90,17 @@ public async Task<ConnectivityState> 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)
Expand All @@ -99,7 +112,7 @@ public async Task<ConnectivityState> 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);
Expand Down Expand Up @@ -203,6 +216,12 @@ public async Task<ConnectivityState> Disconnect()
UartRX.Service.Dispose();
UartRX = null;
}
if (RSCMeasure != null)
{
RSCMeasure.ValueUpdated -= RSCMeasurement_ValueUpdated;
RSCMeasure.Service.Dispose();
RSCMeasure = null;
}
if (UartTX != null)
{
UartTX.Service.Dispose();
Expand All @@ -214,6 +233,12 @@ public async Task<ConnectivityState> Disconnect()
ServiceTXRX = null;
}

if (ServiceRSC != null)
{
ServiceRSC.Dispose();
ServiceRSC = null;
}

//ResponseBuffer = null;

if (ConnectedASM != null)
Expand Down Expand Up @@ -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;
/// <summary>
/// Disconnect and Dispose Veriense BLE Device
Expand All @@ -311,6 +344,12 @@ public void Dispose(bool disposing)
UartRX = null;
}

if (RSCMeasure != null)
{
RSCMeasure.ValueUpdated -= RSCMeasurement_ValueUpdated;
RSCMeasure = null;
}

UartTX = null;
//ResponseBuffer = null;

Expand Down
12 changes: 12 additions & 0 deletions ShimmerBLE/ShimmerBLEAPI/Devices/VerisenseBLEDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down Expand Up @@ -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 });
Expand Down
3 changes: 2 additions & 1 deletion ShimmerBLE/ShimmerBLEAPI/Models/ShimmerBLEEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum VerisenseBLEEvent
RequestResponse = 5,
WriteResponse = 6,
RequestResponseFail = 7,
DataStreamCRCFail = 8
DataStreamCRCFail = 8,
NewStepsData = 9
}
}

Expand Down
43 changes: 43 additions & 0 deletions ShimmerBLE/ShimmerBLEAPI/Sensors/SensorLSM6DS3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -268,6 +270,7 @@ public void SetAccelEnabled(bool enable)
{
Accel2_Enabled = enable;
}

/// <summary>
/// Turns on/off data collection from the gyroscope
/// </summary>
Expand All @@ -276,6 +279,28 @@ public void SetGyroEnabled(bool enable)
{
Gyro_Enabled = enable;
}

/// <summary>
/// Returns true if step count is enabled
/// </summary>
public bool IsStepCountEnabled()
{
return StepCountEnabled;
}

/// <summary>
/// Enable or disable step count
/// </summary>
/// <param name="enabled"></param>
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;
}

/// <summary>
/// Returns true if the data collection from the secondary accelerometer is enabled
/// </summary>
Expand All @@ -284,6 +309,7 @@ public bool IsAccelEnabled()
{
return Accel2_Enabled;
}

/// <summary>
/// Returns true if the data collection from the gyroscope is enabled
/// </summary>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down