Skip to content

Feature: Joystick support for up to 4 Devices. #39

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Feature: Joystick support for up to 4 Devices. #39

wants to merge 9 commits into from

Conversation

seclorum
Copy link

This patch adds Joystick support to LOAD81. It allows up to 4 devices to be used within the Lua environment, and for that purpose adds a new global Lua table called 'joystick', with fields x, y, and name, where:

x = X-axis value of the joystick
y = Y-axis value of the joystick
name = name of the joystick device

This patch has been mainly targeted at Open Pandora users, where the onboard nubs are featured as independent high-resolution joysticks. For that reason, complete button support is not finished - but will be added in another patch shortly.

Tested on Open Pandora hardware, and Macbook Pro with paired iControlpad controllers. On Open Pandora hardware, joysticks will be named thus:

joystick[1].name = "gpio-keys" (Special feature of Open Pandora, for hardware hackers mostly)
joystick[2].name = "nub0" (The Left nub)
joystick[3].name = "nub1" (The Right nub)

@seclorum
Copy link
Author

Also, please see new examples/joysticks.lua for demo purposes.

@antirez
Copy link
Owner

antirez commented Mar 16, 2012

I definitely like the idea of supporting joysticks, but I think the exported API may be more consistent with what we have currently, more info ASAP, but I've some ideas :) I wonder if there is a way for me to simulate a joystick on osx or Linux...

Thanks!

@seclorum
Copy link
Author

I'm sorry I don't quite understand what you mean by the exported API - do you mean the joysticks[] table, or something? I'm rather eager to get this merged so I can move on to other things while using joysticks (this works really nicely on Open Pandora and OSX with iControlpad) so if you could clear up whats blocking this merge, it'd be helpful.

@antirez
Copy link
Owner

antirez commented Mar 17, 2012

This is what I need to merge it:

  • Removal of additional newlines before return in sdlInit() and createFrameBuffer() that was out of the scope of the patch.
  • updateJoystick(State|Name)() should use setTableField() instead, that is now generically able to set fields of global tables. If this is not possible at least the two functions should be unified because they do a very similar thing.
  • initJoysticks() should contain the code to properly initialize joystick[...] up to MAX_JOYSTICKS. Static initialization of first four joysticks should be removed.
  • initJoysticks() should not contain commented #if 0 / #endif blocks.
  • API: there should not be global JOYSTICKS, it should use a joystick table field, like joystick.num_joysticks.
  • API: Non existing joysticks should probably have the 'name' field set to nil instead of "none" that may conceptually be a valid joystick name.
  • API: Support for buttons is needed since day 0 IMHO, but this is not blocking.

Thanks!
Salvatore

@seclorum
Copy link
Author

Okay I will work on these points and submit a new patch shortly. Thanks for the feedback.

@seclorum
Copy link
Author

Re: Removal of additional newlines before return in sdlInit() and createFrameBuffer() that was out of the scope of the patch.

Can we come up with an indent config, or comment-string for vim or something, that solves this code-formatting issue? I'm an "indent -kr -ts4" kind of guy, and those returns might be the result of that .. maybe you have a rule for the indent cmd that we should use to enforce formatting? (this way I could run the rule before checkins, and still have our own local preferences for indentation/layout..)

@seclorum
Copy link
Author

Re: updateJoystick(State|Name)() should use setTableField() instead, that is now generically able to set fields of global tables. If this is not possible at least the two functions should be unified because they do a very similar thing.

There is a difference between the API's. " setTableFieldNumber sets a "table.field = number", whereas updateJoystickState goes "table[int].field = number".

Alas, there is probably a way to nest the lua atoms, I confess to not having the fortitude to know how to do that yet, but perhaps it would instead be better to refactor updateJoystickState[Name,Number] to be API calls "setTableIndexedFieldNumber" and "setTableIndexedFieldString" and use them elsewhere as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants