Jimmy Engström

NAVIGATION - SEARCH

Universal apps and NotificationsExtensions - Toasts (Part 3)

Here is how to handle toasts the easy way in Universal apps.

First add the “NotificationsExtensions.UniversalApps” Nuget package.

See blog post showing how.

Toast templates:
http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx

It is possible to send any toast template to Windows Phone 8.1 but it will always be shown as an modified version of ToastText02.

You can add a Toast notification like this:

IToastText02 toastContent = ToastContentFactory.CreateToastText02();
toastContent.TextHeading.Text = "Tosty!";
toastContent.TextBodyWrap.Text = "Toasts, best invention since.. ehmm toast";

ScheduledToastNotification toast;
toast = new ScheduledToastNotification(toastContent.GetXml(), DateTime.Now.AddSeconds(10));
toast.Id = "SomeID";
ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);

Universal apps and NotificationsExtensions - Live Tiles (Part2)

Here is how to handle live tiles the easy way in Universal apps.

First add the “NotificationsExtensions.UniversalApps” Nuget package.

See blog post showing how.


Tile templates comparison:
http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx


This is how to update your tile with a scheduled update.

//Create wide tile update
ITileWide310x150Text09 tileContent = TileContentFactory.CreateTileWide310x150Text09();
tileContent.TextHeading.Text = "Wide Tile Text";
tileContent.TextBodyWrap.Text = "More text on the tile";

//Always add a 150x150 tile update also  
ITileSquare150x150Text04 squareContent = TileContentFactory.CreateTileSquare150x150Text04();
squareContent.TextBodyWrap.Text = "More text on the tile";
tileContent.Square150x150Content = squareContent;


ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), DateTime.Now.AddSeconds(15));
TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(futureTile);

 

To update your tile right away you can use these lines instead of the last two above:

TileNotification tileNotification=new TileNotification(tileContent.GetXml());
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

 

Recources

Microsofts code sample:

http://code.msdn.microsoft.com/Alarm-toast-notifications-fe81fc74#content

Nuget version

https://www.nuget.org/packages/NotificationsExtensions.UniversalApps/

Universal apps and NotificationsExtensions (Part 1)

 

This is a series of blog posts on how to do notifications in Universal apps.


Managing notifications can be a bit “tricky”, you need to edit xml (or write the xml as a string yourself).
Luckily Microsoft has provided an Universal app project in their sample code that helps with creating notifications, it uses nice interfaces and classes to create the notifications.
I took their help classes from the sample, compiled and uploaded it as a Nuget package to make it simple to do notifications.

Right click on the solution then choose “Manage Nuget packages for solution”

Search for NotificationsExtensions.UniversalApps, press install.

image

You need to make sure you add the package to both the Windows phone and the Windows Store project (you don’t need to add it to the shared project).

To be able to do notifications you also need to enable Toasts, open edit Package.appxmanifest in the Windows phone and Windows 8 project and set Toast capable to “yes”.

image

Now you are good to go!

Microsoft has made the tiles and toast templates available on both platforms (Awesome!), they may look a bit different, see links in each blog post:
Live Tiles

Toasts

 

Recources

Microsofts code sample:

http://code.msdn.microsoft.com/Alarm-toast-notifications-fe81fc74#content

Nuget version

https://www.nuget.org/packages/NotificationsExtensions.UniversalApps/

Download all the videos from Build 2014

Build 2014 was packed with announcements and fun stuff.
Still have a lot of videos to watch =)

Here is an updated version of my script I previously blogged about here.

cd "d:\build14"

$pattern = "[{0},\:,\']" -f ([Regex]::Escape([String][System.IO.Path]::GetInvalidPathChars()))             
$pattern
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$a = ([xml](new-object net.webclient).downloadstring("http://s.ch9.ms/Events/Build/2014/RSS/mp4high"))
$a.rss.channel.item | foreach{ 
    $url = New-Object System.Uri($_.enclosure.url)
    $file = [Regex]::Replace($_.Title + " " + $url.Segments[-1] , $pattern, ' ')
    $file
    if (!(test-path $file))
    {
            (New-Object System.Net.WebClient).DownloadFile($url, $file)
    }
}

 

Just copy the code, paste it into a file called “Build2014.ps1”, create a directory (in my case “d:\Build14”) and change the path in the first line of the script.

Right click on the file and choose run with PowerShell.

 

In case you get a problem similar like “Build2014.ps1 cannot be loaded because running scripts is disabled on this system.”

Start PowerShell as an administrator and run “set-executionpolicy unrestricted”, this is probably a bad thing to do for security.


Using Visual Studio 2013 as an external editor with Unity 3D

Unity is really hot right now.
Out of the box unity comes with MonoDevelop, even though I like MonoDevelop I like CodeRush even more, and I have noticed that MonoDevelop doesn't always do the things that I want.
The solution is of course to use Visual Studio instead.

1. Start unity and choose Edit –> Preferences…
2. Select External tools

In the External Script Editor drop down you may notice that Visual Studio 2013 is not part of the items.
(earlier versions will be available if you have them installed).

image


3. Choose browse… and browse to “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe”
Now “Microsoft Visual Studio 2013” will appear in the drop down and you are all set, from now on Visual Studio will launch when you edit script files.

 

image

Using RC API on Windows 8.1

This is a short blog post on how to get RC API working on your Windows 8.1 Device.

Setup

Download RCAPI from Nuget

image_thumb[1]

 

Bluetooth

To be able to communicate thru Bluetooth you need to edit Package.appxmanifest

Add the following lines:

<Capabilities>
    ....
    <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <m2:Function Type="name:serialPort" />
      </m2:Device>
    </m2:DeviceCapability>
  </Capabilities>

 

 

Pair with the device

Go into settings (win + c, Settings) , Change PC Settings, PC and Devices, Bluetooth

  image

 

The Car

Instantiate the car and you are good to go, the car class connects to the correct Bluetooth device automagically.

Ferrari458Italia ferrari = new Ferrari458Italia();

To start sending commands to the car you need to call the ConnectAsync method and call the Start method.

await ferrari.ConnectAsync();
ferrari.Start();

 

Controlling steering and speed

There are two properties controlling speed and steering.

Steering is –1 to 1 (left to right) and speed –1 to 1 (backward to forward).

In the sample projects I have used the Virtual Joystick project available on Codeplex for speed and steering, there is a modified version in the Windows Store sample project.

 

Controlling the lights

The lights are exposed through properties, to turn the light on use:

ferrari.HeadLightOn = true;

The lights available on the Ferrari 458 Italia is Headlights,blinkers (left and right) and break.

To get the lights to blink it is possible to supply an array with a light enum so if you want the blinkers to blink left

ferrari.LightSequence = new byte[] { (byte)LightEnum.LeftBlinker, 0 };

To get a more fun blinking sequence you might want to try something like this

ferrari.LightSequence = new byte[] { (byte)LightEnum.Head, (byte)LightEnum.RightBlinker, (byte)LightEnum.Break, (byte)LightEnum.LeftBlinker };

 

Trimmer

Trimmer property makes it possible to adjust the wheel orientation 0 to 15 and 8 is straight forward.

Using RC API on Windows Phone

This is a short blog post on how to get RC API working on your Windows Phone Device.

Setup

Download RCAPI from Nuget

image

 

Capabilities

To be able to communicate thru Bluetooth you need to enable ID_CAP_Proximity.

Open WMAppManifest.xml and make sure ID_CAP_Proximity is ticked.

  image

 

Pair with the device

Open Settings, Bluetooth and pair the phone with your device.

 

The Car

Instantiate the car and you are good to go, the car class connects to the correct Bluetooth device automagically.

Ferrari458Italia ferrari = new Ferrari458Italia();

To start sending commands to the car you need to call the ConnectAsync method and call the Start method.

await ferrari.ConnectAsync();
ferrari.Start();

 

Controlling steering and speed

There are two properties controlling speed and steering.

Steering is –1 to 1 (left to right) and speed –1 to 1 (backward to forward).

In the sample projects I have used the Virtual Joystick project available on Codeplex for speed and steering.

 

Controlling the lights

The lights are exposed through properties, to turn the light on use:

ferrari.HeadLightOn = true;

The lights available on the Ferrari 458 Italia is Headlights,blinkers (left and right) and break.

To get the lights to blink it is possible to supply an array with a light enum so if you want the blinkers to blink left

ferrari.LightSequence = new byte[] { (byte)LightEnum.LeftBlinker, 0 };

To get a more fun blinking sequence you might want to try something like this

ferrari.LightSequence = new byte[] { (byte)LightEnum.Head, (byte)LightEnum.RightBlinker, (byte)LightEnum.Break, (byte)LightEnum.LeftBlinker };

 

Trimmer

Trimmer property makes it possible to adjust the wheel orientation 0 to 15 and 8 is straight forward.

RC API now available

Backstory

For Christmas 2 years ago my mother-in-law got me a Silverlit Bluetooth car.

Sadly it was a MFI device (Made for iPhone) and it seems to be more or less impossible to connect to an MFI-device without an iPhone (if someone has more info on this please let me know).

After talking to Silverlit, trying to convince them to share the protocol I got a Silverlit Ferrari 458 Italia (for android) and managed to figure out how the protocol worked.

RC API is an open source project on Codeplex which currently support controlling the Silverlit Ferrari 458 Italia from Windows 8.1 and Windows phone 8.

 

How to use

Windows 8.1

Windows phone

 

The future

I hope to be able to add more veichles and helicopters to the API, please let me know (or contribute) what you want me too add =D


If you are an RC device manufacturer and would like to include your device in the API, please let me know and I’ll make it happen.
Making the API I have used inspiration from the Lego EV3 codeplex project, I liked how they solved Bluetooth communication and I decided to do it basically the same way.

Source code for RC API is available on Codeplex and also available as a nuget package.

 

Let’s bring more gadgets and RC-stuff to the Windows platforms =D

Developer Christmas list

Here is my take on what is the most exciting products for the 2013 Christmas.
Some are available and some will be available early 2014, I mention these cause they are so awesome it could be worth the wait.
For those who know me, wait isn't what I do best so I feel your pain and I am sorry, I just had to include them.

 

Lumia 1520

6” Screen, 20 MP camera, enough said =)

http://www.nokia.com/global/products/phone/lumia1520/

 

Xbox One

If you live in a country that gets the Xbox One in the first batch, I guess it won't be on any Christmas list cause you already should have bought it :D
For those (like me) who live in a country that is not included in the first batch there might still be time to import one :)


Lego Mindstorms EV3

There is no age restrictions for Lego, this is a really awesome product.
It has motors, sensors and you can build almost anything.
The best part is that there is a .net library so you can build your own apps.

LEGO.com Mindstorms

http://legoev3.codeplex.com/

Raspberry Pi

A micro computer that runs Linux. It has everything you might need, Ethernet, hdmi, USB, audio and controllable pins you can use to connect to other things.
Since it runs on Linux, Mono can be used to develop for it.

http://www.raspberrypi.org/


Agent Smartwatch

A wristwatch capable of running .net Micro framework code (how awesome is that?), much like the S.P.O.T watch back in the day.
As far as I understand they won't ship until after Christmas bit there is an SDK already available so start coding :)

http://agentwatches.com/


.NET Gadgeteer

Speaking of .NET micro framework, this is a fast prototyping kit, that makes building basically any electronics really easy.
It has standardized connectors that means you don't have to know any electronics. It is really simple to get going.

https://www.ghielectronics.com/catalog/category/265


Myo

A gesture controlled arm and, you can control your electronics by using gestures.
Becoming a Jedi is no longer a dream.
I have no idea how the development environment looks like, still want one.

https://www.thalmic.com/en/myo/


Nymi

It can use unique cardiac rhythm to authenticate your identity, allowing you to wirelessly take control of your computer, your smartphone, your car and so much more.

http://www.getnymi.com/


Kinect 2 for Windows

The new Kinect is even more sensitive than the first generation, it can even read your heartbeat *mind blown*.
I think wearable tech is the next big thing, but lets face it, tech you don't even have to wear is even cooler.

http://www.microsoft.com/en-us/kinectforwindows/ (this is still the old one)

 

Leap Motion

All devices that makes it possible to control your computer is always fun.
The leap motion can track your fingers and also other objects like pens and such.

https://www.leapmotion.com/


Anki

This is a racing track that connects to your iOS device (iPhone/iPad) using Bluetooth, the cars will drive around that track themselves but you control speed, lane and weapons. Yes weapons.
Real cars and real track but software shields and weapons *bummer*.
All the logic is in the iOS app and you can "upgrade" the cars with shields and new weapons.
If you shoot a car it will derail.
Very cool stuff so if you have an iPhone or iPad this is probably the must by Christmas gift this year.

http://anki.com/

 

If you don't find anything on the list or if you have a husband or wife that share my love for not waiting (eg already have or have ordered most of this stuff) you might consider printing your own.


3D Printer

There are many 3D printer out there. I like the cube 2, it is small and so is (sadly) the printing size. But it is large enough, the alternatives (having a reeeeally large one) isn't that appealing.
If you have trouble convincing your wife about a 3D printer, show her that it is possible to print chocolate :P
Besides that, Windows 8.1 has build in support for 3D Printers.

http://cubify.com/

http://makerbot.com/

Building your own Lego Mindstorms EV3 Windows Phone app

I just love gadgets, especially those I can develop for.

I recently got the Lego Mindstorms EV3-kit and of course I wanted to make a Windows Phone app to control it =D.
Here is a tutorial on how to make your own.

The basics

The EV3 has 2 different types of ports, motors and sensors.
Motor ports are A, B, C and D, Sensor ports are 1, 2, 3 and 4.

Check the firmware

To be able to use the API you need to have a firmware version >= 1.03, You can check the version on the brick from the Settings tab-> Brick Info –> Brick FW
To update the firmware run “LEGO MINDSTORMS EV3 Home Edition” and choose Tools –> Firmware Update

image

Enable Bluetooth

To be able to connect to the brick you need to enable Bluetooth you can do that on the brick from the Settings tab-> Bluetooth.
Enable Visibility and Bluetooth.

Pair with the brick

Pair your phone with the brick by going to Settings –> Bluetooth tap on “EV3”, the brick will now ask Ii f its ok to pair and then show a pin code.
Accept the default pin “1234” and enter it on the phone.

We are now all set up to start coding.

I have a Nokia Lumia 920 that I got from //Build, I can’t connect to the brick using that one, it might be a problem with all Lumia 920 developer phone (please let me know).
Luckily I also have a retail Lumia 920 and I have tested this code on a Lumia 1020, 720, 920 and HTC 8X and it works great (just not the //Build one).

Start a new project

image

 

Right click on references and click Manage Nuget packages

Search for "EV3”

image

Click install on “Lego Mindstorms EV3 API”


Enable Bluetooth by opening Properties/WMAppManifest.xml
Enable the capability ID_CAP_PROXIMITY

image

 

The API has the ability to connect to the EV3 by Wi-Fi, Bluetooth and USB for this project I will focus on Bluetooth only.

In MainPage.xaml
Create a button named “ConnectButton” and give it the text “Connect”
Create a button named “MotorAForwardButton” and give it the text “Motor A forward”
Create a button named “MotorStopButton” and give it the text “Stop”

Double click on each button to create the event handler in the code behind.

In MailPage.Xaml.cs att the following code:

private Brick brick;
private async void ConnectButton_Click(object sender, RoutedEventArgs e)
{
    brick = new Brick(new BluetoothCommunication(), true);
    await brick.ConnectAsync();
}

private void MotorAForwardButton_Click(object sender, RoutedEventArgs e)
{
    brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 50);
}
        
private void StopStopButton_Click(object sender, RoutedEventArgs e)
{
    brick.DirectCommand.StopMotorAsync(OutputPort.All, false);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    brick.Disconnect();
    base.OnNavigatedFrom(e);
}

 

I have kept this sample really simple so you can get a quick start.
You should always add error handling and you should disable the buttons unless you already connected and so on.
This is just to get you started.
I realize that this sample isn’t that exciting, but now we know how to control motors, time to kick things into gear and build some fun stuff =D

Related links

https://legoev3.codeplex.com/
The site for the EV3 API, with video instructions

http://www.lego.com/en-us/mindstorms/downloads/software/ddsoftwaredownload/download-software/
Download for LEGO MINDSTORMS EV3 Home Edition