Technical Evangelist @Microsoft

The powershell script to convert Windows ISOs to VHDs works pretty well. However, its usage is pretty confusing and although it is documented on the page, it is buried half way through and I always struggle with it before I get it to work. So more than anything, this blog post is just there as a reminder to myself on how to do it correctly.

run the script like the following “. .\Convert-WindowsImage.ps1″ . This executes the powershell script and inserts a cmdlet with the exact same name “Convert-WindowsImage” into the powershell.

You can now use the cmdlet to create a VHD like: PS D:\Software\win10vhd> Convert-WindowsImage -Edition “Enterprise” -SourcePath Windows_10_Enterprise_EN-US_x64.ISO -VHDFormat VHDX -SizeBytes 100GB -Verbose

Developing a prototype with the CC2540DK (SmartRF05EB + CC2540EM) I hit the issue where the pin mapping from the CC2540 chip to the final breakout pin headers is extremely convoluted. Here is source of this issue:

CC2540 is mounted on the CC2540EM module using Pin headers P1 and P2. This implies one pin mapping from CC2540 to the EM module’s pin out

The CC2540 EM module connects to the SmartRF0EB via the EM connectors P5 and P5 on the SmartRF05EB board. The Pin mapping, at least numerically is preserved, but you don’t know which of P1 and P2 is connected to P5 or P6.

Finally, P5 and P6 on the SmartRF05EB are routed over to the GPIO pin headers P18 and P20 and now you are 100% lost how the original CC2540 pins got routed over to the P18 and P20.

Essentially, between CC2540->CC2540 EM Module->SmartRF05EB EM Connectors -> SmartRF05EB breakout headers, you will be twisted like a pretzel. This blog post on mono devices pointed me roughly in the right direction. Essentially, you need to correlate between them like the following

First you go to the Spec sheet for CC2540EM. Here you note down which pins are connected to which pin headers on the EM module

Then you Look at the physical layout of the pin headers in the same Spec sheet as above. OK, so P1 is to the left and P2 is to the right. Based on that you infer that once mounted on the SmartRF05EB board, P1 is connected to P5 and P2 is connected to P6.

Cool. Now you look at the SmartRF05EB user guide and look for the EM Connector Pin out which looks like the following:

Thankfully, since the pin numbers are exactly the same between the CC2540EM board and the EM connector because they are physically compatible, you know which pins of the EM connector map to which pins of the CC2540EM.

As the next step, you look at the GPIO headers, which the manual calls Probe connectors.

There does not seem to be any particular method behind which pin from the EM connector maps to the pin on the Probe/GPIO header, but essentially, what you have to do is to take the Pin names on the EM connector headers and map the names to the Pin names on the Probe headers. Pretty painful. Anyways, I did it so I am sharing here in case it is useful to someone. Make sure to cross check if things are not working. I am not guaranteeing that my brain is not already busted from counting and cross referencing a million times.

Today, while building a sample game, I noticed that there were weird black lines between my sprites. Since the sprites are exact size and I am drawing them at integer coordinates exactly, that did not make any sense.

After messing around for a while, the culprit was TexturePacker that I used to pack all my sprites. When you are tiling sprites to create a tiled background, it is a good idea to set “Extrude” property on the right hand side to one so that these weird artifacts don’t show up. Here are the two screenshots with and without the problem.

I was testing out a piece of Arduino code that someone sent my way. They complained that a globalVariable value increment was not having any effect whatsoever. To better understand see the following sketch. Essentially, if all goes well, once the globalVariableTesting hits a value of 10, the program should stop blinking the LEDs. However, this was not happening. The program would continue blinking the LED forever. This was quite a headscratcher. I thought about it quite a bit and tried various things… It was so simple a program that I started doubting the compiler optimization etc and could not understand it. Finally, after I set the Serial monitor on with values being printed, I started seeing values of the variable being -32768, -32767 and thought oops looks like some corruption and still did not connect the dots. Finally, after spending a good bit more of time, I realized that the if condition takes time because there are delay statements in there. Once the variable goes over 10, there is no delay in the loop function since the if statement is not executed anymore. The loop just blows over the next 32758 values of the global variable in a jiffy given that the arduino oscillator runs at 16Mhz. It then promptly overflows the variable value to -32768 and merrily starts executing the loop again. Aha, so the mystery is finally solved.

To ‘FIX’ the program, just move the globalVariableTesting variable on line 12 in the ‘if’ block so that it does not get incremented after it has reached the value of 10.

Heard from a friend who loves TortoiseGit, that you can do the same in TortoiseGit by selecting “Wincred – current Windows user” in the “credential” section. See screenshot below for better illustration:

I have used git-bash for a long while and finally gotten sick of typing passwords all the time.. on Linux/Mac, It Just Works with the ssh-agent. Finally got bugged enough to do the research and found a solution..

After manually cleaning up Visual Studio C++ solutions for a long time, finally I had enough when I was trying to clean a Cocos2d-x project with its nested hierarchy of projects.. each with its own bin/debug/arm folders. So I started searching for a solution using powershell. Then I found this awesome blog post by Ricky.

Unfortunately, Ricky left out one particularly egregious file, the sdf file which contains the parsed symbols for C++ projects and helps with the Visual Studio intellisense. This file easily grows to be a few hundred megs so definitely warrants removal. So, I added a teensy bit to Ricky’s script and my life is now a lot easier.

One of those things that you almost never need, but if you need it, you need it. I hit a scenario where in Windows Phone 8 app, I had to have a Protocol launch handler. If you are not familiar, the protocol launch handler in Windows Phone 8 is done by deriving from the UriMapper class (Irrelevant but interesting fact: in Windows 8.0, 8.1 and WP 8.1, you handle protocol activation from an OnActivated event handler). What I did not count on was that I will be making an async call from the MapUri function which handles the protocol activation of the app.

Usually, the way I handle an async call within a function is to mark the containing function async as well.. i.e. just following the chain till everything is marked async. Unfortunately, the signature of the MapUri function is fixed. It looks like:

1

public override Uri MapUri(Uri uri)

As you can see, trying to muck with the signature and make it ‘async’ does not go well with the compiler which complains.

Anyways, a bit of research revealed that you can await an async call in the following way without having to add the ‘async’ keyword to the containing function:

Recently, someone asked me that if a pure C++/Direct3d application on Windows Phone 8.0 was invoked via LaunchUriAsync, how would one go about getting the Launch Parameters? The MSDN documentation seems to say that you can use the “ProtocolActivatedEventArgs” parameter in the OnActivated event handler and retrieve the data. After consulting with the appropriate engineering teams the answer is: Unfortunately, the documentation is incorrect. The OnActivated event handler is called only during Launch. It is not invoked during “Resume”. Even then, you cannot retrieve the launch parameters from there.

While creating a simple web app, where I created an ajax powered form using backbone.js, I needed the ability to clear the form if the user hit the reset button. So, I thought how about if I just refresh the current view. Backbone.js does not have a method to do that, which is a bit counter intuitive. After searching and trying a few things, the best answer was found in the comments of this blog post. Thanks to user mpeg for the contribution. The solution is simply to add the following extension method to the router prototype anywhere before you call the refresh method. Since Javascript is a prototypal inheritance language, this gets added dynamically to the existing instances of the router.

During Build 2014, I ported over the Fall Fury game, that was originally written for Windows Store using DirectX. Porting it over to a Universal app was quite an experience. The game would compile and work on Windows just fine but as soon as I put Windows Phone 8.1 in the mix, things started going haywire. The resolution was askew, the items were going off screen etc. It took quite a bit of working but eventually, I managed to fix the game so it would run fine on the 1080p phone. There are some resolution gotchas that I could not get around to before I ran out of time.