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

Open
wants to merge 9 commits into
from

Conversation

Projects
None yet
2 participants
@seclorum

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

This comment has been minimized.

Show comment Hide comment
@seclorum

seclorum Mar 12, 2012

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

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

@antirez

This comment has been minimized.

Show comment Hide comment
@antirez

antirez Mar 16, 2012

Owner

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!

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

This comment has been minimized.

Show comment Hide comment
@seclorum

seclorum Mar 17, 2012

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.

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

This comment has been minimized.

Show comment Hide comment
@antirez

antirez Mar 17, 2012

Owner

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

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

This comment has been minimized.

Show comment Hide comment
@seclorum

seclorum Mar 17, 2012

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

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

@seclorum

This comment has been minimized.

Show comment Hide comment
@seclorum

seclorum Mar 17, 2012

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..)

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

This comment has been minimized.

Show comment Hide comment
@seclorum

seclorum Mar 17, 2012

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?

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