/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Diagonal Joystick

Username:     
Password:     
             

Forum

# 1   2009-07-13 19:31:03 Diagonal Joystick

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Diagonal Joystick

Would it be possible to expose diagonal directions to applications?

Code :

enum JOYSTICK_directState
{
JOYSTICK_RELEASED   =  0,
JOYSTICK_LEFT       =  1, //0000 0001
JOYSTICK_RIGHT      =  2, //0000 0010
JOYSTICK_UP         =  4, //0000 0100
JOYSTICK_DOWN       =  8, //0000 1000
JOYSTICK_RIGHT_UP   =  JOYSTICK_RIGHT | JOYSTICK_UP,  //0000 0110
JOYSTICK_LEFT_UP    =  JOYSTICK_LEFT  | JOYSTICK_UP,  //0000 0101
JOYSTICK_RIGHT_DOWN =  JOYSTICK_RIGHT | JOYSTICK_DOWN,//0000 1010
JOYSTICK_LEFT_DOWN  =  JOYSTICK_LEFT  | JOYSTICK_DOWN //0000 1001
}


enum JOYSTICK_state JOYSTICK_GetDirectInput(void)
    {
    enum JOYSTICK_state direction = JOYSTICK_RELEASED;

#ifdef PRIMER2

    if (GPIO_ReadInputDataBit(GPIOx_JOYSTICK, GPIO_JOYSTICK_R_PIN))
    abs_direction = JOYSTICK_RIGHT;

    if (GPIO_ReadInputDataBit(GPIOx_JOYSTICK, GPIO_JOYSTICK_L_PIN))
        abs_direction = JOYSTICK_LEFT;

    if (GPIO_ReadInputDataBit(GPIOx_JOYSTICK, GPIO_JOYSTICK_U_PIN))
        abs_direction |= JOYSTICK_UP;

    if (GPIO_ReadInputDataBit(GPIOx_JOYSTICK, GPIO_JOYSTICK_D_PIN))
        abs_direction |= JOYSTICK_DOWN;
#endif //PRIMER2

    return direction;
}

Last edited by ShadowPhoenix (2009-07-13 19:32:13)

Offline

 

# 2   2009-07-14 01:25:51 Diagonal Joystick

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Re: Diagonal Joystick

Would it be possible to at least do something like this?
Then you can simple generate correspanding defines.

u8 GetCurrentJoystick()
{

u8 result = (u8)GPIO_ReadInputData(GPIOx_JOYSTICK);
return (result & (GPIO_JOYSTICK_U_PIN | GPIO_JOYSTICK_D_PIN | GPIO_JOYSTICK_L_PIN| GPIO_JOYSTICK_R_PIN));
}

Last edited by ShadowPhoenix (2009-07-14 01:26:39)

Offline

 

# 3   2009-07-16 06:53:35 Diagonal Joystick

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Diagonal Joystick

You are right !
I believed that the mechanical part of the joystick allows a single direction only, but I just open the GPIOE view, and when I push the button in diagonal, I see 2 '1' ....
Very good suggestion!

Offline

 

# 4   2009-07-17 14:55:20 Diagonal Joystick

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Re: Diagonal Joystick

Francis :

You are right !
I believed that the mechanical part of the joystick allows a single direction only, but I just open the GPIOE view, and when I push the button in diagonal, I see 2 '1' ....
Very good suggestion!

Thank you!
I've done lots of game programming on the TI-84+, a very prominent graphing calculator. Has a z80 with 6-20 MHz, black/white (and we achieved grayscale by interrupt use) 96 by 64 screen.


The reason I started working with joystick is because I dislike the motion..

Oh, and my MEMS is acting up a bit, like it's extremely hard to use it. I tried chess, tetris, and it feels very awkward. I can very rarely do the same rotation twice. Am I doing something wrong or is my mems bad?

Offline

 

# 5   2009-07-20 04:04:05 Diagonal Joystick

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Re: Diagonal Joystick

Is there any chance this will make it into the next CircleOS release? I am making a simple shoot him up and diagonal moving is pretty necessary smile

Offline

 

# 6   2009-07-21 06:45:03 Diagonal Joystick

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Diagonal Joystick

We added the 'diagonal' feature in the next release (that will be published in the first half of August). Thanks for the suggestion.

Offline

 

# 7   2009-07-21 14:41:14 Diagonal Joystick

ShadowPhoenix
Member
Registered: 2009-02-11
Posts: 57

Re: Diagonal Joystick

Awesome! Thanks!

By the way... I am working on a small malloc... it will probably be finished in the next ten days too.

Offline

 

Board footer