Archive for March, 2013
Failure and Success
Well, in one sense, I have failed. Caleb had finally reached the point where if the CES was complete, he could use it. And it wasn’t there. I thought I had more time before he got to this point, but I guess he’s growing up too fast. He was able to play Excitebike, Fisher Price Firehouse Rescue, and even a little bit of Super Mario Bros., but I would have to close the game and load up the next one every time he wanted to switch.
But, this sparked a mad rush of many late nights of coding and lost sleep working on the core CES software, but I’m proud to say, I have succeeded and it is now in a state usable by Caleb! Here’s a screenshot of the main screen:
The CES acquires all the joysticks in the system, so Caleb can use the NES gamepad to navigate and choose a game. Once a game is selected, it releases all the joysticks and then launches the emulator for that game, in full screen mode. A background service then sits and waits for the emulator executable to exit, at which point it returns to this main screen and re-acquires all the joysticks.
But Caleb also needed to be able to switch games. I originally planned to use the Reset button on the front of the NES to exit a game. But because the computer is not fully built yet, and Caleb might press the Power button instead at this age, I bought a simple push button and connected it instead with a long cord coming out by the front of the TV. What did I connect it to? Why, another Teensy of course! This teensy will sit inside the computer and connect to all the buttons on the NES case (the Reset, plus more I plan to add for things live saving and loading game state). This Teensy is not a joystick, but rather a standard keyboard. When the button is pushed, the Teesny sends a Control-Alt-Shift-R keypress like any other keyboard, and my software watches for this and automatically closes the running application (emulator). So Caleb can choose a game, play it, and push the button to close it and pick another game all by himself now.
I had to add one more thing to this version. Caleb has been playing flash games on Nick Jr.’s website recently. But this we also had to load for him, scroll the page down to see the game, etc. So I decided to add the functionality to the CES. It’s not much different from an emulator – an executable is launched with the game as the parameter, or in this case a website. So I have it launch Firefox in fullscreen mode to the flash application, and it works beautifully. The ‘Reset’ button closes it too.
There’s just one more thing left. The flash games use a keyboard and mouse to play. So I wrote a special background service that runs when a flash game is launched. It reads input from the joystick (NES Gamepad with Teensy), and translates the up/down/left/right into the arrow keys on the keyboard, and it translates the button presses into the space bar. Fortunately, all the games on Nick Jr. use the spacebar as their button. Pressing the select button on the NES Gamepad switches it into mouse mode, so he can play mouse games too! The arrow buttons on the gamepad move the mouse cursor, and the A button does a mouse click. With some help and practice, Caleb has been able to understand how to switch in and out of mouse mode. That’s pretty good for a 2 1/2 year old!
So, the bottom line is, we can now just turn the application on, give Caleb the gamepad, and he can play and switch between whichever of his games he wants without our help. The biggest problem now is keeping his daily ‘TV Time’ under his 2 hour limit 🙂
Gamepad Teensy Code
I finished the Teensy gamepad code I’ll be using for the gamepads back in January. The base code allows me to very easily configure the number of buttons, the name it shows up as in Windows, and a serial number.
I have made this code available as Open Source for anyone interested at http://robertbyam.com/code
In other news, I’ve successfully written a small library that allows me to find out what USB device is attached to a specific USB port on the computer. I have a small 4 port USB hub that will be inside the computer and plugged directly into the motherboard, and the 4 ports will be on the front of the NES case where the original NES controllers would plug in. I search all USB devices on the system for this specific hub, which I find by the manufacturer and product IDs. I can then tell what is plugged into each of the 4 ports on the hub.
Using this information, I will be able to show at the bottom of the main CES screen what controllers are plugged in, and also show which will be player 1, 2, etc. whenever a specific game is selected, as well as which controllers are disabled because they don’t have enough buttons. This way, it will work similar to the original Nintendo, where the player number was determined by what spot the controller was plugged into.
I built one NES controller with the Teensy inside, and it just barely fits and works well. I also got some SNES controllers off of ebay, and they are thicker, so there will be too much room. I’ll have to glue the Teensy down so it doesn’t rattle around inside.