Skip to content

Commit

Permalink
Added binding to Band distance sensor.
Browse files Browse the repository at this point in the history
  • Loading branch information
philliphoff committed Jan 7, 2016
1 parent a7198c4 commit 5c2ba8a
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Microsoft.Band.WindowsRuntime/BandClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public BandClient(Band.IBandClient bandClient)
this.barometer = new Lazy<BandBarometerSensor>(() => new BandBarometerSensor(this.bandClient.SensorManager.Barometer));
this.calories = new Lazy<BandCaloriesSensor>(() => new BandCaloriesSensor(this.bandClient.SensorManager.Calories));
this.contact = new Lazy<BandContactSensor>(() => new BandContactSensor(this.bandClient.SensorManager.Contact));
this.distance = new Lazy<BandDistanceSensor>(() => new BandDistanceSensor(this.bandClient.SensorManager.Distance));
}

#region IBandClient Members
Expand Down Expand Up @@ -201,6 +202,7 @@ IAsyncAction IBandPersonalizationManager.SetThemeAsync(BandTheme theme)
private readonly Lazy<BandBarometerSensor> barometer;
private readonly Lazy<BandCaloriesSensor> calories;
private readonly Lazy<BandContactSensor> contact;
private readonly Lazy<BandDistanceSensor> distance;

IBandAccelerometerSensor IBandSensorManager.Accelerometer
{
Expand Down Expand Up @@ -250,6 +252,14 @@ IBandContactSensor IBandSensorManager.Contact
}
}

IBandDistanceSensor IBandSensorManager.Distance
{
get
{
return this.distance.Value;
}
}

#endregion

#region IBandTileManager Members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<Compile Include="Sensors\BandContactSensor.cs" />
<Compile Include="Sensors\BandContactSensorReadingChangedEventArgs.cs" />
<Compile Include="Sensors\BandContactState.cs" />
<Compile Include="Sensors\BandDistanceReading.cs" />
<Compile Include="Sensors\BandDistanceSensor.cs" />
<Compile Include="Sensors\BandDistanceSensorReadingEventArgs.cs" />
<Compile Include="Sensors\BandSensorReadingBase.cs" />
<Compile Include="Sensors\IBandAccelerometerReading.cs" />
<Compile Include="Sensors\IBandAccelerometerSensor.cs" />
Expand All @@ -152,11 +155,14 @@
<Compile Include="Sensors\IBandCaloriesSensor.cs" />
<Compile Include="Sensors\IBandContactReading.cs" />
<Compile Include="Sensors\IBandContactSensor.cs" />
<Compile Include="Sensors\IBandDistanceReading.cs" />
<Compile Include="Sensors\IBandDistanceSensor.cs" />
<Compile Include="Sensors\IBandSensor.cs" />
<Compile Include="Sensors\IBandSensorManager.cs" />
<Compile Include="Sensors\IBandSensorReading.cs" />
<Compile Include="Sensors\BandAccelerometerSensorReadingEventArgs.cs" />
<Compile Include="Sensors\BandSensorBase.cs" />
<Compile Include="Sensors\MotionType.cs" />
<Compile Include="Tiles\BandTile.cs" />
<Compile Include="Tiles\IBandTileManager.cs" />
<Compile Include="UserConsent.cs" />
Expand Down
77 changes: 77 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/BandDistanceReading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Band.Sensors;

namespace Microsoft.Band.WindowsRuntime.Sensors
{
internal sealed class BandDistanceReading : BandSensorReadingBase, IBandDistanceReading
{
private readonly Band.Sensors.IBandDistanceReading reading;

public BandDistanceReading(Band.Sensors.IBandDistanceReading reading)
: base(reading)
{
if (reading == null)
{
throw new ArgumentNullException("reading");
}

this.reading = reading;
}

#region IBandDistanceReading Members

public MotionType CurrentMotion
{
get
{
return FromMotionType(this.reading.CurrentMotion);
}
}

public double Pace
{
get
{
return this.reading.Pace;
}
}

public double Speed
{
get
{
return this.reading.Speed;
}
}

public long TotalDistance
{
get
{
return this.reading.TotalDistance;
}
}

#endregion

private static MotionType FromMotionType(Band.Sensors.MotionType currentMotion)
{
switch (currentMotion)
{
case Band.Sensors.MotionType.Idle: return MotionType.Idle;
case Band.Sensors.MotionType.Jogging: return MotionType.Jogging;
case Band.Sensors.MotionType.Running: return MotionType.Running;
case Band.Sensors.MotionType.Unknown: return MotionType.Unknown;
case Band.Sensors.MotionType.Walking: return MotionType.Walking;

default:

throw new ArgumentOutOfRangeException("currentMotion");
}
}
}
}
22 changes: 22 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/BandDistanceSensor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Band.Sensors;

namespace Microsoft.Band.WindowsRuntime.Sensors
{
internal sealed class BandDistanceSensor : BandSensorBase<Band.Sensors.IBandDistanceReading, BandDistanceSensorReadingEventArgs>, IBandDistanceSensor
{
public BandDistanceSensor(Band.Sensors.IBandSensor<Band.Sensors.IBandDistanceReading> sensor)
: base(sensor)
{
}

protected override BandDistanceSensorReadingEventArgs CreateEventArgs(Band.Sensors.IBandDistanceReading reading)
{
return new BandDistanceSensorReadingEventArgs(new BandDistanceReading(reading));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Microsoft.Band.WindowsRuntime.Sensors
{
public sealed class BandDistanceSensorReadingEventArgs
{
public BandDistanceSensorReadingEventArgs(IBandDistanceReading sensorReading)
{
if (sensorReading == null)
{
throw new ArgumentNullException("sensorReading");
}

this.SensorReading = sensorReading;
}

public IBandDistanceReading SensorReading { get; }
}
}
19 changes: 19 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/IBandDistanceReading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Band.WindowsRuntime.Sensors
{
public interface IBandDistanceReading : IBandSensorReading
{
MotionType CurrentMotion { get; }

double Pace { get; }

double Speed { get; }

long TotalDistance { get; }
}
}
13 changes: 13 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/IBandDistanceSensor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Band.WindowsRuntime.Sensors
{
public interface IBandDistanceSensor : IBandSensor
{
event EventHandler<BandDistanceSensorReadingEventArgs> ReadingChanged;
}
}
2 changes: 2 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/IBandSensorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public interface IBandSensorManager
IBandCaloriesSensor Calories { get; }

IBandContactSensor Contact { get; }

IBandDistanceSensor Distance { get; }
}
}
12 changes: 12 additions & 0 deletions Microsoft.Band.WindowsRuntime/Sensors/MotionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Microsoft.Band.WindowsRuntime.Sensors
{
public enum MotionType
{
Unknown = 0,

Idle,
Jogging,
Running,
Walking
}
}

0 comments on commit 5c2ba8a

Please sign in to comment.