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.

  1. 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.
  2. 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
Understanding the GPIO pin out mapping for CC2540DK (SmartRF05EB + CC2540EM module)

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

 

CC2540EM

 

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.

CC2540EM-connector View

 

 

 

 

 

 

 

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

SmartRF05EB-EMConnectors

 

 

 

 

 

 

 

 

 

 

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.

SmartRF05EB-GPIO

 

 

 

 

 

 

 

 

 

 

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.

 

CC2540DK SmartRF05-EB Pin Mapping

Weird black lines between sprites in Cocos2d-x

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.

 

artifacts
no_artifacts_

Arduino integer overflow headscratcher

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.

Hope this helps you avoid some headscratching.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
int globalVariableTesting = 0;
int ledPin = 10;

void setup() {
    // put your setup code here, to run once:
    pinMode (ledPin, OUTPUT);
    //Serial.begin(9600);
}

void loop()
{
    globalVariableTesting++;
    if (globalVariableTesting < 10)
    {
       //Serial.println(globalVariableTesting);
       BlinkLed(500, 500);
     }
}

void BlinkLed(int x, int y)
{
    digitalWrite (ledPin, HIGH);
    delay (x);
    digitalWrite (ledPin, LOW);
    delay(y);
    digitalWrite (ledPin, HIGH);
    delay (x);
    digitalWrite (ledPin, LOW);
    delay(y);
}

Update

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:

tortoisegit

 

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..

See this link on stackoverflow

Net is, head over to codeplex download the exe, run it with

1
git-credential-winstore -i C:\Path\To\Git.exe

And next time you run a git connection, you get prompted by credvault to store your passwords and viola, no more pesky passwords..

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.

1
Get-ChildItem .\ -include ARM,bin,obj,bld,Backup,_UpgradeReport_Files,Debug,Release,ipch -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse };Get-ChildItem -Path *.sdf -Recurse -Force |  foreach ($_) { remove-item $_.fullname -Force -Recurse }

In case you are curious, let’s deconstruct the above command line:

1
Get-ChildItem .\ -include ARM,bin,obj,bld,Backup,_UpgradeReport_Files,Debug,Release,ipch -Recurse

The above recursively finds all folders under the current folder that match the names ARM, bin, obj etc.

1
foreach ($_) { remove-item $_.fullname -Force -Recurse }

This line simply gets whatever gets passed to it via the pipe command and simply removes everything under it recursively.

It is not too hard to decipher, that all I did was to add one more command to Ricky’s script which simply finds all files that have extension sdf and removes them using the above command.

Enjoy!

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:

1
2
3
  var task = Task.Run(async () => await MyAsyncFunction()
  task.Wait();
  var asyncFunctionResult = task.Result;

So, I can finally write my async function within the synchronous MapUri in the following manner:

1
2
3
4
5
6
public override Uri MapUri(Uri uri)
{
  var task = Task.Run(async () => await MyAsyncFunction()
  task.Wait();
  var asyncFunctionResult = task.Result;
}

Hope this helps.

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.

Sigh.

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.

1
2
3
_.extend(Backbone.Router.prototype, {
      refresh: function () { var tmp = Backbone.history.fragment; this.navigate(tmp + (new Date).getTime()); this.navigate(tmp, { trigger: true }); }
  });

I would just put it right where I am creating the AppRouter.

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.

Anyways, if you want to play around with it, I published the source for the Universal App on github for you to check out.