Re: [pygame] Wii Remote support -- first patch
René Dudfield wrote: Hi, good links. It looks like someone is making a ctypes based library for windows based on that first code. Luke, are you reading this? Did you get anywhere with your ctypes wiimote code? Yep, I can read buttons and set LEDs and rumble right now. I actually just started working on this again a few days ago. There's been lots of school recently, but it's finals time so I have long breaks between study sessions right now where I can code. I'm writing it in such a way that the HID communication is abstracted away from the actual wiimote library. The HID stuff is all windows-dependent right now (calling windows DLLs directly). Currently it just uses kernel32.WriteFile for communication, which doesn't work on all bluetooth stacks (you use hid.hidD_SetOutputReport on the ones where WriteFile doesn't work) but I don't have a stack that doesn't work for WriteFile, so when I eventually write the compatibility code that tries writefile and if it fails, tries SetOutputReport, I'll ask the list if anyone wants to give it a try. I'm not actually using ctypes to interface with a compiled version of cwiimote, I'm rewriting it in Python, so that I can have more control over the structure of everything (or so I'm telling myself... plus it's fun :D) It was working perfectly last night but I'm refactoring the code and I broke everything. svn://commons.game-host.org/PyWiimote is the URL for SVN, but I didn't commit when it was working (_) so there's only the broken version right now. I have a CS assignment due at 5 pm tonight (binary search tree sorting cities by zipcode) but after that I should have the rest of the week to work on the library, so hopefully I'll get more done. Eventually I'll write a cross-platform HID library, and we'll all be happy :D Unless someone else wants to do it? All you have to do is find out what the path is on your os for all the HID devices, then open each one, make sure it's a wii remote, and then send output reports to it whenever the write() method is called. All the code it fairly simple, I've just been learning ctypes while I did it, so it's taken a while. Also, I'm using overlapped I/O for the reads/writes, but right after I call the read and it returns control to me, I call the kernel32.GetOverlappedResult to get the result, which is blocking. So my question was: Is it cool to run the wii remote's update method in a thread, or should I recode it to where it doesn't block and just returns nothing if it doesn't get a read within a few milliseconds or something? -Luke Cheers, On 4/25/07, Dave LeCompte (really) [EMAIL PROTECTED] wrote: If people are interested in adding Windows support for this, they might like to look at either http://simulatedcomicproduct.com/2006/12/cwiimote-02.php or http://digitalretrograde.com/projects/wiim/ Both of them have source code that could be a useful starting point for a Windows/PyGame module. I was able to put a SWIG wrapper around CWiiMote and read accelerometer and button inputs and set LED outputs with little difficulty. Very cool. Are you still working on this? On 12/18/06, robomancer [EMAIL PROTECTED] wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py, wiimote.py Full versions of the Pygame 0.7.1 files I changed to enable Wiimote support. If you don't want to use the patch program, you can just drop these in to the lib/ directory of the Pygame-0.7.1 source distribution. robomancer
Re: [pygame] Wii Remote support -- first patch
great work, I'm already looking forward to creating games for wii-controllers - I will definitly check out this wiimote package some time in the next weeks. Does it work under linux? from the last email it doesn't seem so but the code looks like it does?? greetings simon On 4/25/07, Luke Paireepinart [EMAIL PROTECTED] wrote: René Dudfield wrote: Hi, good links. It looks like someone is making a ctypes based library for windows based on that first code. Luke, are you reading this? Did you get anywhere with your ctypes wiimote code? Yep, I can read buttons and set LEDs and rumble right now. I actually just started working on this again a few days ago. There's been lots of school recently, but it's finals time so I have long breaks between study sessions right now where I can code. I'm writing it in such a way that the HID communication is abstracted away from the actual wiimote library. The HID stuff is all windows-dependent right now (calling windows DLLs directly). Currently it just uses kernel32.WriteFile for communication, which doesn't work on all bluetooth stacks (you use hid.hidD_SetOutputReport on the ones where WriteFile doesn't work) but I don't have a stack that doesn't work for WriteFile, so when I eventually write the compatibility code that tries writefile and if it fails, tries SetOutputReport, I'll ask the list if anyone wants to give it a try. I'm not actually using ctypes to interface with a compiled version of cwiimote, I'm rewriting it in Python, so that I can have more control over the structure of everything (or so I'm telling myself... plus it's fun :D) It was working perfectly last night but I'm refactoring the code and I broke everything. svn://commons.game-host.org/PyWiimote is the URL for SVN, but I didn't commit when it was working (_) so there's only the broken version right now. I have a CS assignment due at 5 pm tonight (binary search tree sorting cities by zipcode) but after that I should have the rest of the week to work on the library, so hopefully I'll get more done. Eventually I'll write a cross-platform HID library, and we'll all be happy :D Unless someone else wants to do it? All you have to do is find out what the path is on your os for all the HID devices, then open each one, make sure it's a wii remote, and then send output reports to it whenever the write() method is called. All the code it fairly simple, I've just been learning ctypes while I did it, so it's taken a while. Also, I'm using overlapped I/O for the reads/writes, but right after I call the read and it returns control to me, I call the kernel32.GetOverlappedResult to get the result, which is blocking. So my question was: Is it cool to run the wii remote's update method in a thread, or should I recode it to where it doesn't block and just returns nothing if it doesn't get a read within a few milliseconds or something? -Luke Cheers, On 4/25/07, Dave LeCompte (really) [EMAIL PROTECTED] wrote: If people are interested in adding Windows support for this, they might like to look at either http://simulatedcomicproduct.com/2006/12/cwiimote-02.php or http://digitalretrograde.com/projects/wiim/ Both of them have source code that could be a useful starting point for a Windows/PyGame module. I was able to put a SWIG wrapper around CWiiMote and read accelerometer and button inputs and set LED outputs with little difficulty. Very cool. Are you still working on this? On 12/18/06, robomancer [EMAIL PROTECTED] wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py,
Re: [pygame] Wii Remote support -- first patch
Simon Oberhammer wrote: great work, I'm already looking forward to creating games for wii-controllers - I will definitly check out this wiimote package some time in the next weeks. Does it work under linux? from the last email it doesn't seem so but the code looks like it does?? there's no reason the wii remote library wouldn't work under linux, if the HID library supported it. So I can probably steal some code from that other, Linux wii remote library later and set it up in the HID library... but that's not my primary concern. I want to get the wiimote library more featureful, and it needs a bit more abstraction, and then I'll work on getting it set up on Linux too. But like I said, feel free to add that support yourself if you want, it shouldn't be difficult. Let me know if you do want to do this, and I can let you know when a working version of the rest of the library is set up. I'm fairly certain I'll have Linux and Mac compatibility in the next few weeks, if no one else feels like doing it (luckily I have a friend with a Macbook, so I should be able to bum it off him a few days to test the mac code), but I can't guarantee it :D I'll probably do the mac support before Linux, since when school ends he'll move back home, but I can easily get access to linux whenever I want. I know you all probably hate me for doing Linux last :P but it works out better for me this way. -Luke
Re: [pygame] Wii Remote support -- first patch
Alex Holkner wrote: Luke Paireepinart wrote: Also, I'm using overlapped I/O for the reads/writes, but right after I call the read and it returns control to me, I call the kernel32.GetOverlappedResult to get the result, which is blocking. So my question was: Is it cool to run the wii remote's update method in a thread, or should I recode it to where it doesn't block and just returns nothing if it doesn't get a read within a few milliseconds or something? Polling (with optional timeout) is the PyGame/SDL way; any blocking or threaded API can then be layered on top if the application desires it. The way the i/o works is that you pass an Overlapped structure to the read method, then you call GetOverlappedResult with the same overlapped structure to get the read result later. So the way the built-in pygame.mouse and such work is that they keep checking for input, and when they get it, they report it to pygame.event, right? I can just keep track of whether there's a read pending, and not start another read until I get the result of the first read first. I'd do this by calling GetOverlappedResult without blocking enabled [if my readpending variable is set] so it will just return, and call that every x milliseconds. Then when I find out that something has given a result, I process the input, start another read and repeat the cycle. Is that what you mean by polling? should I let the user set the delay between reads, if there is no result, or is there a recommended amount of time? (if there were a result, I wouldn't delay, that way if there's a constant stream of input it won't start lagging behind.) The longer the delay, the less processor is used by my library, and the more there is for games, but the greater potential there is for input lag, right? -Luke Alex.
Re: [pygame] Wii Remote support -- first patch
Sounds all good. I think I want to get a wii now :) Just for the remotes. For pygame integration posting events into the event queue would be a good idea ( pygame.event.post ). Maybe run in another thread, or polled at the required frequency with pygame.time.set_timer ? Cheers, On 4/26/07, Luke Paireepinart [EMAIL PROTECTED] wrote: Alex Holkner wrote: Luke Paireepinart wrote: Also, I'm using overlapped I/O for the reads/writes, but right after I call the read and it returns control to me, I call the kernel32.GetOverlappedResult to get the result, which is blocking. So my question was: Is it cool to run the wii remote's update method in a thread, or should I recode it to where it doesn't block and just returns nothing if it doesn't get a read within a few milliseconds or something? Polling (with optional timeout) is the PyGame/SDL way; any blocking or threaded API can then be layered on top if the application desires it. The way the i/o works is that you pass an Overlapped structure to the read method, then you call GetOverlappedResult with the same overlapped structure to get the read result later. So the way the built-in pygame.mouse and such work is that they keep checking for input, and when they get it, they report it to pygame.event, right? I can just keep track of whether there's a read pending, and not start another read until I get the result of the first read first. I'd do this by calling GetOverlappedResult without blocking enabled [if my readpending variable is set] so it will just return, and call that every x milliseconds. Then when I find out that something has given a result, I process the input, start another read and repeat the cycle. Is that what you mean by polling? should I let the user set the delay between reads, if there is no result, or is there a recommended amount of time? (if there were a result, I wouldn't delay, that way if there's a constant stream of input it won't start lagging behind.) The longer the delay, the less processor is used by my library, and the more there is for games, but the greater potential there is for input lag, right? -Luke Alex.
Re: [pygame] Wii Remote support -- first patch
René Dudfield [EMAIL PROTECTED] suggested: For pygame integration posting events into the event queue would be a good idea ( pygame.event.post ). Maybe run in another thread, or polled at the required frequency with pygame.time.set_timer ? I'd suggest not creating another thread if we don't absolutely need to. Would it be possible to query the result of the overlapped IO as part of the pygame.event.pump / pygame.event.get calls? The game is going to be calling those already. Some reasons why that might not work: - I recall reading in the code that some of the accelerometer calculations work best if the device is polled with inconsistent frequency. I don't know how big a problem that is in practice. - The bluetooth library code might want to be called more frequently than once per (graphics) frame. I haven't dug around very much inside the code, so I don't know how it looks in there, but it seems like the pygame.event.pump code is already doing periodic input work, just like what we would need for the Wii controllers. -Dave LeCompte
Re: [pygame] Wii Remote support -- first patch
I typoed: - I recall reading in the code that some of the accelerometer calculations work best if the device is polled with inconsistent frequency. Er, I meant: the accelerometer reading code works best when polled with CONSISTENT frequency. If that turns out to be a big deal, a dedicated thread would seem like a pretty good idea, especially if it had to run at frequencies higher than 60hz. -Dave
Re: [pygame] Wii Remote support -- first patch
Dave LeCompte (really) wrote: René Dudfield [EMAIL PROTECTED] suggested: For pygame integration posting events into the event queue would be a good idea ( pygame.event.post ). Maybe run in another thread, or polled at the required frequency with pygame.time.set_timer ? I'd suggest not creating another thread if we don't absolutely need to. Does anyone know how the mouse works in Pygame? how is it polled? I'd think the wiimote should be done in a similar manner. Depending on what mode you have the wiimote in, it either reports a result whenever a button is pressed/released (buttons-only mode) or it reports continuously (when in accel+buttons, or accel+buttons+IR). so button-only mode is more similar to how mouse reporting happens in Pygame (only when the state changes.) Would it be possible to query the result of the overlapped IO as part of the pygame.event.pump / pygame.event.get calls? Yes, I believe so. The game is going to be calling those already. Some reasons why that might not work: - I recall reading in the code that some of the accelerometer calculations work best if the device is polled with inconsistent frequency. I don't know how big a problem that is in practice. We'll see, I guess. It makes sense that a consistent frequency would be ideal, but from what I can tell, the Wii remote issues reports only when it wants to, and the read will just block if it has nothing to report. (well, unless you tell it not to block, but my point is that the wii mote doesn't just constantly stream data) Does this mean that it would work the other way, and cache output until you read it in? I'm not sure. The bluetooth adapter driver code could do that for you (I doubt the wii mote would cache output) so couldn't you theoretically read all outputs that occurred since your last frame every time you get a chance to read? I bet the wiimote reports at a consistent frequency either way, when in accelerometer mode. - The bluetooth library code might want to be called more frequently than once per (graphics) frame. I don't know why it would care... my code has nothing to do with bluetooth. As far as it's concerned, the Wiimotes could be USB HID devices. I haven't dug around very much inside the code, so I don't know how it looks in there, but it seems like the pygame.event.pump code is already doing periodic input work, Are you assuming that the user calls pump, or does pygame have some internal thread that consistently calls pump? or does pygame.event.get call pump as well? how does all that jazz work? -Luke
Re: [pygame] Wii Remote support -- first patch
Very cool. Are you still working on this? On 12/18/06, robomancer [EMAIL PROTECTED] wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py, wiimote.py Full versions of the Pygame 0.7.1 files I changed to enable Wiimote support. If you don't want to use the patch program, you can just drop these in to the lib/ directory of the Pygame-0.7.1 source distribution. robomancer
Re: [pygame] Wii Remote support -- first patch
If people are interested in adding Windows support for this, they might like to look at either http://simulatedcomicproduct.com/2006/12/cwiimote-02.php or http://digitalretrograde.com/projects/wiim/ Both of them have source code that could be a useful starting point for a Windows/PyGame module. I was able to put a SWIG wrapper around CWiiMote and read accelerometer and button inputs and set LED outputs with little difficulty. Very cool. Are you still working on this? On 12/18/06, robomancer [EMAIL PROTECTED] wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py, wiimote.py Full versions of the Pygame 0.7.1 files I changed to enable Wiimote support. If you don't want to use the patch program, you can just drop these in to the lib/ directory of the Pygame-0.7.1 source distribution. robomancer
Re: [pygame] Wii Remote support -- first patch
Hi, good links. It looks like someone is making a ctypes based library for windows based on that first code. Luke, are you reading this? Did you get anywhere with your ctypes wiimote code? Cheers, On 4/25/07, Dave LeCompte (really) [EMAIL PROTECTED] wrote: If people are interested in adding Windows support for this, they might like to look at either http://simulatedcomicproduct.com/2006/12/cwiimote-02.php or http://digitalretrograde.com/projects/wiim/ Both of them have source code that could be a useful starting point for a Windows/PyGame module. I was able to put a SWIG wrapper around CWiiMote and read accelerometer and button inputs and set LED outputs with little difficulty. Very cool. Are you still working on this? On 12/18/06, robomancer [EMAIL PROTECTED] wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py, wiimote.py Full versions of the Pygame 0.7.1 files I changed to enable Wiimote support. If you don't want to use the patch program, you can just drop these in to the lib/ directory of the Pygame-0.7.1 source distribution. robomancer
Re: [pygame] Wii Remote support -- first patch
On, Sun Dec 17, 2006, robomancer wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ [...] Argh! Shame on you, you gave me another damn reason to buy me a Wii ;-). Regards Marcus pgpIwMwXnBPqi.pgp Description: PGP signature
Re: [pygame] Wii Remote support -- first patch
this looks great, I've been meaning to get this running for my research, but I'm swamped until after the holidays. I'd be happy to help/submit some samples etc. -an On Dec 17, 2006, at 9:36 AM, robomancer wrote: Hi all, I've created a first step toward Wii Remote support in Pygame. Patch is against 0.7.1 because the current SVN doesn't build for me. I expect that future patches will be against SVN head, or 0.8 when that is released. Let me know what you think. You can download the current sample code here: http://gs3080.sp.cs.cmu.edu/wiimote/ Here's the README file: Preliminary Wii Remote support for Pygame. This is definitely proof-of-concept code, and is only likely to work in Linux. The only supported features are: discovering Wiimotes via Bluetooth, polling the buttons and 3-axis force vector, and setting the LEDs. The wiimote.py module has useful docstrings for all public functions, so pydoc pygame.wiimote should give you some helpful documentation once it's installed. You can also just look at the LiiPong sample code. Files in this package: liipong-0.1.py Pong for Linux with the Wii Remote. See the top of liipong-0.1.py for some setup instructions. You can play 1-player or 2-player! To play 2-player, just sync 2 Wii Remotes when the game prompts you to. pygame-0.7.1-wiimote1.patch Patch to Pygame 0.7.1 that enables preliminary Wii Remote support. I'll generate a new patch against Pygame 0.8 when that comes out (for now, the SVN isn't building for me; I seem to need a new version of SDL, which I'm too lazy to compile from scratch at the moment). __init__.py, locals.py, wiimote.py Full versions of the Pygame 0.7.1 files I changed to enable Wiimote support. If you don't want to use the patch program, you can just drop these in to the lib/ directory of the Pygame-0.7.1 source distribution. robomancer