libctru icon indicating copy to clipboard operation
libctru copied to clipboard

Add (incomplete) ir:USER API based on ctru-rs implementation for Circle Pad Pro support

Open syelan34 opened this issue 9 months ago • 4 comments

Adds basic API similar to the ir:U and ir:RST APIs, with all commands documented on 3DBrew implemented. Implementation of some functions was based on that of ctru-rs.

I don't have a circle pad pro to test with so I'm unable to check if everything works correctly, but it should match any documentation that exists.

syelan34 avatar Mar 31 '25 16:03 syelan34

I'm not super satisfied with my implementation of the iruserGetPackets() function, since it allocates two separate buffers, so please suggest any alternatives which might match how other libctru functions might act. The variable length encoding of packets, as well as the unknown number of packets makes it difficult to do any other way which is why I haven't so far.

syelan34 avatar Apr 17 '25 02:04 syelan34

Forgot to add review comment:

I think CPP support is good to have (though ideally this would need to be better integrated with hid/ir key sampling code).

There are a few critical bugs with your impl (notably with regards to lifetime and memory ownership).

I wonder if the API could be redesigned such that user provides user buffer instead of it being allocated. I haven't checked if this is possible, but dynamic allocations should be avoided there are cheap alternatives.

TuxSH avatar Sep 26 '25 16:09 TuxSH

Would it be better to simply return a pointer into the existing receive buffer as opposed to dynamically allocating a new one? It’d have no guarantee of still having the data when you read it but so long as you don’t request more packets I think it would be fine?

syelan34 avatar Sep 27 '25 13:09 syelan34

I haven't added hid integration yet because I'm not sure what a good approach would be. Constantly pinging to see if there is a CPP attached would take a lot of resources so it's not something I want to do. I suppose I could add a connect/disconnect CPP function to hid along with reading data if it's connected, but in that case error handling would be fairly annoying.

syelan34 avatar Sep 30 '25 17:09 syelan34