Archive for March 2015
In the previous post we started to discuss features and approaches to build Universal Applications. I am going to show that already today you may build applications which will be ready for Windows 10. And today we are going to discuss XAML.
Full Screen and Snap mode
When Microsoft introduced Windows 8, Windows Runtime and Modern UI patterns, there were three things which developers needed to know about applications: all Modern UI applications work in full screen mode; 1024×768 is minimal supported resolution for Windows 8 devices; for resolutions 1360×768 and more Windows 8 allows to show applications in Snap mode with fixed width in 320 pixels. Based on these assumptions many developers designed interfaces for their applications in 1024×768 resolution using these parameters like minimal amount of available space for application. In case of Snap mode, many developers ignored it and tried to avoid to design something for 320×768 resolution. Frankly speaking I didn’t like Snap mode as well. Usually I showed a message like this: “Application doesn’t work in Snap mode. Please, move the application to Full screen mode to continue”. This messages helped me to pass certification.
But everything is changing and Windows 8.1 added some more pixels to Snap mode. Today, default width of Snap mode for Windows 8.1 is 500 pixels. This amount is harder to ignore and that’s more important – Windows 10 allows to run Modern UI applications in window mode like legacy desktop applications.
So, if you are going to create the best UX in your application you should think about different resolutions in advance. Windows 8.1 already doesn’t support events which let the user see that application is in Snap mode, instead, Windows proposes the SizeChanged event. This event is related to Page and you can easy get access to page width and height in order to understand the current size and change layout according to it. The event handler can look like this:
void Page_SizeChanged(object sender, SizeChangedEventArgs e)
if (e.NewSize.Width <= 500)
. . . .
else if (e.NewSize.Width < 1024)
. . . .
. . . .
So in order to guarantee the best UX in Windows 10 you should think about smaller resolutions. But there is a trick: if you already implement application’s layouts for small resolutions, can you apply it for Windows Phone application – I believe, so.
Therefore, in case of XAML and layouts you can think about resolutions only because both platforms support almost the same set of controls.
Right now, we are ready to change layouts depending on width of the window. So, it’s time to think how to make it.
The best way to change layouts is using ViewStateManager there. You can use it in XAML to define different visual state groups. Each group can contain Storyboard with animations inside. You can use these animations to hide or show some controls, change ItemTemplate, change controls’ properties etc. It’s easy to declare several groups for different resolutions and, thanks to animations, specify different look for each layout.
. . . .
. . . .
. . . .
As I mentioned before, you can change Visability properties, assign new ItemTemplate value etc.
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
Onc, you defined all needed visual states, you can implement code, which allows to change visual state based on windows size. You can do it in SizeChanged event handler using this line of code:
VisualStateManager.GoToState(this, "Layout500", true);
I believe that we can finish for today but I am going to continue the series and next time we will discuss DPIs and images.
During Global Developer Conference there were many announcements like Unity 5 availability for free. Of course, Unity has been offering a free version of the editor for many years but it was an editor without many important features. For example it was not possible to use external libraries in free version of the editor. It was the main stopper for many educational projects like projects related to Kinect. From one side we have a very cool solution like Kinect, which researches can use in many interesting projects but from other side, it’s very hard to develop something using DirectX directly. Unity might save the situation but Kinect SDK worked with Pro version only.
But Unity decided to change business model and announced that since Unity 5 there is Personal Edition, which contains all features.
Of course, I decided to return to my projects with Kinect and tried to rebuild some of them using the Unity 5 Personal. And there is great news – everything works fine! So the last stopper was broken and today you can try to use Kinect and Unity for free.
If you are interested in the topic I would recommend to use my previous article about Kinect as an instruction how to start.
Several Days ago Microsoft made a first look at Windows 10 App platform. Of course, it’s great to have one developer platform and one core but we still have two months before Build. Therefore, many developers wonder, if they can do something right now to be ready for Windows 10. That’s why I decided to make a series of posts about Universal Applications to help developers start porting their applications right now. In order to do it I am going to describe several topics, which are most important for Universal application development for Windows 8.1 and Windows Phone 8.1. So, let’s start with templates and directives.
Universal Apps Template
Since Windows Phone 8.1 announcement developers got a chance to use Windows Runtime for both platforms. It allows to use the same application model, the same set of controls, the same async/await patterns etc. Of course, there was partial support for Windows Runtime since Windows Phone 8.0 but there was no chance to forget Silverlight and use Windows Runtime only. Windows Phone 8.1 brought Windows Runtime to the new level and developers may forget about Silverlight.
Therefore, developers got a chance to develop applications for both platforms with minimum amount of work. Of course, you still need to compile your application for Windows Phone and Windows separately and you need to upload two (or more) packages to the Store but, in many cases, you may use the same code and it relates not just to business logic but to interface as well.
In order to help developers get better experience there, Microsoft introduced Universal Apps template in Visual Studio (Visual Studio 2013 Update 3 and later), which helps to create applications for both platforms at the same time.
In fact, when you are creating applications using this template, Visual Studio is creating three projects: Windows Phone project, Windows 8 project and Shared project.
The idea is very simple. All things that you are adding to the Shared Project will be precompiled to Windows and Windows Phone projects. Therefore you can put there common resources, business logic and XAML pages, if you believe that they are common for both projects.
Many developers believe that it’s all that you need to know about existing Universal Apps template and that the best way to make universal applications is creating business logic in a Shared project and different pages for Windows Phone and Windows. But this is not true and this approach will not help you to be ready for Windows 10.
If you are going to make real Universal applications you need to know how to build universal pages and page logic as well. So, I will start with directives, which should help you to tune your code for different platforms.
Of course, Windows Phone and Windows 8 have some differences. For example, Windows Phone supports just buttons and menu items in applications bar but Windows can present any containers there; Windows Phone contains hardware or software emulated back button but Windows doesn’t and so on. So, from time to time you need to create code snippets just for Windows Phone or Windows. You can do it using #if…#endif directive. It’s possible thanks to WINDOWS_APP and WINDOWS_PHONE_APP constants. Of course you can define your own constants but I recommend to use these ones because it should be clear for many developers and Visual Studio Intellisense mode already supports possibility to switch between two platforms based on these constants.
So, if you are going to create platform specific code, you can use the following lines:
Next time I am going to discuss common XAML pages for both platforms.
In one of my articles about Galileo I showed how to run a simple DC motor using L293D chip. But it’s not very interesting because if you are going to build your own robot or drone, you need to use more powerful motors. For example, I have a dream: I want to build my own drone using boards like Galileo or Netduino. So, I decided to start my research with the most expensive part of drones – motor system. I already printed several propellers using my 3D printer, so I wanted to reach two goals: test the printed propellers to understand, if I can use them; understand, how to use Netduino or Galileo boards to operate more powerful motor.
If you are going to build your own drone you need several multirotor brushless motors. It’s very important because motor should work in both directions to guarantee stability of the drone and you should have a way to regulate speed to move drone in 3D space. Additionally you need to buy ESC (electronic speed controller), which will help to operate the motor. It’s kind of like more advanced version of L293D chip. Finally you need a battery. Because your motor should be powerful and you need 4-6 motors there (I decided to use 6), you cannot use a simple 9V battery – you should use lithium polymer and a charger for your LiPo battery as well. All these things are not very cheap and you need to spend more than 150 dollars in order to buy everything but don’t worry, because it’s the most expensive part of the drone.
Finally I bought the following things:
· 1000 Kv brushless motor + 30A ESC – I bought 6 motors and 6 ESC;
· 5100 mAh IRIS+ battery – It’s a very powerful battery, which is used by IRIS drone;
· A charger – there many different charges in the market, so you can select the cheapest one;
Once I got my package I spent much time to run the motor. It was not easy because you should understand which signals to send ESC to start moving. In my case I got ESC without any instructions, model number etc. So, I tried to use the standard procedure to initialize it:
Attention: ESC has three wires, which you connect to your board (ground, signal and power). Don’t connect red wire (power) to your board. ESC doesn’t require additional power because it’s enough power from LiPo battery. Officially you can use it in order to send some power to your board (or fly controller) but I still didn’t test it.
· First of all, you should setup your ESC. In order to do it you need to send the highest power signal from ESC range and plugin you ESC to power (LiPo). Your ESC should initialize the highest number and finish it with one beep;
· Once you have heard ESC beep you should send the lowest signal. If you are using your ESC for the second time you need to send the lowest signal before you connect ESC to LiPo. If everything is OK, your ESC will send several beeps, which are signals about number of cells in your battery;
· If everything is OK, you can start to send different signals inside your range in order to operate your motor;
Attention. ESC has three wires which you should connect to the motor wires. You can use any sequence. Depends on sequence, the motor will operate in different directions.
The procedure looks very simple but there are still several questions. For example, it is not clear, which signal I should send to ESC and how to setup your PWM pin in order to send the right signals.
Attention. In order to send signals to ESC you should use PMW signals. In case of Galileo, all PMW are marked by “~”. In case of Netduino 2 Plus you can use pins 3,5,6,9,10,11.
Officially you can use Servo library for Galileo and find the similar library for Netduino. I tried to use this approach but my ESC just sent beep-beep-beep… signals without any results (these beeps say that signals from the board are not in the range). So, I decided to forget about standard libraries and use PMW directly. Finally I found the following parameters for PMW constructor in .NET Micro Framework:
· High signal – PWM(PWMChannels.PWM_PIN_D5, 20000, 1750, PWM.ScaleFactor.Microseconds, false);
· Low signal – PWM(PWMChannels.PWM_PIN_D5, 20000, 1250, PWM.ScaleFactor.Microseconds, false);
So, in order to initialize my PMW I just use these lines of code in debug mode. I send high signal, stop execution (using breakpoint) there and attach my LiPo battery. Once the motor sent the right signal I executed the second command.
In order to test my motor I connected a joystick to my board and implemented the following code:
public static void Main()
AnalogInput an1 = new AnalogInput(AnalogChannels.ANALOG_PIN_A0,1000,0,-1);
AnalogInput an2 = new AnalogInput(AnalogChannels.ANALOG_PIN_A1, 1000, 0, -1);
InputPort p = new InputPort(Pins.GPIO_PIN_D8,
PWM pwm = new PWM(Cpu.PWMChannel.PWM_0, 20000,
1750, PWM.ScaleFactor.Microseconds, false);
bool flag = false;
bool isStarted = false;
pwm.Duration = 1250;
pwm.Period = 20000;
isStarted = true;
uint duration = pwm.Duration;
if (duration > 1750) duration = 1750;
if (duration < 1250) duration = 1250;
pwm.Duration = duration;
pwm.Period = 20000;
if (p.Read() == false)
isStarted = false;
flag = false;
flag = true;
Thanks to that code I got a chance to turn on and turn off my motor using click, and speed up and down my motor using up and left directions of joystick (my joystick has been broken, so I could not use up and down).
Of course, in order to test the motor with a propeller, you should think about the right environment. First of all you should fix your motor. I made a mistake there, I used several bolts in order to fix my motor on top of the cardboard box. It didn’t stop my motor and it was trying to fly with a piece of the box. Thanks to Galaxy I am still alive but right now I am printing a new propeller. I still don’t understand why I decided that a cardboard box would stop the motor which should be able to get the drone up to the sky.