wx.Joystick codes/values

rama wrote:

Hi all,

I'm using the joystick interface to control an wxPy app,
and I'm going crazy about an eternal problem I can't solution to since
long.

Each time I switch to a different kernel, the codes for each button
pressed on the joystick change to different values.

I'm using always the same joystick which is Logitech WingMan Rumblepad.

I've started using wx.Joystick one year ago with the help of Robin,
and by that time, ie, button A from my joystick (a gamepad actually) was
producing a value of 1 when pressed... B was producing 2, C was
producing 4......

now A produces 795649, now B = 795650, C = 795652....

it wouldn't be very serious problem if it just changed between different
kernel versions, but I've found and proved that "sometimes" for unkown
reasons to me, it changes *also* within the same kernel version (at
least after reboots, and not always).

sounds strange, no? how could I debug this? I can't figure out.

This value is a bitmask, is it not? You can have multiple buttons pressed at once? That means you should not be saying:

    if button == 1:
        # A button pressed
    elif button == 2:
        # B button pressed
    elif button == 4:
        # C button pressed

Instead, you should be saying:

    if button & 1:
        # A button pressed
    if button & 2:
        # B button pressed
    if button & 4:
        # C button pressed

If you had written it that way to begin with, you never even would have noticed this change. The new values are the same as the old ones in the lower 8 bits.

···

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

rama wrote:

>> I've started using wx.Joystick one year ago with the help of Robin,
>> and by that time, ie, button A from my joystick (a gamepad actually) was
>> producing a value of 1 when pressed... B was producing 2, C was
>> producing 4......
>>
>> now A produces 795649, now B = 795650, C = 795652....
>>
>> it wouldn't be very serious problem if it just changed between different
>> kernel versions, but I've found and proved that "sometimes" for unkown
>> reasons to me, it changes *also* within the same kernel version (at
>> least after reboots, and not always).
>>
>> sounds strange, no? how could I debug this? I can't figure out.
>
>

This value is a bitmask, is it not?

I don't know, it semms like, or should be I guess.
how to verify that?

You can have multiple buttons pressed at once?

yes, and they produce different values close to the same range.
I can send more details and the result values if it helps.

That means you should not be saying:

    if button == 1:
        # A button pressed
    elif button == 2:
        # B button pressed
    elif button == 4:
        # C button pressed

I'm doing exactly this, can you tell me why this is wrong please?
I have different mappings based on the kernel versions.

something like:

if kernel is '2.4.29':
    A = 535553
    B = 535554
    C = 535556
elif kernel is '2.4.22':
    A = 1
    B = 2
    C = 4

and so on...

then doing:

if button == A:
    # A button pressed

and so on...

Instead, you should be saying:

    if button & 1:
        # A button pressed
    if button & 2:
        # B button pressed
    if button & 4:
        # C button pressed

ok, so here there is something I don't understand quite well.

this about if button & XX. this "&" is what is called a "logical and",
right? I guess I have some knowledge gap, so if you can explain this
part a little bit more, or direct me to some further doc, it will really
help me.

If you had written it that way to begin with, you never even would have
noticed this change. The new values are the same as the old ones in the
lower 8 bits.

hmm, I guess I should try that out.
anyway an update: running latest kernel 2.6.11-3 released last week, it
seems I get the original "nice" values back, which seem bitmask-like: 1,
2, 4, 8, 16, etc..

beside that I'm not sure I'm happy with this kernel as I have some
problems with some realtime audio apps, so I think there should be way
to fix the "values" problem along the problematic kernel versions.

I will try your advise with those kernels.

thanks a lot for your time!
greetings,
Ramiro.

···

El mar, 15-03-2005 a las 10:23 -0800, Tim Roberts escribió:

--