Skip to content

Commit

Permalink
closes #10 Implemented lap toggle event.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHidem committed Jul 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 67fee1f commit 3a4ebfd
Showing 10 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -103,8 +103,8 @@ public void Parse_GeneralDataPage_DataValid()
{
// Arrange
var fitnessEquipment = CreateFitnessEquipment();
fitnessEquipment.Parse(new byte[] { 16, 0, 0, 0, 0, 0, 0, 0 });
byte[] dataPage = { 16, 0, 128, 64, 0x00, 0x80, 70, 0 };
fitnessEquipment.Parse(new byte[] { 16, 0, 0, 0, 0, 0, 0, 0x34 });
byte[] dataPage = { 16, 0, 128, 64, 0x00, 0x80, 70, 0x34 };

// Act
fitnessEquipment.Parse(
23 changes: 17 additions & 6 deletions AntPlus/DeviceProfiles/FitnessEquipment/Equipment.cs
Original file line number Diff line number Diff line change
@@ -110,7 +110,8 @@ public class GeneralDataPage
public FitnessEquipmentType EquipmentType { get; private set; }
/// <summary>Gets the elapsed time.</summary>
public TimeSpan ElapsedTime { get; private set; }
/// <summary>Gets the distance traveled in meters.</summary>
/// <summary>Gets the distance traveled in meters. This property is only valid when
/// <see cref="DistanceTraveledEnabled"/> is enabled.</summary>
public int DistanceTraveled { get; private set; }
/// <summary>Gets the instantaneous speed.</summary>
/// <value>The instantaneous speed in meters per second.</value>
@@ -214,12 +215,17 @@ internal void Parse(byte[] dataPage)
}
}

private bool lapToggleState;
/// <summary>Occurs when a lap toggle is signaled by the device.</summary>
/// <remarks>
/// The event itself does not convey any information. It is the responsibilty of the application/view model to
/// capture any relevant state from the equipment and/or specific equipment for user consumption. For
/// example, it may be useful to capture elapsed time and accumulated distance from the class.
/// </remarks>
public event EventHandler LapToggled;

/// <summary>Gets the equipment state.</summary>
public FEState State { get; private set; }
/// <summary>Gets a value indicating whether [lap toggle].</summary>
public bool LapToggle { get; private set; }

/// <summary>Gets the general data.</summary>
public GeneralDataPage GeneralData { get; private set; }
/// <summary>Gets the general settings.</summary>
@@ -278,6 +284,13 @@ public override void Parse(byte[] dataPage)
CreateSpecificEquipment(GeneralData.EquipmentType);
}
RaisePropertyChange(nameof(GeneralData));

// check for lap toggle
if (lapToggleState != ((dataPage[7] & 0x80) == 0x80))
{
lapToggleState = (dataPage[7] & 0x80) == 0x80;
LapToggled?.Invoke(this, EventArgs.Empty);
}
break;
case DataPage.GeneralSettings:
HandleFEState(dataPage[7]);
@@ -353,8 +366,6 @@ private void HandleFEState(byte state)
{
logger.LogWarning("Invalid state. Received {State}", st);
}
LapToggle = (state & 0x80) == 0x80;
RaisePropertyChange(nameof(LapToggle));
}

/// <summary>Sets the percentage of maximum resistance resistance.</summary>
1 change: 0 additions & 1 deletion Examples/WpfUsbStickApp/Controls/ClimberControl.xaml
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<TextBlock Text="{Binding Climber.Cadence, StringFormat='Cadence: {0}'}"/>
<TextBlock Text="{Binding Climber.InstantaneousPower, StringFormat='Instantaneous Power: {0}'}"/>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
1 change: 0 additions & 1 deletion Examples/WpfUsbStickApp/Controls/EllipticalControl.xaml
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
<TextBlock Text="{Binding Elliptical.InstantaneousPower, StringFormat='Instantaneous Power: {0}'}"/>
<TextBlock Text="{Binding Elliptical.PosVerticalDistance, StringFormat='PosVerticalDistance: {0}'}"/>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
1 change: 0 additions & 1 deletion Examples/WpfUsbStickApp/Controls/NordicSkierControl.xaml
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<TextBlock Text="{Binding NordicSkier.Cadence, StringFormat='Cadence: {0}'}"/>
<TextBlock Text="{Binding NordicSkier.InstantaneousPower, StringFormat='Instantaneous Power: {0}'}"/>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
1 change: 0 additions & 1 deletion Examples/WpfUsbStickApp/Controls/RowerControl.xaml
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<TextBlock Text="{Binding Rower.Cadence, StringFormat='Cadence: {0}'}"/>
<TextBlock Text="{Binding Rower.InstantaneousPower, StringFormat='Instantaneous Power: {0}'}"/>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
<TextBlock Text="{Binding TrainerTorque.AccumulatedDistance, StringFormat='Accumulated Distance: {0:F2}'}"/>
</StackPanel>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
1 change: 0 additions & 1 deletion Examples/WpfUsbStickApp/Controls/TreadmillControl.xaml
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
<TextBlock Text="{Binding Treadmill.NegVerticalDistance, StringFormat='NegVerticalDistance: {0}'}"/>
<TextBlock Text="{Binding Treadmill.PosVerticalDistance, StringFormat='PosVerticalDistance: {0}'}"/>
<TextBlock Text="{Binding State, StringFormat='State: {0}'}"/>
<TextBlock Text="{Binding LapToggle, StringFormat='Lap Toggle: {0}'}"/>
</StackPanel>
</GroupBox>
</Grid>
10 changes: 9 additions & 1 deletion Examples/WpfUsbStickApp/ViewModels/FitnessEquipmentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SmallEarthTech.AntPlus.DeviceProfiles.FitnessEquipment;
using System;
using System.Windows.Controls;
using WpfUsbStickApp.Controls;

@@ -21,11 +22,13 @@ internal partial class FitnessEquipmentViewModel : ObservableObject
private double wheelDiameter;
[ObservableProperty]
private double gearRatio;
[ObservableProperty]
private TimeSpan lapSplitTime;

public FitnessEquipmentViewModel(Equipment fitnessEquipment)
{
FitnessEquipment = fitnessEquipment;

FitnessEquipment.LapToggled += FitnessEquipment_LapToggled;
switch (fitnessEquipment.GeneralData.EquipmentType)
{
case Equipment.FitnessEquipmentType.Treadmill:
@@ -51,6 +54,11 @@ public FitnessEquipmentViewModel(Equipment fitnessEquipment)
}
}

private void FitnessEquipment_LapToggled(object sender, System.EventArgs e)
{
LapSplitTime = ((Equipment)sender).GeneralData.ElapsedTime;
}

[RelayCommand]
private void FECapabilitiesRequest() => FitnessEquipment.RequestFECapabilities();
[RelayCommand]
1 change: 1 addition & 0 deletions Examples/WpfUsbStickApp/Views/FitnessEquipmentWindow.xaml
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
<TextBlock Text="{Binding FitnessEquipment.GeneralData.DistanceTraveled, StringFormat='Distance Traveled: {0}'}" Visibility="{Binding FitnessEquipment.GeneralData.DistanceTraveledEnabled, Converter={StaticResource BoolToVisibility}}"/>
<TextBlock Text="{Binding FitnessEquipment.GeneralData.InstantaneousSpeed, StringFormat='Speed: {0}'}"/>
<TextBlock Text="{Binding FitnessEquipment.GeneralData.InstantaneousHeartRate, StringFormat='Heart Rate: {0}'}"/>
<TextBlock Text="{Binding LapSplitTime, StringFormat='Lap Split Time: {0:hh\\:mm\\:ss\\.ff}'}"/>
</StackPanel>
</GroupBox>
<GroupBox Header="General Settings" Grid.Column="1" Grid.Row="1">

0 comments on commit 3a4ebfd

Please sign in to comment.