Analog Stick 2 access with Android SDK ?

SimonTSimonT LondonPosts: 24Member
I am using the standard Android SDK and I have located all of the KeyEvent codes/enumerations for the wonderful Ouya game pad ( e.g. KEYCODE_BUTTON_R1 ) apart from those for the second analogue stick.

Its not critical I access that other "joystick" but it would be nice. I cannot trap the keycodes either for it other than when i push directly down on it ( the event that makes that character run in a game like Call of Duty for example ).

Is it possible to access this second analogue stick from the standard Android SDK ?

Many thanks in advance

Comments

  • ShushShush Posts: 178Member
    edited July 2013
    I use Android Input with the following OUYA constants and code without any issues:

    // Left stick
    OuyaController.AXIS_L2,
    OuyaController.AXIS_LS_X,
    OuyaController.AXIS_LS_Y
    x0 = event.getAxisValue(MotionEvent.AXIS_X);
    y0 = event.getAxisValue(MotionEvent.AXIS_Y);

    // Right stick
    OuyaController.AXIS_R2,
    OuyaController.AXIS_RS_X,
    OuyaController.AXIS_RS_Y
    x1 = event.getAxisValue(MotionEvent.AXIS_Z);
    y1 = event.getAxisValue(MotionEvent.AXIS_RZ);
    Post edited by Shush on
  • dra6onfiredra6onfire Posts: 91Member
    All of the key codes are accessible by overriding the onKeyDown event handler except the right stick. The key values for the analog triggers are depracated though because the correct method for grabbing the analog inputs it by overriding the onGenericMotionEvent handler. If you dig around in there you can get everything you need but if you start debugging the values being received by the events it will be tough to decipher because they are not consistently zero when not being used. Refer to Shush's post for the correct ways to handle the event analog values or refer to the ouya docs. You can still do all of this without the ODK but its a little tougher to handle the analog because you can't just sysout the key codes and program from there. You have to know them in advance to be able to call out the axis Value you want.
  • SimonTSimonT LondonPosts: 24Member
    Apologies for not replying to both these posts. Thank you very much for the information. I will get back to you as soon as I have implemented these suggestions.
  • SimonTSimonT LondonPosts: 24Member
    Once again thank you for the help. 

    In case it helps other people on this forum, here is the full code that we ended up using ( the methods are actually in two different classes in our app, but I have normalised the code so that it could run from the main class as it is ). 

    Incidentally, if anyone wants a complete project that allows two Ouya joysticks to be connected and to see all the outputs then please let me know and we can post it somewhere ( somewhere within the Ouya community ) as we wrote it to understand the numbers coming out of the joysticks:

    Here is the code:

    float straff = 0;
    float forward_back = 0;
    float tilt = 0;


    @Override public boolean onGenericMotionEvent(final MotionEvent event) {
       
        if( OuyaController.getPlayerNumByDeviceId(event.getDeviceId())==0) {

            if (gamestate==GameState.GAMEPLAY)     
    analogue_controls(event);

        }
    return true;
    }


    public void analogue_controls(MotionEvent event) {
    if ( event.getAxisValue(OuyaController.AXIS_LS_X) > 0.1f || event.getAxisValue(OuyaController.AXIS_LS_X) < -0.1f )
    straff = -event.getAxisValue(OuyaController.AXIS_LS_X) * 5;
    else
    straff = 0;
    if ( event.getAxisValue(OuyaController.AXIS_LS_Y) > 0.1f || event.getAxisValue(OuyaController.AXIS_LS_Y) < -0.1f)
    forward_back = -event.getAxisValue(OuyaController.AXIS_LS_Y) * 5;
    else
    forward_back = 0;
    if ( event.getAxisValue(OuyaController.AXIS_RS_X) > 0.2f || event.getAxisValue(OuyaController.AXIS_RS_X) < -0.2f)
    rotate = -event.getAxisValue(OuyaController.AXIS_RS_X) * 5;
    else
    rotate = 0;
    if ( event.getAxisValue(OuyaController.AXIS_RS_Y) > 0.1f || event.getAxisValue(OuyaController.AXIS_RS_Y) < -0.1f)
    tilt = -event.getAxisValue(OuyaController.AXIS_RS_Y);
    else
    tilt = 0;
    }
  • SimonTSimonT LondonPosts: 24Member
    Oh yes and you need to put just the ouya-sdk.jar in your lib directory for this to work ( sorry forgot to mention that )
Sign In or Register to comment.