AlanChatham / UnoJoy

UnoJoy! allows you to easily turn an Arduino Uno (or Mega or Leonardo) into a PS3-compatible USB game controller
GNU General Public License v3.0
482 stars 130 forks source link

Raising the amount of buttons on megajoy #25

Open Mikkelhost opened 5 years ago

Mikkelhost commented 5 years ago

Hi

Im trying to make som flightsim hardware as cheaply as possible. So i started using this, and it works great with 64 buttons. But when i edit the descriptor and everything to add more buttons. as an example im using 80 buttons for this project. The buttons 64-71 (8 buttons which is exactly 1 byte of buttons) doesnt work. i have looked through the descriptor and everything, and i can't find out why this 1 byte of buttons doesn't work.

20190101_230951 Here is a gif of what im talking about. I made the arduino cycle through the buttons from 0-79 and then repeat. As seen on the gif, every button works exept those 8 buttons.

I also tried one time changing the amount of buttons to 144, her there are 16 buttons that doesn't work. more specifically buttons 64-71 and 128-135. So it seems to behappening after every 8th byte.

AlanChatham commented 5 years ago

Hey, thanks for looking into this! I have ZERO idea why that is the case, and it's been like 8 years or whatever since I really was doing a bunch of USB stuff, so I'm not gonna really be any help, unfortunately.... I do seem to recall I set MegaJoy up with 64 buttons originally since I couldn't get a higher number of buttons to work in Windows, so I guess I just didn't go high enough lol.

My recollection is that programming USB descriptors was a real ugly mess, since I didn't ever learn USB too deep, so my recommendation is to maybe just map your buttons in your sim to step around the dead block of buttons? Not the most elegant solution, but you may be in a niche case. Might be interesting to post a bug report on the GitHub about it and see if anyone else eventually pokes around on it?

Thanks for putting the time into messing with it, and sorry I'm not much help...

-Chatham

On Tue, Jan 1, 2019, 5:15 PM Mikkelhost <notifications@github.com wrote:

[image: 20190101_230951] https://user-images.githubusercontent.com/36157675/50576828-97c94780-0e1a-11e9-8e75-3841aff71f7d.gif Here is a gif of what im talking about. I made the arduino cycle through the buttons from 0-79 and then repeat. As seen on the gif, every button works exept those 8 buttons.

I also tried one time changing the amount of buttons to 144, her there are 16 buttons that doesn't work. more specifically buttons 64-71 and 128-135. So it seems to behappening at every 8th byte.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AlanChatham/UnoJoy/issues/25#issuecomment-450760898, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG01db97tC6D9m8CvPDhIWaFC9dQnPPks5u-932gaJpZM4ZmC6v .

Mikkelhost commented 5 years ago

I've fixed the problem. Found out that it was in the arduino ". h" file itself. Don't know why i hadn't looked there yet😅 but seems to have fixed the problem. Now i would just have to find out how i will be able to activate all buttons at once. Maybe you have an idea on how that is supposed to happen :-)

Best regards Mikkel

AlanChatham commented 5 years ago

If you wanted to activate all the buttons at once, shouldn't you be able to set up the dataForController_t that you're using to have all the buttons on? Let me know if that's not working!

Thanks, -Chatham

On Tue, Jan 8, 2019, 2:07 AM Mikkelhost <notifications@github.com wrote:

I've fixed the problem. Found out that it was in the arduino ". h" file itself. Don't know why i hadn't looked there yet😅 but seems to have fixed the problem. Now i would just have to find out how i will be able to activate all buttons at once. Maybe you have an idea on how that is supposed to happen :-)

Best regards Mikkel

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AlanChatham/UnoJoy/issues/25#issuecomment-452196780, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG01Q383SRuQ6W88cFhmXDfDeWt0pBdks5vBEPPgaJpZM4ZmC6v .

Mikkelhost commented 5 years ago

Im not sure i understand quite what you mean. All i have tried is to let the arduino run through a sequence which turns all the buttons on. but it doesnt work :/

AlanChatham commented 5 years ago

I mean something like this from the sample MegaJoy code:

...

megaJoyControllerData_t getControllerData(void){

// Set up a place for our controller data // Use the getBlankDataForController() function, since // just declaring a fresh dataForController_t tends // to get you one filled with junk from other, random // values that were in those memory locations before megaJoyControllerData_t controllerData = getBlankDataForMegaController(); // Since our buttons are all held high and // pulled low when pressed, we use the "!" // operator to invert the readings from the pins

// old line //for (int i = 2; i < 54; i++){ // controllerData.buttonArray[(i - 2) / 8] |= (!digitalRead(i)) << ((i - 2) % 8); //} //new line, for however many buttons, assuming you also changed what a dataForController_t struct looks like // to have enough size for the buttons here like: #define BUTTON_ARRAY_SIZE 10 for (int i = 2; i < 80; i++){ controllerData.buttonArray[(i - 2) / 8] |= (0b1) << ((i - 2) % 8); }

.....

Let me know if that makes sense? It's using bitwise operators in the MegaJoy! code to toggle button states, as MegaJoy holds its button data as an array of bytes, with each byte holding the button data for 8 buttons, one for each bit.

Hope that helps! -Chatham

On Thu, Jan 10, 2019 at 10:59 AM Mikkelhost notifications@github.com wrote:

Im not sure i understand quite what you mean. All i have tried is to let the arduino run through a sequence which turns all the buttons on. but it doesnt work :/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AlanChatham/UnoJoy/issues/25#issuecomment-453212906, or mute the thread https://github.com/notifications/unsubscribe-auth/ABG01SAMSql4s7w6-EGQ9eBA9zkHycavks5vB42igaJpZM4ZmC6v .

Coachidoachi commented 5 years ago

Hello there, at the moment i plan on building a similar Project for my flightsim. I am planning for ca. 52 digital inputs. However, i would like to build it, so i can expand on it in the future. My problem is, no matter what i do, Pointys Joysticktester only shows 2 devices with 32 buttons. I veryfied this by trying to assain a button beyond that to a controll in the flightsim (DCS) and it doesn't recognize it either, so something isn't working. I don't have that much experience in programming and i tried solving this problem for the last 3 days, so i thought that someone here could maybe help me. What i did was changing the button array size in Megajoy.h and expanding the "for loop" to assain the new buttons in the array. Can someone please give me a hint on what to try additionaly? I am currently testing running on a 64bit Win10 computer. Thank you and greetings! (and sorry for my bad english speaking skills, i am working on them :) )

Mikkelhost commented 5 years ago

Hey Coach

add me on discord Mikkelhost#1366

I got something that might help you out

briancavanaugh commented 5 years ago

@AlanChatham @Mikkelhost I was going to start a new issue thread, but I saw this one and based on what I see as the original post, I believe this ties directly to what I am trying to do. I'm trying to use UnoJoy to add a couple more buttons but I'm having a bit of difficulty. For starters, I've only tried to add 1 new button as a test to see what I get. I have download Atmel Studio 7, but I'll admit this is the first I've used it, so I'm not exactly sure what I could be missing.

For starters, I modified the UnoJoyArduinoSample and UnoJoy.h files and flashed them to my UNO. For my test, I decided to make pin A3 a digitalWrite, just like A4 and A5. After turning into a joystick, obviously nothing new happened because I didn't change any of the ATmega code. So........

Next, I modified the following files in the ATmega8u2Code folder... usb_gamepad.h uint8_t newTest_btn : 1; usb_gamepad.c .newTest_btn = 0 (added in the gamepad_idle_state function signature) gamepad_state.newTest_btn = btnList.newTestOn; (in the sendPS3Data function) UnoJoy.c dataToSend.newTestOn = 1 & (buttonData3 >> 1); dataForController_t.h uint8_t newTestOn : 1; (right below the dpadDownOn line) ButtonMapping.txt (I realize this is only a reference file) physicalButtonList_t.h (this file didn't seem to be included in the solution, so after my first attempt which didn't work, I decided to include it, but got the same results)

After modifying and building successfully, I copied the output files into the ATmega8u2Code/HexFiles folder and turned into a joystick again. Unfortunately, I did not get a new button to show up in the controller tester. However, this time grounding the A3 pin did cause button 5 to turn on. I'm really unsure why it made that button turn on.

Is there some sort of constant I need to increase that defines the total number of buttons? I can include additional code snippets if I've been unclear on anything. I appreciate any help with this.

AlanChatham commented 5 years ago

Are you using UnoJoy or MegaJoy? MegaJoy has a bunch of buttons, way more than the 13 that UnoJoy has, so if you haven't, give that a shot. Otherwise, you're going to be entering the horrible world that is USB HID device programming, which is a real pain. If you're trying to add more buttons, you'll also need to update the HID report descriptor, and possibly some other HID stuff somewhere (I don't totally remember at this point, but doing a diff between the UnoJoy and MegaJoy files could help a lot there). You also might need to add 8 buttons at a time, since you may run into some issues packing bits into things here and there. Importantly, between tests, you'll need to uninstall your controller from Windows, since the OS will cache the HID report descriptor between device plug-ins, so if you don't uninstall the device on the system level, it won't actually pay attention to the new HID device report you're trying to give it.

Hope this is helpful!

briancavanaugh commented 5 years ago

Thanks for such a quick reply! I found the issue though! It was in the gamepad_hid_report_desc constant. I saw that I had to increase the REPORT_COUNT and USAGE_MAXIMUM, but missed the fact that I then had to decrease the REPORT_COUNT for the next INPUT which was essentially the padding.

Also, I found the other issue that I had of the wrong button turning on from my pin. For that one, I simply had the order of my button names wrong in the typedef struct in my usb_gamepad.h file.

FYI....I'm using UnoJoy, not MegaJoy. The buttons that I'm adding, I'll be able to fit in using a matrix pattern with the number of pins that the UNO provides, plus I found a couple of UNOs for much cheaper than the Megas. I'm learning a ton with this in a very short while. Thanks for creating a cool project!

AlanChatham commented 5 years ago

Glad things worked out! Just FYI, you should be able to use the MegaJoy! code on an Uno, giving you more buttons to play with.

briancavanaugh commented 5 years ago

Thanks! I'll give that a shot too.

Assamita81 commented 1 year ago

Hello mr @Mikkelhost. I wanted to ask you about your project because I'm doing something similar, but couldn't find your Discord ID. Would you be so kind to contact me for some help? my ID is SrSosio#4606 Thank you

Mikkelhost commented 1 year ago

Hi @Assamita81 I abandoned my own project years ago. So im no longer able to assist as i havn't looked into it since 😕

briancavanaugh commented 1 year ago

Hello @Assamita81, I used this project for awhile, but I ended up going a different direction. Feel free to take a look at what I did here... https://github.com/briancavanaugh/RetroGameController

Assamita81 commented 1 year ago

Thank you @briancavanaugh I'm pretty confident building button boxes with Leonardos and Pro Micros. In fact, my current project was designed originally for a Pro Micro. However, it has too many inputs and I run out of pins, that's why I'm exploring the Mega solution. I tried port expanders like the PCF8575, but the only library I found for them to handle 8x8 matrix could not handle several buttons pressed at once, like the Keypad library does, and I'm not smart enough to program the code for a matrix myself. @Mikkelhost my project is not really that complex. If you could let me know how did you wire your 80 buttons that'd be enough, I could try to figure out the rest from there. Did you use a matrix?

Mikkelhost commented 1 year ago

I believe that i ended up using a matrix yes, and then i used diodes to make sure that i could push multiple buttons at the same time.