MIX11

Posted April 8, 2011 11:18 AM Categories: Coding4Fun | Wiimote | Hardware | Coding4Fun Show | Channel 9 | MIX11

imageIt's almost time for another MIX conference! Once again I'll be there with the Coding4Fun crew showing off some spiffy new projects for attendees to play around with, along with a few other surprises. I'll also be taking part in John Papa's Open Source Fest on Monday evening, demonstrating WiimoteLib and my MJPEG Decoder.

Anyone else heading to the conference? If you are, be sure to stop by the Coding4Fun area in the Connect Lounge and say hello, and stop by the Open Source Fest on Monday night to take a look at over 50 great open source projects and vote for your favorites. I'd say I'd trade drinks for votes, but those are free, too.

And finally, if anyone attending is working on a fun or interesting project and would like to do an interview for my Coding4Fun Show on Channel 9, please let me know.  Almost anything goes, so I'd love to see what everyone out there is working on.

Hope to see you there!

NuGet-enabled WiimoteLib and ThinkGearNET

Posted January 21, 2011 3:00 AM Categories: .NET | Neurosky MindSet | NuGet | Visual Studio | Wiimote

With the official release of NuGet and the NuGet gallery, I decided to try it all out by uploading the current versions of WiimoteLib and ThinkGearNET to the gallery.  The process was pretty smooth, but I learned a little bit along the way which I thought I’d share.

So what’s NuGet?
From their own page:  NuGet (formerly known as NuPack) is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development.

In short, this means you can right-click and add a reference to a third party library without having to download it yourself, extract it, locate it manually on your drive, deal with dependencies, etc.  All of this is handled automatically, as is finding and integrating new versions of those libraries with your projects.

NuGet as a User
If you want to use NuGet to download packages, you’ll first need to install the NuGet Package Manager extension for Visual Studio 2010.  You can find this in the Visual Studio Extension Manager or at the NuGet CodePlex site

image

Install the extension and you’ll find a new right-click entry when adding a reference: Add Library Package Reference….

image

Select this and you’ll be presented with a dialog similar to that of the Extension Manager.  You can see/search what’s installed, what’s in the gallery, and which packages you already have installed have updates available.  As an example, you can search for WiimoteLib or ThinkGearNet and pull down the package.

image

In either case, a reference will be set to the assembly, and, with the way I created the package, you’ll get a readme file as well as an Extras directory with additional documentation, license info, samples, etc.

NuGet as a Package Developer
If you are the developer of a third party library, getting it up to the NuGet Gallery for the rest of the world to consume is pretty simple.  Full documentation on all of the advanced features is located on CodePlex, but I’m going to explain the basics using WiimoteLib as an example.

First, you will need to download the command line NuGet Command Line Tool from CodePlex to create packages.  Put this executable in a location in your PATH or somewhere else that’s easily accessible.

Next, you will need to organize your library, documentation, etc. in a way that NuGet can handle.  Three main directories will exist inside any package.  Use those which make sense for your distribution.

Directory

Usage

\lib The assemblies that will be referenced by the user’s project when this package is installed
\content Anything in here will be copied to the user’s project root and added to the project/solution
\tools Executables that will get copied to the target project and will be added to the PATH environment variable

For my packages, I only needed the lib and content directories.  Inside of the lib directory, I copied the WiimoteLib.dll assembly.  Inside of the content directory, I created a directory named Wiimote_Extras in addition to a Wiimote_Readme.txt file.  Inside the Wiimote_Extras directory, I placed a zipped copy of the WiimoteLib samples, a docs directory containing the CHM help file and license files, and a MSRS directory containing the MSRS libraries for the Wiimote.  So, my full directory list looked as follows:

image

One of the issues I ran into was including the samples as projects/source directly.  When they get added to the project as shown, they become source code for the project, and that can cause conflicts.  So, to work around the issue, I just zipped up the projects and made them easily accessible.  Just remember if you include a source code file directly in that content directory, it will become part of the user’s project.

You can go much further with this by specifying subdirectories for different versions of your library with multiple subdirectories, PowerShell scripts, etc. but for my needs this was all that was required.

The final piece of the puzzle is creating a manifest file, called the .nuspec file, which details the package and its contents.  You can find full documentation for the .nuspec file on CodePlex, but I’ll cover the basic items that are required.  Here is the .nuspec file for WiimoteLib:

<?xml version="1.0" encoding="utf-8"?> 
<package> 
  <metadata> 
    <id>WiimoteLib</id> 
    <version>1.7</version>
    <title>WiimoteLib</title>
    <authors>Brian Peek</authors>
    <description>Managed Library for Nintendo's Wiimote</description> 
    <summary>A library for using a Nintendo Wii Remote (Wiimote) from .NET.</summary>
    <language>en-US</language>
    <licenseUrl>http://wiimotelib.codeplex.com/license</licenseUrl>
    <projectUrl>http://wiimotelib.codeplex.com/</projectUrl>
    <tags>Wiimote Nintendo Games</tags>
  </metadata> 
</package>

Of the items listed, only the id, version, authors and description fields are required.  The rest add some useful data that will get displayed in the package manager and on the Gallery site.

Element

Description

id A unique identifier for the package.  Make this something short but unique.
version The version of the library this package contains
title A pretty title for the package
authors A comma-delimited list of authors
description A longer description of the package
summary A shorter description of the package
language Locale ID for the package
licenseUrl URL pointing to the license file on the web
projectUrl URL pointing to the project homepage on the web
tags A space-delimited list of tags to help find the package when searching

When uploading to the NuGet Gallery, everything but the id and version can be added or changed on the site itself.  These items are used for display both on the NuGet Gallery site, as well as inside the package manager in Visual Studio.

So, create your .nuspec file and save it somewhere to be reference for the next step.

With the directory organized and the .nuspec file in place, the package can be created with the nuget.exe command line tool downloaded earlier.  At its simplest the command to create a package is as follows:

 
nuget pack <.nuspec file> –b <root package directory>

Running this command will generate a file with a .nupkg extension.  This is your final package ready to upload to the Gallery!

Currently, if you wish to upload a package, you need to register on the NuGet Gallery and then send an email to the address specified to have your account activated.  Once activated, go to the Contribute tab on the site, click Add New Package and follow the steps.  When complete, your package will be available to download by anyone with the package manager installed.

Conclusion
There is obviously a ton more to NuGet, the package manager, the package creator, etc. and I highly recommend going through the documentation on the NuGet CodePlex site to get the full details.  Your package may be far more advanced than this and require additional configuration, so please read up!  Otherwise, take a look at the gallery and get started using some third party libraries in your projects!

WiimoteLib Future

Posted May 27, 2010 9:25 PM Categories: .NET | Coding4Fun | Wiimote | Hardware

image I’ve been working on a version 2.0 of WiimoteLib which reorganizes the library quite a bit to clean up the codebase.  It’s not quite ready for release, and I don’t have an ETA currently, but I wanted to note some of the changes and get some feedback as I finish things up.

  • I will be including a VS2010 solution for the project in addition to the original VS2008 solution
  • I’m hoping to have support for both sound and the WiiMotion Plus extension completed
  • Support for the Taiko Drum and DJ Hero turntable (testers welcome for the DJ Hero turntable)
  • Extensions have been broken out into separate classes so their code is self contained:
    • image
    • All extensions inherit from ExtensionController
    • All state objects for extensions implement the IExtensionState interface
    • Here’s an example of the new Nunchuk class.  As you can see, everything related to the Nunchuk is located in this class:
    • using System;
      using System.Drawing;
       
      namespace WiimoteLib.Extensions
      {
          public class Nunchuk : ExtensionController<NunchukState>
          {
              internal Nunchuk(Wiimote wm) : base(wm)
              {
              }
       
              internal override void Initialize()
              {
                  byte[] buff = Wiimote.ReadData(REGISTER_EXTENSION_CALIBRATION, 16);
       
                  State.CalibrationInfo.AccelCalibration.X0 = buff[0];
                  State.CalibrationInfo.AccelCalibration.Y0 = buff[1];
                  State.CalibrationInfo.AccelCalibration.Z0 = buff[2];
                  State.CalibrationInfo.AccelCalibration.XG = buff[4];
                  State.CalibrationInfo.AccelCalibration.YG = buff[5];
                  State.CalibrationInfo.AccelCalibration.ZG = buff[6];
                  State.CalibrationInfo.MaxX = buff[8];
                  State.CalibrationInfo.MinX = buff[9];
                  State.CalibrationInfo.MidX = buff[10];
                  State.CalibrationInfo.MaxY = buff[11];
                  State.CalibrationInfo.MinY = buff[12];
                  State.CalibrationInfo.MidY = buff[13];
              }
       
              internal override void ParseData(byte[] buff, int offset)
              {
                  State.RawJoystick.X = buff[offset];
                  State.RawJoystick.Y = buff[offset + 1];
                  State.AccelState.RawValues.X = buff[offset + 2];
                  State.AccelState.RawValues.Y = buff[offset + 3];
                  State.AccelState.RawValues.Z = buff[offset + 4];
       
                  State.C = (buff[offset + 5] & 0x02) == 0;
                  State.Z = (buff[offset + 5] & 0x01) == 0;
       
                  State.AccelState.Values.X = (float)((float)State.AccelState.RawValues.X - State.CalibrationInfo.AccelCalibration.X0) / 
                                                  ((float)State.CalibrationInfo.AccelCalibration.XG - State.CalibrationInfo.AccelCalibration.X0);
                  State.AccelState.Values.Y = (float)((float)State.AccelState.RawValues.Y - State.CalibrationInfo.AccelCalibration.Y0) /
                                                  ((float)State.CalibrationInfo.AccelCalibration.YG - State.CalibrationInfo.AccelCalibration.Y0);
                  State.AccelState.Values.Z = (float)((float)State.AccelState.RawValues.Z - State.CalibrationInfo.AccelCalibration.Z0) /
                                                  ((float)State.CalibrationInfo.AccelCalibration.ZG - State.CalibrationInfo.AccelCalibration.Z0);
       
                  if(State.CalibrationInfo.MaxX != 0x00)
                      State.Joystick.X = (float)((float)State.RawJoystick.X - State.CalibrationInfo.MidX) / 
                                              ((float)State.CalibrationInfo.MaxX - State.CalibrationInfo.MinX);
       
                  if(State.CalibrationInfo.MaxY != 0x00)
                      State.Joystick.Y = (float)((float)State.RawJoystick.Y - State.CalibrationInfo.MidY) / 
                                              ((float)State.CalibrationInfo.MaxY - State.CalibrationInfo.MinY);
              }
       
              public override ExtensionType ExtensionType
              {
                  get { return ExtensionType.Nunchuk; }
              }
          }
       
          /// <summary>
          /// Current state of the Nunchuk extension
          /// </summary>
          [Serializable]
          [DataContract]    
          public class NunchukState : IExtensionState
          {
              /// <summary>
              /// Calibration data for Nunchuk extension
              /// </summary>
              [DataMember]
              public NunchukCalibrationInfo CalibrationInfo;
              /// <summary>
              /// State of accelerometers
              /// </summary>
              [DataMember]
              public AccelState AccelState;
              /// <summary>
              /// Raw joystick position before normalization.  Values range between 0 and 255.
              /// </summary>
              [DataMember]
              public Point RawJoystick;
              /// <summary>
              /// Normalized joystick position.  Values range between -0.5 and 0.5
              /// </summary>
              [DataMember]
              public PointF Joystick;
              /// <summary>
              /// Digital button on Nunchuk extension
              /// </summary>
              [DataMember]
              public bool C, Z;
          }
       
          /// <summary>
          /// Calibration information stored on the Nunchuk
          /// </summary>
          [Serializable]
          [DataContract]
          public struct NunchukCalibrationInfo
          {
              /// <summary>
              /// Accelerometer calibration data
              /// </summary>
              public AccelCalibrationInfo AccelCalibration;
              /// <summary>
              /// Joystick X-axis calibration
              /// </summary>
              [DataMember]
              public byte MinX, MidX, MaxX;
              /// <summary>
              /// Joystick Y-axis calibration
              /// </summary>
              [DataMember]
              public byte MinY, MidY, MaxY;
          }
      }
       
  • Minimal changes will need to be handled in application code, which is demonstrated in the WiimoteTest application included with the library.  The biggest change is in handling extensions.  Now, the Wiimote object itself will contain an ExtentionType property.  Use this to determine which extension is attached and cast the Wiimote.ExtensionController property to the proper object to access its state information as shown:
      switch(mWiimote.ExtensionController.ExtensionType)
      {
          case ExtensionType.Nunchuk:
              NunchukState ns = ((Nunchuk)mWiimote.ExtensionController).State;
              break;
      }

      I welcome any questions, comments and concerns on the direction I’m heading.  Thanks!

      MindBlaster Article Posted

      Posted March 8, 2010 10:05 AM Categories: .NET | Coding4Fun | Wiimote | XNA | Hardware | PDC2009 | MIX10

      mindblaster My latest Coding4Fun article on the creation of my game MindBlaster is now available!  This is a game I wrote using XNA Game Studio 3.1 that combines a Nintendo Wiimote and a Neurosky MindSet headset to create a game you play entirely with your head.  If you were at PDC09 and stopped by the Coding4Fun area you may have seen it, or, if you’ll be at MIX10, please stop by the Coding4Fun area and see this and 3 or 4 more even better projects by Coding4Fun authors.

      Links

      WiimoteLib 1.8 Beta 1 Posted

      Posted July 20, 2009 1:01 AM Categories: .NET | Coding4Fun | Wiimote | Hardware

      image I have posted a new version of WiimoteLib as a beta for people to play around with the Wii MotionPlus accessory.  Please note that this is not a stable release and should only be used if you wish to mess around with the MotionPlus.  Also note that only C# source code is included in this release as it is not a final build.  Here’s the change log:

      v1.8.0.0

      • Taiko Drum Master's TaTaCon drum controller supported (Dean Herbert)
      • Bare-bones Wii MotionPlus support (wiibrew.org, testing by Tyler Tolley)
      • WiimoteTest UI changed to add MotionPlus data
        • Please note that the current version is VERY flakey and may not work at all for you.
        • Pair your Wiimote, plug in your MotionPlus, call InitializeMotionPlus()
        • Extensions plugged into the MotionPlus will give wacky results...not supported...yet!
        • Internal changes to perhaps fix some threading issues

      So remember, it’s a beta, it may not work for you, and the data you’ll get back from the accessory is just the raw data it provides.  You won’t get real orientation values.

      That said, head over to CodePlex and give it a try!

      My Info

      • View Brian Peek's profile on LinkedIn

      Sponsored Ad

      My Book

      Sponsored Ad