-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read timing slow if no controller plugged in. #51
Comments
It might be related to this delay in ` // Initial loop waits for the line to go low.
I'm unfamiliar with how to reduce that timeout, and it might cause issues for controller initializaion because the library waits for the controller to respond to know if it's connected. My suggestion to fix this: |
http://www.int03.co.uk/crema/hardware/gamecube/gc-control.html Here is a pin out of the plug; pins 3 and 4 and the outer shield are all grounds. if you can isolate one of them so they are not connected to each other you can use that as the 'sense' pin. |
Sadly these little breakout boards for the ports have pins 3 and 4 connected together. |
Well, I just ended up making a timer that will only call gc_init every second or so if there's no controller connected. Seems to have mostly fixed the issue. |
So there is not signal generated when the controller is plugged in/turns on. I just double checked with my scope. If possible you might be able to cut the trace between pin 3 and 4 and solder directly to one of them as a sense pin. |
Good to know. I'll have to keep that in mind when I design a custom PCB for this. |
This may reduce communication issues, but if there are not two controllers plugged in then it will still hiccup your program every second while it times out for 70ms. This might cause issues still. 70ms is several typical read cycles. Perhaps you put a reset button on the outside of the box and only initialize the number of controllers plugged in at startup. When adding a second controller you can press the reset button. Also, if a controller does not respond for a certain amount of time (a few seconds) it could just stop checking for that controller until a reset. |
@NicoHood It might be worth noting that in my observation of communication with a data analyzer; a connected gamecube controllers is responding to the 3 byte command within <1us. So 71ms timeout might be unnecessary. I know it's based off of the gamecube polling rate, but perhaps it times out after a shorter period and then waits the remaining 71ms to try again in a non-blocking manor. That way the program can continue un-halted. Maybe controller.Read() can take an optional timeout argument for use cases like this, so someone can specify how long to wait for a response before returning. |
Worth noting but, I changed this line Line 344 in e4130ff
to
to disable the outer timeout loop, and it seems to work great. I even disabled my timer surrounding |
But wouldn't this break the code for communicating with the console? |
Interesting question. In regards to a use case where the Arduino is a man-in-the middle between the console and the controller: (The scenario might depend on whether the firmware sends data to the console every loop, or if it only sends data on a successful read of the controller.) console.write is blocking, so it waits to receive a command from the console to reply. On initialization, if the console thinks there is no controller attached it would poll every 70ms. When the Arduino receives the command it polls the controller to receive the data for the next write cycle. If there were no controller attached, the Arduino would not receive a response and assume controller.read failed. The console would send the next poll and not receive a reply and continue to assume the controller is not connected. The library works as is, so it might be a non issue. |
If the Arduino replies to the console with the last known data, regardless of whether controller.read return true, the console would assume there was a connected controller and poll at the usual connected rate. Each subsequent controller.read would attempt to reconnect to the controller if there was no response. I don't think there's any harm in checking if a controller is connected more than once every 70ms. In a normal use case, a assume a connected controller would respond very quickly. There maybe situations with damaged hardware or a poor connection that might inhibit the response speed? |
I'm only using this for turning two controllers into a HID joystick devices, so I'm not doing any communication with a console. This allows me to constantly check for a second controller if there's not one plugged in without any performance loss. |
Sure, but there are other people that do use this feature. I suggest, that you both create a PR that in you opinion fixes this issue as best as possible and then we need a 3rd opinion/tester that checks if that code also works in controller moder (acting as a controller to the console). |
Hey again. I have a weird issue and I'm curious if you could provide any insight on why this is happening.
I converted an old and broken Mayflash 2 port adapater to use an arduino and this library.
It works great, however, one thing I noticed is the polling rate drops significantly if I only have one controller plugged in.
Is there an explanation on why this happens? It would be nice if I didn't have to plug in two controllers just to have a usable device. I tried looking through the assembly of
gc_n64_get
and noticed there's a mention of a timeout. Can this be adjusted or lowered?The text was updated successfully, but these errors were encountered: