Having issues with the joystick module

I cant get the JoystickPressed or the JoystickReleased event to fire… I have somthign like the folowwing in the code


        void ProgramStarted()
        {
              objJoystick.JoystickPressed += objJoystick_JoystickPressed;
              objJoystick.JoystickReleased += objJoystick_JoystickPressed;
        }
        void objJoystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            Debug.Print("Something happened !!!!!");
        }

Did you change the name of the joystick variable? Normally, when using the designer, the name of the joystick should be “joystick” not "objJoystick:?

I assume you did use the designer?

@ Mike - I did use the designer and changed the name form the properties window… Also i should have mentioned that i can retrieve the position of the joystick correctly when i use


void ProgramStarted()
        {
              objJoystick.JoystickPressed += objJoystick_JoystickPressed;
              objJoystick.JoystickReleased += objJoystick_JoystickPressed;
              Thread objPosThred = new Thread(() =>
                                            {
                                                while (true)
                                                {
                                                    Thread.Sleep(50);
                                                    var pos = objJoystick.GetJoystickPostion();
                                                    if ((pos.X == 1) && (pos.Y > 0.4))
                                                        newCommand = "f";
                                                    else
                                                        if ((pos.X == 0) && (pos.Y > 0.4))
                                                            newCommand = "b";
                                                        else
                                                            if ((pos.Y == 1) && (pos.X > 0.4))
                                                                newCommand = "l";
                                                            else
                                                                if ((pos.Y == 0) && (pos.X > 0.4))
                                                                    newCommand = "r";
                                                                else
                                                                    newCommand = "s";
                                                   
                                                    Debug.Print(newCommand);
                                                   
                                                }
                                            });
        }
        void objJoystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            Debug.Print("Something happened !!!!!");
        }

I’ve actually not been able to get that event to fire properly either, but it’s very low on my priority list.

please read the press state without events, read directly. Does it read teh right value.

Also, leave code as is and then put button instead of joystick. Do you get events?

@ Gus - When i read

objJoystick.IsPressed

it gives me the correct value. Also as you suggested i tried adding a button via an EBlock expansion on socket 4 pin 3

GT.Interfaces.InterruptInput Button = eBlockExpansion.SetupInterruptInput(GT.Socket.Pin.Three, GT.Interfaces.GlitchFilterMode.Off, GT.Interfaces.ResistorMode.Disabled, GT.Interfaces.InterruptMode.RisingAndFallingEdge);
Button.Interrupt += new GT.Interfaces.InterruptInput.InterruptEventHandler(Button_Interrupt);

where


void Button_Interrupt(GT.Interfaces.InterruptInput sender, bool value)
{
     Debug.Print("Button state now is: " + (value ? "Up" : "Down"));
}

but nothing in the output window. It seems that no interrupts are getting handled. I also copied the driver code for joystick from codeplex and explicitly added it to my project with a different class name and the same result


private void _input_Interrupt(GTI.InterruptInput input, bool value)
        {
            JoystickState joystickState = value ? JoystickState.Released : JoystickState.Pressed;

            this.OnJoystickEvent(this, joystickState);
        }

was never called.

This doesn’t make sense. You can read the state correctly but events do not fire!

The button I am talking about is the button module. Remove joystick and plug the button in the same socket without changing any code.

Use the very first code you posted above.

I don’t have a button module but i did put the extender module on the same port where the joystick was and with a button ebock on pin 3.
Still no event.

Can anyone in the community test if any interrupt event are getting fired.

I’ll test today when I get home.

Switching out for a button module does not cause the event to raise either.

Update 1
Changing the designer to say it’s a button does work as does having a sketch with nothing but a joystick & T35 display. I’ll have to work through it and see if I can’t find where exactly the disconnect happens.

Update 2
OK, from my end it was the way I’m using Gadgeteer. I actually run regular NETMF and construct modules as needed based off startup data (which allows me to work w/ dynamic modules and switch between device states handheld/console). As soon as I called Program.Run() the event started firing.

That, of course, stems from the Program.CheckAndInvoke that is called in the OnJoystickEvent method, so a modified driver could eliminate the need for calling Program.Run() (not that I need one, I’m happy doing it this way, just info for anyone might need it).

@ Tanu please use the joystick but in the designer use a button! I want to see if the button driver work for your joystick presses please.

Thanks @ skewworks

Anytime Gus. See update #2 above. Joystick now works perfectly for me (you know, if I use it the way it was intended to be used ;))

@ Gus: I used a button in the designer as you suggested but still no luck…
I also created a small project with just the hydra and a button but still no event. I have attached the project solution for someone to test out at their end.

[Update] - Just realized i cant attach a zip file… But anyways if any one can test a button module on socket 14 and get an event it would be great…

Are you sure you didn’t block “ProgramStarted”? This will block all events.

@ Gus- I did block the thread and once i remove the Thred.Sleep everything was working… Thanks for the help… This is my first experience with Gadgeteer and i though the ProgramStarted method was like the Main method in non gadgeteer netmf.

@ Tanu - this will help explain the details behind why…

http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx