Windows 10 RTM Release - April 2016 Update

This commit is contained in:
Raymond Chen 2016-04-20 14:12:24 -07:00
Родитель a31928c0fb
Коммит 2d839d3090
88 изменённых файлов: 1075 добавлений и 2522 удалений

Просмотреть файл

@ -23,3 +23,10 @@ Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Sc
{ "OrientationChanged", "SDKTemplate.Scenario4_OrientationChanged" },
{ "Data Events Batching", "SDKTemplate.Scenario5_DataEventsBatching" }
};
void MainPage::SetReadingText(Windows::UI::Xaml::Controls::TextBlock^ textBlock, Windows::Devices::Sensors::AccelerometerReading^ reading)
{
textBlock->Text = "X: " + reading->AccelerationX.ToString() +
", Y: " + reading->AccelerationY.ToString() +
", Z: " + reading->AccelerationZ.ToString();
}

Просмотреть файл

@ -35,6 +35,8 @@ namespace SDKTemplate
}
}
static void SetReadingText(Windows::UI::Xaml::Controls::TextBlock^ textBlock, Windows::Devices::Sensors::AccelerometerReading^ reading);
private:
static Platform::Array<Scenario>^ scenariosInner;
};

Просмотреть файл

@ -19,63 +19,37 @@
using namespace SDKTemplate;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Platform;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
Scenario1_DataEvents::Scenario1_DataEvents() : rootPage(MainPage::Current), desiredReportInterval(0)
Scenario1_DataEvents::Scenario1_DataEvents()
{
InitializeComponent();
}
void Scenario1_DataEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
accelerometer = Accelerometer::GetDefault();
if (accelerometer != nullptr)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint32 minReportInterval = accelerometer->MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
ScenarioEnableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
rootPage->NotifyUser("No accelerometer not found", NotifyType::ErrorMessage);
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario1_DataEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario1_DataEvents::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->ReadingChanged::remove(readingToken);
// Restore the default report interval to release resources while the sensor is not in use
accelerometer->ReportInterval = 0;
ScenarioDisable();
}
}
@ -95,12 +69,12 @@ void Scenario1_DataEvents::VisibilityChanged(Object^ sender, VisibilityChangedEv
if (e->Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
readingToken = accelerometer->ReadingChanged::add(ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged));
readingToken = accelerometer->ReadingChanged += ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged);
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
accelerometer->ReadingChanged::remove(readingToken);
accelerometer->ReadingChanged -= readingToken;
}
}
}
@ -113,40 +87,29 @@ void Scenario1_DataEvents::ReadingChanged(Accelerometer^ sender, AccelerometerRe
ref new DispatchedHandler(
[this, e]()
{
AccelerometerReading^ reading = e->Reading;
ScenarioOutput_X->Text = reading->AccelerationX.ToString();
ScenarioOutput_Y->Text = reading->AccelerationY.ToString();
ScenarioOutput_Z->Text = reading->AccelerationZ.ToString();
MainPage::SetReadingText(ScenarioOutput, e->Reading);
},
CallbackContext::Any
)
);
}
void Scenario1_DataEvents::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario1_DataEvents::ScenarioEnable()
{
if (accelerometer != nullptr)
{
// Establish the report interval
accelerometer->ReportInterval = desiredReportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
accelerometer->ReportInterval = (std::max)(accelerometer->MinimumReportInterval, 16U);
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged));
readingToken = accelerometer->ReadingChanged::add(ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged);
readingToken = accelerometer->ReadingChanged += ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged);
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario1_DataEvents::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario1_DataEvents::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->ReadingChanged::remove(readingToken);
Window::Current->VisibilityChanged -= visibilityToken;
accelerometer->ReadingChanged -= readingToken;
// Restore the default report interval to release resources while the sensor is not in use
accelerometer->ReportInterval = 0;

Просмотреть файл

@ -35,16 +35,16 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::Devices::Sensors::Accelerometer^ accelerometer;
Windows::Foundation::EventRegistrationToken visibilityToken;
Windows::Foundation::EventRegistrationToken readingToken;
uint32 desiredReportInterval;
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void ReadingChanged(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -19,53 +19,37 @@
using namespace SDKTemplate;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Platform;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
Scenario2_ShakeEvents::Scenario2_ShakeEvents() : rootPage(MainPage::Current), shakeCounter(0)
Scenario2_ShakeEvents::Scenario2_ShakeEvents()
{
InitializeComponent();
}
void Scenario2_ShakeEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
accelerometer = Accelerometer::GetDefault();
if (accelerometer == nullptr)
if (accelerometer != nullptr)
{
ScenarioEnableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario2_ShakeEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario2_ShakeEvents::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->Shaken::remove(shakenToken);
ScenarioDisable();
}
}
@ -85,12 +69,12 @@ void Scenario2_ShakeEvents::VisibilityChanged(Object^ sender, VisibilityChangedE
if (e->Visible)
{
// Re-enable sensor input
shakenToken = accelerometer->Shaken::add(ref new TypedEventHandler<Accelerometer^, AccelerometerShakenEventArgs^>(this, &Scenario2_ShakeEvents::Shaken));
shakenToken = accelerometer->Shaken += ref new TypedEventHandler<Accelerometer^, AccelerometerShakenEventArgs^>(this, &Scenario2_ShakeEvents::Shaken);
}
else
{
// Disable sensor input
accelerometer->Shaken::remove(shakenToken);
accelerometer->Shaken -= shakenToken;
}
}
}
@ -112,26 +96,19 @@ void Scenario2_ShakeEvents::Shaken(Accelerometer^ sender, AccelerometerShakenEve
);
}
void Scenario2_ShakeEvents::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario2_ShakeEvents::ScenarioEnable()
{
if (accelerometer != nullptr)
{
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario2_ShakeEvents::VisibilityChanged));
shakenToken = accelerometer->Shaken::add(ref new TypedEventHandler<Accelerometer^, AccelerometerShakenEventArgs^>(this, &Scenario2_ShakeEvents::Shaken));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario2_ShakeEvents::VisibilityChanged);
shakenToken = accelerometer->Shaken += ref new TypedEventHandler<Accelerometer^, AccelerometerShakenEventArgs^>(this, &Scenario2_ShakeEvents::Shaken);
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario2_ShakeEvents::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario2_ShakeEvents::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->Shaken::remove(shakenToken);
Window::Current->VisibilityChanged -= visibilityToken;
accelerometer->Shaken -= shakenToken;
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;

Просмотреть файл

@ -35,17 +35,18 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::UI::Core::CoreDispatcher^ dispatcher;
Windows::Devices::Sensors::Accelerometer^ accelerometer;
Windows::Foundation::EventRegistrationToken visibilityToken;
Windows::Foundation::EventRegistrationToken shakenToken;
uint16 shakeCounter;
uint16 shakeCounter = 0;
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void Shaken(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerShakenEventArgs^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -19,25 +19,26 @@
using namespace SDKTemplate;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Platform;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
Scenario3_Polling::Scenario3_Polling() : rootPage(MainPage::Current), desiredReportInterval(0)
Scenario3_Polling::Scenario3_Polling()
{
InitializeComponent();
}
void Scenario3_Polling::OnNavigatedTo(NavigationEventArgs^ e)
{
accelerometer = Accelerometer::GetDefault();
if (accelerometer != nullptr)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint32 minReportInterval = accelerometer->MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
desiredReportInterval = (std::max)(accelerometer->MinimumReportInterval, 16U);
// Set up a DispatchTimer
TimeSpan span;
@ -45,6 +46,8 @@ Scenario3_Polling::Scenario3_Polling() : rootPage(MainPage::Current), desiredRep
dispatcherTimer = ref new DispatcherTimer();
dispatcherTimer->Interval = span;
dispatcherTimer->Tick += ref new Windows::Foundation::EventHandler<Object^>(this, &Scenario3_Polling::DisplayCurrentReading);
ScenarioEnableButton->IsEnabled = true;
}
else
{
@ -52,37 +55,11 @@ Scenario3_Polling::Scenario3_Polling() : rootPage(MainPage::Current), desiredRep
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario3_Polling::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario3_Polling::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
dispatcherTimer->Stop();
// Restore the default report interval to release resources while the sensor is not in use
accelerometer->ReportInterval = 0;
ScenarioDisable();
}
}
@ -117,35 +94,26 @@ void Scenario3_Polling::DisplayCurrentReading(Object^ sender, Object^ e)
AccelerometerReading^ reading = accelerometer->GetCurrentReading();
if (reading != nullptr)
{
ScenarioOutput_X->Text = reading->AccelerationX.ToString();
ScenarioOutput_Y->Text = reading->AccelerationY.ToString();
ScenarioOutput_Z->Text = reading->AccelerationZ.ToString();
MainPage::SetReadingText(ScenarioOutput, reading);
}
}
void Scenario3_Polling::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario3_Polling::ScenarioEnable()
{
if (accelerometer != nullptr)
{
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario3_Polling::VisibilityChanged));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario3_Polling::VisibilityChanged);
// Set the report interval to enable the sensor for polling
accelerometer->ReportInterval = desiredReportInterval;
// Set the report interval to enable the sensor for polling
accelerometer->ReportInterval = desiredReportInterval;
dispatcherTimer->Start();
dispatcherTimer->Start();
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario3_Polling::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario3_Polling::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
Window::Current->VisibilityChanged -= visibilityToken;
dispatcherTimer->Stop();

Просмотреть файл

@ -34,17 +34,18 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::UI::Core::CoreDispatcher^ dispatcher;
Windows::Devices::Sensors::Accelerometer^ accelerometer;
Windows::Foundation::EventRegistrationToken visibilityToken;
uint32 desiredReportInterval;
uint32 desiredReportInterval = 0;
Windows::UI::Xaml::DispatcherTimer^ dispatcherTimer;
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void DisplayCurrentReading(Platform::Object^ sender, Platform::Object^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -19,19 +19,22 @@
using namespace SDKTemplate;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
using namespace Windows::Graphics::Display;
Scenario4_OrientationChanged::Scenario4_OrientationChanged() : rootPage(MainPage::Current)
Scenario4_OrientationChanged::Scenario4_OrientationChanged()
{
InitializeComponent();
}
void Scenario4_OrientationChanged::OnNavigatedTo(NavigationEventArgs^ e)
{
// Get two instances of the accelerometer:
// One that returns the raw accelerometer data
accelerometerOriginal = Accelerometer::GetDefault();
@ -42,53 +45,21 @@ Scenario4_OrientationChanged::Scenario4_OrientationChanged() : rootPage(MainPage
{
rootPage->NotifyUser("No accelerometerReadingTransform found", NotifyType::ErrorMessage);
}
displayInformation = DisplayInformation::GetForCurrentView();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario4_OrientationChanged::OnNavigatedTo(NavigationEventArgs^ e)
{
if (nullptr == accelerometerOriginal || nullptr == accelerometerReadingTransform)
{
ScenarioEnableButton->IsEnabled = false;
}
else
{
ScenarioEnableButton->IsEnabled = true;
}
ScenarioDisableButton->IsEnabled = false;
// Register for orientation change
displayInformation = DisplayInformation::GetForCurrentView();
orientationChangedToken = displayInformation->OrientationChanged += ref new Windows::Foundation::TypedEventHandler<Windows::Graphics::Display::DisplayInformation ^, Platform::Object ^>(this, &Scenario4_OrientationChanged::OnOrientationChanged);
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario4_OrientationChanged::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (NavigationMode::Forward == e->NavigationMode && nullptr == e->Uri)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged -= visibilityToken;
accelerometerOriginal->ReadingChanged -= readingTokenOriginal;
accelerometerReadingTransform->ReadingChanged -= readingTokenReadingTransform;
// Restore the default report interval to release resources while the sensor is not in use
accelerometerOriginal->ReportInterval = 0;
accelerometerReadingTransform->ReportInterval = 0;
ScenarioDisable();
}
displayInformation->OrientationChanged -= orientationChangedToken;
@ -98,9 +69,7 @@ void Scenario4_OrientationChanged::OnNavigatedFrom(NavigationEventArgs^ e)
/// <summary>
/// Invoked on pressing 'Enable' button'.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario4_OrientationChanged::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario4_OrientationChanged::ScenarioEnable()
{
// Establish the report interval
accelerometerOriginal->ReportInterval = accelerometerReadingTransform->MinimumReportInterval;
@ -121,18 +90,14 @@ void Scenario4_OrientationChanged::ScenarioEnable(Platform::Object^ sender, Wind
ScenarioDisableButton->IsEnabled = true;
}
/// <summary>
/// Invoked on pressing 'Disable' button'.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario4_OrientationChanged::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario4_OrientationChanged::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometerOriginal->ReadingChanged::remove(readingTokenOriginal);
accelerometerReadingTransform->ReadingChanged::remove(readingTokenReadingTransform);
Window::Current->VisibilityChanged -= visibilityToken;
accelerometerOriginal->ReadingChanged -= readingTokenOriginal;
accelerometerReadingTransform->ReadingChanged -= readingTokenReadingTransform;
// Restore the default report interval to release resources while the sensor is not in use
accelerometerOriginal->ReportInterval = 0;
@ -140,7 +105,6 @@ void Scenario4_OrientationChanged::ScenarioDisable(Platform::Object^ sender, Win
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
@ -165,8 +129,8 @@ void Scenario4_OrientationChanged::VisibilityChanged(Object^ sender, VisibilityC
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
accelerometerOriginal->ReadingChanged::remove(readingTokenOriginal);
accelerometerReadingTransform->ReadingChanged::remove(readingTokenReadingTransform);
accelerometerOriginal->ReadingChanged -= readingTokenOriginal;
accelerometerReadingTransform->ReadingChanged -= readingTokenReadingTransform;
}
}
}
@ -188,11 +152,7 @@ void Scenario4_OrientationChanged::ReadingChangedOriginal(Accelerometer^ sender,
ref new DispatchedHandler(
[this, e]()
{
AccelerometerReading^ reading = e->Reading;
ScenarioOutput_X_Original->Text = reading->AccelerationX.ToString();
ScenarioOutput_Y_Original->Text = reading->AccelerationY.ToString();
ScenarioOutput_Z_Original->Text = reading->AccelerationZ.ToString();
MainPage::SetReadingText(ScenarioOutputOriginal, e->Reading);
},
CallbackContext::Any
)
@ -217,11 +177,7 @@ void Scenario4_OrientationChanged::ReadingChangedReadingTransform(Accelerometer^
ref new DispatchedHandler(
[this, e]()
{
AccelerometerReading^ reading = e->Reading;
ScenarioOutput_X_ReadingTransform->Text = reading->AccelerationX.ToString();
ScenarioOutput_Y_ReadingTransform->Text = reading->AccelerationY.ToString();
ScenarioOutput_Z_ReadingTransform->Text = reading->AccelerationZ.ToString();
MainPage::SetReadingText(ScenarioOutputReadingTransform, e->Reading);
},
CallbackContext::Any
)

Просмотреть файл

@ -30,8 +30,11 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::Devices::Sensors::Accelerometer^ accelerometerOriginal;
Windows::Devices::Sensors::Accelerometer^ accelerometerReadingTransform;
Windows::Foundation::EventRegistrationToken visibilityToken;
@ -40,9 +43,6 @@ namespace SDKTemplate
Windows::Foundation::EventRegistrationToken orientationChangedToken;
Windows::Graphics::Display::DisplayInformation^ displayInformation;
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void ReadingChangedOriginal(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ e);
void ReadingChangedReadingTransform(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ e);

Просмотреть файл

@ -19,29 +19,32 @@
using namespace SDKTemplate;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
using namespace Platform;
using namespace Windows::Devices::Sensors;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;
Scenario5_DataEventsBatching::Scenario5_DataEventsBatching() : rootPage(MainPage::Current), desiredReportInterval(0), desiredReportLatency(0)
Scenario5_DataEventsBatching::Scenario5_DataEventsBatching()
{
InitializeComponent();
}
void Scenario5_DataEventsBatching::OnNavigatedTo(NavigationEventArgs^ e)
{
accelerometer = Accelerometer::GetDefault();
if (accelerometer != nullptr)
{
// Select a report interval and report latency that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint32 minReportInterval = accelerometer->MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
desiredReportInterval = (std::max)(accelerometer->MinimumReportInterval, 16U);
// MaxBatchSize will be 0 if the accelerometer does not support batching.
uint32 maxSupportedLatency = desiredReportInterval * accelerometer->MaxBatchSize;
desiredReportLatency = maxSupportedLatency < 10000 ? maxSupportedLatency : 10000;
desiredReportLatency = (std::min)(desiredReportInterval * accelerometer->MaxBatchSize, 10000U);
ScenarioEnableButton->IsEnabled = true;
}
else
{
@ -49,37 +52,11 @@ Scenario5_DataEventsBatching::Scenario5_DataEventsBatching() : rootPage(MainPage
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario5_DataEventsBatching::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario5_DataEventsBatching::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->ReadingChanged::remove(readingToken);
// Restore the default report interval to release resources while the sensor is not in use
accelerometer->ReportInterval = 0;
ScenarioDisable();
}
}
@ -99,12 +76,12 @@ void Scenario5_DataEventsBatching::VisibilityChanged(Object^ sender, VisibilityC
if (e->Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
readingToken = accelerometer->ReadingChanged::add(ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario5_DataEventsBatching::ReadingChanged));
readingToken = accelerometer->ReadingChanged += ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario5_DataEventsBatching::ReadingChanged);
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
accelerometer->ReadingChanged::remove(readingToken);
accelerometer->ReadingChanged -= readingToken;
}
}
}
@ -117,43 +94,32 @@ void Scenario5_DataEventsBatching::ReadingChanged(Accelerometer^ sender, Acceler
ref new DispatchedHandler(
[this, e]()
{
AccelerometerReading^ reading = e->Reading;
ScenarioOutput_X->Text = reading->AccelerationX.ToString();
ScenarioOutput_Y->Text = reading->AccelerationY.ToString();
ScenarioOutput_Z->Text = reading->AccelerationZ.ToString();
MainPage::SetReadingText(ScenarioOutput, e->Reading);
},
CallbackContext::Any
)
);
}
void Scenario5_DataEventsBatching::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario5_DataEventsBatching::ScenarioEnable()
{
if (accelerometer != nullptr)
{
// Establish the report interval
accelerometer->ReportInterval = desiredReportInterval;
// Establish the report interval
accelerometer->ReportInterval = desiredReportInterval;
// Establish the report latency. This is a no-op if the accelerometer does not support batching
accelerometer->ReportLatency = desiredReportLatency;
// Establish the report latency. This is a no-op if the accelerometer does not support batching
accelerometer->ReportLatency = desiredReportLatency;
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario5_DataEventsBatching::VisibilityChanged));
readingToken = accelerometer->ReadingChanged::add(ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario5_DataEventsBatching::ReadingChanged));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario5_DataEventsBatching::VisibilityChanged);
readingToken = accelerometer->ReadingChanged += ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &Scenario5_DataEventsBatching::ReadingChanged);
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No accelerometer found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario5_DataEventsBatching::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario5_DataEventsBatching::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
accelerometer->ReadingChanged::remove(readingToken);
Window::Current->VisibilityChanged -= visibilityToken;
accelerometer->ReadingChanged -= readingToken;
// Restore the default report interval to release resources while the sensor is not in use
accelerometer->ReportInterval = 0;

Просмотреть файл

@ -35,17 +35,18 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::Devices::Sensors::Accelerometer^ accelerometer;
Windows::Foundation::EventRegistrationToken visibilityToken;
Windows::Foundation::EventRegistrationToken readingToken;
uint32 desiredReportInterval;
uint32 desiredReportLatency;
uint32 desiredReportInterval = 0;
uint32 desiredReportLatency = 0;
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void ReadingChanged(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using Windows.Devices.Sensors;
using Windows.UI.Xaml.Controls;
namespace SDKTemplate
@ -24,9 +25,15 @@ namespace SDKTemplate
new Scenario() { Title = "Data events", ClassType = typeof(Scenario1_DataEvents) },
new Scenario() { Title = "Shake events", ClassType = typeof(Scenario2_ShakeEvents) },
new Scenario() { Title = "Polling", ClassType = typeof(Scenario3_Polling) },
new Scenario() { Title = "OrientationChange", ClassType = typeof(Scenario4_OrientationChanged) },
new Scenario() { Title = "Orientation change", ClassType = typeof(Scenario4_OrientationChanged) },
new Scenario() { Title = "Data events batching", ClassType = typeof(Scenario5_DataEventsBatching)}
};
public static void SetReadingText(TextBlock textBlock, AccelerometerReading reading)
{
textBlock.Text = string.Format("X: {0,5:0.00}, Y: {1,5:0.00}, Z: {2,5:0.00}",
reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);
}
}
public class Scenario

Просмотреть файл

@ -9,14 +9,12 @@
//
//*********************************************************
using System;
using Windows.Devices.Sensors;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
namespace SDKTemplate
{
@ -27,19 +25,18 @@ namespace SDKTemplate
MainPage rootPage = MainPage.Current;
private Accelerometer _accelerometer;
private uint _desiredReportInterval;
public Scenario1_DataEvents()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint minReportInterval = _accelerometer.MinimumReportInterval;
_desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
ScenarioEnableButton.IsEnabled = true;
}
else
{
@ -47,37 +44,12 @@ namespace SDKTemplate
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
// Restore the default report interval to release resources while the sensor is not in use
_accelerometer.ReportInterval = 0;
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -95,12 +67,12 @@ namespace SDKTemplate
if (e.Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
_accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
_accelerometer.ReadingChanged += ReadingChanged;
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
_accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
_accelerometer.ReadingChanged -= ReadingChanged;
}
}
}
@ -114,46 +86,32 @@ namespace SDKTemplate
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccelerometerReading reading = e.Reading;
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
MainPage.SetReadingText(ScenarioOutput, e.Reading);
});
}
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (_accelerometer != null)
{
// Establish the report interval
_accelerometer.ReportInterval = _desiredReportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
_accelerometer.ReportInterval = Math.Max(_accelerometer.MinimumReportInterval, 16);
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
Window.Current.VisibilityChanged += VisibilityChanged;
_accelerometer.ReadingChanged += ReadingChanged;
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
Window.Current.VisibilityChanged -= VisibilityChanged;
_accelerometer.ReadingChanged -= ReadingChanged;
// Restore the default report interval to release resources while the sensor is not in use
_accelerometer.ReportInterval = 0;

Просмотреть файл

@ -11,20 +11,19 @@
// Windows Store code
using System;
using Windows.Devices.Sensors;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using Windows.UI.Core;
namespace SDKTemplate
{
public sealed partial class Scenario2_ShakeEvents : Page
{
private Accelerometer _accelerometer;
private ushort _shakeCount;
private ushort _shakeCount = 0;
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
// as NotifyUser()
@ -33,43 +32,27 @@ namespace SDKTemplate
public Scenario2_ShakeEvents()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer == null)
if (_accelerometer != null)
{
ScenarioEnableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
_shakeCount = 0;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.Shaken -= new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -87,12 +70,12 @@ namespace SDKTemplate
if (e.Visible)
{
// Re-enable sensor input
_accelerometer.Shaken += new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
_accelerometer.Shaken += Shaken;
}
else
{
// Disable sensor input
_accelerometer.Shaken -= new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
_accelerometer.Shaken -= Shaken;
}
}
}
@ -114,32 +97,21 @@ namespace SDKTemplate
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (_accelerometer != null)
{
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.Shaken += new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
Window.Current.VisibilityChanged += VisibilityChanged;
_accelerometer.Shaken += Shaken;
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_accelerometer.Shaken -= new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
Window.Current.VisibilityChanged -= VisibilityChanged;
_accelerometer.Shaken -= Shaken;
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}

Просмотреть файл

@ -9,15 +9,12 @@
//
//*********************************************************
using System;
using Windows.Devices.Sensors;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
namespace SDKTemplate
{
@ -34,19 +31,23 @@ namespace SDKTemplate
public Scenario3_Polling()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint minReportInterval = _accelerometer.MinimumReportInterval;
_desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
_desiredReportInterval = Math.Max(_accelerometer.MinimumReportInterval, 16);
// Set up a DispatchTimer
_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Tick += DisplayCurrentReading;
_dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval);
_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(_desiredReportInterval);
ScenarioEnableButton.IsEnabled = true;
}
else
{
@ -54,39 +55,12 @@ namespace SDKTemplate
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
// Stop the dispatcher
_dispatcherTimer.Stop();
// Restore the default report interval to release resources while the sensor is not in use
_accelerometer.ReportInterval = 0;
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -124,44 +98,31 @@ namespace SDKTemplate
AccelerometerReading reading = _accelerometer.GetCurrentReading();
if (reading != null)
{
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
MainPage.SetReadingText(ScenarioOutput, reading);
}
}
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (_accelerometer != null)
{
// Set the report interval to enable the sensor for polling
_accelerometer.ReportInterval = _desiredReportInterval;
// Set the report interval to enable the sensor for polling
_accelerometer.ReportInterval = _desiredReportInterval;
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_dispatcherTimer.Start();
Window.Current.VisibilityChanged += VisibilityChanged;
_dispatcherTimer.Start();
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
Window.Current.VisibilityChanged -= VisibilityChanged;
// Stop the dispatcher
_dispatcherTimer.Stop();

Просмотреть файл

@ -9,15 +9,13 @@
//
//*********************************************************
using System;
using Windows.Devices.Sensors;
using Windows.Graphics.Display;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.Graphics.Display;
namespace SDKTemplate
{
@ -37,7 +35,10 @@ namespace SDKTemplate
public Scenario4_OrientationChanged()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Get two instances of the accelerometer:
// One that returns the raw accelerometer data
accelerometerOriginal = Accelerometer.GetDefault();
@ -48,54 +49,24 @@ namespace SDKTemplate
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
displayInformation = DisplayInformation.GetForCurrentView();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (accelerometerOriginal == null || accelerometerReadingTransform == null)
{
ScenarioEnableButton.IsEnabled = false;
}
else
{
ScenarioEnableButton.IsEnabled = true;
}
ScenarioDisableButton.IsEnabled = false;
// Register for orientation change
displayInformation = DisplayInformation.GetForCurrentView();
displayInformation.OrientationChanged += displayInformation_OrientationChanged;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
accelerometerOriginal.ReadingChanged -= _accelerometerOriginal_ReadingChanged;
accelerometerReadingTransform.ReadingChanged -= _accelerometerReadingTransform_ReadingChanged;
// Restore the default report interval to release resources while the sensor is not in use
accelerometerOriginal.ReportInterval = 0;
accelerometerReadingTransform.ReportInterval = 0;
ScenarioDisable();
}
displayInformation.OrientationChanged -= displayInformation_OrientationChanged;
base.OnNavigatingFrom(e);
}
@ -117,9 +88,7 @@ namespace SDKTemplate
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ScenarioEnable(object sender, RoutedEventArgs e)
void ScenarioEnable()
{
// Establish the report interval
accelerometerOriginal.ReportInterval = accelerometerOriginal.MinimumReportInterval;
@ -138,7 +107,6 @@ namespace SDKTemplate
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the event handler for ReadingChanged event of the 'accelerometerOriginal' and should
/// notify of the accelerometer reading changes.
@ -151,10 +119,7 @@ namespace SDKTemplate
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccelerometerReading reading = args.Reading;
ScenarioOutput_X_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
MainPage.SetReadingText(ScenarioOutputOriginal, args.Reading);
});
}
@ -171,10 +136,7 @@ namespace SDKTemplate
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccelerometerReading reading = args.Reading;
ScenarioOutput_X_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
MainPage.SetReadingText(ScenarioOutputReadingTransform, args.Reading);
});
}
@ -208,9 +170,7 @@ namespace SDKTemplate
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ScenarioDisable(object sender, RoutedEventArgs e)
void ScenarioDisable()
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
accelerometerOriginal.ReadingChanged -= _accelerometerOriginal_ReadingChanged;

Просмотреть файл

@ -9,14 +9,12 @@
//
//*********************************************************
using System;
using Windows.Devices.Sensors;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
namespace SDKTemplate
{
@ -34,18 +32,22 @@ namespace SDKTemplate
public Scenario5_DataEventsBatching()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
accelerometer = Accelerometer.GetDefault();
if (accelerometer != null)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint minReportInterval = accelerometer.MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
desiredReportInterval = Math.Max(accelerometer.MinimumReportInterval, 16);
// MaxBatchSize will be 0 if the accelerometer does not support batching.
uint maxLatency = accelerometer.MaxBatchSize * desiredReportInterval;
desiredReportLatency = maxLatency < 10000 ? maxLatency : 10000;
desiredReportLatency = Math.Min(maxLatency, 10000);
ScenarioEnableButton.IsEnabled = true;
}
else
{
@ -53,37 +55,12 @@ namespace SDKTemplate
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
// Restore the default report interval to release resources while the sensor is not in use
accelerometer.ReportInterval = 0;
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -101,12 +78,12 @@ namespace SDKTemplate
if (e.Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
accelerometer.ReadingChanged += ReadingChanged;
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
accelerometer.ReadingChanged -= ReadingChanged;
}
}
}
@ -120,48 +97,34 @@ namespace SDKTemplate
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
AccelerometerReading reading = e.Reading;
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);
MainPage.SetReadingText(ScenarioOutput, e.Reading);
});
}
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (accelerometer != null)
{
// Establish the report interval
accelerometer.ReportInterval = desiredReportInterval;
// Establish the report interval
accelerometer.ReportInterval = desiredReportInterval;
// Establish the report latency. This is a no-op if the accelerometer does not support batching
accelerometer.ReportLatency = desiredReportLatency;
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
// Establish the report latency. This is a no-op if the accelerometer does not support batching
accelerometer.ReportLatency = desiredReportLatency;
Window.Current.VisibilityChanged += VisibilityChanged;
accelerometer.ReadingChanged += ReadingChanged;
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage);
}
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
accelerometer.ReadingChanged -= new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
Window.Current.VisibilityChanged -= VisibilityChanged;
accelerometer.ReadingChanged -= ReadingChanged;
// Restore the default report interval to release resources while the sensor is not in use
accelerometer.ReportInterval = 0;

Просмотреть файл

@ -54,11 +54,6 @@
<AppxManifest Include="package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<Content Include="css\scenario1_DataEvents.css" />
<Content Include="css\scenario2_ShakeEvents.css" />
<Content Include="css\scenario3_Polling.css" />
<Content Include="css\scenario4_OrientationChanged.css" />
<Content Include="css\scenario5_DataEventsBatching.css" />
<Content Include="..\..\..\SharedContent\js\default.html">
<Link>default.html</Link>
</Content>

Просмотреть файл

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -6,24 +6,19 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario1_DataEvents.css">
<script src="/js/scenario1_DataEvents.js"></script>
</head>
<body class="win-type-body">
<div>
<p>Registers an event listener for accelerometer data and displays the X, Y and Z acceleration values as they are reported.</p>
<button class="action win-button" id="scenario1Open">Enable</button>
<button class="action secondary win-button" id="scenario1Revoke">Disable</button>
<br>
<br>
</div>
<div>
X: <a id="eventOutputX" class="win-link">no data</a>
<br> Y: <a id="eventOutputY" class="win-link">no data</a>
<br> Z: <a id="eventOutputZ" class="win-link">no data</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Data events</div>
<p>Registers an event listener for accelerometer data and displays the X, Y and Z acceleration values as they are reported.</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p id="eventOutput">no data</p>
</body>
</html>

Просмотреть файл

@ -6,22 +6,21 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario2_ShakeEvents.css">
<script src="/js/scenario2_ShakeEvents.js"></script>
</head>
<body class="win-type-body">
<div>
<p>
Registers an event listener for accelerometer shake events and displays the cumulative count of shake events.
</p>
<button class="action win-button" id="scenario2Open">Enable</button>
<button class="action secondary win-button" id="scenario2Revoke">Disable</button>
</div>
<div>
Shake count: <a id="shakeOutput" class="win-link">0</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Shake events</div>
<p>Registers an event listener for accelerometer shake events and displays the cumulative count of shake events.</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p>
Shake count: <span id="shakeOutput">0</span>
</p>
</body>
</html>

Просмотреть файл

@ -6,24 +6,19 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario3_Polling.css">
<script src="/js/scenario3_Polling.js"></script>
</head>
<body class="win-type-body">
<div>
<p>Polls for accelerometer data and displays the X, Y and Z acceleration values at a set interval.</p>
<button class="action win-button" id="scenario3Open">Enable</button>
<button class="action secondary win-button" id="scenario3Revoke">Disable</button>
<br>
<br>
</div>
<div>
X: <a id="readingOutputX" class="win-link">no data</a>
<br> Y: <a id="readingOutputY" class="win-link">no data</a>
<br> Z: <a id="readingOutputZ" class="win-link">no data</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Polling</div>
<p>Polls for accelerometer data and displays the X, Y and Z acceleration values at a set interval.</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p id="readingOutput">no data</p>
</body>
</html>

Просмотреть файл

@ -6,44 +6,24 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario4_OrientationChanged.css">
<script src="/js/scenario4_OrientationChanged.js"></script>
</head>
<body class="win-type-body">
<div>
<p>
Registers for OrientationChanged event of the DisplayInformation class to illustrate the usage of the &apos;ReadingTransform&apos; Property. Displays accelerometer readings with and without the transformation.
</p>
<button class="action win-button" id="scenario4Open">Enable</button>
<button class="action secondary win-button" id="scenario4Revoke">Disable</button>
<br>
<br>
</div>
<div>
<table style="width:100%;">
<tr>
<td>Transform:</td>
<td>None</td>
<td>DisplayOrientation</td>
</tr>
<tr>
<td>X:</td>
<td id="eventOutputXOriginal">no data</td>
<td id="eventOutputXDataTransform">no data</td>
</tr>
<tr>
<td>Y:</td>
<td id="eventOutputYOriginal">no data</td>
<td id="eventOutputYDataTransform">no data</td>
</tr>
<tr>
<td>Z:</td>
<td id="eventOutputZOriginal">no data</td>
<td id="eventOutputZDataTransform">no data</td>
</tr>
</table>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Orientation changed</div>
<p>
Registers for OrientationChanged event of the DisplayInformation class to illustrate the usage of the ReadingTransform pProperty. Displays accelerometer readings with and without the transformation.
</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p>Untransformed:</p>
<p id="eventOutputOriginal">no data</p>
<p>Transformed to DisplayOrientation:</p>
<p id="eventOutputDataTransform">no data</p>
</body>
</html>

Просмотреть файл

@ -6,26 +6,21 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario5_DataEventsBatching.css">
<script src="/js/scenario5_DataEventsBatching.js"></script>
</head>
<body class="win-type-body">
<div>
<p>
Registers an event listener for accelerometer data (with a report latency specified) and displays the X, Y and Z acceleration values as they are reported.
</p>
<button class="action win-button" id="scenario5Open">Enable</button>
<button class="action secondary win-button" id="scenario5Revoke">Disable</button>
<br>
<br>
</div>
<div>
X: <a id="eventOutputX" class="win-link">no data</a>
<br> Y: <a id="eventOutputY" class="win-link">no data</a>
<br> Z: <a id="eventOutputZ" class="win-link">no data</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Data events batching</div>
<p>
Registers an event listener for accelerometer data (with a report latency specified) and displays the X, Y and Z acceleration values as they are reported.
</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p id="eventOutput">no data</p>
</body>
</html>

Просмотреть файл

Просмотреть файл

@ -13,8 +13,15 @@
{ url: "/html/scenario5_DataEventsBatching.html", title: "Data Events Batching" }
];
function setReadingText(e, reading) {
e.innerText = "X: " + reading.accelerationX.toFixed(2) +
", Y: " + reading.accelerationY.toFixed(2) +
", Z: " + reading.accelerationZ.toFixed(2);
}
WinJS.Namespace.define("SdkSample", {
sampleTitle: sampleTitle,
scenarios: new WinJS.Binding.List(scenarios)
scenarios: new WinJS.Binding.List(scenarios),
setReadingText: setReadingText
});
})();

Просмотреть файл

@ -2,33 +2,32 @@
(function () {
"use strict";
var reportInterval = 0;
var accelerometer;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var eventOutput;
var page = WinJS.UI.Pages.define("/html/scenario1_DataEvents.html", {
ready: function (element, options) {
document.getElementById("scenario1Open").addEventListener("click", enableReadingChangedScenario, false);
document.getElementById("scenario1Revoke").addEventListener("click", disableReadingChangedScenario, false);
document.getElementById("scenario1Open").disabled = false;
document.getElementById("scenario1Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
eventOutput = document.getElementById("eventOutput");
scenarioEnable.addEventListener("click", enableReadingChangedScenario, false);
scenarioDisable.addEventListener("click", disableReadingChangedScenario, false);
accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
if (accelerometer) {
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
var minimumReportInterval = accelerometer.minimumReportInterval;
reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario1Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("readingchanged", onDataChanged);
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableReadingChangedScenario();
}
}
});
@ -36,7 +35,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario1Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
accelerometer.addEventListener("readingchanged", onDataChanged);
@ -48,43 +47,27 @@
}
function onDataChanged(e) {
var reading = e.reading;
// event can still be in queue after unload is called
// so check if elements are still loaded
if (document.getElementById("eventOutputX")) {
document.getElementById("eventOutputX").innerHTML = reading.accelerationX.toFixed(2);
}
if (document.getElementById("eventOutputY")) {
document.getElementById("eventOutputY").innerHTML = reading.accelerationY.toFixed(2);
}
if (document.getElementById("eventOutputZ")) {
document.getElementById("eventOutputZ").innerHTML = reading.accelerationZ.toFixed(2);
}
SdkSample.setReadingText(eventOutput, e.reading);
}
function enableReadingChangedScenario() {
if (accelerometer) {
// Set the reportInterval to enable the sensor events
accelerometer.reportInterval = reportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
accelerometer.reportInterval = Math.max(accelerometer.minimumReportInterval, 16);
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("readingchanged", onDataChanged);
document.getElementById("scenario1Open").disabled = true;
document.getElementById("scenario1Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("readingchanged", onDataChanged);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableReadingChangedScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("readingchanged", onDataChanged);
document.getElementById("scenario1Open").disabled = false;
document.getElementById("scenario1Revoke").disabled = true;
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -3,23 +3,32 @@
(function () {
"use strict";
var accelerometer;
var shakeCount = 0;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var shakeOutput;
var page = WinJS.UI.Pages.define("/html/scenario2_ShakeEvents.html", {
ready: function (element, options) {
document.getElementById("scenario2Open").addEventListener("click", enableShakenScenario, false);
document.getElementById("scenario2Revoke").addEventListener("click", disableShakenScenario, false);
document.getElementById("scenario2Open").disabled = false;
document.getElementById("scenario2Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
shakeOutput = document.getElementById("shakeOutput");
scenarioEnable.addEventListener("click", enableShakenScenario, false);
scenarioDisable.addEventListener("click", disableShakenScenario, false);
accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
if (accelerometer === null) {
if (accelerometer) {
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario2Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("shaken", onShaken);
if (!scenarioDisable.disabled) {
disableShakenScenario();
}
}
});
@ -27,7 +36,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario2Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input
accelerometer.addEventListener("shaken", onShaken);
@ -38,30 +47,22 @@
}
}
var onShaken = (function () {
var shakeCount = 0;
return function (e) {
shakeCount++;
document.getElementById("shakeOutput").innerHTML = shakeCount;
};
})();
function onShaken() {
shakeCount++;
shakeOutput.innerHTML = shakeCount;
}
function enableShakenScenario() {
if (accelerometer) {
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("shaken", onShaken);
document.getElementById("scenario2Open").disabled = true;
document.getElementById("scenario2Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("shaken", onShaken);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableShakenScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("shaken", onShaken);
document.getElementById("scenario2Open").disabled = false;
document.getElementById("scenario2Revoke").disabled = true;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -6,30 +6,30 @@
var intervalId = 0;
var accelerometer;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var readingOutput;
var page = WinJS.UI.Pages.define("/html/scenario3_Polling.html", {
ready: function (element, options) {
document.getElementById("scenario3Open").addEventListener("click", enableGetReadingScenario, false);
document.getElementById("scenario3Revoke").addEventListener("click", disableGetReadingScenario, false);
document.getElementById("scenario3Open").disabled = false;
document.getElementById("scenario3Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
readingOutput = document.getElementById("readingOutput");
scenarioEnable.addEventListener("click", enableGetReadingScenario, false);
scenarioDisable.addEventListener("click", disableGetReadingScenario, false);
accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
if (accelerometer) {
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
var minimumReportInterval = accelerometer.minimumReportInterval;
reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario3Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
clearInterval(intervalId);
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableGetReadingScenario();
}
}
});
@ -37,13 +37,14 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario3Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
// Resume polling. No need to restore the desired reportInterval (it is restored for us upon app resume)
intervalId = setInterval(getCurrentReading, reportInterval);
} else {
// Disable sensor input. No need to restore the default reportInterval (resources will be released upon app suspension)
clearInterval(intervalId);
intervalId = 0;
}
}
}
@ -51,33 +52,28 @@
function getCurrentReading() {
var reading = accelerometer.getCurrentReading();
if (reading) {
document.getElementById("readingOutputX").innerHTML = reading.accelerationX.toFixed(2);
document.getElementById("readingOutputY").innerHTML = reading.accelerationY.toFixed(2);
document.getElementById("readingOutputZ").innerHTML = reading.accelerationZ.toFixed(2);
SdkSample.setReadingText(readingOutput, reading);
}
}
function enableGetReadingScenario() {
if (accelerometer) {
// Set the report interval to enable the sensor for polling
accelerometer.reportInterval = reportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
accelerometer.reportInterval = Math.max(accelerometer.minimumReportInterval, 16);
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
intervalId = setInterval(getCurrentReading, reportInterval);
document.getElementById("scenario3Open").disabled = true;
document.getElementById("scenario3Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
intervalId = setInterval(getCurrentReading, reportInterval);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableGetReadingScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
clearInterval(intervalId);
document.getElementById("scenario3Open").disabled = false;
document.getElementById("scenario3Revoke").disabled = true;
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -6,14 +6,21 @@
var accelerometerReadingTransform;
var displayInformation;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var eventOutputOriginal;
var eventOutputDataTransform;
var page = WinJS.UI.Pages.define("/html/scenario4_OrientationChanged.html", {
ready: function (element, options) {
var disableOpen = true;
document.getElementById("scenario4Open").addEventListener("click", enableOrientationChangedScenario, false);
document.getElementById("scenario4Revoke").addEventListener("click", disableOrientationChangedScenario, false);
document.getElementById("scenario4Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
eventOutputOriginal = document.getElementById("eventOutputOriginal");
eventOutputDataTransform = document.getElementById("eventOutputDataTransform");
displayInformation = Windows.Graphics.Display.DisplayInformation.getForCurrentView();
scenarioEnable.addEventListener("click", enableOrientationChangedScenario, false);
scenarioDisable.addEventListener("click", disableOrientationChangedScenario, false);
// Get two instances of the accelerometer:
// One that returns the raw accelerometer data
@ -24,21 +31,15 @@
if (!accelerometerOriginal || !accelerometerReadingTransform) {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
} else {
disableOpen = false;
displayInformation.addEventListener("orientationchanged", onOrientationChanged);
scenarioEnable.disabled = false;
}
document.getElementById("scenario4Open").disabled = disableOpen;
displayInformation = Windows.Graphics.Display.DisplayInformation.getForCurrentView();
displayInformation.addEventListener("orientationchanged", onOrientationChanged);
},
unload: function () {
if (!document.getElementById("scenario4Revoke").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
displayInformation.removeEventListener("orientationchanged", onOrientationChanged);
accelerometerOriginal.removeEventListener("readingchanged", onDataChangedOriginal);
accelerometerReadingTransform.removeEventListener("readingchanged", onDataChangedReadingTransform);
// Return the report interval to its default to release resources while the sensor is not in use
accelerometerOriginal.reportInterval = 0;
accelerometerReadingTransform.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableOrientationChangedScenario();
}
}
});
@ -46,7 +47,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (!document.getElementById("scenario4Revoke").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
accelerometerOriginal.addEventListener("readingchanged", onDataChangedOriginal);
@ -60,43 +61,17 @@
}
function onDataChangedOriginal(e) {
var reading = e.reading;
// event can still be in queue after unload is called
// so check if elements are still loaded
if (document.getElementById("eventOutputXOriginal")) {
document.getElementById("eventOutputXOriginal").innerHTML = reading.accelerationX.toFixed(2);
}
if (document.getElementById("eventOutputYOriginal")) {
document.getElementById("eventOutputYOriginal").innerHTML = reading.accelerationY.toFixed(2);
}
if (document.getElementById("eventOutputZOriginal")) {
document.getElementById("eventOutputZOriginal").innerHTML = reading.accelerationZ.toFixed(2);
}
SdkSample.setReadingText(eventOutputOriginal, e.reading);
}
function onDataChangedReadingTransform(e) {
var reading = e.reading;
// event can still be in queue after unload is called
// so check if elements are still loaded
if (document.getElementById("eventOutputXDataTransform")) {
document.getElementById("eventOutputXDataTransform").innerHTML = reading.accelerationX.toFixed(2);
}
if (document.getElementById("eventOutputYDataTransform")) {
document.getElementById("eventOutputYDataTransform").innerHTML = reading.accelerationY.toFixed(2);
}
if (document.getElementById("eventOutputZDataTransform")) {
document.getElementById("eventOutputZDataTransform").innerHTML = reading.accelerationZ.toFixed(2);
}
SdkSample.setReadingText(eventOutputDataTransform, e.reading);
}
function enableOrientationChangedScenario() {
// Set the reportInterval to enable the sensor events
accelerometerOriginal.reportInterval = accelerometerOriginal.minimumReportInterval;
accelerometerReadingTransform.reportInterval = accelerometerReadingTransform.minimumReportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
accelerometerOriginal.reportInterval = Math.max(accelerometerOriginal.minimumReportInterval, 16);
accelerometerReadingTransform.reportInterval = Math.max(accelerometerReadingTransform.minimumReportInterval, 16);
// Set the readingTransform to align with the current display orientation
accelerometerReadingTransform.readingTransform = displayInformation.currentOrientation;
@ -106,8 +81,8 @@
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
document.getElementById("scenario4Open").disabled = true;
document.getElementById("scenario4Revoke").disabled = false;
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableOrientationChangedScenario() {
@ -119,8 +94,8 @@
accelerometerOriginal.reportInterval = 0;
accelerometerReadingTransform.reportInterval = 0;
document.getElementById("scenario4Open").disabled = false;
document.getElementById("scenario4Revoke").disabled = true;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
function onOrientationChanged(eventArgs) {

Просмотреть файл

@ -2,38 +2,32 @@
(function () {
"use strict";
var reportInterval = 0;
var reportLatency = 0;
var accelerometer;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var eventOutput;
var page = WinJS.UI.Pages.define("/html/scenario5_DataEventsBatching.html", {
ready: function (element, options) {
document.getElementById("scenario5Open").addEventListener("click", enableReadingChangedScenario, false);
document.getElementById("scenario5Revoke").addEventListener("click", disableReadingChangedScenario, false);
document.getElementById("scenario5Open").disabled = false;
document.getElementById("scenario5Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
eventOutput = document.getElementById("eventOutput");
scenarioEnable.addEventListener("click", enableReadingChangedScenario, false);
scenarioDisable.addEventListener("click", disableReadingChangedScenario, false);
accelerometer = Windows.Devices.Sensors.Accelerometer.getDefault();
if (accelerometer) {
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
var minimumReportInterval = accelerometer.minimumReportInterval;
reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
// MaxBatchSize will be 0 if the accelerometer does not support batching.
var maxLatency = accelerometer.MaxBatchSize * reportLatency;
reportLatency = maxLatency < 10 ? maxLatency : 10;
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario5Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("readingchanged", onDataChanged);
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableReadingChangedScenario();
}
}
});
@ -41,7 +35,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario5Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
accelerometer.addEventListener("readingchanged", onDataChanged);
@ -53,46 +47,34 @@
}
function onDataChanged(e) {
var reading = e.reading;
// event can still be in queue after unload is called
// so check if elements are still loaded
if (document.getElementById("eventOutputX")) {
document.getElementById("eventOutputX").innerHTML = reading.accelerationX.toFixed(2);
}
if (document.getElementById("eventOutputY")) {
document.getElementById("eventOutputY").innerHTML = reading.accelerationY.toFixed(2);
}
if (document.getElementById("eventOutputZ")) {
document.getElementById("eventOutputZ").innerHTML = reading.accelerationZ.toFixed(2);
}
SdkSample.setReadingText(eventOutput, e.reading);
}
function enableReadingChangedScenario() {
if (accelerometer) {
// Set the reportInterval to enable the sensor events
accelerometer.reportInterval = reportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
var reportInterval = Math.max(accelerometer.minimumReportInterval, 16);
accelerometer.reportInterval = reportInterval;
// Set the report latency. This is a no-op if the accelerometer does not support batching
accelerometer.reportLatency = reportLatency;
// MaxBatchSize will be 0 if the accelerometer does not support batching.
var reportLatency = Math.min(accelerometer.MaxBatchSize * reportInterval, 10000);
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("readingchanged", onDataChanged);
document.getElementById("scenario5Open").disabled = true;
document.getElementById("scenario5Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No accelerometer found", "sample", "error");
}
// Set the report latency. This is a no-op if the accelerometer does not support batching
accelerometer.reportLatency = reportLatency;
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.addEventListener("readingchanged", onDataChanged);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableReadingChangedScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
accelerometer.removeEventListener("readingchanged", onDataChanged);
document.getElementById("scenario5Open").disabled = false;
document.getElementById("scenario5Revoke").disabled = true;
// Return the report interval to its default to release resources while the sensor is not in use
accelerometer.reportInterval = 0;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -14,34 +14,19 @@
x:Class="SDKTemplate.Scenario1_DataEvents"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers an event listener for accelerometer data and displays the X, Y and Z acceleration values as they are reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="20"/>
<ColumnDefinition Width="Auto" MinWidth="60"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="X:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Y:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Z:"/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
</Grid>
</StackPanel>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Data events"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Registers an event listener for accelerometer data and displays the X, Y and Z acceleration values as they are reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock x:Name="ScenarioOutput" TextWrapping="Wrap" Margin="0,10,0,0">No data</TextBlock>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -14,29 +14,20 @@
x:Class="SDKTemplate.Scenario2_ShakeEvents"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers an event listener for accelerometer shake events and displays the cumulative count of shake events."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Shake events"/>
<TextBlock TextWrapping="Wrap" Text="Registers an event listener for accelerometer shake events and displays the cumulative count of shake events."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock Margin="0,10,0,0">Shake count: <Run x:Name="ScenarioOutputText" Text="0"/></TextBlock>
</StackPanel>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="100"/>
<ColumnDefinition Width="Auto" MinWidth="30"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Shake count:"/>
<TextBlock x:Name="ScenarioOutputText" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="0"/>
</Grid>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -10,31 +10,24 @@
//
//*********************************************************
-->
<Page x:Class="SDKTemplate.Scenario3_Polling" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDKTemplate" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Polls for accelerometer data and displays the X, Y and Z acceleration values at a set interval."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="20"/>
<ColumnDefinition Width="Auto" MinWidth="60"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="X:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Y:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Z:"/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
</Grid>
</StackPanel>
</Grid>
<Page
x:Class="SDKTemplate.Scenario3_Polling"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Polling"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Polls for accelerometer data and displays the X, Y and Z acceleration values at a set interval."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock x:Name="ScenarioOutput" TextWrapping="Wrap" Margin="0,10,0,0">No data</TextBlock>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -14,47 +14,23 @@
x:Class="SDKTemplate.Scenario4_OrientationChanged"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="327*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Grid.RowSpan="2">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers for OrientationChanged event of the DisplayInformation class to illustrate the usage of the 'ReadingTransform' Property. Displays accelerometer readings with and without the transformation."/>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Orientation change"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Registers for OrientationChanged event of the DisplayInformation class to illustrate the usage of the 'ReadingTransform' Property. Displays accelerometer readings with and without the transformation."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="95"/>
<ColumnDefinition Width="Auto" MinWidth="80"/>
<ColumnDefinition Width="Auto" MinWidth="175"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Transform:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="None"/>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="Display Orientation"/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="X:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Y:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Z:"/>
<TextBlock x:Name="ScenarioOutput_X_Original" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y_Original" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z_Original" TextWrapping="Wrap" Grid.Row="3" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_X_ReadingTransform" TextWrapping="Wrap" Grid.Row="1" Grid.Column="3" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y_ReadingTransform" TextWrapping="Wrap" Grid.Row="2" Grid.Column="3" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z_ReadingTransform" TextWrapping="Wrap" Grid.Row="3" Grid.Column="3" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Center" Text="No data"/>
</Grid>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Untransformed:"/>
<TextBlock x:Name="ScenarioOutputOriginal" TextWrapping="Wrap" Margin="0,10,0,0">No data</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Transformed to DisplayOrientation:"/>
<TextBlock x:Name="ScenarioOutputReadingTransform" TextWrapping="Wrap" Margin="0,10,0,0">No data</TextBlock>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -2,35 +2,20 @@
x:Class="SDKTemplate.Scenario5_DataEventsBatching"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers an event listener for accelerometer data (with a report latency specified) and displays the X, Y and Z acceleration values as they are reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="20"/>
<ColumnDefinition Width="Auto" MinWidth="60"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="X:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Y:"/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Z:"/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="No data"/>
</Grid>
</StackPanel>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Orientation change"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Registers an event listener for accelerometer data (with a report latency specified) and displays the X, Y and Z acceleration values as they are reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock x:Name="ScenarioOutput" TextWrapping="Wrap" Margin="0,10,0,0">No data</TextBlock>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -10,6 +10,7 @@
'*********************************************************
Imports System
Imports System.Collections.Generic
Imports Windows.Devices.Sensors
Imports Windows.UI.Xaml.Controls
Namespace Global.SDKTemplate
@ -20,6 +21,11 @@ Namespace Global.SDKTemplate
Public Const FEATURE_NAME As String = "Accelerometer"
Public ReadOnly Property scenarios As New List(Of Scenario) From {New Scenario() With {.Title = "Data events", .ClassType = GetType(Scenario1_DataEvents)}, New Scenario() With {.Title = "Shake events", .ClassType = GetType(Scenario2_ShakeEvents)}, New Scenario() With {.Title = "Polling", .ClassType = GetType(Scenario3_Polling)}, New Scenario() With {.Title = "OrientationChange", .ClassType = GetType(Scenario4_OrientationChanged)}, New Scenario() With {.Title = "Data events batching", .ClassType = GetType(Scenario5_DataEventsBatching)}}
Public Shared Sub SetReadingText(textBlock As TextBlock, reading As AccelerometerReading)
textBlock.Text = String.Format("X: {0,5:0.00}, Y: {1,5:0.00}, Z: {2,5:0.00}",
reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ)
End Sub
End Class
Public Class Scenario

Просмотреть файл

@ -8,13 +8,7 @@
' PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
'
'*********************************************************
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System
Imports Windows.Devices.Sensors
Imports Windows.Foundation
Imports System.Threading.Tasks
Imports Windows.UI.Core
Namespace Global.SDKTemplate
@ -26,47 +20,23 @@ Namespace Global.SDKTemplate
Private _accelerometer As Accelerometer
Private _desiredReportInterval As UInteger
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
_accelerometer = Accelerometer.GetDefault()
If _accelerometer IsNot Nothing Then
' Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
' This value will be used later to activate the sensor.
Dim minReportInterval As UInteger = _accelerometer.MinimumReportInterval
_desiredReportInterval = If(minReportInterval > 16, minReportInterval, 16)
ScenarioEnableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
End Sub
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False
End Sub
''' <summary>
''' Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
''' </summary>
''' <param name="e">
''' Event data that can be examined by overriding code. The event data is representative
''' of the navigation that will unload the current Page unless canceled. The
''' navigation can potentially be canceled by setting Cancel.
''' </param>
Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
If ScenarioDisableButton.IsEnabled Then
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler _accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
_accelerometer.ReportInterval = 0
ScenarioDisable()
End If
MyBase.OnNavigatingFrom(e)
End Sub
''' <summary>
@ -80,9 +50,9 @@ Namespace Global.SDKTemplate
Private Sub VisibilityChanged(sender As Object, e As VisibilityChangedEventArgs)
If ScenarioDisableButton.IsEnabled Then
If e.Visible Then
AddHandler _accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
AddHandler _accelerometer.ReadingChanged, AddressOf ReadingChanged
Else
RemoveHandler _accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
RemoveHandler _accelerometer.ReadingChanged, AddressOf ReadingChanged
End If
End If
End Sub
@ -94,38 +64,28 @@ Namespace Global.SDKTemplate
''' <param name="e"></param>
Async Private Sub ReadingChanged(sender As Object, e As AccelerometerReadingChangedEventArgs)
Await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Sub()
Dim reading As AccelerometerReading = e.Reading
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX)
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY)
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ)
MainPage.SetReadingText(ScenarioOutput, e.Reading)
End Sub)
End Sub
''' <summary>
''' This is the click handler for the 'Enable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioEnable(sender As Object, e As RoutedEventArgs)
If _accelerometer IsNot Nothing Then
_accelerometer.ReportInterval = _desiredReportInterval
AddHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
AddHandler _accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
Private Sub ScenarioEnable()
' Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
_accelerometer.ReportInterval = Math.Max(_accelerometer.MinimumReportInterval, 16)
AddHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
AddHandler _accelerometer.ReadingChanged, AddressOf ReadingChanged
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
End Sub
''' <summary>
''' This is the click handler for the 'Disable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioDisable(sender As Object, e As RoutedEventArgs)
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler _accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
Private Sub ScenarioDisable()
RemoveHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
RemoveHandler _accelerometer.ReadingChanged, AddressOf ReadingChanged
_accelerometer.ReportInterval = 0
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False

Просмотреть файл

@ -9,12 +9,7 @@
'
'*********************************************************
' Windows Store code
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System
Imports Windows.Devices.Sensors
Imports Windows.Foundation
Imports Windows.UI.Core
Namespace Global.SDKTemplate
@ -24,45 +19,27 @@ Namespace Global.SDKTemplate
Private _accelerometer As Accelerometer
Private _shakeCount As UShort
Private _shakeCount As UShort = 0
Dim rootPage As MainPage = MainPage.Current
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
_accelerometer = Accelerometer.GetDefault()
If _accelerometer Is Nothing Then
If _accelerometer IsNot Nothing Then
ScenarioEnableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
_shakeCount = 0
End Sub
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False
End Sub
''' <summary>
''' Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
''' </summary>
''' <param name="e">
''' Event data that can be examined by overriding code. The event data is representative
''' of the navigation that will unload the current Page unless canceled. The
''' navigation can potentially be canceled by setting Cancel.
''' </param>
Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
If ScenarioDisableButton.IsEnabled Then
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler _accelerometer.Shaken, New TypedEventHandler(Of Accelerometer, AccelerometerShakenEventArgs)(AddressOf Shaken)
ScenarioDisable()
End If
MyBase.OnNavigatingFrom(e)
End Sub
''' <summary>
@ -76,9 +53,9 @@ Namespace Global.SDKTemplate
Private Sub VisibilityChanged(sender As Object, e As VisibilityChangedEventArgs)
If ScenarioDisableButton.IsEnabled Then
If e.Visible Then
AddHandler _accelerometer.Shaken, New TypedEventHandler(Of Accelerometer, AccelerometerShakenEventArgs)(AddressOf Shaken)
AddHandler _accelerometer.Shaken, AddressOf Shaken
Else
RemoveHandler _accelerometer.Shaken, New TypedEventHandler(Of Accelerometer, AccelerometerShakenEventArgs)(AddressOf Shaken)
RemoveHandler _accelerometer.Shaken, AddressOf Shaken
End If
End If
End Sub
@ -98,27 +75,19 @@ Namespace Global.SDKTemplate
''' <summary>
''' This is the click handler for the 'Enable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioEnable(sender As Object, e As RoutedEventArgs)
If _accelerometer IsNot Nothing Then
AddHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
AddHandler _accelerometer.Shaken, New TypedEventHandler(Of Accelerometer, AccelerometerShakenEventArgs)(AddressOf Shaken)
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
Private Sub ScenarioEnable()
AddHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
AddHandler _accelerometer.Shaken, AddressOf Shaken
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
End Sub
''' <summary>
''' This is the click handler for the 'Disable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioDisable(sender As Object, e As RoutedEventArgs)
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler _accelerometer.Shaken, New TypedEventHandler(Of Accelerometer, AccelerometerShakenEventArgs)(AddressOf Shaken)
Private Sub ScenarioDisable()
RemoveHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
RemoveHandler _accelerometer.Shaken, AddressOf Shaken
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False
End Sub

Просмотреть файл

@ -8,13 +8,7 @@
' PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
'
'*********************************************************
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System
Imports Windows.Devices.Sensors
Imports Windows.Foundation
Imports System.Threading.Tasks
Imports Windows.UI.Core
Namespace Global.SDKTemplate
@ -32,46 +26,30 @@ Namespace Global.SDKTemplate
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
_accelerometer = Accelerometer.GetDefault()
If _accelerometer IsNot Nothing Then
' Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
' This value will be used later to activate the sensor.
Dim minReportInterval As UInteger = _accelerometer.MinimumReportInterval
_desiredReportInterval = If(minReportInterval > 16, minReportInterval, 16)
_desiredReportInterval = Math.Max(_accelerometer.MinimumReportInterval, 16)
' Set up a DispatchTimer
_dispatcherTimer = New DispatcherTimer()
AddHandler _dispatcherTimer.Tick, AddressOf DisplayCurrentReading
_dispatcherTimer.Interval = New TimeSpan(0, 0, 0, 0, CType(_desiredReportInterval, Integer))
ScenarioEnableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
End Sub
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False
End Sub
''' <summary>
''' Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
''' </summary>
''' <param name="e">
''' Event data that can be examined by overriding code. The event data is representative
''' of the navigation that will unload the current Page unless canceled. The
''' navigation can potentially be canceled by setting Cancel.
''' </param>
Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
If ScenarioDisableButton.IsEnabled Then
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
_dispatcherTimer.Stop()
_accelerometer.ReportInterval = 0
ScenarioDisable()
End If
MyBase.OnNavigatingFrom(e)
End Sub
''' <summary>
@ -100,36 +78,26 @@ Namespace Global.SDKTemplate
Private Sub DisplayCurrentReading(sender As Object, args As Object)
Dim reading As AccelerometerReading = _accelerometer.GetCurrentReading()
If reading IsNot Nothing Then
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX)
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY)
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ)
MainPage.SetReadingText(ScenarioOutput, reading)
End If
End Sub
''' <summary>
''' This is the click handler for the 'Enable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioEnable(sender As Object, e As RoutedEventArgs)
If _accelerometer IsNot Nothing Then
_accelerometer.ReportInterval = _desiredReportInterval
AddHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
_dispatcherTimer.Start()
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
Private Sub ScenarioEnable()
_accelerometer.ReportInterval = _desiredReportInterval
AddHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
_dispatcherTimer.Start()
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
End Sub
''' <summary>
''' This is the click handler for the 'Disable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioDisable(sender As Object, e As RoutedEventArgs)
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
Private Sub ScenarioDisable()
RemoveHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
_dispatcherTimer.Stop()
_accelerometer.ReportInterval = 0
ScenarioEnableButton.IsEnabled = True

Просмотреть файл

@ -8,15 +8,8 @@
' PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
'
'*********************************************************
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System
Imports Windows.Devices.Sensors
Imports Windows.Foundation
Imports System.Threading.Tasks
Imports Windows.UI.Core
Imports Windows.Graphics.Display
Namespace Global.SDKTemplate
@ -36,50 +29,27 @@ Namespace Global.SDKTemplate
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
accelerometerOriginal = Accelerometer.GetDefault()
accelerometerReadingTransform = Accelerometer.GetDefault()
If accelerometerOriginal Is Nothing OrElse accelerometerReadingTransform Is Nothing Then
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
displayInformation = DisplayInformation.GetForCurrentView()
End Sub
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
If accelerometerOriginal Is Nothing OrElse accelerometerReadingTransform Is Nothing Then
ScenarioEnableButton.IsEnabled = False
Else
ScenarioEnableButton.IsEnabled = True
End If
ScenarioDisableButton.IsEnabled = False
displayInformation = DisplayInformation.GetForCurrentView()
AddHandler displayInformation.OrientationChanged, AddressOf displayInformation_OrientationChanged
End Sub
''' <summary>
''' Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
''' </summary>
''' <param name="e">
''' Event data that can be examined by overriding code. The event data is representative
''' of the navigation that will unload the current Page unless canceled. The
''' navigation can potentially be canceled by setting Cancel.
''' </param>
Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
If ScenarioDisableButton.IsEnabled Then
RemoveHandler Window.Current.VisibilityChanged, AddressOf Current_VisibilityChanged
RemoveHandler accelerometerOriginal.ReadingChanged, AddressOf _accelerometerOriginal_ReadingChanged
RemoveHandler accelerometerReadingTransform.ReadingChanged, AddressOf _accelerometerReadingTransform_ReadingChanged
accelerometerOriginal.ReportInterval = 0
accelerometerReadingTransform.ReportInterval = 0
ScenarioDisable()
End If
RemoveHandler displayInformation.OrientationChanged, AddressOf displayInformation_OrientationChanged
MyBase.OnNavigatingFrom(e)
End Sub
''' <summary>
@ -98,8 +68,6 @@ Namespace Global.SDKTemplate
''' <summary>
''' This is the click handler for the 'Enable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Sub ScenarioEnable(sender As Object, e As RoutedEventArgs)
accelerometerOriginal.ReportInterval = accelerometerOriginal.MinimumReportInterval
accelerometerReadingTransform.ReportInterval = accelerometerReadingTransform.MinimumReportInterval
@ -121,10 +89,7 @@ Namespace Global.SDKTemplate
''' </param>
Async Sub _accelerometerOriginal_ReadingChanged(sender As Accelerometer, args As AccelerometerReadingChangedEventArgs)
Await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Sub()
Dim reading As AccelerometerReading = args.Reading
ScenarioOutput_X_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationX)
ScenarioOutput_Y_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationY)
ScenarioOutput_Z_Original.Text = String.Format("{0,5:0.00}", reading.AccelerationZ)
MainPage.SetReadingText(ScenarioOutputOriginal, args.Reading)
End Sub)
End Sub
@ -138,10 +103,7 @@ Namespace Global.SDKTemplate
''' </param>
Async Sub _accelerometerReadingTransform_ReadingChanged(sender As Accelerometer, args As AccelerometerReadingChangedEventArgs)
Await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Sub()
Dim reading As AccelerometerReading = args.Reading
ScenarioOutput_X_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationX)
ScenarioOutput_Y_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationY)
ScenarioOutput_Z_ReadingTransform.Text = String.Format("{0,5:0.00}", reading.AccelerationZ)
MainPage.SetReadingText(ScenarioOutputReadingTransform, args.Reading)
End Sub)
End Sub
@ -168,9 +130,7 @@ Namespace Global.SDKTemplate
''' <summary>
''' This is the click handler for the 'Disable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Sub ScenarioDisable(sender As Object, e As RoutedEventArgs)
Sub ScenarioDisable()
RemoveHandler Window.Current.VisibilityChanged, AddressOf Current_VisibilityChanged
RemoveHandler accelerometerOriginal.ReadingChanged, AddressOf _accelerometerOriginal_ReadingChanged
RemoveHandler accelerometerReadingTransform.ReadingChanged, AddressOf _accelerometerReadingTransform_ReadingChanged

Просмотреть файл

@ -8,13 +8,7 @@
' PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
'
'*********************************************************
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports System
Imports Windows.Devices.Sensors
Imports Windows.Foundation
Imports System.Threading.Tasks
Imports Windows.UI.Core
Namespace Global.SDKTemplate
@ -32,46 +26,28 @@ Namespace Global.SDKTemplate
Public Sub New()
Me.InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
accelerometer = Accelerometer.GetDefault()
If accelerometer IsNot Nothing Then
' Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
' This value will be used later to activate the sensor.
Dim minReportInterval As UInteger = accelerometer.MinimumReportInterval
desiredReportInterval = If(minReportInterval > 16, minReportInterval, 16)
desiredReportInterval = Math.Max(accelerometer.MinimumReportInterval, 16)
' MaxBatchSize will be 0 if the accelerometer does not support batching.
Dim maxLatency As UInteger = accelerometer.MaxBatchSize * desiredReportInterval
desiredReportLatency = If(maxLatency < 10000, maxLatency, 10000)
desiredReportLatency = Math.Min(maxLatency, 10000)
ScenarioEnableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
End Sub
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False
End Sub
''' <summary>
''' Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
''' </summary>
''' <param name="e">
''' Event data that can be examined by overriding code. The event data is representative
''' of the navigation that will unload the current Page unless canceled. The
''' navigation can potentially be canceled by setting Cancel.
''' </param>
Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
If ScenarioDisableButton.IsEnabled Then
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
accelerometer.ReportInterval = 0
ScenarioDisable()
End If
MyBase.OnNavigatingFrom(e)
End Sub
''' <summary>
@ -85,9 +61,9 @@ Namespace Global.SDKTemplate
Private Sub VisibilityChanged(sender As Object, e As VisibilityChangedEventArgs)
If ScenarioDisableButton.IsEnabled Then
If e.Visible Then
AddHandler accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
AddHandler accelerometer.ReadingChanged, AddressOf ReadingChanged
Else
RemoveHandler accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
RemoveHandler accelerometer.ReadingChanged, AddressOf ReadingChanged
End If
End If
End Sub
@ -99,39 +75,28 @@ Namespace Global.SDKTemplate
''' <param name="e"></param>
Async Private Sub ReadingChanged(sender As Object, e As AccelerometerReadingChangedEventArgs)
Await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, Sub()
Dim reading As AccelerometerReading = e.Reading
ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AccelerationX)
ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AccelerationY)
ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AccelerationZ)
MainPage.SetReadingText(ScenarioOutput, e.Reading)
End Sub)
End Sub
''' <summary>
''' This is the click handler for the 'Enable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioEnable(sender As Object, e As RoutedEventArgs)
If accelerometer IsNot Nothing Then
accelerometer.ReportInterval = desiredReportInterval
accelerometer.ReportLatency = desiredReportLatency
AddHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
AddHandler accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
Else
rootPage.NotifyUser("No accelerometer found", NotifyType.ErrorMessage)
End If
Private Sub ScenarioEnable()
accelerometer.ReportInterval = desiredReportInterval
accelerometer.ReportLatency = desiredReportLatency
AddHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
AddHandler accelerometer.ReadingChanged, AddressOf ReadingChanged
ScenarioEnableButton.IsEnabled = False
ScenarioDisableButton.IsEnabled = True
End Sub
''' <summary>
''' This is the click handler for the 'Disable' button.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub ScenarioDisable(sender As Object, e As RoutedEventArgs)
RemoveHandler Window.Current.VisibilityChanged, New WindowVisibilityChangedEventHandler(AddressOf VisibilityChanged)
RemoveHandler accelerometer.ReadingChanged, New TypedEventHandler(Of Accelerometer, AccelerometerReadingChangedEventArgs)(AddressOf ReadingChanged)
Private Sub ScenarioDisable()
RemoveHandler Window.Current.VisibilityChanged, AddressOf VisibilityChanged
RemoveHandler accelerometer.ReadingChanged, AddressOf ReadingChanged
accelerometer.ReportInterval = 0
ScenarioEnableButton.IsEnabled = True
ScenarioDisableButton.IsEnabled = False

Просмотреть файл

@ -20,7 +20,7 @@
switch (pageSections) {
case "1":
// Animate the whole page together
enterPage = WinJS.UI.Animation.enterPage([scenarioHeader, input, output], null);
enterPage = WinJS.UI.Animation.enterPage([[scenarioHeader, input, output]], null);
break;
case "2":
// Stagger the header and body

Просмотреть файл

@ -138,7 +138,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CalibrationBar.xaml.h">
<DependentUpon>CalibrationBar.xaml</DependentUpon>
<DependentUpon>..\shared\CalibrationBar.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="pch.h" />
<ClInclude Include="..\..\..\SharedContent\cpp\App.xaml.h">
@ -149,26 +149,26 @@
</ClInclude>
<ClInclude Include="SampleConfiguration.h" />
<ClInclude Include="Scenario1_DataEvents.xaml.h">
<DependentUpon>Scenario1_DataEvents.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario1_DataEvents.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="Scenario2_Polling.xaml.h">
<DependentUpon>Scenario2_Polling.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario2_Polling.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="Scenario3_Calibration.xaml.h">
<DependentUpon>Scenario3_Calibration.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario3_Calibration.xaml</DependentUpon>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="..\..\..\SharedContent\xaml\App.xaml">
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="CalibrationBar.xaml" />
<Page Include="..\shared\CalibrationBar.xaml" />
<Page Include="..\..\..\SharedContent\cpp\MainPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Scenario1_DataEvents.xaml" />
<Page Include="Scenario2_Polling.xaml" />
<Page Include="Scenario3_Calibration.xaml" />
<Page Include="..\shared\Scenario1_DataEvents.xaml" />
<Page Include="..\shared\Scenario2_Polling.xaml" />
<Page Include="..\shared\Scenario3_Calibration.xaml" />
<Page Include="..\..\..\SharedContent\xaml\Styles.xaml">
<Link>Styles\Styles.xaml</Link>
</Page>
@ -183,7 +183,7 @@
<DependentUpon>..\..\..\SharedContent\xaml\App.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="CalibrationBar.xaml.cpp">
<DependentUpon>CalibrationBar.xaml</DependentUpon>
<DependentUpon>..\shared\CalibrationBar.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="..\..\..\SharedContent\cpp\MainPage.xaml.cpp">
<DependentUpon>..\..\..\SharedContent\cpp\MainPage.xaml</DependentUpon>
@ -198,13 +198,13 @@
</ClCompile>
<ClCompile Include="SampleConfiguration.cpp" />
<ClCompile Include="Scenario1_DataEvents.xaml.cpp">
<DependentUpon>Scenario1_DataEvents.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario1_DataEvents.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="Scenario2_Polling.xaml.cpp">
<DependentUpon>Scenario2_Polling.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario2_Polling.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="Scenario3_Calibration.xaml.cpp">
<DependentUpon>Scenario3_Calibration.xaml</DependentUpon>
<DependentUpon>..\shared\Scenario3_Calibration.xaml</DependentUpon>
</ClCompile>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -53,11 +53,11 @@
<AppxManifest Include="Package.appxmanifest" />
</ItemGroup>
<ItemGroup>
<Page Include="CalibrationBar.xaml" />
<Page Include="..\shared\CalibrationBar.xaml" />
<Page Include="..\..\..\SharedContent\cpp\MainPage.xaml" />
<Page Include="Scenario1_DataEvents.xaml" />
<Page Include="Scenario2_Polling.xaml" />
<Page Include="Scenario3_Calibration.xaml" />
<Page Include="..\shared\Scenario1_DataEvents.xaml" />
<Page Include="..\shared\Scenario2_Polling.xaml" />
<Page Include="..\shared\Scenario3_Calibration.xaml" />
<Page Include="..\..\..\SharedContent\xaml\Styles.xaml">
<Filter>Styles</Filter>
</Page>

Просмотреть файл

@ -12,8 +12,11 @@
#include "pch.h"
#include "MainPage.xaml.h"
#include "SampleConfiguration.h"
#include <sstream>
using namespace SDKTemplate;
using namespace Windows::Devices::Sensors;
using namespace Windows::UI::Xaml::Controls;
Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Scenario>
{
@ -21,3 +24,46 @@ Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Sc
{ "Polling", "SDKTemplate.Scenario2_Polling" },
{ "Calibration", "SDKTemplate.Scenario3_Calibration" }
};
void MainPage::SetReadingText(TextBlock^ textBlock, OrientationSensorReading^ reading)
{
std::wostringstream ss;
ss.flags(std::ios::right | std::ios::fixed);
ss.width(5);
ss.precision(3);
SensorQuaternion^ quaternion = reading->Quaternion; // get a reference to the object to avoid re-creating it for each access
ss << "Quaternion:" << std::endl;
ss << "W: " << quaternion->W << ", X: " << quaternion->X << ", Y: " << quaternion->Y << ", Z: " << quaternion->Z << std::endl;
ss << std::endl;
SensorRotationMatrix^ rotationMatrix = reading->RotationMatrix;
ss << "M11: " << rotationMatrix->M11 << ", M12: " << rotationMatrix->M12 << ", M13: " << rotationMatrix->M13 << std::endl;
ss << "M21: " << rotationMatrix->M21 << ", M22: " << rotationMatrix->M22 << ", M23: " << rotationMatrix->M23 << std::endl;
ss << "M31: " << rotationMatrix->M31 << ", M32: " << rotationMatrix->M32 << ", M33: " << rotationMatrix->M33 << std::endl;
ss << std::endl;
ss << "Yaw Accuracy:" << std::endl;
switch (reading->YawAccuracy)
{
case MagnetometerAccuracy::Unknown:
ss << "unknown";
break;
case MagnetometerAccuracy::Unreliable:
ss << "unreliable";
break;
case MagnetometerAccuracy::Approximate:
ss << "approximate";
break;
case MagnetometerAccuracy::High:
ss << "high";
break;
default:
ss << "other";
break;
}
textBlock->Text = ref new Platform::String(ss.str().c_str());
}

Просмотреть файл

@ -35,6 +35,8 @@ namespace SDKTemplate
}
}
static void SetReadingText(Windows::UI::Xaml::Controls::TextBlock^ textBlock, Windows::Devices::Sensors::OrientationSensorReading^ reading);
private:
static Platform::Array<Scenario>^ scenariosInner;
};

Просмотреть файл

@ -1,70 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="SDKTemplate.Scenario1_DataEvents" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDKTemplate" xmlns:common="using:SDKSample.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers an event listener for orientation sensor data and displays the rotation data as it is reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Rotation Matrix:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="ScenarioOutput_M11" TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M12" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M13" TextWrapping="Wrap" Grid.Row="0" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M21" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M22" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M23" TextWrapping="Wrap" Grid.Row="1" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M31" TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M32" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M33" TextWrapping="Wrap" Grid.Row="2" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
</Grid>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Quaternion:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="X: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Y: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Z: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="W: "/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_W" TextWrapping="Wrap" Grid.Row="3" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
</Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<TextBlock x:Name="ScenarioOutput_YawAccuracy" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="10,0,0,0" Text="No data"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -27,17 +27,17 @@ using namespace Windows::Foundation;
using namespace Windows::UI::Core;
using namespace Platform;
Scenario1_DataEvents::Scenario1_DataEvents() : rootPage(MainPage::Current), desiredReportInterval(0)
Scenario1_DataEvents::Scenario1_DataEvents()
{
InitializeComponent();
}
void Scenario1_DataEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
sensor = OrientationSensor::GetDefault();
if (sensor != nullptr)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint32 minReportInterval = sensor->MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
ScenarioEnableButton->IsEnabled = true;
}
else
{
@ -45,37 +45,11 @@ Scenario1_DataEvents::Scenario1_DataEvents() : rootPage(MainPage::Current), desi
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario1_DataEvents::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario1_DataEvents::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
sensor->ReadingChanged::remove(readingToken);
// Restore the default report interval to release resources while the sensor is not in use
sensor->ReportInterval = 0;
ScenarioDisable();
}
}
@ -95,12 +69,12 @@ void Scenario1_DataEvents::VisibilityChanged(Object^ sender, VisibilityChangedEv
if (e->Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
readingToken = sensor->ReadingChanged::add(ref new TypedEventHandler<OrientationSensor^, OrientationSensorReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged));
readingToken = sensor->ReadingChanged += ref new TypedEventHandler<OrientationSensor^, OrientationSensorReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged);
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
sensor->ReadingChanged::remove(readingToken);
sensor->ReadingChanged -= readingToken;
}
}
}
@ -113,75 +87,29 @@ void Scenario1_DataEvents::ReadingChanged(OrientationSensor^ sender, Orientation
ref new DispatchedHandler(
[this, e]()
{
OrientationSensorReading^ reading = e->Reading;
// Quaternion values
SensorQuaternion^ quaternion = reading->Quaternion; // get a reference to the object to avoid re-creating it for each access
ScenarioOutput_X->Text = quaternion->X.ToString();
ScenarioOutput_Y->Text = quaternion->Y.ToString();
ScenarioOutput_Z->Text = quaternion->Z.ToString();
ScenarioOutput_W->Text = quaternion->W.ToString();
// Rotation Matrix values
SensorRotationMatrix^ rotationMatrix = reading->RotationMatrix;
ScenarioOutput_M11->Text = rotationMatrix->M11.ToString();
ScenarioOutput_M12->Text = rotationMatrix->M12.ToString();
ScenarioOutput_M13->Text = rotationMatrix->M13.ToString();
ScenarioOutput_M21->Text = rotationMatrix->M21.ToString();
ScenarioOutput_M22->Text = rotationMatrix->M22.ToString();
ScenarioOutput_M23->Text = rotationMatrix->M23.ToString();
ScenarioOutput_M31->Text = rotationMatrix->M31.ToString();
ScenarioOutput_M32->Text = rotationMatrix->M32.ToString();
ScenarioOutput_M33->Text = rotationMatrix->M33.ToString();
// Yaw accuracy
switch (reading->YawAccuracy)
{
case MagnetometerAccuracy::Unknown:
ScenarioOutput_YawAccuracy->Text = "Unknown";
break;
case MagnetometerAccuracy::Unreliable:
ScenarioOutput_YawAccuracy->Text = "Unreliable";
break;
case MagnetometerAccuracy::Approximate:
ScenarioOutput_YawAccuracy->Text = "Approximate";
break;
case MagnetometerAccuracy::High:
ScenarioOutput_YawAccuracy->Text = "High";
break;
default:
ScenarioOutput_YawAccuracy->Text = "No data";
break;
}
MainPage::SetReadingText(ScenarioOutput, e->Reading);
},
CallbackContext::Any
)
);
}
void Scenario1_DataEvents::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario1_DataEvents::ScenarioEnable()
{
if (sensor != nullptr)
{
// Establish the report interval
sensor->ReportInterval = desiredReportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
sensor->ReportInterval = (std::max)(sensor->MinimumReportInterval, 16U);
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged));
readingToken = sensor->ReadingChanged::add(ref new TypedEventHandler<OrientationSensor^, OrientationSensorReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario1_DataEvents::VisibilityChanged);
readingToken = sensor->ReadingChanged += ref new TypedEventHandler<OrientationSensor^, OrientationSensorReadingChangedEventArgs^>(this, &Scenario1_DataEvents::ReadingChanged);
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No orientation sensor found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario1_DataEvents::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario1_DataEvents::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
sensor->ReadingChanged::remove(readingToken);
Window::Current->VisibilityChanged -= visibilityToken;
sensor->ReadingChanged -= readingToken;
// Restore the default report interval to release resources while the sensor is not in use
sensor->ReportInterval = 0;

Просмотреть файл

@ -35,16 +35,16 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::MainPage^ rootPage = MainPage::Current;
Windows::Devices::Sensors::OrientationSensor^ sensor;
Windows::Foundation::EventRegistrationToken visibilityToken;
Windows::Foundation::EventRegistrationToken readingToken;
uint32 desiredReportInterval;
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void ReadingChanged(Windows::Devices::Sensors::OrientationSensor^ sender, Windows::Devices::Sensors::OrientationSensorReadingChangedEventArgs^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -1,70 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="SDKTemplate.Scenario2_Polling" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDKTemplate" xmlns:common="using:SDKSample.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Polls for orientation sensor data and displays the rotation data at a set interval."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Rotation Matrix:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="ScenarioOutput_M11" TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M12" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M13" TextWrapping="Wrap" Grid.Row="0" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M21" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M22" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M23" TextWrapping="Wrap" Grid.Row="1" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M31" TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M32" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M33" TextWrapping="Wrap" Grid.Row="2" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
</Grid>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Quaternion:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="X: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Y: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Z: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="W: "/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_W" TextWrapping="Wrap" Grid.Row="3" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
</Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<TextBlock x:Name="ScenarioOutput_YawAccuracy" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="10,0,0,0" Text="No data"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -30,14 +30,16 @@ using namespace Platform;
Scenario2_Polling::Scenario2_Polling() : rootPage(MainPage::Current), desiredReportInterval(0)
{
InitializeComponent();
}
void Scenario2_Polling::OnNavigatedTo(NavigationEventArgs^ e)
{
sensor = OrientationSensor::GetDefault();
if (sensor != nullptr)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint32 minReportInterval = sensor->MinimumReportInterval;
desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
desiredReportInterval = (std::max)(sensor->MinimumReportInterval, 16U);
// Set up a DispatchTimer
TimeSpan span;
@ -45,6 +47,8 @@ Scenario2_Polling::Scenario2_Polling() : rootPage(MainPage::Current), desiredRep
dispatcherTimer = ref new DispatcherTimer();
dispatcherTimer->Interval = span;
dispatcherTimer->Tick += ref new Windows::Foundation::EventHandler<Object^>(this, &Scenario2_Polling::DisplayCurrentReading);
ScenarioEnableButton->IsEnabled = true;
}
else
{
@ -52,37 +56,11 @@ Scenario2_Polling::Scenario2_Polling() : rootPage(MainPage::Current), desiredRep
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario2_Polling::OnNavigatedTo(NavigationEventArgs^ e)
{
ScenarioEnableButton->IsEnabled = true;
ScenarioDisableButton->IsEnabled = false;
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario2_Polling::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
if (ScenarioDisableButton->IsEnabled)
{
Window::Current->VisibilityChanged::remove(visibilityToken);
dispatcherTimer->Stop();
// Restore the default report interval to release resources while the sensor is not in use
sensor->ReportInterval = 0;
ScenarioDisable();
}
}
@ -117,70 +95,26 @@ void Scenario2_Polling::DisplayCurrentReading(Object^ sender, Object^ e)
OrientationSensorReading^ reading = sensor->GetCurrentReading();
if (reading != nullptr)
{
// Quaternion values
SensorQuaternion^ quaternion = reading->Quaternion; // get a reference to the object to avoid re-creating it for each access
ScenarioOutput_X->Text = quaternion->X.ToString();
ScenarioOutput_Y->Text = quaternion->Y.ToString();
ScenarioOutput_Z->Text = quaternion->Z.ToString();
ScenarioOutput_W->Text = quaternion->W.ToString();
// Rotation Matrix values
SensorRotationMatrix^ rotationMatrix = reading->RotationMatrix;
ScenarioOutput_M11->Text = rotationMatrix->M11.ToString();
ScenarioOutput_M12->Text = rotationMatrix->M12.ToString();
ScenarioOutput_M13->Text = rotationMatrix->M13.ToString();
ScenarioOutput_M21->Text = rotationMatrix->M21.ToString();
ScenarioOutput_M22->Text = rotationMatrix->M22.ToString();
ScenarioOutput_M23->Text = rotationMatrix->M23.ToString();
ScenarioOutput_M31->Text = rotationMatrix->M31.ToString();
ScenarioOutput_M32->Text = rotationMatrix->M32.ToString();
ScenarioOutput_M33->Text = rotationMatrix->M33.ToString();
// Yaw accuracy
switch (reading->YawAccuracy)
{
case MagnetometerAccuracy::Unknown:
ScenarioOutput_YawAccuracy->Text = "Unknown";
break;
case MagnetometerAccuracy::Unreliable:
ScenarioOutput_YawAccuracy->Text = "Unreliable";
break;
case MagnetometerAccuracy::Approximate:
ScenarioOutput_YawAccuracy->Text = "Approximate";
break;
case MagnetometerAccuracy::High:
ScenarioOutput_YawAccuracy->Text = "High";
break;
default:
ScenarioOutput_YawAccuracy->Text = "No data";
break;
}
MainPage::SetReadingText(ScenarioOutput, reading);
}
}
void Scenario2_Polling::ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario2_Polling::ScenarioEnable()
{
if (sensor != nullptr)
{
visibilityToken = Window::Current->VisibilityChanged::add(ref new WindowVisibilityChangedEventHandler(this, &Scenario2_Polling::VisibilityChanged));
visibilityToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario2_Polling::VisibilityChanged);
// Set the report interval to enable the sensor for polling
sensor->ReportInterval = desiredReportInterval;
// Set the report interval to enable the sensor for polling
sensor->ReportInterval = desiredReportInterval;
dispatcherTimer->Start();
dispatcherTimer->Start();
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
else
{
rootPage->NotifyUser("No orientation sensor found", NotifyType::ErrorMessage);
}
ScenarioEnableButton->IsEnabled = false;
ScenarioDisableButton->IsEnabled = true;
}
void Scenario2_Polling::ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
void Scenario2_Polling::ScenarioDisable()
{
Window::Current->VisibilityChanged::remove(visibilityToken);
Window::Current->VisibilityChanged -= visibilityToken;
dispatcherTimer->Stop();

Просмотреть файл

@ -35,6 +35,9 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void ScenarioEnable();
void ScenarioDisable();
private:
SDKTemplate::MainPage^ rootPage;
Windows::UI::Core::CoreDispatcher^ dispatcher;
@ -45,7 +48,5 @@ namespace SDKTemplate
void VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
void DisplayCurrentReading(Platform::Object^ sender, Platform::Object^ e);
void ScenarioEnable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void ScenarioDisable(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -1,25 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="SDKTemplate.Scenario3_Calibration" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:SDKTemplate" xmlns:common="using:SDKSample.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Simulates the current sensor accuracy. Setting to 'Unreliable' will invoke the calibration bar until accuracy improves or 30 seconds passes. The calibration bar will not be shown again for at least 5 minutes, even when accuracy returns to 'Unreliable'."/>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<RadioButton Margin="0, 0, 0, 0" Content="High" Click="OnHighAccuracy" IsChecked="True"/>
<RadioButton Margin="0, 0, 0, 0" Content="Approximate" Click="OnApproximateAccuracy"/>
<RadioButton Margin="0, 0, 0, 0" Content="Unreliable" Click="OnUnreliableAccuracy"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -33,28 +33,12 @@ Scenario3_Calibration::Scenario3_Calibration() : rootPage(MainPage::Current)
calibrationBar = ref new CalibrationBar();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void Scenario3_Calibration::OnNavigatedTo(NavigationEventArgs^ e)
{
}
/// <summary>
/// Invoked when this page is no longer displayed.
/// </summary>
/// <param name="e"></param>
void Scenario3_Calibration::OnNavigatedFrom(NavigationEventArgs^ e)
{
// If the navigation is external to the app do not clean up.
// This can occur on Phone when suspending the app.
if (e->NavigationMode == NavigationMode::Forward && e->Uri == nullptr)
{
return;
}
calibrationBar->Hide();
}
@ -64,7 +48,7 @@ void Scenario3_Calibration::OnNavigatedFrom(NavigationEventArgs^ e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario3_Calibration::OnHighAccuracy(Object^ sender, RoutedEventArgs^ e)
void Scenario3_Calibration::OnHighAccuracy()
{
calibrationBar->Hide();
}
@ -75,7 +59,7 @@ void Scenario3_Calibration::OnHighAccuracy(Object^ sender, RoutedEventArgs^ e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario3_Calibration::OnApproximateAccuracy(Object^ sender, RoutedEventArgs^ e)
void Scenario3_Calibration::OnApproximateAccuracy()
{
calibrationBar->Hide();
}
@ -86,7 +70,7 @@ void Scenario3_Calibration::OnApproximateAccuracy(Object^ sender, RoutedEventArg
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Scenario3_Calibration::OnUnreliableAccuracy(Object^ sender, RoutedEventArgs^ e)
void Scenario3_Calibration::OnUnreliableAccuracy()
{
calibrationBar->RequestCalibration(MagnetometerAccuracy::Unreliable);
}

Просмотреть файл

@ -36,12 +36,12 @@ namespace SDKTemplate
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void OnHighAccuracy();
void OnApproximateAccuracy();
void OnUnreliableAccuracy();
private:
SDKTemplate::MainPage^ rootPage;
SDKTemplate::CalibrationBar^ calibrationBar;
void OnHighAccuracy(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnApproximateAccuracy(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnUnreliableAccuracy(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

Просмотреть файл

@ -1,125 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<!-- Windows Store App Layout -->
<Page x:Class="Microsoft.Samples.Devices.Sensors.Calibration.CalibrationBar" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Microsoft.Samples.Devices.Sensors.Calibration" xmlns:common="using:SDKTemplate.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<UserControl.Resources>
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CalibrationPopupStyle" TargetType="Grid" BasedOn="{StaticResource LayoutRootStyle}">
<Setter Property="Background" Value="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
</Style>
<Style x:Key="GuidanceButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource ApplicationForegroundThemeBrush}"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="40"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid" Margin="13,-5,0,0" Width="34" Height="34">
<Grid Margin="0,-12,0,0">
<TextBlock x:Name="BackgroundGlyph" Text="&#xE0A8;" Foreground="{StaticResource ListBoxItemPointerOverBackgroundThemeBrush}"/>
<TextBlock x:Name="OutlineGlyph" Text="&#xE0A7;"/>
<ContentPresenter x:Name="Content" FontSize="20" Margin="11,12,0,0"/>
</Grid>
<Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Stroke="{StaticResource FocusVisualWhiteStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="1.5"/>
<Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Stroke="{StaticResource FocusVisualBlackStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="0.5"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemPointerOverBackgroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemPointerOverForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="OutlineGlyph" Storyboard.TargetProperty="Opacity" To="0" Duration="0"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemPointerOverForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ListBoxItemPressedForegroundThemeBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="FocusVisualWhite" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
<DoubleAnimation Storyboard.TargetName="FocusVisualBlack" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused"/>
<VisualState x:Name="PointerFocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ShowGuidanceButtonStyle" TargetType="Button" BasedOn="{StaticResource GuidanceButtonStyle}">
<Setter Property="Content" Value="&#xE015;"/>
</Style>
<Style x:Key="HideGuidanceButtonStyle" TargetType="Button" BasedOn="{StaticResource GuidanceButtonStyle}">
<Setter Property="Content" Value="&#xE014;"/>
</Style>
</UserControl.Resources>
<Popup x:Name="CalibrationPopup">
<Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" BorderThickness="0,0,0,2">
<Grid x:Name="CalibrationGrid" Style="{StaticResource CalibrationPopupStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid x:Name="CalibrationGridTop" Grid.Row="0" Height="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel x:Name="GuidanceButton" Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
<Button x:Name="ShowGuidanceButton" Style="{StaticResource ShowGuidanceButtonStyle}" Visibility="Visible" Click="ShowGuidanceButton_Click"/>
<Button x:Name="HideGuidanceButton" Style="{StaticResource HideGuidanceButtonStyle}" Visibility="Collapsed" Click="HideGuidanceButton_Click"/>
</StackPanel>
<TextBlock Text="In order to improve the accuracy of the information displayed, we need your help to calibrate your device. Expand to see how." x:Name="CalibrationText" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="Wrap"/>
<Button x:Name="DismissPopup" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" Content="Do not show again" Click="DismissPopup_Click"/>
</Grid>
<Image x:Name="Guidance" Stretch="Uniform" Source="Assets/mobius.png" Grid.Row="1" HorizontalAlignment="Center" Margin="20,20,20,20" Width="400"/>
</Grid>
</Border>
</Popup>
</Page>

Просмотреть файл

@ -10,22 +10,11 @@
//*********************************************************
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Devices.Sensors;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Sensors;
namespace Microsoft.Samples.Devices.Sensors.Calibration
namespace SDKTemplate
{
public sealed partial class CalibrationBar : Page
{

Просмотреть файл

@ -7,7 +7,7 @@
<ProjectGuid>{DC30CE66-DAEE-4CCF-BD02-8837FE918B6F}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OrientationCS</RootNamespace>
<RootNamespace>SDKTemplate</RootNamespace>
<AssemblyName>OrientationCS</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
@ -119,7 +119,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="CalibrationBar.xaml">
<Page Include="..\shared\CalibrationBar.xaml">
<Link>CalibrationBar.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
@ -128,15 +129,18 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Scenario1_DataEvents.xaml">
<Page Include="..\shared\Scenario1_DataEvents.xaml">
<Link>Scenario1_DataEvents.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Scenario2_Polling.xaml">
<Page Include="..\shared\Scenario2_Polling.xaml">
<Link>Scenario2_Polling.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Scenario3_Calibration.xaml">
<Page Include="..\shared\Scenario3_Calibration.xaml">
<Link>Scenario3_Calibration.xaml</Link>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>

Просмотреть файл

@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using Windows.Devices.Sensors;
using Windows.UI.Xaml.Controls;
using OrientationCS;
namespace SDKTemplate
{
@ -22,10 +22,50 @@ namespace SDKTemplate
List<Scenario> scenarios = new List<Scenario>
{
new Scenario() { Title = "Data Events", ClassType = typeof(OrientationCS.Scenario1_DataEvents) },
new Scenario() { Title = "Polling", ClassType = typeof(OrientationCS.Scenario2_Polling) },
new Scenario() { Title = "Calibration", ClassType = typeof(OrientationCS.Scenario3_Calibration) }
new Scenario() { Title = "Data Events", ClassType = typeof(Scenario1_DataEvents) },
new Scenario() { Title = "Polling", ClassType = typeof(Scenario2_Polling) },
new Scenario() { Title = "Calibration", ClassType = typeof(Scenario3_Calibration) }
};
public static void SetReadingText(TextBlock textBlock, OrientationSensorReading reading)
{
SensorQuaternion quaternion = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access
string quaternionReport = string.Format("W: {0,5:0.00}, X: {1,5:0.00}, Y: {2,5:0.00}, Z: {3,5:0.00}",
quaternion.W, quaternion.X, quaternion.Y, quaternion.Z);
SensorRotationMatrix rotationMatrix = reading.RotationMatrix;
string rotationMatrixReport = string.Format(
"M11: {0,5:0.00}, M12: {1,5:0.00}, M13: {2,5:0.00}\n" +
"M21: {3,5:0.00}, M22: {4,5:0.00}, M23: {5,5:0.00}\n" +
"M31: {6,5:0.00}, M32: {7,5:0.00}, M33: {8,5:0.00}",
rotationMatrix.M11, rotationMatrix.M12, rotationMatrix.M13,
rotationMatrix.M21, rotationMatrix.M22, rotationMatrix.M23,
rotationMatrix.M31, rotationMatrix.M32, rotationMatrix.M33);
string yawAccuracyReport;
switch (reading.YawAccuracy)
{
case MagnetometerAccuracy.Unknown:
yawAccuracyReport = "unknown";
break;
case MagnetometerAccuracy.Unreliable:
yawAccuracyReport = "unreliable";
break;
case MagnetometerAccuracy.Approximate:
yawAccuracyReport = "approximate";
break;
case MagnetometerAccuracy.High:
yawAccuracyReport = "high";
break;
default:
yawAccuracyReport = "other";
break;
}
textBlock.Text = "Quaternion:\n" + quaternionReport + "\n\n" +
"Rotation Matrix:\n" + rotationMatrixReport + "\n\n" +
"Yaw Accuracy:\n" + yawAccuracyReport;
}
}
public class Scenario

Просмотреть файл

@ -1,70 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="OrientationCS.Scenario1_DataEvents" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:OrientationCS" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Registers an event listener for orientation sensor data and displays the rotation data as it is reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Rotation Matrix:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="ScenarioOutput_M11" TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M12" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M13" TextWrapping="Wrap" Grid.Row="0" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M21" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M22" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M23" TextWrapping="Wrap" Grid.Row="1" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M31" TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M32" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M33" TextWrapping="Wrap" Grid.Row="2" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
</Grid>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Quaternion:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="X: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Y: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Z: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="W: "/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_W" TextWrapping="Wrap" Grid.Row="3" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
</Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<TextBlock x:Name="ScenarioOutput_YawAccuracy" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="10,0,0,0" Text="No data"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -9,17 +9,15 @@
//
//*********************************************************
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace OrientationCS
namespace SDKTemplate
{
public sealed partial class Scenario1_DataEvents : Page
{
@ -28,19 +26,18 @@ namespace OrientationCS
MainPage rootPage = MainPage.Current;
private OrientationSensor _sensor;
private uint _desiredReportInterval;
public Scenario1_DataEvents()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_sensor = OrientationSensor.GetDefault();
if (_sensor != null)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint minReportInterval = _sensor.MinimumReportInterval;
_desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
ScenarioEnableButton.IsEnabled = true;
}
else
{
@ -48,37 +45,12 @@ namespace OrientationCS
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_sensor.ReadingChanged -= new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(ReadingChanged);
// Restore the default report interval to release resources while the sensor is not in use
_sensor.ReportInterval = 0;
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -96,12 +68,12 @@ namespace OrientationCS
if (e.Visible)
{
// Re-enable sensor input (no need to restore the desired reportInterval... it is restored for us upon app resume)
_sensor.ReadingChanged += new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(ReadingChanged);
_sensor.ReadingChanged += ReadingChanged;
}
else
{
// Disable sensor input (no need to restore the default reportInterval... resources will be released upon app suspension)
_sensor.ReadingChanged -= new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(ReadingChanged);
_sensor.ReadingChanged -= ReadingChanged;
}
}
}
@ -115,82 +87,32 @@ namespace OrientationCS
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
OrientationSensorReading reading = e.Reading;
// Quaternion values
SensorQuaternion quaternion = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access
ScenarioOutput_X.Text = String.Format("{0,8:0.00000}", quaternion.X);
ScenarioOutput_Y.Text = String.Format("{0,8:0.00000}", quaternion.Y);
ScenarioOutput_Z.Text = String.Format("{0,8:0.00000}", quaternion.Z);
ScenarioOutput_W.Text = String.Format("{0,8:0.00000}", quaternion.W);
// Rotation Matrix values
SensorRotationMatrix rotationMatrix = reading.RotationMatrix;
ScenarioOutput_M11.Text = String.Format("{0,8:0.00000}", rotationMatrix.M11);
ScenarioOutput_M12.Text = String.Format("{0,8:0.00000}", rotationMatrix.M12);
ScenarioOutput_M13.Text = String.Format("{0,8:0.00000}", rotationMatrix.M13);
ScenarioOutput_M21.Text = String.Format("{0,8:0.00000}", rotationMatrix.M21);
ScenarioOutput_M22.Text = String.Format("{0,8:0.00000}", rotationMatrix.M22);
ScenarioOutput_M23.Text = String.Format("{0,8:0.00000}", rotationMatrix.M23);
ScenarioOutput_M31.Text = String.Format("{0,8:0.00000}", rotationMatrix.M31);
ScenarioOutput_M32.Text = String.Format("{0,8:0.00000}", rotationMatrix.M32);
ScenarioOutput_M33.Text = String.Format("{0,8:0.00000}", rotationMatrix.M33);
// Yaw accuracy
switch (reading.YawAccuracy)
{
case MagnetometerAccuracy.Unknown:
ScenarioOutput_YawAccuracy.Text = "Unknown";
break;
case MagnetometerAccuracy.Unreliable:
ScenarioOutput_YawAccuracy.Text = "Unreliable";
break;
case MagnetometerAccuracy.Approximate:
ScenarioOutput_YawAccuracy.Text = "Approximate";
break;
case MagnetometerAccuracy.High:
ScenarioOutput_YawAccuracy.Text = "High";
break;
default:
ScenarioOutput_YawAccuracy.Text = "No data";
break;
}
MainPage.SetReadingText(ScenarioOutput, e.Reading);
});
}
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (_sensor != null)
{
// Establish the report interval
_sensor.ReportInterval = _desiredReportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
_sensor.ReportInterval = Math.Max(_sensor.MinimumReportInterval, 16);
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_sensor.ReadingChanged += new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(ReadingChanged);
Window.Current.VisibilityChanged += VisibilityChanged;
_sensor.ReadingChanged += ReadingChanged;
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage);
}
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
_sensor.ReadingChanged -= new TypedEventHandler<OrientationSensor, OrientationSensorReadingChangedEventArgs>(ReadingChanged);
Window.Current.VisibilityChanged -= VisibilityChanged;
_sensor.ReadingChanged -= ReadingChanged;
// Restore the default report interval to release resources while the sensor is not in use
_sensor.ReportInterval = 0;

Просмотреть файл

@ -1,70 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="OrientationCS.Scenario2_Polling" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:OrientationCS" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Polls for orientation sensor data and displays the rotation data at a set interval."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="ScenarioEnable"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="ScenarioDisable"/>
</StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Rotation Matrix:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="ScenarioOutput_M11" TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M12" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M13" TextWrapping="Wrap" Grid.Row="0" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M21" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M22" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M23" TextWrapping="Wrap" Grid.Row="1" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M31" TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M32" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
<TextBlock x:Name="ScenarioOutput_M33" TextWrapping="Wrap" Grid.Row="2" Grid.Column="2" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text=" No data"/>
</Grid>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="0,10,0,0" Text="Quaternion:"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="X: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Y: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="2" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="Z: "/>
<TextBlock TextWrapping="Wrap" Grid.Row="3" Grid.Column="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Text="W: "/>
<TextBlock x:Name="ScenarioOutput_X" TextWrapping="Wrap" Grid.Row="0" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Y" TextWrapping="Wrap" Grid.Row="1" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_Z" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
<TextBlock x:Name="ScenarioOutput_W" TextWrapping="Wrap" Grid.Row="3" Grid.Column="1" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Right" Margin="10,0,0,0" Text="No data"/>
</Grid>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<TextBlock x:Name="ScenarioOutput_YawAccuracy" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Margin="10,0,0,0" Text="No data"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -19,7 +19,7 @@ using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
namespace OrientationCS
namespace SDKTemplate
{
public sealed partial class Scenario2_Polling : Page
{
@ -34,19 +34,23 @@ namespace OrientationCS
public Scenario2_Polling()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
_sensor = OrientationSensor.GetDefault();
if (_sensor != null)
{
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
uint minReportInterval = _sensor.MinimumReportInterval;
_desiredReportInterval = minReportInterval > 16 ? minReportInterval : 16;
_desiredReportInterval = Math.Max(_sensor.MinimumReportInterval, 16);
// Set up a DispatchTimer
_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Tick += DisplayCurrentReading;
_dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, (int)_desiredReportInterval);
_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(_desiredReportInterval);
ScenarioEnableButton.IsEnabled = true;
}
else
{
@ -54,39 +58,12 @@ namespace OrientationCS
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ScenarioEnableButton.IsEnabled = true;
ScenarioDisableButton.IsEnabled = false;
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ScenarioDisableButton.IsEnabled)
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
// Stop the dispatcher
_dispatcherTimer.Stop();
// Restore the default report interval to release resources while the sensor is not in use
_sensor.ReportInterval = 0;
ScenarioDisable();
}
base.OnNavigatingFrom(e);
}
/// <summary>
@ -124,79 +101,31 @@ namespace OrientationCS
OrientationSensorReading reading = _sensor.GetCurrentReading();
if (reading != null)
{
// Quaternion values
SensorQuaternion quaternion = reading.Quaternion; // get a reference to the object to avoid re-creating it for each access
ScenarioOutput_X.Text = String.Format("{0,8:0.00000}", quaternion.X);
ScenarioOutput_Y.Text = String.Format("{0,8:0.00000}", quaternion.Y);
ScenarioOutput_Z.Text = String.Format("{0,8:0.00000}", quaternion.Z);
ScenarioOutput_W.Text = String.Format("{0,8:0.00000}", quaternion.W);
// Rotation Matrix values
SensorRotationMatrix rotationMatrix = reading.RotationMatrix;
ScenarioOutput_M11.Text = String.Format("{0,8:0.00000}", rotationMatrix.M11);
ScenarioOutput_M12.Text = String.Format("{0,8:0.00000}", rotationMatrix.M12);
ScenarioOutput_M13.Text = String.Format("{0,8:0.00000}", rotationMatrix.M13);
ScenarioOutput_M21.Text = String.Format("{0,8:0.00000}", rotationMatrix.M21);
ScenarioOutput_M22.Text = String.Format("{0,8:0.00000}", rotationMatrix.M22);
ScenarioOutput_M23.Text = String.Format("{0,8:0.00000}", rotationMatrix.M23);
ScenarioOutput_M31.Text = String.Format("{0,8:0.00000}", rotationMatrix.M31);
ScenarioOutput_M32.Text = String.Format("{0,8:0.00000}", rotationMatrix.M32);
ScenarioOutput_M33.Text = String.Format("{0,8:0.00000}", rotationMatrix.M33);
// Yaw accuracy
switch (reading.YawAccuracy)
{
case MagnetometerAccuracy.Unknown:
ScenarioOutput_YawAccuracy.Text = "Unknown";
break;
case MagnetometerAccuracy.Unreliable:
ScenarioOutput_YawAccuracy.Text = "Unreliable";
break;
case MagnetometerAccuracy.Approximate:
ScenarioOutput_YawAccuracy.Text = "Approximate";
break;
case MagnetometerAccuracy.High:
ScenarioOutput_YawAccuracy.Text = "High";
break;
default:
ScenarioOutput_YawAccuracy.Text = "No data";
break;
}
MainPage.SetReadingText(ScenarioOutput, reading);
}
}
/// <summary>
/// This is the click handler for the 'Enable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioEnable(object sender, RoutedEventArgs e)
private void ScenarioEnable()
{
if (_sensor != null)
{
// Set the report interval to enable the sensor for polling
_sensor.ReportInterval = _desiredReportInterval;
// Set the report interval to enable the sensor for polling
_sensor.ReportInterval = _desiredReportInterval;
Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
_dispatcherTimer.Start();
Window.Current.VisibilityChanged += VisibilityChanged;
_dispatcherTimer.Start();
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
else
{
rootPage.NotifyUser("No orientation sensor found", NotifyType.ErrorMessage);
}
ScenarioEnableButton.IsEnabled = false;
ScenarioDisableButton.IsEnabled = true;
}
/// <summary>
/// This is the click handler for the 'Disable' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScenarioDisable(object sender, RoutedEventArgs e)
private void ScenarioDisable()
{
Window.Current.VisibilityChanged -= new WindowVisibilityChangedEventHandler(VisibilityChanged);
Window.Current.VisibilityChanged -= VisibilityChanged;
// Stop the dispatcher
_dispatcherTimer.Stop();

Просмотреть файл

@ -1,26 +0,0 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page x:Class="OrientationCS.Scenario3_Calibration" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:OrientationCS" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="InputTextBlock" TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Simulates the current sensor accuracy. Setting to 'Unreliable' will invoke the calibration bar until accuracy improves or 30 seconds passes. The calibration bar will not be shown again for at least 5 minutes, even when accuracy returns to 'Unreliable'."/>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" Text="Yaw Accuracy: "/>
<RadioButton Margin="0, 0, 0, 0" Content="High" Click="OnHighAccuracy" IsChecked="True"/>
<RadioButton Margin="0, 0, 0, 0" Content="Approximate" Click="OnApproximateAccuracy"/>
<RadioButton Margin="0, 0, 0, 0" Content="Unreliable" Click="OnUnreliableAccuracy"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -9,18 +9,12 @@
//
//*********************************************************
using Windows.Devices.Sensors;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;
using Windows.Devices.Sensors;
using Windows.Foundation;
using System.Threading.Tasks;
using Windows.UI.Core;
using Microsoft.Samples.Devices.Sensors.Calibration;
namespace OrientationCS
namespace SDKTemplate
{
public sealed partial class Scenario3_Calibration : Page
{
@ -34,36 +28,16 @@ namespace OrientationCS
this.InitializeComponent();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
/// <summary>
/// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
/// </summary>
/// <param name="e">
/// Event data that can be examined by overriding code. The event data is representative
/// of the navigation that will unload the current Page unless canceled. The
/// navigation can potentially be canceled by setting Cancel.
/// </param>
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
calibrationBar.Hide();
base.OnNavigatingFrom(e);
}
/// <summary>
/// This is the click handler for high accuracy. Acceptable accuracy met, so
/// hide the calibration bar.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnHighAccuracy(object sender, RoutedEventArgs e)
private void OnHighAccuracy()
{
calibrationBar.Hide();
}
@ -72,9 +46,7 @@ namespace OrientationCS
/// This is the click handler for approximate accuracy. Acceptable accuracy met, so
/// hide the calibration bar.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnApproximateAccuracy(object sender, RoutedEventArgs e)
private void OnApproximateAccuracy()
{
calibrationBar.Hide();
}
@ -83,9 +55,7 @@ namespace OrientationCS
/// This is the click handler for unreliable accuracy. Sensor does not meet accuracy
/// requirements. Request to show the calibration bar per the calibration guidance.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnUnreliableAccuracy(object sender, RoutedEventArgs e)
private void OnUnreliableAccuracy()
{
calibrationBar.RequestCalibration(MagnetometerAccuracy.Unreliable);
}

Просмотреть файл

@ -55,9 +55,6 @@
<SubType>Designer</SubType>
</AppxManifest>
<Content Include="css\CalibrationBar.css" />
<Content Include="css\scenario1_DataEvents.css" />
<Content Include="css\scenario2_Polling.css" />
<Content Include="css\scenario3_Calibration.css" />
<Content Include="..\..\..\SharedContent\js\default.html">
<Link>default.html</Link>
</Content>

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -1,14 +0,0 @@
/*
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
*/
/* styles */

Просмотреть файл

@ -6,21 +6,19 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario1_DataEvents.css">
<script src="/js/scenario1_DataEvents.js"></script>
</head>
<body class="win-type-body">
<div>
<p>Registers an event listener for orientation sensor data and displays the rotation data as it is reported.</p>
<button class="action win-button" id="scenario1Open">Enable</button>
<button class="action secondary win-button" id="scenario1Revoke">Disable</button>
<br>
<br> Quaternion: <a id="eventOutputQuaternion" class="win-link">no data</a>
<br> Rotation Matrix: <a id="eventOutputRotationMatrix" class="win-link">no data</a>
<br> Yaw Accuracy: <a id="eventOutputYawAccuracy" class="win-link">no data</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Data events</div>
<p>Registers an event listener for orientation sensor data and displays the rotation data as it is reported.</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p id="output">no data</p>
</body>
</html>

Просмотреть файл

@ -6,21 +6,19 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario2_Polling.css">
<script src="/js/scenario2_Polling.js"></script>
</head>
<body class="win-type-body">
<div>
<p>Polls for orientation sensor data and displays the rotation data at a set interval.</p>
<button class="action win-button" id="scenario2Open">Enable</button>
<button class="action secondary win-button" id="scenario2Revoke">Disable</button>
<br>
<br> Quaternion: <a id="readingOutputQuaternion" class="win-link">no data</a>
<br> Rotation Matrix: <a id="readingOutputRotationMatrix" class="win-link">no data</a>
<br> Yaw Accuracy: <a id="eventOutputYawAccuracy" class="win-link">no data</a>
<br>
</div>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Polling</div>
<p>Polls for orientation sensor data and displays the rotation data at a set interval.</p>
<p>
<button class="win-button" id="scenarioEnable" disabled>Enable</button>
<button class="win-button" id="scenarioDisable" disabled>Disable</button>
</p>
<p id="output">no data</p>
</body>
</html>

Просмотреть файл

@ -6,28 +6,29 @@ Copyright (c) Microsoft Corporation. All rights reserved
<head>
<title></title>
<link rel="stylesheet" href="/css/scenario3_Calibration.css">
<script src="/js/scenario3_Calibration.js"></script>
<script src="/js/calibrationBar.js"></script>
</head>
<body class="win-type-body">
<div>
<p>Simulates the current sensor accuracy. Setting to &apos;Unreliable&apos; will invoke the calibration bar until accuracy improves or 30 seconds passes. The calibration bar will not be shown again for at least 5 minutes, even when accuracy returns
to &apos;Unreliable&apos;.</p>
<p>Yaw accuracy: </p>
<input type="radio" id="accuracyHighRadio" name="accuracyRadio" class="win-radio">
<label for="accuracyHigh">High</label>
<h2 id="sampleHeader" class="win-type-subheader">Description:</h2>
<div id="scenarioDescription">Calibration</div>
<p>Simulates the current sensor accuracy. Setting to Unreliable will invoke the calibration bar until accuracy improves or 30 seconds passes. The calibration bar will not be shown again for at least 5 minutes, even when accuracy returns
to Unreliable.</p>
<p>Yaw accuracy:</p>
<p>
<input type="radio" id="accuracyHighRadio" name="accuracyRadio" class="win-radio" checked>
<label for="accuracyHighRadio">High</label>
<br>
<input type="radio" id="accuracyApproximateRadio" name="accuracyRadio" class="win-radio">
<label for="accuracyApproximate">Approximate</label>
<label for="accuracyApproximateRadio">Approximate</label>
<br>
<input type="radio" id="accuracyUnreliableRadio" name="accuracyRadio" class="win-radio">
<label for="accuracyUnreliable">Unreliable</label>
<br>
</div>
<label for="accuracyUnreliableRadio">Unreliable</label>
</p>
<div id="calibrationBarControl" data-win-control="CalibrationControls.CalibrationBar">
</div>
</div>
</body>
</html>

Просмотреть файл

Просмотреть файл

@ -5,14 +5,60 @@
var sampleTitle = "Orientation Sensor";
var MagnetometerAccuracy = Windows.Devices.Sensors.MagnetometerAccuracy;
var scenarios = [
{ url: "/html/scenario1_DataEvents.html", title: "Data Events" },
{ url: "/html/scenario2_Polling.html", title: "Polling" },
{ url: "/html/scenario3_Calibration.html", title: "Calibration" }
];
function setReadingText(e, reading) {
var quaternion = reading.quaternion; // get a reference to the object to avoid re-creating it for each access
var quaternionReport = "W: " + quaternion.w.toFixed(2) +
", X: " + quaternion.x.toFixed(2) +
", Y: " + quaternion.y.toFixed(2) +
", Z: " + quaternion.z.toFixed(2);
var rotationMatrix = reading.rotationMatrix;
var rotationMatrixReport = "M11: " + rotationMatrix.m11.toFixed(2) +
", M12: " + rotationMatrix.m12.toFixed(2) +
", M13: " + rotationMatrix.m13.toFixed(2) +
"\nM21: " + rotationMatrix.m21.toFixed(2) +
", M22: " + rotationMatrix.m22.toFixed(2) +
", M23: " + rotationMatrix.m23.toFixed(2) +
"\nM31: " + rotationMatrix.m31.toFixed(2) +
", M32: " + rotationMatrix.m32.toFixed(2) +
", M33: " + rotationMatrix.m33.toFixed(2);
var yawAccuracyReport;
switch (reading.yawAccuracy) {
case MagnetometerAccuracy.unknown:
yawAccuracyReport = "unknown";
break;
case MagnetometerAccuracy.unreliable:
yawAccuracyReport = "unreliable";
break;
case MagnetometerAccuracy.approximate:
yawAccuracyReport = "approximate";
break;
case MagnetometerAccuracy.high:
yawAccuracyReport = "high";
break;
default:
yawAccuracyReport = "other";
break;
}
e.innerText = "Quaternion:\n" + quaternionReport + "\n\n" +
"Rotation Matrix:\n" + rotationMatrixReport + "\n\n" +
"Yaw Accuracy:\n" + yawAccuracyReport;
}
WinJS.Namespace.define("SdkSample", {
sampleTitle: sampleTitle,
scenarios: new WinJS.Binding.List(scenarios)
scenarios: new WinJS.Binding.List(scenarios),
setReadingText: setReadingText
});
})();

Просмотреть файл

@ -2,33 +2,32 @@
(function () {
"use strict";
var reportInterval = 0;
var sensor;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var output;
var page = WinJS.UI.Pages.define("/html/scenario1_DataEvents.html", {
ready: function (element, options) {
document.getElementById("scenario1Open").addEventListener("click", enableReadingChangedScenario, false);
document.getElementById("scenario1Revoke").addEventListener("click", disableReadingChangedScenario, false);
document.getElementById("scenario1Open").disabled = false;
document.getElementById("scenario1Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
output = document.getElementById("output");
scenarioEnable.addEventListener("click", enableReadingChangedScenario, false);
scenarioDisable.addEventListener("click", disableReadingChangedScenario, false);
sensor = Windows.Devices.Sensors.OrientationSensor.getDefault();
if (sensor) {
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
var minimumReportInterval = sensor.minimumReportInterval;
reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No orientation sensor found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario1Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
sensor.removeEventListener("readingchanged", onDataChanged);
// Return the report interval to its default to release resources while the sensor is not in use
sensor.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableReadingChangedScenario();
}
}
});
@ -36,7 +35,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario1Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
sensor.addEventListener("readingchanged", onDataChanged);
@ -48,79 +47,27 @@
}
function onDataChanged(e) {
var reading = e.reading;
// event can still be in queue after unload is called
// so check if elements are still loaded
// Quaternion values
if (document.getElementById("eventOutputQuaternion")) {
var quaternion = reading.quaternion; // get a reference to the object to avoid re-creating it for each access
document.getElementById("eventOutputQuaternion").innerHTML =
"W: " + quaternion.w.toFixed(6)
+ " X: " + quaternion.x.toFixed(6)
+ " Y: " + quaternion.y.toFixed(6)
+ " Z: " + quaternion.z.toFixed(6);
}
// Rotation Matrix values
if (document.getElementById("eventOutputRotationMatrix")) {
var rotationMatrix = reading.rotationMatrix;
document.getElementById("eventOutputRotationMatrix").innerHTML =
"M11: " + rotationMatrix.m11.toFixed(6)
+ " M12: " + rotationMatrix.m12.toFixed(6)
+ " M13: " + rotationMatrix.m13.toFixed(6)
+ " M21: " + rotationMatrix.m21.toFixed(6)
+ " M22: " + rotationMatrix.m22.toFixed(6)
+ " M23: " + rotationMatrix.m23.toFixed(6)
+ " M31: " + rotationMatrix.m31.toFixed(6)
+ " M32: " + rotationMatrix.m32.toFixed(6)
+ " M33: " + rotationMatrix.m33.toFixed(6);
}
// Yaw accuracy
if (document.getElementById("eventOutputYawAccuracy")) {
switch (e.reading.yawAccuracy) {
case Windows.Devices.Sensors.MagnetometerAccuracy.unknown:
document.getElementById("eventOutputYawAccuracy").innerHTML = "unknown";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.unreliable:
document.getElementById("eventOutputYawAccuracy").innerHTML = "unreliable";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.approximate:
document.getElementById("eventOutputYawAccuracy").innerHTML = "approximate";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.high:
document.getElementById("eventOutputYawAccuracy").innerHTML = "high";
break;
default:
document.getElementById("eventOutputYawAccuracy").innerHTML = "no data";
break;
}
}
SdkSample.setReadingText(output, e.reading);
}
function enableReadingChangedScenario() {
if (sensor) {
// Set the reportInterval to enable the sensor events
sensor.reportInterval = reportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
sensor.reportInterval = Math.max(sensor.minimumReportInterval, 16);
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
sensor.addEventListener("readingchanged", onDataChanged);
document.getElementById("scenario1Open").disabled = true;
document.getElementById("scenario1Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No orientation sensor found", "sample", "error");
}
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
sensor.addEventListener("readingchanged", onDataChanged);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableReadingChangedScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
sensor.removeEventListener("readingchanged", onDataChanged);
document.getElementById("scenario1Open").disabled = false;
document.getElementById("scenario1Revoke").disabled = true;
// Return the report interval to its default to release resources while the sensor is not in use
sensor.reportInterval = 0;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -2,34 +2,33 @@
(function () {
"use strict";
var reportInterval = 0;
var intervalId = 0;
var sensor;
// DOM elements
var scenarioEnable;
var scenarioDisable;
var output;
var page = WinJS.UI.Pages.define("/html/scenario2_Polling.html", {
ready: function (element, options) {
document.getElementById("scenario2Open").addEventListener("click", enableGetReadingScenario, false);
document.getElementById("scenario2Revoke").addEventListener("click", disableGetReadingScenario, false);
document.getElementById("scenario2Open").disabled = false;
document.getElementById("scenario2Revoke").disabled = true;
scenarioEnable = document.getElementById("scenarioEnable");
scenarioDisable = document.getElementById("scenarioDisable");
output = document.getElementById("output");
scenarioEnable.addEventListener("click", enableGetReadingScenario, false);
scenarioDisable.addEventListener("click", disableGetReadingScenario, false);
sensor = Windows.Devices.Sensors.OrientationSensor.getDefault();
if (sensor) {
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
// This value will be used later to activate the sensor.
var minimumReportInterval = sensor.minimumReportInterval;
reportInterval = minimumReportInterval > 16 ? minimumReportInterval : 16;
scenarioEnable.disabled = false;
} else {
WinJS.log && WinJS.log("No orientation sensor found", "sample", "error");
}
},
unload: function () {
if (document.getElementById("scenario2Open").disabled) {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
clearInterval(intervalId);
// Return the report interval to its default to release resources while the sensor is not in use
sensor.reportInterval = 0;
if (!scenarioDisable.disabled) {
disableGetReadingScenario();
}
}
});
@ -37,7 +36,7 @@
function visibilityChangeHandler() {
// This is the event handler for VisibilityChanged events. You would register for these notifications
// if handling sensor data when the app is not visible could cause unintended actions in the app.
if (document.getElementById("scenario2Open").disabled) {
if (!scenarioDisable.disabled) {
if (document.msVisibilityState === "visible") {
// Re-enable sensor input. No need to restore the desired reportInterval (it is restored for us upon app resume)
intervalId = setInterval(getCurrentReading, reportInterval);
@ -51,69 +50,34 @@
function getCurrentReading() {
var reading = sensor.getCurrentReading();
if (reading) {
// Quaternion values
var quaternion = reading.quaternion; // get a reference to the object to avoid re-creating it for each access
document.getElementById("readingOutputQuaternion").innerHTML =
"W: " + quaternion.w.toFixed(6)
+ " X: " + quaternion.x.toFixed(6)
+ " Y: " + quaternion.y.toFixed(6)
+ " Z: " + quaternion.z.toFixed(6);
// Rotation Matrix values
var rotationMatrix = reading.rotationMatrix;
document.getElementById("readingOutputRotationMatrix").innerHTML =
"M11: " + rotationMatrix.m11.toFixed(6)
+ " M12: " + rotationMatrix.m12.toFixed(6)
+ " M13: " + rotationMatrix.m13.toFixed(6)
+ " M21: " + rotationMatrix.m21.toFixed(6)
+ " M22: " + rotationMatrix.m22.toFixed(6)
+ " M23: " + rotationMatrix.m23.toFixed(6)
+ " M31: " + rotationMatrix.m31.toFixed(6)
+ " M32: " + rotationMatrix.m32.toFixed(6)
+ " M33: " + rotationMatrix.m33.toFixed(6);
// Yaw accuracy
switch (reading.yawAccuracy) {
case Windows.Devices.Sensors.MagnetometerAccuracy.unknown:
document.getElementById("eventOutputYawAccuracy").innerHTML = "unknown";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.unreliable:
document.getElementById("eventOutputYawAccuracy").innerHTML = "unreliable";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.approximate:
document.getElementById("eventOutputYawAccuracy").innerHTML = "approximate";
break;
case Windows.Devices.Sensors.MagnetometerAccuracy.high:
document.getElementById("eventOutputYawAccuracy").innerHTML = "high";
break;
default:
document.getElementById("eventOutputYawAccuracy").innerHTML = "no data";
break;
}
SdkSample.setReadingText(output, reading);
}
}
function enableGetReadingScenario() {
if (sensor) {
// Set the report interval to enable the sensor for polling
sensor.reportInterval = reportInterval;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
var reportInterval = Math.max(sensor.minimumReportInterval, 16);
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
intervalId = setInterval(getCurrentReading, reportInterval);
document.getElementById("scenario2Open").disabled = true;
document.getElementById("scenario2Revoke").disabled = false;
} else {
WinJS.log && WinJS.log("No orientation sensor found", "sample", "error");
}
// Set the report interval to enable the sensor for polling
sensor.reportInterval = reportInterval;
document.addEventListener("visibilitychange", visibilityChangeHandler, false);
intervalId = setInterval(getCurrentReading, reportInterval);
scenarioEnable.disabled = true;
scenarioDisable.disabled = false;
}
function disableGetReadingScenario() {
document.removeEventListener("visibilitychange", visibilityChangeHandler, false);
clearInterval(intervalId);
document.getElementById("scenario2Open").disabled = false;
document.getElementById("scenario2Revoke").disabled = true;
intervalId = 0;
// Return the report interval to its default to release resources while the sensor is not in use
sensor.reportInterval = 0;
scenarioEnable.disabled = false;
scenarioDisable.disabled = true;
}
})();

Просмотреть файл

@ -3,27 +3,28 @@
(function () {
"use strict";
// DOM elements
var calibrationBarControl;
var page = WinJS.UI.Pages.define("/html/scenario3_Calibration.html", {
ready: function (element, options) {
calibrationBarControl = document.getElementById("calibrationBarControl");
document.getElementById("accuracyHighRadio").addEventListener("click", onAccuracyHigh, false);
document.getElementById("accuracyApproximateRadio").addEventListener("click", onAccuracyApproximate, false);
document.getElementById("accuracyUnreliableRadio").addEventListener("click", onAccuracyUnreliable, false);
document.getElementById("accuracyHighRadio").checked = "true";
},
unload: function () {
}
});
function onAccuracyHigh() {
document.getElementById("calibrationBarControl").winControl.hide();
calibrationBarControl.winControl.hide();
}
function onAccuracyApproximate() {
document.getElementById("calibrationBarControl").winControl.hide();
calibrationBarControl.winControl.hide();
}
function onAccuracyUnreliable() {
document.getElementById("calibrationBarControl").winControl.requestCalibration(Windows.Devices.Sensors.MagnetometerAccuracy.unreliable);
calibrationBarControl.winControl.requestCalibration(Windows.Devices.Sensors.MagnetometerAccuracy.unreliable);
}
})();

Просмотреть файл

@ -1,4 +1,4 @@
<!--
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
@ -17,11 +17,9 @@
x:Class="SDKTemplate.CalibrationBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SDKTemplate"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<UserControl.Resources>
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
@ -130,4 +128,4 @@
</Grid>
</Border>
</Popup>
</Page>
</Page>

Просмотреть файл

@ -0,0 +1,32 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page
x:Class="SDKTemplate.Scenario1_DataEvents"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Data events"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Registers an event listener for orientation sensor data and displays the rotation data as it is reported."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock x:Name="ScenarioOutput" Margin="0,10,0,0" Text="no data"/>
</StackPanel>
</ScrollViewer>
</Page>

Просмотреть файл

@ -0,0 +1,32 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page
x:Class="SDKTemplate.Scenario2_Polling"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ScrollViewer Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Polling"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Polls for orientation sensor data and displays the rotation data at a set interval."/>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Button x:Name="ScenarioEnableButton" Content="Enable" Margin="0,0,10,0" Click="{x:Bind ScenarioEnable}" IsEnabled="False"/>
<Button x:Name="ScenarioDisableButton" Content="Disable" Margin="0,0,10,0" Click="{x:Bind ScenarioDisable}" IsEnabled="False"/>
</StackPanel>
<TextBlock x:Name="ScenarioOutput" Margin="0,10,0,0" Text="no data"/>
</StackPanel>
</ScrollViewer>
</Page>

Просмотреть файл

@ -0,0 +1,34 @@
<!--
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
-->
<Page
x:Class="SDKTemplate.Scenario3_Calibration"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="12,10,12,12">
<StackPanel>
<TextBlock Text="Description:" Style="{StaticResource SampleHeaderTextStyle}"/>
<TextBlock Style="{StaticResource ScenarioDescriptionTextStyle}" Text="Calibration"/>
<TextBlock TextWrapping="Wrap" Margin="0,10,0,0" Text="Simulates the current sensor accuracy. Setting to 'Unreliable' will invoke the calibration bar until accuracy improves or 30 seconds passes. The calibration bar will not be shown again for at least 5 minutes, even when accuracy returns to 'Unreliable'."/>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Left" Text="Yaw Accuracy:"/>
<RadioButton Content="High" Click="{x:Bind OnHighAccuracy}" IsChecked="True"/>
<RadioButton Content="Approximate" Click="{x:Bind OnApproximateAccuracy}"/>
<RadioButton Content="Unreliable" Click="{x:Bind OnUnreliableAccuracy}"/>
</StackPanel>
</StackPanel>
</Grid>
</Page>