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
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
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