I tried to keep it as simple as possible. Everything is abstracted out, so you can focus on implementing the stage kit, instead of doing complicated bitwise mathematics.

First, XNA is NOT required, however you can use this from within XNA easily. To enable the XNA framework, simply add "XBOX" (without the quotes) in the Conditional compilation symbols portion of the Build tab of the project. It will then utilize the XNA framework, and you can freely distribute this from within your games. If you are using this API from outside of XNA, then leaving out the XBOX conditional compilation symbol will not reference XNA at all, and will instead utilize an interop library which uses the xinput1_3.dll library (only ~80k). If your computer does not have this library, then you will need to install the DirectX redistributable, SDK, or web installer. Make sure your distributions also include the redistributable if you're not going the XNA route.

There are no other configuration changes, nor an app.config file.

So here's how to use it.

Step one: Create an instance of the StageKitController class.

StageKitController controller = new StageKitController(controllerId);

The controllerId being passed in is an integer representing the ID of the controller that the stage kit is being recognized as (1-4). When you plug in the stage kit, the Big X button should light up, and indicate which controller it's acting as. This is the number to pass in. If you're running this on windows, chances are, this is a 1. Originally, I didn't have this, but added it in so to be able to control multiple stage kits at once.

If you are using XNA, and have a Microsoft.Xna.Framework.PlayerIndex value which you are using to represent the stage kit, you must cast it to an int then add 1. This is because the Microsoft.Xna.Framework.PlayerIndex is zero based. I'm not using this enumeration publically simply because I didn't want exposed methods to have to care whether XNA was used or not, keeping implementations framework agnostic.

Eventually, I will provide an array of possible IDs to pass in. The stage kit reports itself as type "9" to the computer/XBOX, so this won't be too hard to figure out which controller(s) is the stage kit.

Step two: Call the appropriate methods to interact with the stage kit.

-- Fog: There are two methods that interact with the fogger. One to turn it on, and one to turn it off.

void TurnFogOn()
void TurnFogOff()

-- Strobe: There are two methods that interact with the strobe light. One to turn it on (and specify speed), and another to turn it off.

void TurnStrobeOn(StrobeSpeed speed)
void TurnStrobeOff()

There are four speeds to the strobe light, Slow, Medium, Faster, Fastest. These are enumerations that are passed in.

enum StrobeSpeed

-- LED Display: There is one method that interacts with the LED Display. It takes a representation of the LED Display.

void DisplayLeds(LedDisplay display)

The LedDisplay class basically has four members of type LedColor:

LedColor RedLedArray
LedColor BlueLedArray
LedColor GreenLedArray
LedColor YellowLedArray

Each one represents the 8 LEDs for each color. Each member contains 8 members of type bool.

bool Led1
bool Led2
bool Led3
bool Led4
bool Led5
bool Led6
bool Led7
bool Led8

Set the bool to true to turn the LED on, set it to false to turn it off. Led 1 is typically at the 12 o'clock position, 3 is at 3 o'clock, 5 is at 6 o'clock and 7 is at 9 o'clock. I say typically, because red and green are offset a little to the right on the Display.

LedDisplay display = new LedDisplay();
display.RedLedArray.Led1 = true;

Both the LedDisplay and LedColor classes implement the INotifyPropertyChanged interface, as well as have a PropertyChanged event to ease databinding from within applications.

Once the LEDs that you want turned on or off are set, pass the LedDisplay object to the DisplayLeds() method and the associated LEDs will light up.

Creating sequences of LED displays are also very easy. You can cast your LedDisplay object to and from an int.

int myValue = (int)display;

This will give you a representation of all of the LEDs on and off values in the form of an integer to persist in memory, files, databases, etc. To turn an int back into a LedDisplay object, simply cast the other way.

LedDisplay display = (LedDisplay)myValue;

The solution also contains a Unit Test project, which runs through all of the actions (fog, strobe, LEDs), and should give you a pretty good idea of how it all works.

Last edited Oct 28, 2009 at 5:38 AM by brantestes, version 3


No comments yet.