I'm looking to create a driver for a game controller I have (a cobalt flux www.cobaltflux.com ). The physical controller itself has nine face buttons and two control-box buttons (start/select). The control box has a usb port, but as far as I can tell no one has ever written drivers for it before. The end result I want is to be able to plug in the cobalt flux via the usb port and have windows recognize it as a game controller.
I have some programming experience. I'm a senior undergraduate student in computer science at UC Davis and an intern at a large embedded systems company, however this project involves several aspects I have no experience in: interfacing hardware and software via a USB port, investigating feedback from hardware I didn't build (which bits light up when I press a button?), and creating drivers and indeed programs in general for windows.
Since I don't personally know anyone who would be able to set me on the right track for a workflow to solve this problem, I'm asking here. I imagine the approach going something like:
I connect the device via a usb
I open up a program to poll what the effects of pushing buttons are on the USB channel
I write a program that interfaces those signals from the USB port to the game controller drivers that windows has
It may be worthwhile to note that I need to have joyPAD support and not joySTICK support for the buttons since play will involve pressing down any number of buttons at once and joysticks generally only register one direction of input at any given time.
Any advice or help would be greatly appreciated. I am having trouble figuring out where to start.
I have exactly the same problem for more than a year now and I did not found the right solution yet.
When you plug in the pad via USB it announces with a device ID and a vendor ID which device it is. Windows Plug-and-Play starts searching for a driver. This mechanism spots it is a pointing device (in my case one or 2 mice) and makes sure that it is treated as a raw data input device. Input from these devices is converted to messages handled by the OS. The solution seems to be to pass the messages of such a raw input device to the right handler. In my case the two mice are both recognised as mice and the messages are used by the same handler as the ones coming from the 3rd mouse that is really my pointing device. I am not experienced enough in C++ coding in order to dig into the rawinput API. I just received an interesting link as answer on my question: http://www.icculus.org/manymouse/ at least this gives an answer on my problem. May be it will give you ideas for writing your driver! Good luck !!! Stefan
Related
After receiving some feedback on this question: How to create lParam for WM_CHAR or WM_KEYUP/WM_KEYDOWN?, I`ve started looking for a broader answer to a general solution. One thing I realized that using windows API's might not work for every app and in every case.
My first step in the follow up research was to make an Arduino powered servo to press the keys (yeah the concept is horrible ik).
But that prompted yet another idea, a hardware augmented small numpad keyboard which is also operated by Arduino which was controlled via another usb. This was at least somewhat usable - but still not very.
Then I tried to use Digispark Atiny85 microcontroller which in turn used Digikeyboard library. This solution was much better - but then necessity to have a digispark stuck in your usb port was a bit frustrating.
This made me curious if there are ways to emulate keyboard or any other HID devices using software only? Some brief googling pointed me to Kernel drivers and virtual COM ports, but that seem to be a bit over the top for me to process.
So can that task indeed be achieved by writing a kernel driver? Can it be done in any other manner? In either case are there any pointers which you can give me on the topic?
The SendInput function can be used to generate keyboard and mouse input. This input goes to the foreground window as if generated by real hardware (but lowlevel hooks can tell that it was software generated). It might not let you generate Ctrl+Alt+Delete nor control a UAC prompt but other than that it should be good enough in most cases. Writing a driver to overcome these limitations is normally not worth it.
There is no general way to generate input to a specific application/window if it is not the foreground window.
If you want to control a specific application you should use UI Automation.
Faking key up/down/char messages with PostMessage is not uncommon but it does not always work (the application might be using RAW input, input is not synchronized with real hardware etc.). If you are determined to use this method anyway, make sure you send it to the correct window (the HWND with the keyboard focus, not just the top-level window). Use the Spy++ tool to view the messages to make sure they are going to the correct window.
Scenario: A critical computer system is operator-controlled via standard USB keyboard and mouse. Also, there is a DVI-monitor connected to view the operator-targeted GUI. The computer system runs a soft-PLC system based on Windows 7 Professional or, alternatively, Windows Embedded Standard 7 (the "system software").
Question: Is there a software solution, to detect the loss (disconnect/failure) of USB HID-devices such as the keyboard or mouse, and the single DVI-display? This is important, since the critical system can no longer be expected to function properly, without the operator able to manipulate it or see displayed content.
Own considerations: This likely requires low-level WINAPI calls, which is fine. I am thinking that a windows service might be constantly seeking to enumerate the number of keyboards and displays - perhaps even identify them via model or serial number. If this enumeration and/or identification reaches zero or fails entirely, the system-software must of course react fast and appropriately (i.e. go to fail-mode or similar).
As far as I see it, this is general issue with all critical operator-controlled systems. Question is then: Is there already software or hardware for this in existence perhaps?
Note: Operator is always human.
Alas, as for an answer this isn’t going to be much more than a “read the docs” plus some links... Sorry.
First, MSDN documentation.
RegisterDeviceNotification
Detecting Media Insertion or Removal
Talking to USB devices, start to finish (Windows Store app)
I found a C# class on CodeProject.com that does this; the accompanying article is pretty good.
Detecting USB Drive Removal in a C# Program.
I admit that the last time I did anything like this was some years ago, and only for CD notifications. I’ve since lost the code (both my primary and backup hard drives failed within days of each other, LOL).
I have an arcade stick for my PS3 that I used for fighting games. I rarely play them anymore so I figured I'd plug the stick into my Mac and see if I could get some arcade gaming going on my computer. I have tried this on Windows too and it seems like there are no drivers for either OS.
Now, I'm not one to be disappointed and just give up like that. I thought that this would be the perfect opportunity to attempt to write a driver. How hard can it be? All I need is a plan.
The Plan
I want a driver that supports every function of the arcade stick. This includes:
Eight face buttons
Analog stick
Lock/direction switches (the latter is three steps and the former is two steps)
Home/Turbo buttons
Two side buttons
I was searching around for stuff that could help me accomplish this but I don't really know where to start. I want a tool that can scan a USB port for signals coming from a connected device and from those signals decipher what input it corresponds to. I then want to map that input programmatically to an OS X API for game controllers, put it all in a package and voilá: driver!
Maybe this only works in my head. For starters I can't find this magic USB tool that I'm looking for. I tried USB Prober and it detects my arcade stick but I can't get any log entries when I press buttons on the stick. (Yes, I installed the log kext)
Most of the search results were regarding scanning USB network interfaces. I don't think it's what I'm after.
I also got this idea that maybe USB devices behave like old school Unix devices and I'd be able to do something like cat /dev/usb/port3 and get some good data but I have not found anything like that.
I just don't know where to start. I found some Apple documentation on USB devices but I don't even know if the stick is HID compliant.
Right now I'm mostly looking at libusb and skimming through documentation.
I haven't really dealt with this kind of project before so any ideas and tips are welcome.
Thanks!
Most PS3 controllers are just HID devices, so you should be able to work from that direction.
A much simpler route, and less personally satisfying I suppose, would be to just grab one of the USB->Mac game controller applications and run with that.
I've used USB Overdrive for years and it always seems to work well.
I'm interested in hacking one of those digital picture frames (like you see for sale at Walmart) so it fetches and displays an image off the web every 5 minutes or so. (I'm going to have it load a current image.) Any ideas on how to get started?
I don't think any of them have a form of internet connectivity. I think that would be your first goal. I would start by looking at microcontrollers. The Arduino being a popular one, or the Atmel AVR chips it is based on. The Arduino has at least one add-on called an ethernet shield which you could use to gain network connectivity. You'd have to author some code that is capable of connecting to the site and downloading what you want, depending on the chip storage capacity and your coding ability, it might be very simplistic or quite sophisticated.
Next, you have to have some way of getting the device to use the downloaded images. I don't know if the picture frames use a USB connection to load images onto internal memory, or rely on some sort of flash memory card. If it simply reads an SD card, I don't know how you would be able to hack that, unless you inserted your device between the card reader in the picture frame and your own on-board memory. If it's a USB device, you could make your device emulate a USB flash memory drive.
I'm sure there are many ways to hack these things, you might find some more suggestions on instructables.com, which has numerous microcontroller projects.
Just a note, the Arduino and Atmel AVR chips are a lot of fun to work with, but the learning curve can be a challenge. You can write code for them in C or assembler, or one of the many proprietary languages for microcontrollers. Also Atmel isn't the only choice, there are also PicAxe and BasicX and others.
Robotshop.com has a good selection of controllers, but check around on the web, as there are literally hundreds of choices and vendors.
Image the following situation:
You're on Windows XP (even though the dialog shown below is a Vista screenshot).
You have two physical USB game controllers, let's call them A and B.
You have a piece of software that apparently accesses joysticks in a legacy way, only recognizing and allowing use of one single joystick.
When using this software, you want to use both controllers together, for instance:
use the left thumbstick from A and the right thumbstick from B
use buttons #1, #2 and #6 from A and buttons #2 and #8 from B
I guess this problem must have already popped up in hardcore gaming somewhere, and a kind of "virtual game controller driver" or other piece of software for this is available. This would ideally show up as a game controller in Windows and allow a virtual setup as described above using any inputs available on physically connected controllers to create a compound virtual one.
If this is the case, I'd love to hear where to get my hands on this. And if not, any pointers on trying to get this going are welcome. I guess I'd have to read up on DirectInput and dust off my next to non-existent C++ skills then?
Like Runeborg answered, it now looks like I might have to get cracking at trying to write my own "virtual game controller device driver" if I want this to happen. :-(
Quick update: have asked same question on smartgamer in the hope another crowd there might come up with an existing answer.
If you want to make it generic to all windows applications I would imagine you have to write your own virtual game controller device driver. This gamedev.net thread seems to hold a few clues. It may also be interesting to have a look at Johnny Chung Lee's Wiimote magic or the Wiimote project. Johnny Chung also links to Managed Library for Nintendo's Wiimote.
The Wii projects should contain enough information if you dig a bit to get you going. I can't really think of any other way, other than perhaps plugging in as a middleware between the application and windows somehow by intercepting messages.
Will have to look into Total Game Control to see if it could do what I would like.