Tuesday, March 3, 2009

xPL Gameport Enhanced & Released

This weekend, I was trying to add a CDS sensor in the family room to more accurately sense darkness. It works great with a DS10A, but I wanted to hardwire it to make it more reliable. I tried connecting it to an input on my gameport device that I use for contact closure detection, but the resistance of the CDS sensor with the light on is apparently too high for the gameport to detect a closed condition. What else can I use? What about using the X and Y axis inputs on the gameport as analog inputs? So that's what I did. I updated my gameport app to read the axis values and send out sensor.basic messages on changes. I had to add a larger debounce delay when sampling since the CDS input bounces a little when changing. In any case, it's up & running for a couple days now and works well.

This is probably one of my most favorite apps I've written and I know I haven't released it yet, so here it is. You'll need a config.txt file in the same directory. For each gameport you have hooked up, you'll need to label the inputs - 4 button inputs and 2 axis inputs. The final parameter will be the polling time in ms. The polling interval for the axis inputs in derived from the polling time specified in the file.

config.txt format:
<gameport0_button0>,<gameport0_button1>,<gameport0_button2>,<gameport0_button3>,<gameport0_xaxis>,<gameport0_yaxis>,<polling interval>


If you have more than one gameport connected, then specify all the inputs first, then the polling interval (all on a single line):
garagedoor,doorbell,backdoor,garagemotion,FRDark,yaxis0, amppower,dvdpower,tvpower,blank13,xaxis1,yaxis1,50

Finally, don't forget to install the DirectX redistributable runtime from here.

I have only tested the app with the Super Joy Box 8 USB to gameport adapter, which has 4 gameports and gives you 16 digital and 8 analog inputs for about $20.

No comments:

Post a Comment