<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Coding 4 Fun</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/coding4fun/rss"/>
    <generator>Rev9</generator>
    <description></description>
    <link>http://channel9.msdn.com/coding4fun/rss</link>
    <language>en</language>
  <item>
      <title>An introduction to Unity3D - A 30 minute getting started guide</title>
      <description><![CDATA[<p>A number of times I've mentioned <a href="http://unity3d.com/" target="_blank">Unity3D</a>, usually with the assumption that you all knew what it was, how to get it and how to use it. Well you know what they say about when you&nbsp; &quot;assume&quot; something...</p><p>That's why today's post caught my eye. It's not &quot;code&quot; per-se (though there is a little C#!) instead it's a easy, simple and fairly short introduction to Unity3D.</p><h2><a href="http://mobile.tutsplus.com/tutorials/android/introduction-to-unity3d/" target="_blank">Introduction to Unity3D</a></h2><blockquote><p>Unity3D is a powerful cross-platform 3D engine and a user-friendly development environment. Learn how Unity3D can help you create games in this article!</p><h4>What is Unity3D?</h4><p>Unity3D is a powerful cross-platform 3D engine and a user friendly development environment. Easy enough for the beginner and powerful enough for the expert; Unity should interest anybody who wants to easily create 3D games and applications for mobile, desktop, the web, and consoles.</p></blockquote><p>The article starts off talking about cost, installation and basic getting started stuff.</p><p><a href="http://mobile.tutsplus.com/tutorials/android/introduction-to-unity3d/" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B14%5D-20.png" alt="image" width="670" height="315" border="0"></a></p><p><a href="http://mobile.tutsplus.com/tutorials/android/introduction-to-unity3d/" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B13%5D-16.png" alt="image" width="540" height="427" border="0"></a></p><p>Through to scripting and publishing;</p><p><a href="http://mobile.tutsplus.com/tutorials/android/introduction-to-unity3d/" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B12%5D-24.png" alt="image" width="604" height="427" border="0"></a></p><p>If you've heard of Unity3D before but didn't know how to get started with it, this is the perfect article for you...</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:fc7f1a9edad24c59b0cba056015a01f9">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/blog/An-introduction-to-Unity3D-A-30-minute-getting-started-guide</comments>
      <link>http://channel9.msdn.com/coding4fun/blog/An-introduction-to-Unity3D-A-30-minute-getting-started-guide</link>
      <itunes:summary>A number of times I&#39;ve mentioned Unity3D, usually with the assumption that you all knew what it was, how to get it and how to use it. Well you know what they say about when you&amp;nbsp; &amp;quot;assume&amp;quot; something...That&#39;s why today&#39;s post caught my eye. It&#39;s not &amp;quot;code&amp;quot; per-se (though there is a little C#!) instead it&#39;s a easy, simple and fairly short introduction to Unity3D.Introduction to Unity3DUnity3D is a powerful cross-platform 3D engine and a user-friendly development environment. Learn how Unity3D can help you create games in this article!What is Unity3D?Unity3D is a powerful cross-platform 3D engine and a user friendly development environment. Easy enough for the beginner and powerful enough for the expert; Unity should interest anybody who wants to easily create 3D games and applications for mobile, desktop, the web, and consoles.The article starts off talking about cost, installation and basic getting started stuff.Through to scripting and publishing;If you&#39;ve heard of Unity3D before but didn&#39;t know how to get started with it, this is the perfect article for you...</itunes:summary>
      <pubDate>Wed, 23 May 2012 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/blog/An-introduction-to-Unity3D-A-30-minute-getting-started-guide</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>3d</category>
      <category>3d-modeling</category>
      <category>csharp</category>
      <category>coding4fun</category>
      <category>game+design</category>
      <category>unity</category>
      <category>3d-engine</category>
  </item>
  <item>
      <title>Kinect-cart... A prototype Kinect-enabled Shopping cart</title>
      <description><![CDATA[<p>Today's inspirational project shows off a usage of the Kinect that you might not have ever imagined... I mean who'd have thought of mashing up a Kinect with a...</p><h2>Kinect-enabled shopping cart is smarter than the shopper</h2><blockquote><p>Microsoft has just demoed a <a href="http://dvice.com/archives/2011/06/next-big-step-f.php">Kinect-enabled</a> prototype shopping cart designed to take the guesswork out of your trip to the grocery store. <em>All </em>of the guesswork. In fact, all you are required to do is upload a shopping list and place items in the cart.</p><p>The cart utilizes <a href="http://dvice.com/archives/2011/11/rumor-next-gen-1.php">the Kinect</a> and other sensors to read what you are placing in the cart and check whether the item matches your pre-planned menu and any dietary constrains. If you've blindly placed an item in the cart that doesn't match with your downloaded list, forget about it. The Kinect Cart will tell gently — and slightly disapprovingly — verbally remind you of your mistake.</p><p>As you are scanning your items you are also being rung up so (in theory) forget the long check out lines. Just grab a bag if you haven't brought your own.</p><p>Here's the thing. Not only is the cart smart enough to check your list, scan your items, ring you out and converse with you — it is motorized. That means the cart will follow you as you walk down the aisle.</p><p>...</p></blockquote><p><strong>Project Information URL:</strong> <a title="http://dvice.com/archives/2012/02/kinect-enabled-1.php" href="http://dvice.com/archives/2012/02/kinect-enabled-1.php">http://dvice.com/archives/2012/02/kinect-enabled-1.php</a></p><p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/16GiO8EEVpE&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/16GiO8EEVpE&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p><p><a href="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image%5B2%5D-118.png" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image_thumb-114.png" alt="image" width="504" height="384" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image%5B5%5D-83.png" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image_thumb%5B1%5D-90.png" alt="image" width="504" height="384" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:05ce952e659340a9b8a9a056016d5876">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/kinect/Kinect-cart-A-prototype-Kinect-enabled-Shopping-cart</comments>
      <link>http://channel9.msdn.com/coding4fun/kinect/Kinect-cart-A-prototype-Kinect-enabled-Shopping-cart</link>
      <itunes:summary>Today&#39;s inspirational project shows off a usage of the Kinect that you might not have ever imagined... I mean who&#39;d have thought of mashing up a Kinect with a...Kinect-enabled shopping cart is smarter than the shopperMicrosoft has just demoed a Kinect-enabled prototype shopping cart designed to take the guesswork out of your trip to the grocery store. All of the guesswork. In fact, all you are required to do is upload a shopping list and place items in the cart.The cart utilizes the Kinect and other sensors to read what you are placing in the cart and check whether the item matches your pre-planned menu and any dietary constrains. If you&#39;ve blindly placed an item in the cart that doesn&#39;t match with your downloaded list, forget about it. The Kinect Cart will tell gently — and slightly disapprovingly — verbally remind you of your mistake.As you are scanning your items you are also being rung up so (in theory) forget the long check out lines. Just grab a bag if you haven&#39;t brought your own.Here&#39;s the thing. Not only is the cart smart enough to check your list, scan your items, ring you out and converse with you — it is motorized. That means the cart will follow you as you walk down the aisle....Project Information URL: http://dvice.com/archives/2012/02/kinect-enabled-1.php</itunes:summary>
      <pubDate>Wed, 23 May 2012 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/kinect/Kinect-cart-A-prototype-Kinect-enabled-Shopping-cart</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>coding4fun</category>
      <category>kinect</category>
  </item>
  <item>
      <title>Operating Kinect - The Kinect in the operating room</title>
      <description><![CDATA[<p>Today's projects highlight two inspirational stories about how the Kinect might be used to help surgeons</p><h2>Kinect imaging lets surgeons keep their focus</h2><blockquote><p><a href="http://www.newscientist.com/article/mg21428655.200-kinect-imaging-lets-surgeons-keep-their-focus.html" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image%5B3%5D-18.png" alt="image" width="315" height="247" border="0"></a></p><p>THE surgeon enters the operating theatre, covered in sterile blue scrubs. Machines beep and hiss. Nurses wait, tools at the ready: scalpel, forceps, bandage, Xbox... Xbox?</p><p>On Tuesday last week, a surgeon at <a href="http://www.guysandstthomas.nhs.uk/Home.aspx">Guy's and St Thomas' hospital</a> in London began trials of a new device that uses an Xbox Kinect <a href="http://www.newscientist.com/article/mg21428636.400-kinect-cameras-watch-for-autism.html">camera to sense body position</a>. Just by waving his arms the surgeon can consult and sift through medical images, such as CT scans or real-time X-rays, while in the middle of an operation.</p><p>Maintaining a sterile environment in the operating room is paramount, but scrubbing in and out to scroll through scan images mid-operation can be time-consuming and break a surgeon's concentration or sense of <a href="http://www.newscientist.com/article/mg21328501.600-zap-your-brain-into-the-zone-fast-track-to-pure-focus.html">flow</a>. Depending on the type of surgery, a surgeon will stop and consult medical images anywhere from once an hour to every few minutes. To avoid leaving the table, many surgeons rely on assistants to manipulate the computer for them, a distracting and sometimes frustrating process.</p><p>...</p><p>&quot;You usually think of Kinect in a game-like scenario where you can jump around and move your hands as wide as possible, but surgeons are not allowed to reach such a large area,&quot; says Gerardo Gonzalez of <a href="http://research.microsoft.com/en-us/labs/cambridge/default.aspx">Microsoft Research</a> in Cambridge, UK, who helped develop the system in conjunction with surgeons from Guy's and St Thomas' and King's College London.</p><p>So Gonzalez and colleagues developed a set of gestures that a surgeon can perform in a constrained space, while standing at the operating table. For the most common actions - rotating the 3D model or placing a marker on the image - the team designed one-handed gestures that combine with voice commands, leaving the other hand free for operating. To position a marker, for example, the surgeon simply points at the image to activate a cursor and says, &quot;place marker&quot;. Other functions, such as panning or zooming, require two hands.</p></blockquote><p><strong>Project Information URL:</strong> <a title="http://www.newscientist.com/article/mg21428655.200-kinect-imaging-lets-surgeons-keep-their-focus.html" href="http://www.newscientist.com/article/mg21428655.200-kinect-imaging-lets-surgeons-keep-their-focus.html">http://www.newscientist.com/article/mg21428655.200-kinect-imaging-lets-surgeons-keep-their-focus.html</a></p><h2>Kinect in the operating theater</h2><blockquote><p>I’m often asked where I see Kinect going next and much like the <a href="http://www.youtube.com/watch?v=T_QLguHvACs">Kinect Effect advert</a>, I put that question back on the questioner. One of the answers I give is we see it going into more and more places outside of the living room – places like schools and hospitals. In fact in the advert, there is a brief moment where you see Kinect in an operating theater.</p><p><a href="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image%5B6%5D-12.png" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image_thumb%5B1%5D-89.png" alt="image" width="520" height="283" border="0"></a></p><p>That’s not happening tomorrow, it’s happening today, at Sunnybrook hospital in Toronto. Earlier this week, <strong><a href="http://watch.discoverychannel.ca/daily-planet/february-2012/daily-planet---february-22-2012/#clip619038">Discovery Channel Canada</a></strong> dropped in on Sunnybrook and got a demo of how Kinect is being used.</p></blockquote><p><strong>Project Information URL:</strong> <a title="http://blogs.technet.com/b/next/archive/2012/02/24/kinect-in-the-operating-theater.aspx" href="http://blogs.technet.com/b/next/archive/2012/02/24/kinect-in-the-operating-theater.aspx">http://blogs.technet.com/b/next/archive/2012/02/24/kinect-in-the-operating-theater.aspx</a></p><p><a href="http://watch.discoverychannel.ca/daily-planet/february-2012/daily-planet---february-22-2012/#clip619038" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/f1dda9cc6de74512b7c19f0101402403/image%5B10%5D-8.png" alt="image" width="520" height="299" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:c591b09c65e646d8ab94a056016b0d72">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/kinect/Operating-Kinect-The-Kinect-in-the-operating-room</comments>
      <link>http://channel9.msdn.com/coding4fun/kinect/Operating-Kinect-The-Kinect-in-the-operating-room</link>
      <itunes:summary>Today&#39;s projects highlight two inspirational stories about how the Kinect might be used to help surgeonsKinect imaging lets surgeons keep their focusTHE surgeon enters the operating theatre, covered in sterile blue scrubs. Machines beep and hiss. Nurses wait, tools at the ready: scalpel, forceps, bandage, Xbox... Xbox?On Tuesday last week, a surgeon at Guy&#39;s and St Thomas&#39; hospital in London began trials of a new device that uses an Xbox Kinect camera to sense body position. Just by waving his arms the surgeon can consult and sift through medical images, such as CT scans or real-time X-rays, while in the middle of an operation.Maintaining a sterile environment in the operating room is paramount, but scrubbing in and out to scroll through scan images mid-operation can be time-consuming and break a surgeon&#39;s concentration or sense of flow. Depending on the type of surgery, a surgeon will stop and consult medical images anywhere from once an hour to every few minutes. To avoid leaving the table, many surgeons rely on assistants to manipulate the computer for them, a distracting and sometimes frustrating process....&amp;quot;You usually think of Kinect in a game-like scenario where you can jump around and move your hands as wide as possible, but surgeons are not allowed to reach such a large area,&amp;quot; says Gerardo Gonzalez of Microsoft Research in Cambridge, UK, who helped develop the system in conjunction with surgeons from Guy&#39;s and St Thomas&#39; and King&#39;s College London.So Gonzalez and colleagues developed a set of gestures that a surgeon can perform in a constrained space, while standing at the operating table. For the most common actions - rotating the 3D model or placing a marker on the image - the team designed one-handed gestures that combine with voice commands, leaving the other hand free for operating. To position a marker, for example, the surgeon simply points at the image to activate a cursor and says, &amp;quot;place marker&amp;quot;. Other functions, such as panning</itunes:summary>
      <pubDate>Tue, 22 May 2012 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/kinect/Operating-Kinect-The-Kinect-in-the-operating-room</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>coding4fun</category>
      <category>kinect</category>
      <category>kinectsdk</category>
  </item>
  <item>
      <title>Project Detroit: Lighting System</title>
      <description><![CDATA[<p>In this article, we give a detailed look into the external lighting system of Project Detroit, the Microsoft-West Coast Custom Mustang creation. If you're not already familiar with this project, you can find more <a href="http://channel9.msdn.com/Blogs/Vector/The-400-horsepower-device">information here</a>.</p><h2>Overview</h2><p>The external lighting system for Project Detroit is run on a web server on a Netduino Plus, which uses the .NET Micro Framework (NETMF). To get an accelerated start, we leveraged code from the CodePlex project <a href="http://netduinohelpers.codeplex.com/">Netduino Helpers</a> to control the <a href="http://www.adafruit.com/products/306">AdaFruit LPD8806 LED</a> strip, and the <a href="http://forums.netduino.com/index.php?/topic/575-updated-web-server/">web server base code from the Netduino forums</a>. They have been tweaked slightly for our project.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/netduino%5B8%5D.jpg"><img title="netduino" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/netduino_thumb%5B3%5D.jpg" alt="netduino" width="500" height="375" border="0"></a></p><h2>Controllers, Routes, RESTful oh my!</h2><p>We wanted the NETMF web server to have the exact same routes as the full-blown REST service layer in Detroit. With compiler conditionals, this allowed the same code to use the same routes on both the full .NET stack and NETMF. Since we couldn't use the ASP.NET MVC framework here, we had to make something close to it.</p><h2>Controllers</h2><p>Controllers implement an interface with a method named <strong>ExecuteAction</strong>. When <strong>GetController</strong> is called, we return the correct controller but cast as the interface <strong>IController</strong>. This lets us figure out what controller should be executing the request and continue to work generically in the context of the request connection thread. If new functionality is needed, we create a new controller that inherits from IController&nbsp;and update GetController:</p><p><pre class="brush: csharp">
private static void RequestReceived(Request request)
{
    // url comes in as /foo/bar/12345?style=255
    //
     // /CONTROLLER/ACTION/
    //
    // LIGHTING SAMPLE URL: /0/1/?r=255&amp;g=255&amp;b=255&amp;zone=EnumAsInt
    // /0/... 0 = NetduinoControllerType.Lighting
    var validResponse = false;
    try
    {
        Logger.WriteLine(&quot;Start: &quot; &#43; request.Url &#43; &quot; at &quot; &#43; DateTime.Now);
        var urlInParts = request.Url.TrimStart(UriPathSeparator).Split(new[] {'?'}, 2);
        string[] uriSubParts = null;
        string[] queryStringSubParts = null;
        if (urlInParts.Length &gt; 0)
            uriSubParts = urlInParts[0].Split(UriPathSeparator);
                
        if (urlInParts.Length &gt; 1)
            queryStringSubParts = urlInParts[1].Split(QueryStringSeparator);
        if (uriSubParts != null &amp;&amp; uriSubParts.Length &gt; 1)
        {
            var targetController = GetController(uriSubParts[0]);
            if (targetController != null)
            {
                var action = (uriSubParts.Length &gt;= 2) ? uriSubParts[1] : string.Empty;
                var result = targetController.ExecuteAction(action, queryStringSubParts);
                validResponse = true;
                request.SendResponse(result.ToString());
                Logger.WriteLine(&quot;Result: &quot; &#43; result &#43; &quot; from &quot; &#43; request.Url &#43; &quot; at &quot; &#43; DateTime.Now);
            }
        }
        if (!validResponse)
        {
            SendIndexHtml(request);
        }
    }
    catch(Exception ex0)
    {
        Logger.WriteLine(ex0.ToString());
    }
}
</pre></p><h2>Routes, strings and enums on NETMF</h2><p>NETMF can't parse an enum from a string, which is something that can be done in the full .NET Framework. But what does this actually mean? It means the routes for the NETMF web server are a bit unreadable. Here is the same route but with the parsing issue exposed:</p><p><strong>Detroit's REST service route with ASP.NET MVC:</strong><br>http://…/Lighting/Solid/?zone=all&amp;r=255&amp;g=0&amp;b=0<br><br><strong>Detroit's NETMF route:<br></strong>http://…/0/3/?zone=0&amp;r=255&amp;g=0&amp;b=0</p><p>This issue made direct device debugging a bit harder.</p><h2>Parsing the Action and query string</h2><p>Parsing the route is broken into two parts. The first is determines what controller to target. For Project Detroit, that meant the lighting system or the rear glass system. Once we know the controller, we still need to parse the query string and action into something more useful:</p><p><pre class="brush: csharp">
#if NETMF
private static readonly char[] QueryStringParamSeparator = new[] { '=' };
public static LightingData ParseQueryStringValues(string action, params string[] queryStringParameters)
#else
public static LightingData ParseQueryStringValues(string action, Dictionary&lt;string, object&gt; queryStringParameters)
#endif
{
    var data = new LightingData {LightingZone = LightingZoneType.All, LightingAction = ParseLightingActionType(action)};
#if NETMF
    if (queryStringParameters != null)
    {
        foreach (var queryString in queryStringParameters)
        {
            var valueKey = queryString.Split(QueryStringParamSeparator);
            if (valueKey.Length != 2)
                continue;
            var key = valueKey[0];
            var value = valueKey[1];
#else
        foreach(var key in queryStringParameters.Keys)
        {
            var value = queryStringParameters[key].ToString();
#endif
            switch (key.ToLower())
            {
                case ZoneHuman:
                case ZoneComputer:
                    data.LightingZone = ParseLightingZoneType(value);
                    break;
                // more stuff
            }
        }
#if NETMF
    }
#endif
    // more stuff
            
    return data;
}
</pre></p><h2>Turning on the lights</h2><p>Individually addressable LED strips allow us to tell each individual LED what color to be. To adjust the colors of the LED lights, we loop through all the LEDs, set their color value, and then call <strong>LedRefresh()</strong> on our LED strip. There's no need to set all of them, only the ones being updated:</p><p><pre class="brush: csharp">
private static void SolidAnimationWorker()
{
    var leds = GetLedsToIlluminate();
    var dataCopy = _data;
    for (var i = 0; i &lt; leds.Length; i&#43;&#43;)
        SetLed(leds[i], dataCopy.Red, dataCopy.Green, dataCopy.Blue);
    LedRefresh();
}
</pre></p><h2>Zones / Animation Threads</h2><p>A solid color is boring, but we can use procedural animations to add some flair. The current code&nbsp;supports the following animations:</p><ul><li>Solid - A single solid color. </li><li>Fill - Goes from black to the desired color. The color stays lit. Much like filling a glass of liquid. <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /> </li><li>Random - LEDs are set to a random value. </li><li>Pulse - A glowing effect from bright to black. </li><li>Snake - A one way lighting effect with a fading tail that moves left to right. </li><li>Sweep - This effect was inspired by KITT and a Cylon robot and is similar to a snake pattern. The effect can also handle being split in two while maintaining a continual line for items such as the grill or the wheels. </li><li>Police - Each side flashes a red and blue light. </li></ul><p>Since we know the LED strip is a single strand, we can be clever with offsets and create groupings. By having a dedicated animation thread in each zone, we can have the grill of the car in Police Mode while the bottom fades to red and the vents fill to blue at different refresh rates.</p><p>To run an animation, we need to first kill the old animation thread, spin up a new thread, mark LEDs in the &quot;All LED&quot; zone as do not touch, and execute the new pattern. Without a way to mark the LEDs as &quot;bad&quot; in the &quot;All&quot; zone, the two animation threads would compete for setting the color and result in a flickering effect. Other zones don't have to worry about this since there is zero overlap of LEDs:&nbsp;</p><p><pre class="brush: csharp">
public bool ExecuteAction(string action, params string[] queryStringParameters)
{
    var data = LightingDataHelper.ParseQueryStringValues(action, queryStringParameters);
            
    SignalToEndAnimationThread(data.LightingZone);
    int counter = 0;
    while (counter&#43;&#43; &lt; 5 &amp;&amp; IsThreadAlive(data.LightingZone))
        Thread.Sleep(10);
    if (IsThreadAlive(data.LightingZone))
        AbortAnimationThread(data.LightingZone);
    // moving data bucket into public so new threads can leverage it
    _data = data;
    if (_data.LightingAction == LightingActionType.Police || _data.LightingAction == LightingActionType.Sweep)
    {
        _data.LightingZone = LightingZoneType.Grill;
        if (IsThreadAlive(_data.LightingZone))
            AbortAnimationThread(_data.LightingZone);
    }
    // cleaning up just incase
    if (data.LightingZone != LightingZoneType.All)
    {
        for (var i = 0; i &lt; _zoneAllAnimation.Length; i&#43;&#43;)
        {
            var leds = GetLedsToIlluminate();
            for (var z = 0; z &lt; leds.Length; z&#43;&#43;)
            {
                // flagging item as bad in animation lib
                if (_zoneAllAnimation[i] == leds[z])
                    _zoneAllAnimation[i] = -1;
            }
        }
    }
    switch (_data.LightingAction)
    {
        case LightingActionType.Solid:
            Debug.Print(&quot;Solid&quot;);
            ExecuteThread(SolidAnimationWorker);
            break;
        // more patterns
    }
    return true;
}
</pre></p><p>We can now do something more interesting, like Police Mode:</p><p><pre class="brush: csharp">
private static void PoliceModeAnimationWorker()
{
    var leds = GetLedsToIlluminate();
    var dataCopy = _data;
    var length = leds.Length;
    var half = length / 2;
    var index = 0;
    while (IsThreadSignaledToBeAlive(dataCopy.LightingZone))
    {
        int redIntensity = (index == 0) ? 255 : 0;
        int blueIntensity = (index == 0) ? 0 : 255;
        for (var i = 0; i &lt; half; i&#43;&#43;)
            SetLed(leds[i], redIntensity, 0, 0);
        for (var i = half; i &lt; length; i&#43;&#43;)
            SetLed(leds[i], 0, 0, blueIntensity);
        LedRefresh();
        index&#43;&#43;;
        index %= 2;
        Thread.Sleep(100);
    }
}
</pre></p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/WP_000197%5B5%5D.jpg"><img title="WP_000197" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/WP_000197_thumb%5B2%5D.jpg" alt="WP_000197" width="500" height="375" border="0"></a></p><h2>Improvements</h2><p>Hindsight is 20/20. Nothing is ever perfect and there are of course items we'd love to change. At the start, the goal was to make this fairly generic and not Project Detroit &quot;aware.&quot; As you can see by looking at the source, that wasn't accomplished due to time constraints.</p><p>We would use a different LED system for two reasons: data transfer speed and power. The longer the LED strip is, the longer it takes to address an item further down the line. Project Detroit, having 15 meters of lighting in it, was impacted by this issue. It works well, just not as well as we hoped. The voltage requirements of the LEDs are another consideration. They are 5V, while a car uses 12V. Had we used 12V LEDs, our wiring would have been far simpler and wouldn't have required multiple transformers to get the required amperage needed at the correct voltage.</p><h2>Conclusion</h2><p>We think the lighting solution, coupled with the time and material constraints, worked out pretty well.&nbsp; Project Detroit was a ton of fun to build out and working with West Coast Customs was the chance of a lifetime.</p><p><img src="http://files.channel9.msdn.com/thumbnail/09615539-1a33-49f7-b438-ca1b9543d712.jpg" alt="" width="500" height="284"></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:f6bef172711342dbbca9a046016a6843">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Project-Detroit-Lighting-System</comments>
      <link>http://channel9.msdn.com/coding4fun/articles/Project-Detroit-Lighting-System</link>
      <itunes:summary>In this article, we give a detailed look into the external lighting system of Project Detroit, the Microsoft-West Coast Custom Mustang creation. If you&#39;re not already familiar with this project, you can find more information here.OverviewThe external lighting system for Project Detroit is run on a web server on a Netduino Plus, which uses the .NET Micro Framework (NETMF). To get an accelerated start, we leveraged code from the CodePlex project Netduino Helpers to control the AdaFruit LPD8806 LED strip, and the web server base code from the Netduino forums. They have been tweaked slightly for our project.Controllers, Routes, RESTful oh my!We wanted the NETMF web server to have the exact same routes as the full-blown REST service layer in Detroit. With compiler conditionals, this allowed the same code to use the same routes on both the full .NET stack and NETMF. Since we couldn&#39;t use the ASP.NET MVC framework here, we had to make something close to it.ControllersControllers implement an interface with a method named ExecuteAction. When GetController is called, we return the correct controller but cast as the interface IController. This lets us figure out what controller should be executing the request and continue to work generically in the context of the request connection thread. If new functionality is needed, we create a new controller that inherits from IController&amp;nbsp;and update GetController:
private static void RequestReceived(Request request)
{
    // url comes in as /foo/bar/12345?style=255
    //
     // /CONTROLLER/ACTION/
    //
    // LIGHTING SAMPLE URL: /0/1/?r=255&amp;amp;g=255&amp;amp;b=255&amp;amp;zone=EnumAsInt
    // /0/... 0 = NetduinoControllerType.Lighting
    var validResponse = false;
    try
    {
        Logger.WriteLine(&amp;quot;Start: &amp;quot; &amp;#43; request.Url &amp;#43; &amp;quot; at &amp;quot; &amp;#43; DateTime.Now);
        var urlInParts = request.Url.TrimStart(UriPathSeparator).Split(new[] {&#39;?&#39;}, 2);
        string[] uriSubParts = null;
        stri</itunes:summary>
      <pubDate>Mon, 21 May 2012 16:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Project-Detroit-Lighting-System</guid>
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez</dc:creator>
      <category>netmf</category>
      <category>project+detroit</category>
  </item>
  <item>
      <title>[Special Edition] Kinect for Windows SDK v1.5 now available</title>
      <description><![CDATA[<h2><a href="http://channel9.msdn.com/posts/Kinect-for-Windows-SDK-15-Face-Tracking-Seated-Skeletal-Tracking-Kinect-Studio--More" target="_blank">Kinect for Windows SDK 1.5 - Face Tracking, Seated Skeletal Tracking, Kinect Studio, &amp; More</a></h2><blockquote><p>Rob Relyea, a Principal Program Manager on the Kinect for Windows team joins us again on Channel 9 to discuss all of the new features with the 1.5 release of the Kinect for Windows SDK.</p></blockquote><p><iFrame src="http://channel9.msdn.com/posts/Kinect-for-Windows-SDK-15-Face-Tracking-Seated-Skeletal-Tracking-Kinect-Studio--More/player?h=384&w=512" frameborder="0" scrolling="no" width="512px" height="384px"></iFrame></p><h2><a href="http://blogs.msdn.com/b/kinectforwindows/">Kinect for Windows Blog</a> - <a href="http://blogs.msdn.com/b/kinectforwindows/archive/2012/05/21/kinect-for-windows-runtime-and-sdk-version-1-5-released.aspx">Kinect for Windows Runtime and SDK Version 1.5 Released</a></h2><blockquote><p>I am pleased to announce that today we have released <a href="http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx">version 1.5</a> of the Kinect for Windows runtime and SDK. Additionally, Kinect for Windows hardware is now available in Hong Kong, Korea, Singapore, and Taiwan. Starting next month, Kinect for Windows hardware will be available in 15 additional countries: Austria, Belgium, Brazil, Denmark, Finland, India, the Netherlands, Norway, Portugal, Russia, Saudi Arabia, South Africa, Sweden, Switzerland and the United Arab Emirates. When this wave of expansion is complete, Kinect for Windows will be available in 31 countries around the world. Go to our Kinect for Windows website to find a <a href="http://www.microsoft.com/en-us/kinectforwindows/purchase/resellers.aspx">reseller in your region</a>.</p><p>We have added more capabilities to help <a href="http://www.microsoft.com/en-us/kinectforwindows/develop/">developers </a>build amazing applications, including:</p><ul><li><a href="http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx">Kinect Studio</a>, our new tool which allows developers to record and play back Kinect data, dramatically shortening and simplifying the development lifecycle of a Kinect application. Now a developer writing a Kinect for Windows application can record clips of users in the application’s target environment and then replay those clips at a later time for testing and further development. </li><li>A set of <a href="http://www.microsoft.com/en-us/kinectforwindows/develop/learn.aspx">Human Interface Guidelines (HIG)</a> to guide developers on best practices for the creation of Natural User Interfaces using Kinect. </li><li>The <a href="http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx">Face Tracking SDK</a>, which provides a real-time 3D mesh of facial features—tracking the head position, location of eyebrows, shape of the mouth, etc. </li><li>Significant sample code additions and improvements. There are many new samples in both C&#43;&#43; and C#, plus a “Basics” series of samples with language coverage in C&#43;&#43;, C#, and Visual Basic. </li><li><a href="http://www.microsoft.com/en-us/kinectforwindows/develop/learn.aspx">SDK documentati</a><a href="http://www.microsoft.com/en-us/kinectforwindows/develop/learn.aspx">on improvements</a>, including new resources as well as migration of documentation to MSDN for easier discoverability and real-time updates. </li></ul><p>We have continued to expand and improve our skeletal tracking capabilities in this release:</p><ul><li>Seated Skeletal Tracking is now available.... </li><li>Skeletal Tracking is supported in <a href="http://blogs.msdn.com/b/kinectforwindows/archive/2012/01/20/near-mode-what-it-is-and-isn-t.aspx">Near Mode</a>, including both Default and Seated tracking modes. ... </li></ul><p>We have made performance and data quality enhancements, which improve the experience of all Kinect for Windows applications using the RGB camera or needing RGB and depth data to be mapped together (“<a href="http://en.wikipedia.org/wiki/Green_screen">green screen</a>” applications are a common example):</p><ul><li>Performance for the mapping of a depth frame to a color frame has been significantly improved, with an average speed increase of 5x. </li><li>Depth and color frames will now be kept in sync with each other. The Kinect for Windows runtime continuously monitors the depth and color streams and corrects any drift. </li><li>RGB Image quality has been improved in the RGB 640x480 @30fps and YUV 640x480 @15fps video modes. The image quality is now sharper and more color-accurate in high and low lighting conditions. </li></ul><p>New capabilities to enable avatar animation scenarios, which makes it easier for developers to build applications that control a 3D avatar, such as Kinect Sports.</p><ul><li>Kinect for Windows runtime provides Joint Orientation information for the skeletons tracked by the Skeletal Tracking pipeline. </li><li>The Joint Orientation is provided in two forms: A Hierarchical Rotation based on a bone relationship defined on the Skeletal Tracking joint structure, and an Absolute Orientation in Kinect camera coordinates. </li></ul><p>...&quot;</p></blockquote><h2><a href="http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx" target="_blank">Kinect for Windows SDK Developer Downloads</a></h2><blockquote><p>The Kinect for Windows SDK enables developers to create applications using C&#43;&#43;, C# or Visual Basic, which support gesture and voice recognition using the Kinect for Windows sensor and a PC or embedded device.</p><p><strong>Step 1: Set-up Kinect for Windows SDK</strong></p><p>Includes drivers for using Kinect sensor on a computer running Windows 7, Windows 8 Consumer Preview, and Windows Embedded Standard 7. In addition, the download includes application programming interfaces (APIs) and device interfaces.<br>Version 1.5, updated 05/21/2012, 221 MB, English.</p><p><a href="http://go.microsoft.com/fwlink/?LinkID=247938">DOWNLOAD LATEST SDK</a></p><p><a href="http://go.microsoft.com/fwlink/?LinkID=246664">View Release Notes </a><img src="http://www.microsoft.com/global/en-us/kinectforwindows/PublishingImages/carat-icon-purple.png" alt=""></p><p><a href="http://www.microsoft.com/en-us/kinectforwindows/develop/new.aspx">Explore the features </a><img src="http://www.microsoft.com/global/en-us/kinectforwindows/PublishingImages/carat-icon-purple.png" alt=""></p><p><strong>Step 2: Set-up Kinect for Windows Developer Toolkit</strong></p><p>Contains source code samples, Kinect Studio, Face Tracking SDK, and other resources to simplify developing applications using the Kinect for Windows SDK.<br>Version 1.5, updated 05/21/2012, 60 MB, English.</p><p><a href="http://go.microsoft.com/fwlink/?LinkID=246663">DOWNLOAD TOOLKIT</a></p><p><a href="http://go.microsoft.com/fwlink/?LinkID=246664">View Release Notes </a><img src="http://www.microsoft.com/global/en-us/kinectforwindows/PublishingImages/carat-icon-purple.png" alt=""></p></blockquote> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:e42fba5a0319438b8ac7a05800faccfb">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/kinect/Special-Edition-Kinect-for-Windows-SDK-v15-now-available</comments>
      <link>http://channel9.msdn.com/coding4fun/kinect/Special-Edition-Kinect-for-Windows-SDK-v15-now-available</link>
      <itunes:summary>Kinect for Windows SDK 1.5 - Face Tracking, Seated Skeletal Tracking, Kinect Studio, &amp;amp; MoreRob Relyea, a Principal Program Manager on the Kinect for Windows team joins us again on Channel 9 to discuss all of the new features with the 1.5 release of the Kinect for Windows SDK.Kinect for Windows Blog - Kinect for Windows Runtime and SDK Version 1.5 ReleasedI am pleased to announce that today we have released version 1.5 of the Kinect for Windows runtime and SDK. Additionally, Kinect for Windows hardware is now available in Hong Kong, Korea, Singapore, and Taiwan. Starting next month, Kinect for Windows hardware will be available in 15 additional countries: Austria, Belgium, Brazil, Denmark, Finland, India, the Netherlands, Norway, Portugal, Russia, Saudi Arabia, South Africa, Sweden, Switzerland and the United Arab Emirates. When this wave of expansion is complete, Kinect for Windows will be available in 31 countries around the world. Go to our Kinect for Windows website to find a reseller in your region.We have added more capabilities to help developers build amazing applications, including:Kinect Studio, our new tool which allows developers to record and play back Kinect data, dramatically shortening and simplifying the development lifecycle of a Kinect application. Now a developer writing a Kinect for Windows application can record clips of users in the application’s target environment and then replay those clips at a later time for testing and further development. A set of Human Interface Guidelines (HIG) to guide developers on best practices for the creation of Natural User Interfaces using Kinect. The Face Tracking SDK, which provides a real-time 3D mesh of facial features—tracking the head position, location of eyebrows, shape of the mouth, etc. Significant sample code additions and improvements. There are many new samples in both C&amp;#43;&amp;#43; and C#, plus a “Basics” series of samples with language coverage in C&amp;#43;&amp;#43;, C#, and Visual Basic. SDK documenta</itunes:summary>
      <pubDate>Mon, 21 May 2012 15:16:52 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/kinect/Special-Edition-Kinect-for-Windows-SDK-v15-now-available</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>coding4fun</category>
      <category>kinect</category>
      <category>kinectsdk</category>
  </item>
  <item>
      <title>Gestating your Metro Style App with Cocoon</title>
      <description><![CDATA[<p>Today's Metro Monday project is a framework that will help you in your creation of Windows 8 Metro Style applications, helping take a little of the grunt work out, while helping build applications with some separation of concerns. Plus I dig how it uses MEF to compose a navigable application.</p><h2><a href="http://cocoon.codeplex.com/" target="_blank">Cocoon</a></h2><blockquote><p>Cocoon is a framework to support the development of .Net Windows 8 Metro-style applications, in particular those that link to web services. It simplifies accessing, displaying and editing data using standard Metro controls, and allows easy application of the MVVM pattern.</p><p>For more details, and news on the latest releases visit <a href="http://andyonwpf.blogspot.com">http://andyonwpf.blogspot.com</a></p><h3>Current Features</h3><ul><li>A navigation framework with, <ul><li>Attribute based page and view model discovery using MEF </li><li>Automatic creation and wiring up of page and view model </li><li>Passing of parameters to view models upon activation </li><li>Persistence of navigation and state upon application suspension </li></ul></li></ul><ul><li>A data framework with, <ul><li>Support for observable collections and data virtualization </li><li>An extensible framework for the retrieval, processing and display of data from the cloud </li></ul></li></ul><h3>Documentation</h3><ul><li><a href="http://andyonwpf.blogspot.com/2011/11/cocoon-new-framework-for-windows-8.html">Introduction</a> </li><li>Base Types <ul><li><a href="http://andyonwpf.blogspot.com/2011/12/observablevector-as-replacement-for.html">ObservableVector&lt;T&gt;</a> </li><li><a href="http://andyonwpf.blogspot.com/2011/12/data-virtualization-in-metro-style-apps.html">VirtualizingVector&lt;T&gt;</a> </li></ul></li><li>Cocoon Navigation Framework <ul><li><a href="http://andyonwpf.blogspot.co.uk/2012/04/navigation-in-cocoon-mvvm-for-metro.html">Defining pages and view models</a> </li><li>More to follow... </li></ul></li><li>Cocoon Data Framework (IDataListSource&lt;T&gt; and data lists) <ul><li><a href="http://andyonwpf.blogspot.com/2012/01/bridging-data-dividean-introduction-to.html">Introduction</a> </li><li><a href="http://andyonwpf.blogspot.co.uk/2012/04/using-cocoon-data-framework.html">Example Code</a> </li><li><a href="http://andyonwpf.blogspot.com/2012/01/simpledatalistsource-consuming-data.html">SimpleDataListSource&lt;T&gt;</a> </li><li><a href="http://andyonwpf.blogspot.co.uk/2012/02/pageddatalistsource-consuming-data-from.html">PagedDataListSource&lt;T&gt;</a> </li><li><a href="http://andyonwpf.blogspot.co.uk/2012/03/virtualizingdatalist-displaying-large.html">VirtualizingDataList&lt;T&gt;</a> </li></ul></li></ul></blockquote><h3><a href="http://andyonwpf.blogspot.com/2011/11/cocoon-new-framework-for-windows-8.html" target="_blank">Cocoon – A new framework for Windows 8 Development</a></h3><blockquote><p>To assist with Windows 8 Metro-style applications I would like to announce the Cocoon framework (<a href="http://cocoon.codeplex.com/">http://cocoon.codeplex.com/</a>). This aims to build on top of the learning from the Chrysalis project to provide a simple way to develop Metro-style applications in a manner that fits naturally with the MVVM design pattern.</p><p>It is likely that many Metro-style apps will be connected applications, downloading data from across the internet in response to user navigation. Modern applications are expected to do this in a seamless manner, retrieving data on demand and populating the user interface in response. In some ways this is at odds with the web API programming model that is based upon individual request-response calls, with paging used to retrieve large datasets. One of the first targets of the Cocoon framework is to simplify this process – bridging the world of stateless web API calls, with the “fast and fluid” interfaces expected by users.</p></blockquote><h3>&nbsp;<a href="http://andyonwpf.blogspot.co.uk/2012/04/navigation-in-cocoon-mvvm-for-metro.html" target="_blank">Navigation in Cocoon – MVVM for Metro-style apps</a></h3><blockquote><h4>Navigation in Cocoon</h4><p>Although not limited to this, the Cocoon framework is designed to work great with the Model-View-ViewModel (MVVM) pattern that has become common when designing XAML based applications. One problem when using this pattern is that you need some way of associating a view with a view-model. Often this is done by navigating directly to a page, and using a “ViewModelLocator” to identify and wire up the respective view-model.</p><p>In Cocoon a slightly different approach is used. Here, rather than navigating directly to a view, you navigate to a named page. Although the behaviour is extensible, by default Cocoon will use MEF (the built in composition framework included in .Net) to locate both the view and view-model associated with this page name, create and initialise instances of these and wire them together.</p><p>...</p><h4>The Navigation Manager</h4>In order to navigate between pages, Cocoon includes a navigation manager that can be accessed by importing the INavigationManager interface through MEF (simplified by the fact that all views and view models in Cocoon are themselves are composed by MEF).</blockquote><h3><a href="http://andyonwpf.blogspot.com/2012/05/getting-started-with-cocoon-navigation.html" target="_blank">Getting Started with Cocoon Navigation – The Cocoon Bootstrapper</a></h3><blockquote><p>Since the Cocoon navigation framework is built on top of the Managed Extensibility Framework (MEF), the application is composed with the required dependencies as the user navigates through the application. MEF is a composition framework that is built into the .Net framework, that enables the construction of loosely-coupled, easily maintainable and testable applications to be composed automatically at run time. An introductory guide for those who are not familiar with MEF is available <a href="http://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF">here</a>.</p><p>What I have not covered previously however was how to navigate to the application’s first page when it is launched,</p><h4>Launching Navigation Using The Cocoon Bootstrapper</h4>To simplify the initialization of Cocoon based applications the framework includes the ‘CocoonBootstrapper’ class that can be used at startup. This manages the configuration of MEF for the most common scenarios, initialization of services and activation of the application. <p>...</p></blockquote><p>Here's a snip of the sample app running.</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(8)%5B2%5D.png" target="_blank"><img title="Screenshot (8)" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(8)_thumb.png" alt="Screenshot (8)" width="650" height="365" border="0"></a></p><p>Note, to get the sample app to run, you'll need your own <a href="http://www.flickr.com" target="_blank">Flickr</a> API Key.</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%5B3%5D.png" target="_blank"><img title="Screenshot" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot_thumb%5B4%5D.png" alt="Screenshot" width="669" height="354" border="0"></a></p><p>Here's a snap of the Solution;</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B2%5D-47.png" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb-46.png" alt="image" width="258" height="407" border="0"></a><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B5%5D-21.png" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image_thumb%5B1%5D-59.png" alt="image" width="251" height="407" border="0"></a></p><p>And some snaps of the code, showing a little bit of how MEF is used.</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(9)%5B3%5D.png" target="_blank"><img title="Screenshot (9)" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(9)_thumb%5B4%5D.png" alt="Screenshot (9)" width="670" height="354" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(10)%5B3%5D.png" target="_blank"><img title="Screenshot (10)" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/Screenshot%20(10)_thumb%5B4%5D.png" alt="Screenshot (10)" width="670" height="354" border="0"></a></p><p>If you've thought, &quot;I love MEF and I wonder if I can use it to compose Metro Style App's, without messing up navigation&quot; or looking for a new data handling framework or just want to check out a cool framework, Cocoon, and all its source, is ready for you...</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:2cd707c8ba8445788ca6a0560154382e">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/blog/Gestating-your-Metro-Style-App-with-Cocoon</comments>
      <link>http://channel9.msdn.com/coding4fun/blog/Gestating-your-Metro-Style-App-with-Cocoon</link>
      <itunes:summary>Today&#39;s Metro Monday project is a framework that will help you in your creation of Windows 8 Metro Style applications, helping take a little of the grunt work out, while helping build applications with some separation of concerns. Plus I dig how it uses MEF to compose a navigable application.CocoonCocoon is a framework to support the development of .Net Windows 8 Metro-style applications, in particular those that link to web services. It simplifies accessing, displaying and editing data using standard Metro controls, and allows easy application of the MVVM pattern.For more details, and news on the latest releases visit http://andyonwpf.blogspot.comCurrent FeaturesA navigation framework with, Attribute based page and view model discovery using MEF Automatic creation and wiring up of page and view model Passing of parameters to view models upon activation Persistence of navigation and state upon application suspension A data framework with, Support for observable collections and data virtualization An extensible framework for the retrieval, processing and display of data from the cloud DocumentationIntroduction Base Types ObservableVector&amp;lt;T&amp;gt; VirtualizingVector&amp;lt;T&amp;gt; Cocoon Navigation Framework Defining pages and view models More to follow... Cocoon Data Framework (IDataListSource&amp;lt;T&amp;gt; and data lists) Introduction Example Code SimpleDataListSource&amp;lt;T&amp;gt; PagedDataListSource&amp;lt;T&amp;gt; VirtualizingDataList&amp;lt;T&amp;gt; Cocoon – A new framework for Windows 8 DevelopmentTo assist with Windows 8 Metro-style applications I would like to announce the Cocoon framework (http://cocoon.codeplex.com/). This aims to build on top of the learning from the Chrysalis project to provide a simple way to develop Metro-style applications in a manner that fits naturally with the MVVM design pattern.It is likely that many Metro-style apps will be connected applications, downloading data from across the internet in response to user navigation. Modern applications are expected to do </itunes:summary>
      <pubDate>Mon, 21 May 2012 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/blog/Gestating-your-Metro-Style-App-with-Cocoon</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>csharp</category>
      <category>coding4fun</category>
      <category>mef</category>
      <category>metro</category>
      <category>mvvm</category>
  </item>
  <item>
      <title>A triple dose of the .NET Micro Framework. Netduino, .NET Gadgeteer and a FEZ Hydra Basic Kit</title>
      <description><![CDATA[<p>Today's Hardware Friday is a triple dose of .NET Micro Framework and .NET Gadgeteer getting started, into, kicked off, hooked, what are they and getting started posts.</p><p>From a slide deck and great link round-up my Pete Brown, to watching him geek out for an hour to a getting started with FEZ Hydra Basic Kit post by Ian Lee, Sr. it's all here. If at the end of this, your &quot;I wanna build something&quot; itch isn't asking for attention...</p><h2><a href="http://10rem.net/blog/2012/02/26/the-net-micro-framework-and-net-gadgeteer" target="_blank">The .NET Micro Framework and .NET Gadgeteer</a></h2><blockquote><p>At the South Florida Code Camp last week, I presented the &quot;.NET Micro Framework and .NET Gadgeteer&quot;. The primary demo was the Gadgeteer diaper monitor, but I also showed off hardware, wired some LEDs to the Netduino etc.</p><p><a href="http://10rem.net/blog/2012/02/26/the-net-micro-framework-and-net-gadgeteer" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B3%5D-50.png" alt="image" width="639" height="358" border="0"></a></p><p><a href="http://10rem.net/blog/2012/02/26/the-net-micro-framework-and-net-gadgeteer" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B7%5D-19.png" alt="image" width="488" height="407" border="0"></a></p></blockquote><h2><a href="http://devhammer.net/blog/pete-brown-geeks-out-on-.net-gadgeteer-and-netduino" target="_blank">Pete Brown Geeks out on .NET Gadgeteer and Netduino</a></h2><blockquote><p>This past week, my friend and fellow Microsoftie, <a href="http://10rem.net/blog">Pete Brown</a>, ran a neat <a href="http://channel9.msdn.com/Events/Patterns-Practices-Symposium-Online/">online symposium for the Microsoft Patterns &amp; Practices group</a>. As part of the event, Pete did an hour-long session introducing the <a href="http://www.netmf.com/">.NET Micro Framework</a>, and many of the cool things you can do with the various devices in the NETMF ecosystem, including <a href="http://netduino.com/">Netduino, Netduino Go</a>, and <a href="http://www.netmf.com/gadgeteer/">.NET Gadgeteer</a> boards like the <a href="http://www.ghielectronics.com/catalog/product/269">FEZ Spider</a>. He was even kind enough to do a demo of <a href="http://devhammer.net/blog/gadgeteer-and-midi-making-music-with-microcontrollers">the Meeblipiator project</a> I put together using his <a href="http://10rem.net/blog/2012/03/31/midi-module-assembly-instructions">Gadgeteer MIDI module</a> (the demo is at around 45 minutes in). Here's the video…enjoy!</p><p><a href="http://channel9.msdn.com/Events/Patterns-Practices-Symposium-Online/Patterns-Practices-Symposium-Online-2012/Gadgeteering-and-hte-NET-Micro-Framework" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B12%5D-23.png" alt="image" width="650" height="364" border="0"></a></p></blockquote><h2><a href="http://blog.ianlee.info/2012/04/getting-started-with-hydra-basic-kit.html" target="_blank">Getting Started With a FEZ Hydra Basic Kit</a></h2><blockquote><p>I’m teaching a <a href="http://www.netmf.com/Home.aspx">NETMF</a> Gadgeteer lab for the <a href="http://nashdotnet.org/">Nashville .NET User’s Group</a> this week. Our gracious sponsors have purchased several <a href="http://www.ghielectronics.com/catalog/product/332">FEZ Hydra Basic Kits</a> made by <a href="http://www.ghielectronics.com/">GHI</a> Electronics that we’ll be using to introduce everyone to the Gadgeteer world.<br><br>The FEZ Hydra Basic Kit consists of:</p><ul><li><a href="http://www.ghielectronics.com/catalog/product/328">FEZ Hydra Mainboard</a> </li><li><a href="http://www.ghielectronics.com/catalog/product/330">USB Client SP Module</a> </li><li><a href="http://www.ghielectronics.com/catalog/product/318">LED7R Module</a> </li><li><a href="http://www.ghielectronics.com/catalog/product/299">Joystick Module</a> </li><li><a href="http://www.ghielectronics.com/catalog/product/336">LightSense Module</a> </li></ul>So, the challenge is what can we build with just these components? <p><strong>THE PLAN</strong><br>We’re going to build a simple project that will use the green LEDs on the outer ring of the LED7R module as a gauge to show the light level that is reported by the LightSense module. In the center of the LED7R module is a bright red LED. I’m going to use the Joystick module to vary the brightness of this LED.</p><p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/Dqa6Ae6CHgA&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Dqa6Ae6CHgA&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p><p><a href="http://blog.ianlee.info/2012/04/getting-started-with-hydra-basic-kit.html" target="_blank"><img title="image" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/image%5B16%5D-15.png" alt="image" width="551" height="180" border="0"></a></p><p>...</p><p>Run the program and now when you move the Joystick up &amp; down you should see a slight variation in the brightness of the red LED in the middle of the LED7R module.</p><p>Surely, you’re having fun now???</p><p>You may be asking yourself why we used Timers instead of just putting a loop in our ProgramStarted() event. This is one area where Gadgeteer is very different than traditional NETMF projects. <a href="http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx">Read this blog post</a> for an excellent explanation and you’ll save yourself some frustration down the line.</p><p><strong>WHAT NEXT?</strong><br>Well, that’s up to you! I’ve given you a simple example of a couple things you can do with the FEZ Hydra Basic Kit. Now, take this example and improve it or come up with something better (a game maybe?). Be sure to leave a comment on this post and tell me what you did or even better post a link to a video.</p><p>Have fun!</p><p>Download the complete project source <a href="https://docs.google.com/open?id=0B2AYdWBXfMJkdUt5SEZUTXRUYW8">here</a>.</p></blockquote> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:18d66b24ca9d47ec95ffa04f0102de1e">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/blog/A-triple-dose-of-the-NET-Micro-Framework-Netduino-NET-Gadgeteer-and-a-FEZ-Hydra-Basic-Kit</comments>
      <link>http://channel9.msdn.com/coding4fun/blog/A-triple-dose-of-the-NET-Micro-Framework-Netduino-NET-Gadgeteer-and-a-FEZ-Hydra-Basic-Kit</link>
      <itunes:summary>Today&#39;s Hardware Friday is a triple dose of .NET Micro Framework and .NET Gadgeteer getting started, into, kicked off, hooked, what are they and getting started posts.From a slide deck and great link round-up my Pete Brown, to watching him geek out for an hour to a getting started with FEZ Hydra Basic Kit post by Ian Lee, Sr. it&#39;s all here. If at the end of this, your &amp;quot;I wanna build something&amp;quot; itch isn&#39;t asking for attention...The .NET Micro Framework and .NET GadgeteerAt the South Florida Code Camp last week, I presented the &amp;quot;.NET Micro Framework and .NET Gadgeteer&amp;quot;. The primary demo was the Gadgeteer diaper monitor, but I also showed off hardware, wired some LEDs to the Netduino etc.Pete Brown Geeks out on .NET Gadgeteer and NetduinoThis past week, my friend and fellow Microsoftie, Pete Brown, ran a neat online symposium for the Microsoft Patterns &amp;amp; Practices group. As part of the event, Pete did an hour-long session introducing the .NET Micro Framework, and many of the cool things you can do with the various devices in the NETMF ecosystem, including Netduino, Netduino Go, and .NET Gadgeteer boards like the FEZ Spider. He was even kind enough to do a demo of the Meeblipiator project I put together using his Gadgeteer MIDI module (the demo is at around 45 minutes in). Here&#39;s the video…enjoy!Getting Started With a FEZ Hydra Basic KitI’m teaching a NETMF Gadgeteer lab for the Nashville .NET User’s Group this week. Our gracious sponsors have purchased several FEZ Hydra Basic Kits made by GHI Electronics that we’ll be using to introduce everyone to the Gadgeteer world.The FEZ Hydra Basic Kit consists of:FEZ Hydra Mainboard USB Client SP Module LED7R Module Joystick Module LightSense Module So, the challenge is what can we build with just these components? THE PLANWe’re going to build a simple project that will use the green LEDs on the outer ring of the LED7R module as a gauge to show the light level that is reported by the LightSense module. In</itunes:summary>
      <pubDate>Fri, 18 May 2012 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/blog/A-triple-dose-of-the-NET-Micro-Framework-Netduino-NET-Gadgeteer-and-a-FEZ-Hydra-Basic-Kit</guid>
      <dc:creator>Greg Duncan</dc:creator>
      <category>.net</category>
      <category>.net+framework</category>
      <category>.net+micro+framework</category>
      <category>coding4fun</category>
  </item>
  <item>
      <title>Project Detroit: An Overview</title>
      <description><![CDATA[<p>In this article, we will give an overview of the technical side of Project Detroit, the Microsoft-West Coast Custom Mustang creation. If you're not already familiar with this project, you can find more <a href="http://channel9.msdn.com/Blogs/Vector/The-400-horsepower-device">information here</a>.&nbsp;</p><h2>Key Design Decisions</h2><p>It’s important to keep in mind that this car was built for a TV show with a set schedule. As a result, there are a number of unique design decisions that came into play.</p><p><img src="http://files.channel9.msdn.com/thumbnail/09615539-1a33-49f7-b438-ca1b9543d712.jpg" alt=""></p><p><strong>Schedule<br><br></strong>Working backwards, the reveal for the car was set for Monday November 28, 2011 at the Microsoft Store in Bellevue, Washington. We started the project in early August, which gave us approximately 12 weeks for research, development, vehicle assembly, and testing. This was by far the #1 design decision as any ideas or features for the car had to be implemented by the reveal date.</p><p><strong>Off the Shelf Parts<br><br></strong>Another key design decision was to, where possible, use off-the-shelf hardware and software in order to allow&nbsp; interested developers to build and reuse some of the subsystems for their own car (at least the ones that don’t require welding). For example, instead of buying pricey custom sized displays for the instrument cluster or passenger display, we used stock <a href="http://www.microsoftstore.com/store/msstore/pd/Samsung-Series-7-Slate/productID.241554200/vip.true">Samsung Series 7 Slate</a> PCs and had West Coast Customs do the hard work of building a custom dash to hold the PC.</p><p>&nbsp;</p><h2>Hardware and Networking</h2><p>The car is packed with a variety of computers and networking hardware.</p><ul><li><strong>Instrument Cluster Slate</strong> – This slate is on the driver's side and manages the instrument cluster application and the On-Board Diagnostic (OBD) connection to read telemetry data from the car. </li><li><strong>Passenger Slate – </strong>This slate, which is built into the passenger's side, runs a custom Windows 8 application (see Passenger slate below). <br><img title="USA_" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/Built-In_Touch_screen_Displays_Web_thumb%5B1%5D.jpg" alt="USA_" width="324" height="212" border="0"> </li><li><strong>Laptop 1 – </strong>This laptop runs the REST service to control different parts of the car, the Kinect socket service for the front Kinect, and the user message service to display messages on the rear glass while driving. </li><li><strong>Laptop 2 </strong>– This laptop runs the Heads Up Display (HUD) service, the Kinect socket service for the back Kinect, the OBD-II database, and Azure services. </li><li><strong>Windows Phone – </strong>A Nokia Lumia 800 connects via WiFi and a custom Windows Phone 7 application (See Windows Phone application below). </li><li><strong>Xbox 360 – </strong>The Xbox 360 displays on either the passenger HUD or the rear glass display. </li><li><strong>Networking</strong> – A <a href="http://www.netgear.com/home/products/wirelessrouters/high-performance/wndr3700.aspx">NETGEAR N600/WNDR3700</a> wireless router provides wired and wireless access for everything in the car, which is used in conjunction with a Verizon USB network card plugged into a <a href="http://www.cradlepoint.com/products/small-business-home-office-routers/mbr900-cellular-router">Cradle Point MBR900</a> to provide an always-on 3G/4G LTE internet connection. The slates, laptops, and Xbox 360 are connected via CAT5e cable, while the Windows Phone 7 connects via WiFi. </li></ul><p><strong>Note: </strong>One of the limitations of the Kinect SDK is that if you have multiple Kinects plugged into one PC, only one of those Kinects can do skeletal tracking at a time (color/depth data works just fine). Because of this, we decided to have a dedicated laptop plugged into the front Kinect and another laptop plugged into the back Kinect in order to allow front and back skeletal tracking at the same time. If we'd not used simultaneous skeletal tracking, we could have combined all of the systems onto a single laptop.</p><h2>Architecture</h2><p>Here is a quick overview of the application architecture.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/detroitArch%5B7%5D-1.png"><img title="detroitArch" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/detroitArch_thumb%5B4%5D.png" alt="detroitArch" width="500" height="319" border="0"></a></p><h2>&nbsp;</h2><h2>REST Service Layer</h2><p>The REST Service Layer allowed different systems talk to one another. More importantly, it allowed different services to control hardware they normally wouldn't be able to access.</p><ol><li><strong>Thin client approach<br></strong>The solution we chose was to have all the services that control different parts of the car reside on the laptops and have client applications like the Windows Phone application send REST commands to execute an action so the service layer would execute the request. <br><br></li><li><strong>REST-enable hardware</strong> <br>Controlling hardware should be invisible to the consuming clients. For example, hardware that requires USB communication would be impossible to control with a Windows Phone. The service layer allowed us to control hardware in a way that was invisible to the end user. <br><br></li><li><strong>Helper Libraries</strong><br>To simplify communication with the service layer, we built a set of helper classes to abstract out repetitive tasks like JSON serialization/deserialization, URI building, etc. For example, to get the list of car horn “ringtones”, the client application can call <strong>HornClient.List()</strong> to get back a list of available ringtone filenames. To set the car horn, the client calls <strong>HornClient.Set(filename)</strong>, and to play the car horn, it then calls <strong>HornClient.Play(filename)</strong>. The Helper libraries were built to work on Windows 7, Windows 8, and Windows Phone 7. </li></ol><h2>OBD-II</h2><p>We have already released an <a href="http://channel9.msdn.com/coding4fun/articles/Project-Detroit-How-to-Read-Your-Cars-Engine-Data-with-OBD-II">article</a> and <a href="http://obd.codeplex.com/">library</a> on the OBD-II portion of the car.&nbsp; In short, OBD-II stands for On-Board Diagnostics. Hooking into this port allows one to query for different types of data from the car, which we use to get the current speed, RPMs, fuel level, etc. for display in the Instrument Cluster and other locations. OBD can do far more than this, but it's all we needed for our project. Please see the linked articles for further details on the OBD-II library itself.</p><p>For the car, because only one application can open and communicate with a serial port at one time, we created a WCF service that polls the OBD-II data from the car and GPS data from a <a href="http://www.microsoftstore.com/store/msstore/en_US/pd/productID.216603800">Microsoft Streets &amp; Trips GPS locator</a>, and returns it to any application that queries the service.</p><p>For the OBD library, we used a manual connection to poll different values at different intervals. For values critical to driving the car—like RPM, speed, etc.—we polled for the values as quickly as the car could return them. With other values that weren’t critical to driving the car—like the fuel level, engine coolant temperature, etc.—we polled at a 1-2 second interval. For GPS, we subscribed to the <strong>LocationChanged</strong> event, which would fire when the GPS values changed.</p><p>Rather than creating a new serial port connection for every WCF request for OBD data, we created a singleton service that is instantiated when the service first runs. Accordingly, there is only one object in the WCF service that represents the last OBD and GPS data returned, which is obtained by the continual reading of the latest OBD data using the OBD library as described above. This means that calls to the WCF service <strong>ReadMeasurement</strong> method didn’t actually compute anything, but instead serialized the last saved data and returned it via the WCF service.</p><p>Since WCF supports multiple protocols, we implemented HTTP and TCP and ensured that any WCF service options we chose worked on Windows Phone, which, for example, can only use basic HTTP bindings.</p><p>To enable the ability to change the programming model later and to simplify the polling of the service, we built a helper library for Windows and Windows Phone that abstracts all the WCF calls.</p><p>The code below creates a new <strong>ObdService</strong> class and signs up for an event when the measurement has changed. The <strong>Start</strong> method does a couple of things: it lets you set the interval that you want to poll the <strong>ObdService</strong>, in this case every second (while the instrument cluster needs fast polling, the database logger can poll once a second). It also determines what IP address the service is hosted at (localhost), the protocol (HTTP or TCP), and whether to send “demo mode” data. Since one of the main ways the car is showcased is when it’s stopped on display, “demo mode” sends fake data, instead of always returning 0's for MPH, RPM, etc., so people can see what the instrument cluster would look like in action.</p><p><pre class="brush: csharp">
_service = new ObdService();
_service.ObdMeasurementChanged &#43;= service_ObdMeasurementChanged;
_service.Start(new TimeSpan(0, 0, 0, 0, 1000), localhost, Protocol.Http, false);

void service_ObdMeasurementChanged(object sender, ObdMeasurementChangedEventArgs e)
{
  Debug.Writeline(&quot;MPH=” &#43; e.Measurement.MilesPerHour);
}
</pre></p><h2>OBD-II Database &amp; Azure Services</h2><p>To record and capture the car telemetry data like MPH, RPM, engine load, and throttle (accelerator) position, as well as location data (latitude, longitude, altitude, and course), we used a SQL Server Express database with a simple, flat Entity Framework model, shown below. The primary key, the <strong>ObdMeasurementID</strong> is a GUID that is returned via the <strong>ObdService</strong>.&nbsp; Just like above, the database logger subscribes to the <strong>ObdMeasurementChanged</strong> event and receives a new reading at the time interval set in the <strong>Start()</strong> method.</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B7%5D-3.png" alt="image" width="319" height="522" border="0"></p><p>The Windows Azure data model uses Azure Table Services instead of SQL Server. The data mapping is essentially the same since both have a flat schema.</p><p>For Azure Table Storage, in addition to the schema above, you also need a partition key and a row key. For the partition key, we used a custom <strong>TripID</strong> (GUID) to represent a Trip. When the car is turned on/off a new TripID is created. That way we could group all measurements for that particular trip and do calculations based on that trip, like the average miles per gallon, distance traveled, fastest speed, etc. For the row key, we used a <strong>DateTimeOffset </strong>and a custom extension method, <strong>ToEndOfDays</strong>() that provides a unique numerical string (since Azure's row key is a string type) that subtracts the time from the <strong>DateTime.</strong><strong>Max</strong> value. The result is that the earlier a <strong>DateTime</strong> value, the larger the number.</p><p>Example:</p><p>Time=5/11/2012 9:14:09 AM, EndOfDays=2520655479509478223 //larger <br>Time=5/11/2012 9:14:11 AM, EndOfDays=2520655479482804811 //smaller</p><p>Since they are ordered in reverse order, with the most recent date/time being the first row, we can write an efficient query to pull just the first row to get the current latitude/longitude without needing to scan the entire table for the last measurment.</p><pre><br><pre class="brush: csharp">
public override string RowKey
{
    get
    {
        return new DateTimeOffset(TimeStamp).ToEndOfDays();
    }
    set
    {
        //do nothing
    }
}

public static class DateTimeExtensions
{
  public static string ToEndOfDays(this DateTimeOffset source)
  {  
    TimeSpan timeUntilTheEnd = DateTimeOffset.MaxValue.Subtract(source);
    return timeUntilTheEnd.Ticks.ToString();
  }

  public static DateTimeOffset FromEndOfDays(this String daysToEnd)
  {
    TimeSpan timeFromTheEnd = newTimeSpan(Int64.Parse(daysToEnd));
    DateTimeOffset source = DateTimeOffset.MaxValue.Date.Subtract(timeFromTheEnd);
    return source;
  }
}
</pre><br><br></pre><p>To upload data to Azure, we used a timer-based background uploader that would check to see if there was an internet connection, and then filter and upload all of the local SQL Express rows that had not been submitted to Azure using the <strong>Submitted </strong>boolean database field. On the Azure side, we used an ASP.NET MVC controller to submit data. The controller deserializes the data into a <strong>List&lt;MeasurementForTransfer&gt; </strong>type, it adds the data to a blob, and adds the blob to a queue as shown below.</p><p>A worker role (or many) will then read items off the queue and the new OBD measurement rows are placed into Azure Table Storage.</p><pre><br><pre class="brush: csharp">
public ActionResult PostData()
{
    try
    {
        StreamReader incomingData = new StreamReader(HttpContext.Request.InputStream);

        string data = incomingData.ReadToEnd();
        JavaScriptSerializer oSerializer =
            new JavaScriptSerializer();

        List&lt;MeasurementForTransfer&gt; measurements;
        measurements = oSerializer.Deserialize(data, typeof(List&lt;MeasurementForTransfer&gt;)) as List&lt;MeasurementForTransfer&gt;;

        if (measurements != null)
        {
            CloudBlob blob = _blob.UploadStringToIncoming(data);
            _queue.PushMessageToPostQueue(blob.Uri.ToString());
            return new HttpStatusCodeResult(200);
        }
        ...
    }
}
</pre><br><br></pre><h2>Instrument Cluster</h2><p>Much of this is also covered in our previously released OBD-II library where the instrument cluster application is included as a sample. This is a WPF application that runs on a Windows 7 slate. It contains three different skins designed by <a href="www.352media.com">352 Media</a>—a 2012 Mustang dashboard, a 1967 Mustang dashboard, and a Metro-style dashboard—each of which can be &quot;swiped&quot; through. This application queries the OBD-II WCF service described above as quickly as it can to retrieve speed, RPM, fuel level, and other data for display to the driver. The gauges are updated in real-time just as a real dashboard instrument cluster would behave.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd1%5B2%5D.png"><img title="obd1" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd1_thumb.png" alt="obd1" width="244" height="139" border="0"></a><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd2%5B2%5D.png"><img title="obd2" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd2_thumb.png" alt="obd2" width="244" height="139" border="0"></a><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd3%5B2%5D.png"><img title="obd3" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/obd3_thumb.png" alt="obd3" width="244" height="139" border="0"></a></p><h2>HUD</h2><p>The HUD (or Heads Up Display) application runs on one of the two Windows 7 computers in the car. This is a full-screen application that is output via a projector to a series of mirrors and a projection screen. This is then reflected onto the front glass of the windshield of the car. To install these, we altered the physical car's body and created brackets to mount mirrors and the projectors. In the picture on the left, you can see the dashboard's structural member pivoted outward. You can see the 12&quot; section we removed and added in the base plate to allow light to be reflected through to the windshield. <a href="http://twitter.com/wjsteele">Bill Steele </a>helped design and implement the physical HUD aspect into the car.</p><p><iFrame src="http://channel9.msdn.com/posts/Project-Detroit-Hud/player?w=512&amp;h=288" frameborder="0" scrolling="no" width="512px" height="288px"></iFrame></p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/alterationFrame%5B2%5D.jpg"><img title="alterationFrame" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/alterationFrame_thumb.jpg" alt="alterationFrame" width="240" height="180" border="0"></a>&nbsp;<a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/mirrors%5B2%5D.jpg"><img title="mirrors" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/mirrors_thumb.jpg" alt="mirrors" width="240" height="180" border="0"></a></p><p>The HUD application has several different modes.&nbsp; The mode is selected from the Windows Phone application.</p><ul><li><strong>POI / Mapping</strong> – This uses <a href="http://msdn.microsoft.com/en-us/library/dd877180.aspx">Bing Maps services</a>. The phone or Windows 8 passenger application can choose one of a select group of categories (Eat, Entertain, Shop, Gas). Once selected, the REST service layer is contacted and the current choice is persisted. The HUD is constantly polling the service to know what the current category is, and when it changes, the HUD switches to an overhead map display with the closest locations of that category displayed, along with your always updated current GPS position and direction. The list of closest items in the category is requested every few seconds from the Bing Maps API and the map is updated appropriately. <br><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B10%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B6%5D-3.png" alt="image" width="324" height="204" border="0"></a> </li><li><strong>Car telemetry</strong> - In the car telemetry mode, the OBD data from the WCF service described above is queried and displayed on the screen.&nbsp; This can be though of as an overall car &quot;status&quot; display with the speed, RPMs, real-time MPG, time, and weather information. </li><li><strong>Weather</strong> – We use the <a href="http://www.worldweatheronline.com/">World Weather Online</a> API to get weather data for display on the HUD. This API allows queries for weather based on a latitude and longitude, which we have at all times. A quick call to the service gives us the current temperature and a general weather forecast, which we display as an icon next to the temperature in the lower-left portion of the screen. <strong><br><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B5%5D-4.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B3%5D-5.png" alt="image" width="324" height="204" border="0"></a></strong> </li><li><strong>Kinect</strong> – Using our <a href="http://kinectservice.codeplex.com/">Kinect Service</a>, with the standard WPF client code, we can display the rear camera on the HUD to help the driver when backing up. See the Kinect Service project for more information on how this works and to use the service in an application of your own. </li></ul><h2>&nbsp;</h2><h2>Windows Phone Application</h2><p>One of the main ways to control the vehicle is through the Windows Phone application.&nbsp; <br><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a%5B4%5D.png"><img title="a" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a_thumb%5B2%5D.png" alt="a" width="196" height="324" border="0"></a></p><p>The first pivot of the app allows the user to lock, unlock, start the car, and set off the alarm.&nbsp; This is done through the <a href="http://www.viper.com">Viper</a> product from <a href="http://www.directed.com">Directed Electronics</a>.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a%5B8%5D.png"><img title="a" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a_thumb%5B4%5D.png" alt="a" width="196" height="324" border="0"></a></p><p>The second pivot contains the remaining ways that a user can interact with the car.</p><ul><li><strong>Kinect</strong> – This uses the Kinect service much in the way the HUD does. It can display both the front and rear cameras as well as allow the user to listen to an audio clip and send it up to the car while applying a voice changing effect.<br><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a%5B13%5D.png"><img title="a" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a_thumb%5B7%5D.png" alt="a" width="196" height="324" border="0"></a> </li><li><strong>Voice Effect</strong> – When the Talk button is pressed, the user can record their voice via the microphone. When released, the audio data is packaged in a simple WAV file and uploaded to the REST service. The user can select from several voice effects, such as Chipmunk and Deep. On the service side, that WAV file is modified with the selected effect and then played through the PA system. The code in this section of the app is very similar to the <a href="http://skypefx.codeplex.com/">Coding4Fun Skype Voice Changer</a>. We use <a href="http://naudio.codeplex.com/">NAudio</a> and several pre-made effects to process the WAV file for play. </li><li><strong>Lighting</strong> – This controls the external lighting for the car. The user can select a zone, an animation, and a color to apply. Once selected, this is communicated through the REST service to the lighting controller.<strong><br><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a%5B17%5D.png"><img title="a" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/a_thumb%5B9%5D.png" alt="a" width="404" height="244" border="0"></a></strong> </li><li><strong>Messaging</strong> – This presents a list of known pictures and videos for the user. The selection is sent to the car through the REST service and displayed on the projector that is pointed at the rear window, allowing following drivers to see the image, video, or message.&nbsp; </li><li><strong>Point Of Interest</strong> – As described earlier, this is the way the user can turn on the Point of Interest map on the HUD.&nbsp; Selecting one of the four items sends the selection to the REST service where it is persisted. The polling HUD will know when the selection is changed and display the map interface as shown above. </li><li><strong>Telemetry</strong> – This is a replica of the instrument cluster that runs on the Windows 7 slate. OBD data is queried via the WCF service, just like the slate, and displayed on the gauges, just like the slate.<br>&nbsp;<a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B13%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B7%5D-2.png" alt="image" width="404" height="199" border="0"></a> </li><li><strong>Projection Screen</strong> – This will raise and lower the projection screen on the rear of the car. </li><li><strong>Horn</strong> – This displays a list of known horn sound effects that live on the REST service layer. Selecting any of the items will send a command through the REST to play that sound file on the external sound system of the car. This selected audio file would play when the horn was pressed in the car. </li><li><strong>Settings</strong> – Internal settings for setting up hardware and software for the car. </li></ul><h2>Passenger Application</h2><p>The passenger interface runs on a Samsung Series 7 slate running the Windows 8 Consumer Preview. This interface has a subset of the functionality provided by the Windows Phone application, but communicates through the same REST service. From this interface, the passenger can set the car horn sound effect, view the front and back Kinect cameras, select a Point of Interest category to be displayed on the HUD, and select the image, video or message that will be displayed on the rear window.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B14%5D-2.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B8%5D-5.png" alt="image" width="324" height="204" border="0"></a></p><h2>External Car Lighting</h2><p>The external lighting system was controlled by a web server running on a <a href="http://netduino.com/netduinoplus/specs.htm">Netduino Plus</a> using a <a title="http://www.sparkfun.com/products/7914" href="http://www.sparkfun.com/products/7914">Sparkfun protoshield board</a> to simplify wiring, and allow for another shield to be used. The actual lights were <a href="http://www.adafruit.com/products/306">Digital Addressable RGB LED w/ PWM</a>. We'll also have a more in-depth article on this system on Coding4Fun shortly.</p><p>The car is broken down into different zones—grill, wheels, vents, etc. It also has a bunch of pre-defined procedural animation patterns that have a few adjustable parameters that allow for things like a snake effect, a sensor sweep, or even a police pattern. Each zone has its own thread which provides the ability to have multiple animation patterns going at the same time. When a command is received, the color, pattern, zone, and other data is then processed.</p><p>Here is a basic animation loop pattern.</p><p><pre class="brush: csharp">
private static void RandomAnimationWorker()
{
    var leds = GetLedsToIlluminate();
    var dataCopy = _data;
    var r = new Random();

    while (IsThreadSignaledToBeAlive(dataCopy.LightingZone))
    {
        for (var i = 0; i &lt; leds.Length; i&#43;&#43;)
            SetLed(leds[i], r.Next(255), r.Next(255), r.Next(255));

        LedRefresh();
        Thread.Sleep(dataCopy.TickDuration);
    }
}
</pre></p><h2>Rear Projection Window</h2><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/rearGlass%5B4%5D.jpg"><img title="rearGlass" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/rearGlass_thumb%5B2%5D.jpg" alt="rearGlass" width="480" height="360" border="0"></a></p><p>The rear projection system consists of <a href="http://www.trossenrobotics.com/store/p/5183-4-Inch-Stroke-110-LB-Linear-Actuator-with-Feedback.aspx">two 4” linear actuators</a>, <a href="http://www.trossenrobotics.com/store/p/5189-Dual-Linear-Actuator-Controller.aspx">a linear actual controller</a>, the NETMF web server from above, a <a href="http://www.seeedstudio.com/depot/relay-shield-p-693.html?cPath=132_134">Seeed Studio Relay Shield</a>, the back glass of a 1967 Ford Mustang, some <a href="http://www.ssidisplays.com/rear-projection-film/intrigue">rear projection film</a>, <a href="http://www.amazon.com/Casio-Green-Projector-Lumens-XJ-A250/sim/B004I36R6Q/2">a low profile yet insanely bright projector that accepts serial port commands</a>, and a standard USB to serial adapter.</p><p>The REST service layer toggles the input of the projector based on the selected state.&nbsp; This would allow us to go from the HDMI output of an Xbox 360 to the VGA output of the laptop.&nbsp; While doing this, the REST layer sends a command to the NETMF web server to either raise or lower the actuators.</p><p>Here is the code for the NETMF to control the raising and lowering the glass:</p><p><pre class="brush: csharp">
public static class Relay
{
    // code for for Electronic Brick Relay Shield
    static readonly OutputPort RaisePort = new OutputPort(Pins.GPIO_PIN_D5, false);
    static readonly OutputPort LowerPort = new OutputPort(Pins.GPIO_PIN_D4, false);

    const int OpenCloseDelay = 1000;

    public static bool Raise()
    {
        return ExecuteRelay(RaisePort);
    }

    public static bool Lower()
    {
        return ExecuteRelay(LowerPort);
    }

    private static bool ExecuteRelay(OutputPort port)
    {
        port.Write(true);
        Thread.Sleep(OpenCloseDelay);
        port.Write(false);

        return true;
    }
}
</pre></p><h2>Messaging System</h2><p>This is a WPF application that leveraged the file system on the computer to communicate between the REST service layer and itself.&nbsp; Visually, it shows the message/image/video in the rear view mirror but it actually does two other tasks, it operates our car horn system and plays the recorded audio output from the phone.</p><ul><li><strong>Displaying Messages</strong><br>To display images, we poll the REST service every second for an update.&nbsp; Depending on the return type, we either display a TextBlock element or a MediaElement.<br><br></li><li><strong>Detecting and Playing Car Horn</strong><br>When someone presses the horn in the car, it is detected by a Phidget 8/8/8 wired into a Digital Input. In-between the car horn and the Phidget, there is a relay as well. This isolates the voltage coming from the horn and solves a grounding issue. We then feed back two wires from that relay and put one into the ground and the other into one of the digital inputs. In the application, we listen to the <strong>InputChange</strong> event on the Phidget and play / stop the audio based on the state.<br><br></li><li><strong>Detecting new recorded audio from the phone and car horn changes</strong><br>When someone talks into the phone or selects a new car horn, the REST service layer places that audio file into a predetermined directory. The Messaging service then uses a <strong>FileSystemWatcher</strong> to detect when this file is added. The difference between the car horn detection and recorded audio is the recorded audio will play once it is done writing to the file system. </li></ul><h2>External PA System</h2><p>To interact with people, we installed an external audio PA or Public Address system. This system is hooked into the laptop that is connected to the car horn, and can play audio data from the phone. Having a PA system that is as simple as an audio jack that plugs into a PC enabled us to have different ringtones for the car horn and to talk through the car using Windows Phone.</p><h2>Conclusion</h2><p>After months of planning and building, the Project Detroit car was shown to the world on an episode of Inside West Coast Customs. Though it was a ton of work, the end product is something we are all proud of. We hope that this project inspires other developers to think outside the box and realize what can be done with some off-the-shelf hardware, software, and passion.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/splash%5B5%5D.jpg"><img title="splash" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/splash_thumb%5B3%5D.jpg" alt="splash" width="480" height="350" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:1a2766655d5e40eb9dbea030013669f1">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Project-Detroit-An-Overview</comments>
      <link>http://channel9.msdn.com/coding4fun/articles/Project-Detroit-An-Overview</link>
      <itunes:summary>In this article, we will give an overview of the technical side of Project Detroit, the Microsoft-West Coast Custom Mustang creation. If you&#39;re not already familiar with this project, you can find more information here.&amp;nbsp;Key Design DecisionsIt’s important to keep in mind that this car was built for a TV show with a set schedule. As a result, there are a number of unique design decisions that came into play.ScheduleWorking backwards, the reveal for the car was set for Monday November 28, 2011 at the Microsoft Store in Bellevue, Washington. We started the project in early August, which gave us approximately 12 weeks for research, development, vehicle assembly, and testing. This was by far the #1 design decision as any ideas or features for the car had to be implemented by the reveal date.Off the Shelf PartsAnother key design decision was to, where possible, use off-the-shelf hardware and software in order to allow&amp;nbsp; interested developers to build and reuse some of the subsystems for their own car (at least the ones that don’t require welding). For example, instead of buying pricey custom sized displays for the instrument cluster or passenger display, we used stock Samsung Series 7 Slate PCs and had West Coast Customs do the hard work of building a custom dash to hold the PC.&amp;nbsp;Hardware and NetworkingThe car is packed with a variety of computers and networking hardware.Instrument Cluster Slate – This slate is on the driver&#39;s side and manages the instrument cluster application and the On-Board Diagnostic (OBD) connection to read telemetry data from the car. Passenger Slate – This slate, which is built into the passenger&#39;s side, runs a custom Windows 8 application (see Passenger slate below).  Laptop 1 – This laptop runs the REST service to control different parts of the car, the Kinect socket service for the front Kinect, and the user message service to display messages on the rear glass while driving. Laptop 2 – This laptop runs the Heads Up Display (HUD) se</itunes:summary>
      <pubDate>Mon, 14 May 2012 16:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Project-Detroit-An-Overview</guid>
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez</dc:creator>
      <category>project+detroit</category>
  </item>
  <item>
      <title>Making Mayhem with Volume Control</title>
      <description><![CDATA[<p>Why, hello there! We are going to pick up where we left off at the end of our Coding4Fun video. In the video we built a reaction that increments the volume level on the computer. We are going to expand from there to make a reaction that enables you to set the volume level to a specified volume.</p><p><iFrame src="http://channel9.msdn.com/Blogs/Clint/Project-Mayhem-Creating-a-module/player?w=512&amp;h=288" frameborder="0" scrolling="no" width="512px" height="288px"></iFrame></p><p><a href="http://media.ch9.ms/c4f/c4f/MayhemVolumeStart.zip"><strong>MayhemVolumeStart.zip file</strong></a>&nbsp;contains the class library project all set up with the NuGet package references and the reaction that increments the volume.</p><p>The first step we are going to take is to add the additional references we need to be configurable. The first reference is <strong>MayhemWpf</strong> from the same NuGet feed <strong>MayhemCore</strong> is from. (<a href="http://makemayhem.com/nuget">http://makemayhem.com/nuget</a>). Add a reference to the following assemblies:</p><ul><li><strong>PresentationCore</strong> </li><li><strong>PresentationFramework</strong> </li><li><strong>System.Runtime.Serialization</strong> </li><li><strong>System.Xaml</strong> </li><li><strong>WindowsBase</strong>. </li></ul><p>Next, we switch the code from incrementing the volume to setting the volume to 50%.</p><p>To do this, replace the line:</p><p><pre class="brush: csharp">
device.AudioEndpointVolume.VolumeStepUp();
</pre></p><p>with</p><p><pre class="brush: csharp">
device.AudioEndpointVolume.MasterVolumeLevelScalar = 50 / 100.0f;
</pre></p><p>The reaction now works successfully to set the volume to half way. The next step is to make that setting configurable, and persist between application runs. Let’s make that 50 a variable. Add a private integer to the class (I’m calling it level) and change the above line to be:</p><p><pre class="brush: csharp">
device.AudioEndpointVolume.MasterVolumeLevelScalar = level / 100.0f;
</pre></p><p>Since that variable will be user configurable, we want to be able to show a string on the main window that says what the reaction is doing. To do this, we have to tell Mayhem that our reaction is configurable by implement the <strong>IWpfConfigurable</strong> interface from <strong>MayhemWpf</strong>.</p><p>In order to set that configuration string we have to implement the method <strong>GetConfigString</strong>. The implementation of this method should return some string that provides a look into what the configuration settings are for the reaction.</p><p>I will make the <strong>GetConfigString</strong> method be the following:</p><p><pre class="brush: csharp">
public string GetConfigString()
{
   return string.Format(&quot;Set the volume to {0}%&quot;,level);
}
</pre></p><pre>&nbsp;</pre><p>Now, in order to make the module save the configured state when the application is shut down and restarted, we need to add a little bit of data contract code. We are going to add the <strong>[DataContract]</strong> attribute to our class. This attribute comes from the <strong>System.Runtime.Serialization</strong> framework.</p><p>Our class header now looks like:</p><p><pre class="brush: csharp">
[DataContract]
[MayhemModule(&quot;Set Volume&quot;, &quot;Sets the master volume level&quot;)]
public class SetVolume : ReactionBase, IWpfConfigurable
</pre></p><p>Note that I also changed the <strong>MayhemModule</strong> attribute’s name and description to reflect the new functionality.</p><p>We also need to mark the configurable variables to be saved as well. To do that, add the <strong>[DataMember]</strong> attribute to our level variable:</p><p><pre class="brush: csharp">
[DataMember]
private int level;
</pre></p><p>In order to set a default value for this variable, we shouldn’t initialize it using a constructor. Constructors should never be used in modules. Instead, we have a method that should be overridden that you get from <strong>ReactionBase</strong>. <strong>OnLoadDefaults</strong> is to load the settings you want to have by default.</p><p><pre class="brush: csharp">
protected override void OnLoadDefaults()
{
   level = 50;
}
</pre></p><p>Now when you use the <strong>SetVolume</strong> reaction in Mayhem, it will at 50%, but if that value is changed and the application is restarted, it will be set to the value it was at before it was closed!</p><p>The next step is to make the configuration window that actually enables that variable to be modified.</p><p>Add a new WPF <strong>UserControl</strong> item to the project named <strong>SetVolumeConfig.xaml</strong>.</p><p>Replace the contents of the XAML file with:</p><p><pre class="brush: xml">
&lt;src:WpfConfiguration x:Class=&quot;Volume.SetVolumeConfig&quot;
   xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
   xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;   
   xmlns:src=&quot;clr-namespace:MayhemWpf.UserControls;assembly=MayhemWpf&quot;
   Width=&quot;300&quot;&gt;
   &lt;Grid&gt;
      &lt;Grid.ColumnDefinitions&gt;
         &lt;ColumnDefinition Width=&quot;100&quot; /&gt;
         &lt;ColumnDefinition Width=&quot;200&quot; /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;Grid.RowDefinitions&gt;
         &lt;RowDefinition /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;TextBlock Style=&quot;{StaticResource ConfigLabel}&quot; Grid.Column=&quot;0&quot; Grid.Row=&quot;0&quot;&gt;Volume:&lt;/TextBlock&gt;
      &lt;Slider Grid.Column=&quot;1&quot; Grid.Row=&quot;0&quot; Height=&quot;23&quot; HorizontalAlignment=&quot;Left&quot;  Name=&quot;VolumeSlider&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;200&quot; Maximum=&quot;100&quot; /&gt;
   &lt;/Grid&gt;
&lt;/src:WpfConfiguration&gt;
</pre></p><p>This configuration window simply has a volume slider allowing values between 0 and 100. <strong>WpfConfiguration</strong> handles the display of how the module asks for information. As you hopefully notice, it doesn’t contain the save button, or the title of the window. All that is handled for you so that we can maintain consistency between configuration windows. We also provide default styles that further maintain consistency and user expectation.</p><p>We now need to create the backing code that makes the configuration window come together. Change <strong>SetVolumeConfig.xaml.cs</strong> to extend the base class <strong>WpfConfiguration</strong> instead of the default <strong>UserControl</strong> base class.</p><p>In the constructor, we should ask for all the information we need to populate the config window with the current settings. In this situation, that only means the current volume level setting. Add an <strong>int</strong> parameter to the constructor called <strong>level</strong>. Also add a public property on the class with a private setter called <strong>Level</strong>. In the constructor, set this property with the parameter passed in to the constructor.</p><p>Your class should now look like this:</p><p><pre class="brush: csharp">
using MayhemWpf.UserControls;
namespace Volume
{
   public partial class SetVolumeConfig : WpfConfiguration
   {
      public int Level
      {
         get;
         private set;
      }
      public SetVolumeConfig(int level)
      {
         this.Level = level;
         InitializeComponent();
      }
   }
}
</pre></p><p><strong>WpfConfiguration</strong> gives us some handy hooks that we can use. We need to set the value property on our slider. This could be done with data bindings, but for simplicity we will just be doing this with code. Also, there is a <strong>Boolean</strong> flag in the <strong>WpfConfiguration</strong> class that enables the <strong>Save</strong> button on the dialog. When handling user input, the save button should only be enabled if the input is valid. Since the slider always has a value in our range, the Save button can always be enabled. We will set this flag in the <strong>OnLoad</strong> method.</p><p>Override the <strong>OnLoad</strong> method as follows:</p><p><pre class="brush: csharp">
public override void OnLoad()
{
   VolumeSlider.Value = this.Level;
   CanSave = true;
}
</pre></p><p>We then also override the <strong>OnSave</strong> method to set the property to the value the <strong>SetVolume</strong> class will expect.</p><p><pre class="brush: csharp">
public override void OnSave()
{
   this.Level = (int)VolumeSlider.Value;
}
</pre></p><p>Lastly, we need to set the title that shows up on the configuration window. To do this, override the <strong>Title</strong> property and have it return “Set Volume”:</p><p><pre class="brush: csharp">
public override string Title
{
   get { return &quot;Set Volume&quot;; }
}
</pre></p><p>Now we need to go back to the <strong>SetVolume</strong> class and implement those configuration related methods.</p><p>The <strong>ConfigurationControl</strong> property needs to return an instance of the <strong>SetVolumeConfig</strong> class. Remember that its constructor expects the current volume setting:</p><p><pre class="brush: csharp">
public WpfConfiguration ConfigurationControl
{
   get
   {
      return new SetVolumeConfig(level);
   }
}
</pre></p><p>Lastly, <strong>OnSaved</strong> takes the instance of <strong>WpfConfiguration</strong> control we just returned in the above property. We need to cast this back to <strong>SetVolumeConfig</strong> to be able to get access to the <strong>Level</strong> property:</p><p><pre class="brush: csharp">
public void OnSaved(WpfConfiguration configurationControl)
{
   var config = (SetVolumeConfig)configurationControl;
   this.level = config.Level;
}
</pre></p><p>That’s all it takes! This code provides us with a complete reaction that enables us to set the volume level on the computer. As you can see, we provide a very straightforward API enabling you, the developer, to write user configurable modules for Mayhem.&nbsp; You can click the <a href="http://media.ch9.ms/c4f/c4f/MayhemVolumeFinal.zip">download link at the top of the screen to get the final code in MayhemVolumeFinal.zip.</a></p><p>We have more documentation available on the available methods and APIs on our <a href="http://mayhem.codeplex.com/documentation">CodePlex documentation page</a>.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Entry:RSSView:faf9580cdc464e22a2d6a041014269f4">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Making-Mayhem-with-Volume-Control</comments>
      <link>http://channel9.msdn.com/coding4fun/articles/Making-Mayhem-with-Volume-Control</link>
      <itunes:summary>Why, hello there! We are going to pick up where we left off at the end of our Coding4Fun video. In the video we built a reaction that increments the volume level on the computer. We are going to expand from there to make a reaction that enables you to set the volume level to a specified volume.MayhemVolumeStart.zip file&amp;nbsp;contains the class library project all set up with the NuGet package references and the reaction that increments the volume.The first step we are going to take is to add the additional references we need to be configurable. The first reference is MayhemWpf from the same NuGet feed MayhemCore is from. (http://makemayhem.com/nuget). Add a reference to the following assemblies:PresentationCore PresentationFramework System.Runtime.Serialization System.Xaml WindowsBase. Next, we switch the code from incrementing the volume to setting the volume to 50%.To do this, replace the line:
device.AudioEndpointVolume.VolumeStepUp();
with
device.AudioEndpointVolume.MasterVolumeLevelScalar = 50 / 100.0f;
The reaction now works successfully to set the volume to half way. The next step is to make that setting configurable, and persist between application runs. Let’s make that 50 a variable. Add a private integer to the class (I’m calling it level) and change the above line to be:
device.AudioEndpointVolume.MasterVolumeLevelScalar = level / 100.0f;
Since that variable will be user configurable, we want to be able to show a string on the main window that says what the reaction is doing. To do this, we have to tell Mayhem that our reaction is configurable by implement the IWpfConfigurable interface from MayhemWpf.In order to set that configuration string we have to implement the method GetConfigString. The implementation of this method should return some string that provides a look into what the configuration settings are for the reaction.I will make the GetConfigString method be the following:
public string GetConfigString()
{
   return string.Format(&amp;quot;</itunes:summary>
      <pubDate>Mon, 30 Apr 2012 21:22:27 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Making-Mayhem-with-Volume-Control</guid>
      <dc:creator></dc:creator>
      <category>csharp</category>
      <category>wpf</category>
  </item>
  <item>
      <title>Project Detroit: OBD-II Manager</title>
      <description><![CDATA[<p>Read diagnostic information from your car and display it on a slick instrument cluster dashboard!</p><p>The <a href="http://obd.codeplex.com/"><strong>OBD-II Manager</strong></a> project is the OBD-II sub-system and instrument cluster application from the <a href="http://channel9.msdn.com/coding4fun/detroit">Project Detroit Mustang</a> we built with West Coast Customs.&nbsp; If you're not familiar with this project, you can find out more about it <a href="http://channel9.msdn.com/coding4fun/detroit">here</a> and <a href="http://channel9.msdn.com/Blogs/Vector/The-400-horsepower-device">here</a>.</p><p>OBD stands for On-Board Diagnostics.&nbsp; In the world of cars, this can be thought of as the computer which has a variety of data points which can be queried, such as speed, fuel level, and even trouble codes that relate to the check engine light.&nbsp; If you've ever taken your car in for service, your service center has hooked up the car to a computer via the OBD port to get the status of the car and what may not be working properly.&nbsp;</p><p>This project contains a library you can use to integrate OBD data into your application, as well as a modified version of the actual Instrument Cluster application used in the Project Detroit car which shows how the library can be used.</p><p><strong>More Information</strong></p><ul><li><a href="http://channel9.msdn.com/coding4fun/articles/Project-Detroit-How-to-Read-Your-Cars-Engine-Data-with-OBD-II">Coding4Fun Article</a> </li><li><a href="http://channel9.msdn.com/coding4fun/detroit">Project Detroit</a> </li><li><a href="http://www.scantool.net/scan-tools/pc-based/obdlink-sx.html">OBD-II to USB cable</a> (ELM323/327-based OBD-II to USB cable) </li><li><a href="http://en.wikipedia.org/wiki/OBD-II#OBD-II">More information on OBD-II</a> </li><li><a href="http://elmelectronics.com/DSheets/ELM327DS.pdf">ELM323/327 Datasheet</a> </li></ul><p><strong>Instrument Cluster Screenshots</strong></p><p><a href="http://files.channel9.msdn.com/thumbnail/b964d3a7-3494-4f60-9ffd-98e10f57cfdc.png" rel="lightbox"><img src="http://files.channel9.msdn.com/thumbnail/b964d3a7-3494-4f60-9ffd-98e10f57cfdc.png" alt=""></a></p><p><a href="http://files.channel9.msdn.com/thumbnail/ffbfa48f-e04b-400d-a79d-058641ed3642.png" rel="lightbox"><img src="http://files.channel9.msdn.com/thumbnail/ffbfa48f-e04b-400d-a79d-058641ed3642.png" alt=""></a></p><p><a href="http://files.channel9.msdn.com/thumbnail/a77f1db4-746d-4743-8e1b-9f0cc5618a84.png" rel="lightbox"><img src="http://files.channel9.msdn.com/thumbnail/a77f1db4-746d-4743-8e1b-9f0cc5618a84.png" alt=""></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Project:RSSView:4afca774455e450bbbd8a02e013f8ee0">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/projects/Project-Detroit-OBD-II-Manager</comments>
      <link>http://channel9.msdn.com/coding4fun/projects/Project-Detroit-OBD-II-Manager</link>
      <itunes:summary>Read diagnostic information from your car and display it on a slick instrument cluster dashboard!The OBD-II Manager project is the OBD-II sub-system and instrument cluster application from the Project Detroit Mustang we built with West Coast Customs.&amp;nbsp; If you&#39;re not familiar with this project, you can find out more about it here and here.OBD stands for On-Board Diagnostics.&amp;nbsp; In the world of cars, this can be thought of as the computer which has a variety of data points which can be queried, such as speed, fuel level, and even trouble codes that relate to the check engine light.&amp;nbsp; If you&#39;ve ever taken your car in for service, your service center has hooked up the car to a computer via the OBD port to get the status of the car and what may not be working properly.&amp;nbsp;This project contains a library you can use to integrate OBD data into your application, as well as a modified version of the actual Instrument Cluster application used in the Project Detroit car which shows how the library can be used.More InformationCoding4Fun Article Project Detroit OBD-II to USB cable (ELM323/327-based OBD-II to USB cable) More information on OBD-II ELM323/327 Datasheet Instrument Cluster Screenshots</itunes:summary>
      <pubDate>Mon, 09 Apr 2012 19:23:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/projects/Project-Detroit-OBD-II-Manager</guid>
      <dc:creator>Brian Peek, Dan Fernandez</dc:creator>
      <category>coding4fun</category>
      <category>hardware</category>
      <category>project+detroit</category>
  </item>
  <item>
      <title>Boxing Bots: Kinect-Driven Pneumatic Boxing Robots</title>
      <description><![CDATA[<p><a title="Boxing Robots!" href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0296%5B5%5D.jpg" rel="lightbox"><img title="IMG_0296" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0296_thumb%5B2%5D.jpg" alt="IMG_0296" width="640" height="480" border="0"></a></p><p>At the SXSW Interactive Opening Party hosted by Frog Design and Microsoft, the Coding4Fun team has unveiled their latest invention, BoxingBots!</p><p>With BoxingBots you are the controller except this time, forget the screen. You’re controlling a 6-foot tall metal robot that’s trying to punch out your opponent’s 6-foot tall machine. It’s Real Steel in real time.</p><h3>Video Demo</h3><p>Watch Laura Foy's video of the <a href="http://channel9.msdn.com/posts/Boxing-Bots-at-South-by-South-West">BoxingBots in action</a>!</p><p>BoxingBots combines Kinect’s motion sensing technology with pneumatic robots in a 6-foot square ring. Two players face off to try to knock each other’s blocks off.</p><h3>Each robot has</h3><ul><li>1 On-board laptop PC </li><li>70 programmatic LEDs in the head and chest controlled by a Phidgets LED controller board </li><li>2 2.5 gallon tanks of compressed air @ 150 PSI </li><li>8 12-volt 17amp batteries </li><li>2 Roboteq motor controllers that power the four omni-directional wheels </li><li>2 5&quot; stroke cylinders that punches/retracts the arms </li><li>1 6' stroke cylinder that lifts the head when the robot is knocked out </li><li>2 button switches on the chest that are triggered by punches and a Phidget 8/8/8 interface board that controls the relays and buttons switches </li></ul><p>&nbsp;</p><h3>How gameplay happens</h3><ul><li>Each robot's on-board PC receive commands over the network from the Admin PC for movement, punches, score, etc </li><li>Each player stands in front of a Kinect for Windows-enabled PC that interprets their gestures (punch, move in a direction, strafe, rotate) and sends that as a command to the Admin PC </li><li>The Admin PC manages the game, including pausing, reset, starting, sending commands to the robots and receiving damage data from the robots when the robot has been punched </li></ul><p>&nbsp;</p><h3>Photos</h3><p>&nbsp;</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0290%5B5%5D.jpg"><img title="IMG_0290" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0290_thumb%5B2%5D.jpg" alt="IMG_0290" width="360" height="480"></a></p><p>&nbsp;</p><p>&nbsp;</p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0291%5B5%5D.jpg"><img title="IMG_0291" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0291_thumb%5B2%5D.jpg" alt="IMG_0291" width="640" height="480" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0292%5B5%5D.jpg"><img title="IMG_0292" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0292_thumb%5B2%5D.jpg" alt="IMG_0292" width="640" height="480" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0295%5B7%5D.jpg"><img title="IMG_0295" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0295_thumb%5B1%5D.jpg" alt="IMG_0295" width="640" height="480" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0298%5B3%5D.jpg"><img title="IMG_0298" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0298_thumb.jpg" alt="IMG_0298" width="640" height="480" border="0"></a></p><p><a href="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0300%5B3%5D.jpg"><img title="IMG_0300" src="http://files.channel9.msdn.com/wlwimages/ae054c0b4d7b402ab1239e6800c0220f/IMG_0300_thumb.jpg" alt="IMG_0300" width="640" height="480" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Project:RSSView:d7eb062302294149a870a011001cbec0">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/projects/BoxingBots</comments>
      <link>http://channel9.msdn.com/coding4fun/projects/BoxingBots</link>
      <itunes:summary>At the SXSW Interactive Opening Party hosted by Frog Design and Microsoft, the Coding4Fun team has unveiled their latest invention, BoxingBots!With BoxingBots you are the controller except this time, forget the screen. You’re controlling a 6-foot tall metal robot that’s trying to punch out your opponent’s 6-foot tall machine. It’s Real Steel in real time.Video DemoWatch Laura Foy&#39;s video of the BoxingBots in action!BoxingBots combines Kinect’s motion sensing technology with pneumatic robots in a 6-foot square ring. Two players face off to try to knock each other’s blocks off.Each robot has1 On-board laptop PC 70 programmatic LEDs in the head and chest controlled by a Phidgets LED controller board 2 2.5 gallon tanks of compressed air @ 150 PSI 8 12-volt 17amp batteries 2 Roboteq motor controllers that power the four omni-directional wheels 2 5&amp;quot; stroke cylinders that punches/retracts the arms 1 6&#39; stroke cylinder that lifts the head when the robot is knocked out 2 button switches on the chest that are triggered by punches and a Phidget 8/8/8 interface board that controls the relays and buttons switches &amp;nbsp;How gameplay happensEach robot&#39;s on-board PC receive commands over the network from the Admin PC for movement, punches, score, etc Each player stands in front of a Kinect for Windows-enabled PC that interprets their gestures (punch, move in a direction, strafe, rotate) and sends that as a command to the Admin PC The Admin PC manages the game, including pausing, reset, starting, sending commands to the robots and receiving damage data from the robots when the robot has been punched &amp;nbsp;Photos&amp;nbsp;&amp;nbsp;&amp;nbsp;</itunes:summary>
      <pubDate>Sun, 11 Mar 2012 02:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/projects/BoxingBots</guid>
      <dc:creator>Brian Peek, Clint Rutkas, Rick Barraza</dc:creator>
  </item>
  <item>
      <title>Kinect Service</title>
      <description><![CDATA[<p>The <strong>Coding4Fun Kinect Service</strong> allows you to stream Kinect color, depth, skeleton, and audio from one PC to another PC or a Windows Phone via sockets. Both server and client libraries are available to send and receive the data.&nbsp; Please review the included WPF and Windows Phone samples for a quick explanation of how to use the libraries.&nbsp; Also check out the <a href="http://kinectservice.codeplex.com/documentation">Documentation tab</a> on CodePlex for more information and sample usage.</p><h2>WPF Sample Screenshots</h2><p><a href="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336814"><img title="Untitled" src="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336815" alt="Untitled" width="426" height="238" border="0"></a></p><h2>Windows Phone Sample Screenshots</h2><p><a href="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336926"><img title="3" src="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336927" alt="3" width="164" height="272" border="0"></a><a href="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336928"><img title="1" src="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336929" alt="1" width="164" height="272" border="0"></a><a href="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336930"><img title="2" src="http://download.codeplex.com/Download?ProjectName=kinectservice&amp;DownloadId=336931" alt="2" width="164" height="272" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/coding4fun/rss&WT.dl=0&WT.entryid=Project:RSSView:8c0d76e8ee8942c69f429feb0050b146">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/projects/Kinect-Service</comments>
      <link>http://channel9.msdn.com/coding4fun/projects/Kinect-Service</link>
      <itunes:summary>The Coding4Fun Kinect Service allows you to stream Kinect color, depth, skeleton, and audio from one PC to another PC or a Windows Phone via sockets. Both server and client libraries are available to send and receive the data.&amp;nbsp; Please review the included WPF and Windows Phone samples for a quick explanation of how to use the libraries.&amp;nbsp; Also check out the Documentation tab on CodePlex for more information and sample usage.WPF Sample ScreenshotsWindows Phone Sample Screenshots</itunes:summary>
      <pubDate>Thu, 02 Feb 2012 04:53:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/projects/Kinect-Service</guid>
      <dc:creator>Brian Peek</dc:creator>
      <category>kinect</category>
  </item>    
</channel>
</rss>
