Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

Commit fd9d6b8

Browse files
Updated to use latest Lumia SensorCore SDK 1.1 Preview
1 parent c817ea2 commit fd9d6b8

File tree

8 files changed

+110
-54
lines changed

8 files changed

+110
-54
lines changed

HelloSensorCore/App.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:local="using:HelloSensorCore">
6-
76
</Application>

HelloSensorCore/App.xaml.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/*
1+
/*
2+
The MIT License (MIT)
23
Copyright (c) 2015 Microsoft
34
45
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -35,7 +36,6 @@ namespace HelloSensorCore
3536
/// </summary>
3637
public sealed partial class App : Application
3738
{
38-
3939
private TransitionCollection transitions;
4040

4141
/// <summary>
@@ -46,7 +46,6 @@ public App()
4646
{
4747
this.InitializeComponent();
4848
this.Suspending += this.OnSuspending;
49-
5049
}
5150

5251
/// <summary>
@@ -63,28 +62,22 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
6362
this.DebugSettings.EnableFrameRateCounter = true;
6463
}
6564
#endif
66-
6765
Frame rootFrame = Window.Current.Content as Frame;
68-
6966
// Do not repeat app initialization when the Window already has content,
7067
// just ensure that the window is active
7168
if (rootFrame == null)
7269
{
7370
// Create a Frame to act as the navigation context and navigate to the first page
7471
rootFrame = new Frame();
75-
7672
// TODO: change this value to a cache size that is appropriate for your application
7773
rootFrame.CacheSize = 1;
78-
7974
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
8075
{
8176
// TODO: Load state from previously suspended application
8277
}
83-
8478
// Place the frame in the current Window
8579
Window.Current.Content = rootFrame;
8680
}
87-
8881
if (rootFrame.Content == null)
8982
{
9083
// Removes the turnstile navigation for startup.
@@ -96,10 +89,8 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
9689
this.transitions.Add(c);
9790
}
9891
}
99-
10092
rootFrame.ContentTransitions = null;
10193
rootFrame.Navigated += this.RootFrame_FirstNavigated;
102-
10394
// When the navigation stack isn't restored navigate to the first page,
10495
// configuring the new page by passing required information as a navigation
10596
// parameter
@@ -108,7 +99,6 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
10899
throw new Exception("Failed to create initial page");
109100
}
110101
}
111-
112102
// Ensure the current window is active
113103
Window.Current.Activate();
114104
}
@@ -135,7 +125,6 @@ private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
135125
private void OnSuspending(object sender, SuspendingEventArgs e)
136126
{
137127
var deferral = e.SuspendingOperation.GetDeferral();
138-
139128
// TODO: Save application state and stop any background activity
140129
deferral.Complete();
141130
}

HelloSensorCore/HelloSensorCore.csproj

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -114,41 +114,16 @@
114114
</Page>
115115
</ItemGroup>
116116
<ItemGroup>
117-
<None Include="Help\LumiaSensorCoreSDK.chm" />
118-
<None Include="packages.config" />
119-
</ItemGroup>
120-
<ItemGroup>
121-
<Reference Include="Lumia.Sense, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
122-
<SpecificVersion>False</SpecificVersion>
123-
<HintPath>..\packages\LumiaSensorCoreSDK.1.0.3.263\lib\portable-wpa81+wp81\x86\Lumia.Sense.winmd</HintPath>
124-
</Reference>
125-
<Reference Include="Lumia.Sense.Testing">
126-
<HintPath>..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\lib\portable-wpa81+wp81\x86\Lumia.Sense.Testing.winmd</HintPath>
127-
</Reference>
117+
<None Include="packages.config">
118+
<SubType>Designer</SubType>
119+
</None>
128120
</ItemGroup>
121+
<ItemGroup />
129122
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
130123
<VisualStudioVersion>12.0</VisualStudioVersion>
131124
</PropertyGroup>
132125
<PropertyGroup Condition=" '$(TargetPlatformIdentifier)' == '' ">
133126
<TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier>
134127
</PropertyGroup>
135128
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
136-
<Import Project="..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets" Condition="Exists('..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets')" />
137-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
138-
<PropertyGroup>
139-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
140-
</PropertyGroup>
141-
<Error Condition="!Exists('..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets'))" />
142-
<Error Condition="!Exists('..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets'))" />
143-
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
144-
</Target>
145-
<Import Project="..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets" Condition="Exists('..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets')" />
146-
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
147-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
148-
Other similar extension points exist, see Microsoft.Common.targets.
149-
<Target Name="BeforeBuild">
150-
</Target>
151-
<Target Name="AfterBuild">
152-
</Target>
153-
-->
154129
</Project>

HelloSensorCore/MainPage.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
1010

1111
<Grid>
12-
<ListBox x:Name="SensorcoreList"/>
12+
<StackPanel>
13+
<ListBox x:Name="SensorcoreList"/>
14+
<Button x:Name="LoadButton" Content="Play preinstalled recording" Click="LoadButton_Click"/>
15+
</StackPanel>
1316
</Grid>
1417
</Page>

HelloSensorCore/MainPage.xaml.cs

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
The MIT License (MIT)
23
Copyright (c) 2015 Microsoft
34
45
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -19,15 +20,19 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1920
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2021
THE SOFTWARE.
2122
*/
22-
2323
using System;
2424
using Windows.UI.Xaml;
2525
using Windows.UI.Xaml.Controls;
2626
using Windows.UI.Xaml.Navigation;
2727
using Windows.UI.Popups;
2828
using Lumia.Sense;
2929
using System.Threading.Tasks;
30+
using Windows.Web;
31+
using Lumia.Sense.Testing;
3032

33+
/// <summary>
34+
/// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
35+
/// </summar
3136
namespace HelloSensorCore
3237
{
3338
/// <summary>
@@ -39,7 +44,7 @@ public sealed partial class MainPage : Page
3944
/// <summary>
4045
/// Step counter instance
4146
/// </summary>
42-
private StepCounter _stepCounter;
47+
private IStepCounter _stepCounter;
4348
#endregion
4449

4550
public MainPage()
@@ -77,6 +82,52 @@ public MainPage()
7782
};
7883
}
7984

85+
/// <summary>
86+
/// Check motion data settings
87+
/// </summary>
88+
private async void CheckMotionDataSettings()
89+
{
90+
if (!(await StepCounter.IsSupportedAsync()))
91+
{
92+
MessageDialog dlg = new MessageDialog("Unfortunately this device does not support step counting");
93+
await dlg.ShowAsync();
94+
Application.Current.Exit();
95+
}
96+
else
97+
{
98+
// MotionDataSettings settings = await SenseHelper.GetSettingsAsync();
99+
// Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
100+
// location setting and Motion data had to be enabled.
101+
uint apiSet = await SenseHelper.GetSupportedApiSetAsync();
102+
MotionDataSettings settings = await SenseHelper.GetSettingsAsync();
103+
if (apiSet > 2)
104+
{
105+
if (!settings.LocationEnabled)
106+
{
107+
MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information");
108+
dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async (cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
109+
dlg.Commands.Add(new UICommand("No"));
110+
await dlg.ShowAsync();
111+
}
112+
if (!settings.PlacesVisited)
113+
{
114+
MessageDialog dlg = null;
115+
if (settings.Version < 2)
116+
{
117+
dlg = new MessageDialog("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information");
118+
}
119+
else
120+
{
121+
dlg = new MessageDialog("In order to collect and view visited places you need to enable Places visited in Motion data settings. Do you want to open settings now? if no, application will exit", "Information");
122+
}
123+
dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async (cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
124+
dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
125+
await dlg.ShowAsync();
126+
}
127+
}
128+
}
129+
}
130+
80131
/// <summary>
81132
/// Performs asynchronous SensorCore SDK operation and handles any exceptions
82133
/// </summary>
@@ -93,7 +144,6 @@ private async Task<bool> CallSensorcoreApiAsync( Func<Task> action )
93144
{
94145
failure = e;
95146
}
96-
97147
if( failure != null )
98148
{
99149
MessageDialog dialog;
@@ -106,21 +156,18 @@ private async Task<bool> CallSensorcoreApiAsync( Func<Task> action )
106156
await dialog.ShowAsync();
107157
new System.Threading.ManualResetEvent( false ).WaitOne( 500 );
108158
return false;
109-
110159
case SenseError.SenseDisabled:
111160
dialog = new MessageDialog( "Motion data has been disabled. Do you want to open Motion data settings now?", "Information" );
112161
dialog.Commands.Add( new UICommand( "Yes", async cmd => await SenseHelper.LaunchSenseSettingsAsync() ) );
113162
dialog.Commands.Add( new UICommand( "No" ) );
114163
await dialog.ShowAsync();
115164
new System.Threading.ManualResetEvent( false ).WaitOne( 500 );
116165
return false;
117-
118166
case SenseError.SensorNotAvailable:
119167
dialog = new MessageDialog( "The sensor is not supported on this device", "Information" );
120168
await dialog.ShowAsync();
121169
new System.Threading.ManualResetEvent( false ).WaitOne( 500 );
122170
return false;
123-
124171
default:
125172
dialog = new MessageDialog( "Failure: " + SenseHelper.GetSenseError( failure.HResult ), "" );
126173
await dialog.ShowAsync();
@@ -157,5 +204,47 @@ await CallSensorcoreApiAsync( async () =>
157204
}
158205
} );
159206
}
207+
208+
protected override void OnNavigatedTo(NavigationEventArgs e)
209+
{
210+
base.OnNavigatedTo(e);
211+
CheckMotionDataSettings();
212+
}
213+
214+
/// <summary>
215+
/// Play preinstalled recording button click handler
216+
/// </summary>
217+
/// <param name="sender">Sender object</param>
218+
/// <param name="args">Event arguments</param>
219+
private async void LoadButton_Click(object sender, RoutedEventArgs e)
220+
{
221+
SenseRecording recording = null;
222+
WebErrorStatus exceptionDetail = new WebErrorStatus();
223+
try
224+
{
225+
recording = await SenseRecording.LoadFromUriAsync(new Uri("https://github.com/Microsoft/steps/raw/master/Steps/Simulations/short%20walk.txt"));
226+
}
227+
catch (Exception ex)
228+
{
229+
exceptionDetail = WebError.GetStatus(ex.GetBaseException().HResult);
230+
}
231+
if (exceptionDetail == WebErrorStatus.HostNameNotResolved)
232+
{
233+
MessageDialog dialog = new MessageDialog("Check your network connection. Host name could not be resolved.", "Information");
234+
await dialog.ShowAsync();
235+
}
236+
if (recording != null)
237+
{
238+
_stepCounter = await StepCounterSimulator.GetDefaultAsync(recording);
239+
MessageDialog dialog = new MessageDialog(
240+
"Recorded sensor type: " + recording.Type.ToString() +
241+
"\r\nDescription: " + recording.Description +
242+
"\r\nRecording date: " + recording.StartTime.ToString() +
243+
"\r\nDuration: " + recording.Duration.ToString(),
244+
"Recording info"
245+
);
246+
await dialog.ShowAsync();
247+
}
248+
}
160249
}
161250
}

HelloSensorCore/Package.appxmanifest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
3-
<Identity Name="340d9f12-2e04-440f-8b42-9a426c037d17" Publisher="CN=janineva" Version="1.0.0.1" />
3+
<Identity Name="340d9f12-2e04-440f-8b42-9a426c037d17" Publisher="CN=janineva" Version="1.1.0.3" />
44
<mp:PhoneIdentity PhoneProductId="340d9f12-2e04-440f-8b42-9a426c037d17" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
55
<Properties>
66
<DisplayName>HelloSensorCore</DisplayName>
@@ -24,6 +24,7 @@
2424
</Application>
2525
</Applications>
2626
<Capabilities>
27+
<Capability Name="internetClientServer" />
2728
<DeviceCapability Name="location" />
2829
<m2:DeviceCapability Name="humaninterfacedevice">
2930
<m2:Device Id="vidpid:0421 0716">

HelloSensorCore/packages.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="LumiaSensorCoreSDK" version="1.0.3.263" targetFramework="wpa81" />
4-
<package id="LumiaSensorCoreSDKTesting" version="1.0.3.263" targetFramework="wpa81" />
53
</packages>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ http://msdn.microsoft.com/en-us/library/gg588378%28v=vs.92%29.aspx
3131

3232
2. Version history
3333
--------------------------------------------------------------------------------
34-
34+
* Version 1.1.0.3:
35+
* Updated to use latest Lumia SensorCore SDK 1.1 Preview
3536
* Version 1.0.0.1:
3637
* Some bug fixes made in this release.
3738
* Version 1.0: The first release.
@@ -41,6 +42,7 @@ http://msdn.microsoft.com/en-us/library/gg588378%28v=vs.92%29.aspx
4142

4243
| Project | Release | Download |
4344
| ------- | --------| -------- |
45+
| Steps | v1.1.0.3 | [hello-sensorcore-1.1.0.3.zip](https://github.com/Microsoft/hello-sensorcore/archive/v1.1.0.3.zip) |
4446
| Steps | v1.0.0.1 | [hello-sensorcore-1.0.0.1.zip](https://github.com/Microsoft/hello-sensorcore/archive/v1.0.0.1.zip) |
4547
| Steps | v1.0 | [hello-sensorcore-1.0.zip](https://github.com/Microsoft/hello-sensorcore/archive/v1.0.zip) |
4648

0 commit comments

Comments
 (0)