Presentation is loading. Please wait.

Presentation is loading. Please wait.

Win8 on Intel Programming Course Desktop : Sensors Cédric Andreolli Intel Software 2013-03-20.

Similar presentations


Presentation on theme: "Win8 on Intel Programming Course Desktop : Sensors Cédric Andreolli Intel Software 2013-03-20."— Presentation transcript:

1 Win8 on Intel Programming Course Desktop : Sensors Cédric Andreolli www.Intel-Software-Academic-Program.com paul.guermonprez@intel.com Intel Software 2013-03-20

2 Agenda

3 Sensors in desktop applications This part will introduce the sensors in desktop applications Enabling WinRT in WPF applications A quick “how to” that shows the steps needed to enable WinRT API in WPF applications Programming the Sensors An example that will show how to use the sensors in your desktop applications

4 Sensors in Desktop applications

5 Sensors in desktop applications Why do we need the sensors? Desktop applications represent the biggest part of todays applications A lot of applications can’t run in Modern UI because of native libraries dependencies How to access the sensors in desktop applications ? Sensors can be programmed with the win32 API but… It is complicated…

6 Sensors in desktop applications And what about the WinRT API? WinRT is way simpler than win32… And WinRT can be enabled in C# but we must change some configuration files to access it! Desktop Applications can use the sensors through WinRT but Visual Studio need some configuration

7 Enabling WinRT in WPF applications

8 Enabling WinRT in WPF apps Create a new WPF project Create also a new solution and name your project “HelloWorld”

9 Enabling WinRT in WPF apps Set up the environment Right now, WinRT is not available, you can’t add the reference to WinRT (You can look for it in References -> Add but you won’t find it)

10 Enabling WinRT in WPF apps How can we reference it? By default, WinRT is available for applications that target Windows 8 Store. This information can be added in the.csproj file Open the file HelloWorld.csproj This file is in your Visual Studio project directory (Documents\Visual Studio 2012\Projects\WPF\HelloWorld)

11 Enabling WinRT in WPF apps Add the target (Version 1) You can add the TargetPlatformVersion in an existing PropertyGroup

12 Enabling WinRT in WPF apps Add the target (Version 2) You can create a PropertyGroup This is the best solution because all your project can access this property

13 Enabling WinRT in WPF apps Reload the project Go back in Visual Studio, you should see: Click on Reload All

14 Enabling WinRT in WPF apps Add the reference In the Solution Explorer, right click on References -> Add References… On the left, select Windows -> Core and check Windows

15 Enabling WinRT in WPF apps Add the reference Click on OK Congratulations, WinRT is Linked! WinRT can be linked by specifying Windows 8 as target for our application

16 Enabling WinRT in WPF apps …but we are not done The devices are available right now but the devices event handlers can’t be used If you try to use it:

17 Enabling WinRT in WPF apps Add the Runtime DLL Some runtime DLL are missing You can find those DLL in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5 The files are: System.Runtime.dll System.Runtime.InteropServices.WindowsRuntime.dll Right click on your project’s name and select Add References…

18 Enabling WinRT in WPF apps Add the Runtime DLL To access WinRT you must also link 2 DLLs (Runtime and InteropServices)

19 Programming the sensors

20 Project settings A part of sensor programming for desktop is similar to sensor programming for Windows Store applications Create a WPF window as follow

21 Programming the sensors Project settings Add name properties for each of your Textbox In the next slides, the Textboxes will be called accX, accY and accZ Create an accelerometer Open the C# file and add

22 Programming the sensors Solve missing references The class Accelerometer is unkown, in the C# editor, right click on it, select Resolve and click on the first option

23 Programming the sensors Retrieve a valid accelerometer As in Windows Store Applications, use the Windows.Devices.Sensors.Accelerometer.GetDefault() method to retrieve a valid accelerometer

24 Programming the sensors Add a handler Visual Studio can help you generating your handler Display auto-completion by pressing Ctrl+Tab Let Visual Studio add the handler by pressing Tab when the tooltip appear

25 Programming the sensors Add a handler Pressing Tab a second time will create the following function

26 Programming the sensors Sensors handlers If you try to access the UI elements in the handler, you will get troubles

27 Programming the sensors Sensors handlers The handler is launched by the sensor manager which doesn’t run on the UI thread This thread is not allowed to access UI elements How to solve this problem? WPF provides dispatchers that can send a job to the thread of a specific element Each UI control has a Dispatcher attribute

28 Programming the sensors Using a Dispatcher (version 1) A dispatcher can invoke a delegate

29 Programming the sensors Using a Dispatcher (version 2) Same code without the Action

30 Programming the sensors Run the program You should see the content of the Textbox change if your computer has an accelerometer Except for the thread managment, using the sensors in desktop applications is almost similar to Windows Store application

31 Conclusion

32 WinRT is available in desktop applications Using WinRT offers an easy way to access interesting features in Windows desktop application You just need to specify the target and to reference 2 DLLs Sensors programming Programming the sensors is not difficult in desktop applications You just need to resolve the thread troubles

33

34 License Creative Commons – By 3.0 You are free: to Share — to copy, distribute and transmit the work to Remix — to adapt the work to make commercial use of the work Under the following conditions: Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). With the understanding that: Waiver — Any of the above conditions can be waived if you get permission from the copyright holder. Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. Other Rights — In no way are any of the following rights affected by the license: – Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; – The author's moral rights; – Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page. http://creativecommons.org/licenses/by/3.0/


Download ppt "Win8 on Intel Programming Course Desktop : Sensors Cédric Andreolli Intel Software 2013-03-20."

Similar presentations


Ads by Google