Go Down

Topic: "OrbDuino" serial gaming device to USB HID shield! (Read 5 times) previous topic - next topic

Budha

Hey, tough i've been lurking the forum for a year by now, this time i decided to post about this usbdrv project.

Im trying also to get my home made joystick to work, but got a *detail* that is driving me crazy.

I got a classic arcade control with switches, so i want to play my roms with my current keyboard configurations.

As i want to use Arrow UP, DOWN, LEFT, RIGHT, i added to the usbKeyboard.h the definitions from HID Keyboard / Keypad reference:

Code: [Select]

#define KEY_UP      82
#define KEY_DOWN    81
#define KEY_LEFT    80
#define KEY_RIGHT   79
#define KEY_SHIFT   225


Used correct F_CPU for my ArduinoDuemilanove atmega328 (16MHZ), it compiles, and executes. Buuut.

When i press any button, which generates Arrow Up, Down, Left, or Right, or key "r" or "t", i can see it is working, open notepad, and can type with my joystick + buttons.

The trouble is that it types tooo fast. So, instead of a classic "im keeping pushed left arrow" i get "hundreds of rapid pushing left arrow".

Like old turbo feature on nintendo pads... The trouble here is i dont seem to be able to fix it.

In the main() i've put a counter, so i loose some cpu cycles, but what happens is that left key gets pushed and released very fast every xxx seconds (depends on how many cpu cycles i lose).

So, does any1 has any idea or suggestion? I want to generate "i keep pushed left arrow" or "i keep pushed right arrow" like when you play your roms on your keyboard... not the "very fast typing left arrow over and over".

Any help will be appreciated. I *had* to let it out of my chest.

Regards



vputz

Hmm.  Is the problem that you have sent a make code and are not breaking it (ie are you seeing autorepeat?  If you push the button does it act like a keyboard and print a character, pause, and then spam them out?) or are you sending a "make/break" code every time you loop?

They keyboard is weird... if you send a "W is pressed" message, say, the computer assumes the key stays pressed until you send another keyboard packet without a "W" in it.  To send just a single keypress, you send two reports, one with the key pressed and then immediately send a second empty keyboard report (or at least a keyboard report without that key).

Hard to tell from here but it almost sounds like you're doing that somehow (like every time you loop you're sending two packets, one with the key and a second packet without it, so you get that spam).  Sorry so vague--been a long time since looking at that code., but I feel like I did have some trouble with that at some point, since I have a comment in my code saying "This stops endlessly repeating keystrokes"... I was forgetting to send the "key no longer pressed" report t and thus it was auto-repeating.  But it sounds like you're having it repeat faster than auto-repeat, which sounds to me like you're sending the "key no longer pressed" report every time.

Not sure that was helpful; let me know if it made sense!

Budha

#7
Jun 10, 2010, 05:00 am Last Edit: Jun 10, 2010, 05:03 am by Budhabar Reason: 1
Quote
Hmm.  Is the problem that you have sent a make code and are not breaking it (ie are you seeing autorepeat?  If you push the button does it act like a keyboard and print a character, pause, and then spam them out?) or are you sending a "make/break" code every time you loop?


Ok, you described it perfectly, make/break every loop that is whats happening.

i've seen the

Code: [Select]
   
// This stops endlessly repeating keystrokes:
   memset(reportBuffer, 0, sizeof(reportBuffer));      
   usbSetInterrupt(reportBuffer, sizeof(reportBuffer));


in the usbkeyboard.h file, but it doesnt makes sense to me. Can you remember if i have to send the keyboard up arrow with some Modifier so it works / behaves like any keyboard?

Thanks for the time  :)


vputz

Quote
Can you remember if i have to send the keyboard up arrow with some Modifier so it works / behaves like any keyboard?


I can't remember for sure, but I'm pretty certain you don't have to; the arrow keysymbols shouldn't require a modifier.  You might try just commenting out that second report and just seeing what happens... it may not be exactly what you want, but I bet it's closer!

Budha

Ok, im giving it a try, for sure the behaviour is somewhat... different.

Gonna try sending the keystroke and then a null keystroke, see what happens.


Go Up