Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:13 06 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: Joystick / Games controller library

     Page 1 of 2    
Author Message
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 08:23am 11 Aug 2020
Copy link to clipboard 
Print this post

Hi, I've made a library to read digital joystick pins as discussed in the forum at CMM2: Recommendations for joystick/game controller I/F standard

The simplest version has a test program pins.bas in the zip file.

If you are connecting up a joystick like this please give the program a test - it should show when you move the joystick or press a button.

I've patched lunar lander to work with it, I'll post that in the lunar lander thread soon.

I've got another version that's compatible with the pins vegipete may have been testing, and one that attempts to emulate a joystick with the terminal keyboard.

There's also a fairly untested version that I want to have autodetect Wii controllers as well, and emulate a joystick.

controllers-test.bas is the test file for that, I don't have a wii controller to test with.

The test program has a "test controls" option that's like the other test programs, and two controller detection routines, one of them that just uses the library's autodetection, and another that may show more information.

If anyone would like to help me test and debug the library, please give these options a try with any wii controllers (classic, classic pro, nunchuk, other) and let me know the results (errors, what the controller shows up as, or what works).

Once it's working, it should support the analog joystick on the nunchuk as if it were a digital joystick, and the dpad on the classic controller or classic controller pro.

I'm also interested in test results with joysticks, or with the terminal (which requires a separate test program, included in the zip file)

cmm2-controllers.zip
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 08:42am 11 Aug 2020
Copy link to clipboard 
Print this post

Lunar lander modification posted in the thread here:
CMM2: Lunar Lander

Download here: LunarLander2Controllers.zip
Edited 2020-08-11 18:43 by capsikin
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 09:46am 11 Aug 2020
Copy link to clipboard 
Print this post

Tests:
controllers-test.bas :
†Wii Classic Controller:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. both error out with "FRONTPORT is not declared"

†Wii Classic Controller Pro:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. error as before

†Super Nintendo Classic:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. error as before

†Nunchuk Controller
† † † † † † † † † † † † 1. Detected as nunchuk
† † † † † † † † † † † † 2. and 3. error as before


So, I thought i'd "dim frontport". then error "t_id in not declared", so "dim t_id"

now. 2. works the same as 1.
So. onto 3.

nunchuk - worked perfectly.
other 3 controllers gave "controlers.inc:277 error expression syntax",
This is the code at that line " †Classic.Left = classic(B) & (1<<8) <> 0"

I don't see anything inherently wrong, but I haven't tried coding for the controllers yet.

That's about as far as I can go.

Looking through the controllers.inc file, I see "wii balance". That only connects through bluetooth, so you can safely remove that lol.

On another note:
https://github.com/mkopack73/cmm2_tests
on here is a "joytest.bas". it detects ALL the controllers I have perfectly AND read all inputs, including analog sticks, extra L and R buttons etc. This test doesn't include the nunchuk, but the nunchuktest.bas does, and that worked fine also. So check that out for sure.
Edited 2020-08-11 19:48 by Atomizer_Zero
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 10:36am 11 Aug 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  Tests:
controllers-test.bas :
†Wii Classic Controller:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. both error out with "FRONTPORT is not declared"

†Wii Classic Controller Pro:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. error as before

†Super Nintendo Classic:
† † † † † † † † † † † † 1. Detected as classic controller
† † † † † † † † † † † † 2. and 3. error as before

†Nunchuk Controller
† † † † † † † † † † † † 1. Detected as nunchuk
† † † † † † † † † † † † 2. and 3. error as before


So, I thought i'd "dim frontport". then error "t_id in not declared", so "dim t_id"

now. 2. works the same as 1.
So. onto 3.

nunchuk - worked perfectly.

Thanks, very helpful. I think I fixed "frontport" and "t_id" already in the .bas but not the .inc.
I'd made it a "local", I'll see if that looks appropriate for the library.
  Quote  

other 3 controllers gave "controlers.inc:277 error expression syntax",
This is the code at that line " †Classic.Left = classic(B) & (1<<8) <> 0"

I probably need "AND" instead of "&", and parentheses around it:
Classic.Left = (classic(B) AND (1<<8)) <> 0

I'll have to fix that for all the directions. Or maybe make a function, (classic(B) AND (1<<bitnumber)) <> 0


update: I think I've fixed those two bugs in the new version:
cmm2-controllers_02.zip
LunarLander2Controllers.zip

  Quote  
I don't see anything inherently wrong, but I haven't tried coding for the controllers yet.

That's about as far as I can go.
  Quote  
If you've fixed the library code to work with the nunchuk, you can also try it with the lunar lander game if you want.


Looking through the controllers.inc file, I see "wii balance". That only connects through bluetooth, so you can safely remove that lol.

On another note:
https://github.com/mkopack73/cmm2_tests
on here is a "joytest.bas". it detects ALL the controllers I have perfectly AND read all inputs, including analog sticks, extra L and R buttons etc. This test doesn't include the nunchuk, but the nunchuktest.bas does, and that worked fine also. So check that out for sure.


Yes I'll have a look, thanks.
Edited 2020-08-11 21:30 by capsikin
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 11:51am 11 Aug 2020
Copy link to clipboard 
Print this post

Excellent! This will enable a very good compatible range in an easy way.

For sure I will use your approach to attach to my games... Why to reinvent the wheel?

Thanks for your great work.
Edited 2020-08-11 21:51 by MauroXavier
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 01:23pm 11 Aug 2020
Copy link to clipboard 
Print this post

Exactly. Having a controller API that we can include into our projects for mass compatibility with controllers is an ideal situation.

One thing I will say is that, I think it would be good if we have the support for ALL buttons on the various controllers. It might limit some users to having to use keyboard if they dont have a classic controller, but at the same time, if you want to be able to play ALL the games, then you should consider getting a controller that will support all the games.

One other thing, in the future, it looks like we'll having the ability to connect multiple nunchuks using an adapter pcb of some kind. This should be considered in the future, as games that use more than 2 buttons and 4 directions could have the other controls mapped to a second nunchuk, which would double the amount of inputs available (meaning some controls can be mapped to two nunchuks, if the user doesnt have a classic controller, for example.)
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 05:18pm 11 Aug 2020
Copy link to clipboard 
Print this post

Really, it would be cool if we can make a standard format for more than 2 players. My Gauntlet port could benefit from this, and why not Final Fight? (3 players version)
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 11:01pm 11 Aug 2020
Copy link to clipboard 
Print this post

Yeah Iím all for making some of these sorts of things as an agreed upon standardized API that we all use. Makes things faster for us to write new code and standardized how people come to expect interacting with the controllers.  

Same reasons why I put together that Highscore api....

Glad my code might be helping!
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 11:06pm 11 Aug 2020
Copy link to clipboard 
Print this post

Also HIGHLY recommend we come up with a standard numbering scheme for versioning these libraries and a standard way to check for them. So if your game was written to work on say v1.4.3 of the joystick or highscore api/library there is a way to check to see if thatís the version they have on the card (or newer assuming you donít remove any old functionality or change the api drastically).  That way the include wonít break things and you can be sure the game is using a valid inc library version.

You all might also notice that in my stdsettings.inc that I do a version check of the system firmware to make sure that the user is on the proper firmware version that my code relies upon.

Probably good practices to start following as things continue to evolve.
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 11:08pm 11 Aug 2020
Copy link to clipboard 
Print this post

For example we have the inc file each provide a (api_name)_getversion() function call so right after you include it you can check the version number and quit out if they arenít using the version you are expecting.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 11:53pm 11 Aug 2020
Copy link to clipboard 
Print this post

Atomizer_Zero
  Quote  One other thing, in the future, it looks like we'll having the ability to connect multiple nunchuks using an adapter pcb of some kind. †


I posted these but can't find it. so here it is again.






2port.zip

there was a post on pcb mounted nunchuk connectors can't find it.

Once it get them I can change the pcb to use them making the board cost
much less.



And I have may be 8 of these  

40 pin gp break out board

scroll down its not going to the exact post
These where made for my MM170 HatStand prototypes


I have in the works something much better just waiting of PCBS test run
Edited 2020-08-12 10:12 by Quazee137
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 05:10am 12 Aug 2020
Copy link to clipboard 
Print this post

I'm glad there's so much interest in this, I won't be able to reply to everything at once.

I did want to ask if anyone with a wii controller had found any bugs in the second version of my library that affect its use in controllers-test.bas or the lunar lander program.

  mkopack73 said  For example we have the inc file each provide a (api_name)_getversion() function call so right after you include it you can check the version number and quit out if they arenít using the version you are expecting.


I was thinking I'd have something like:
CONST Controllers.API.<apiname>.version = 2
because the rest of the interface starts with "Controllers."
and using integers 1 or higher seemed best.

This is for just the very simple, init, 4 direction functions, 2-4 button functions (but multiplayer) API.

I've already done two revisions of the API as I noticed my initial code didn't support an argument for selecting between multiple players in something like Controller.Left(player_number) as I'd intended.

If I support much more than that simple API I'd like to have a separate API or API extension, rather than expect every version library that provides the API to do it.

Maybe with CONST Controllers.API.<secondapiname>.version = 1
Or CONST Classic.API.<secondapiname>.version = 1
if it's a classic controller-specific API.

API versions 1 to 3:
https://gitlab.com/caspianmaclean/cmm2-controllers/-/blob/master/API.md
API version 1 is what the code currently supports (though you can also use the functions that aren't part of the API, as I did with the autodetection test)
Edited 2020-08-12 15:15 by capsikin
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 06:09am 12 Aug 2020
Copy link to clipboard 
Print this post

  MauroXavier said  Really, it would be cool if we can make a standard format for more than 2 players. My Gauntlet port could benefit from this, and why not Final Fight? (3 players version)


Yes I agree, I'd also like to see Gauntlet with multi controller support.

The functions are supposed to support a player argument to select between multiple players, I'll fix this in a future version.

Actually getting multiple controllers supported will be more work and testing.

Quazee137 I'm not sure how far along you are with connecting a second controller. Do you have some type of controller(s) yourself, and would you be able to connect it to different pins (not the front) once I have some code to test? Not that I have it now, just thinking about the future.

I'm also interested in supporting the I2C multiplexers you mentioned some time in the future. I did want to check that the different multiplexers are compatible. There's one from adafruit:
https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout

which supports 8 connections and is already on a breakout board, it would be good if the same code can support that and people wanting to solder a smaller 4 connection chip onto their own board.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 07:53am 12 Aug 2020
Copy link to clipboard 
Print this post

The nunchuk ports 2 and 3 board I posted here plugs into the 40 pins on the back
of the CMM2 would be better with the nunchuk pcb mount connectors.

a two port I2C using the front nunchuk port
two port I2C

an I2C way to make use of joy sticks and other analog devices
joy sticks I2C way


I have not had time to cut into my code for some of my boards using some of the
I2C chips posted in here  some I2C chips
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 01:07pm 12 Aug 2020
Copy link to clipboard 
Print this post

  Atomizer_Zero said  Exactly. Having a controller API that we can include into our projects for mass compatibility with controllers is an ideal situation.

One thing I will say is that, I think it would be good if we have the support for ALL buttons on the various controllers. It might limit some users to having to use keyboard if they dont have a classic controller, but at the same time, if you want to be able to play ALL the games, then you should consider getting a controller that will support all the games.


I thought a bit about this, I think a different API would be better, I don't want to extend the joystick one with buttons E,F,G,H...

Thoughts about what would be useful beyond the built in classic/wii classic support:
Checking that it's not a nunchuk.
Named access to individual buttons. I don't think I'd want to have a function for each button, maybe a constant that can be passed to the function instead.
Analog controls - these may be okay with the built in function.
Would it be useful to be able to loop over all the button numbers?

Anything else?
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 02:07pm 12 Aug 2020
Copy link to clipboard 
Print this post

This release of the library collection includes a version of the library that allows testing two player support of the API, using a USB keyboard. Increasing to 3 players and 4 buttons per player would be fairly easy, but it's already crowded on the keyboard.

I hadn't previously included USB keyboard support because I think the simple API is too limiting - the program can't easily display the movement keys in instructions on the screen, for example. It could be better if the keyboard support is integrated into the program instead of a separate library.

You can change the keys in the library source code:
usb-kbd-multi-controller.inc

the test program is usb-test.bas

cmm2-controllers_0_3.zip
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 02:57am 13 Aug 2020
Copy link to clipboard 
Print this post

I just released a rough port of space invaders that uses and supports the library.

https://www.thebackshed.com/forum/ViewTopic.php?PID=152474#152474
 
capsikin
Guru

Joined: 30/06/2020
Location: Australia
Posts: 341
Posted: 12:59am 14 Aug 2020
Copy link to clipboard 
Print this post

  capsikin said  
  Atomizer_Zero said  Exactly. Having a controller API that we can include into our projects for mass compatibility with controllers is an ideal situation.

One thing I will say is that, I think it would be good if we have the support for ALL buttons on the various controllers. It might limit some users to having to use keyboard if they dont have a classic controller, but at the same time, if you want to be able to play ALL the games, then you should consider getting a controller that will support all the games.


I thought a bit about this, I think a different API would be better, I don't want to extend the joystick one with buttons E,F,G,H...


That said I do plan to support 4 buttons as A,B,C,D.

  capsikin said  
  MauroXavier said  Really, it would be cool if we can make a standard format for more than 2 players. My Gauntlet port could benefit from this, and why not Final Fight? (3 players version)


Yes I agree, I'd also like to see Gauntlet with multi controller support.



I've got a test version using the USB keyboard for up to 3 players, 4 buttons each which I'll release in a few days, though it's probably too crowded for really playing actions games. If that's enough buttons for Final Fight it should work using the existing library interface, which could then later support 3 Wii Classic controllers.

I'm not sure how auto detection will go with more players, there may need to be a way for players to select what type of controller they are using (otherwise you set it by picking which version of the library you include)
 
MauroXavier
Guru

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 11:28am 14 Aug 2020
Copy link to clipboard 
Print this post

I'm fixed my Wii Classic Controller!

... Gauntlet with 2 player support is on the way!
 
Atomizer_Zero
Senior Member

Joined: 04/07/2020
Location: United Kingdom
Posts: 134
Posted: 08:22pm 14 Aug 2020
Copy link to clipboard 
Print this post

  MauroXavier said  I'm fixed my Wii Classic Controller!

... Gauntlet with 2 player support is on the way!


NICE! Cant wait to play! the game as it is right now is so fun to play.. me and my brother will run it through its paces when you release it :D
 
     Page 1 of 2    
Print this page
© JAQ Software 2024