• Advertisement
Sign in to follow this  

C# rumblepad SlimDX reflection

This topic is 1334 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a robot controlled by a joystick.  I am using a Logitech Rumblepad with two POV's and multiple buttons (a gamepad).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SlimDX.DirectInput;
using Rachelbot.API;
using System.Reflection;


namespace Rachelbot.API
{
public class rumblepad
{
private Joystick joystick;
private JoystickState state = new JoystickState();



public rumblepad(DirectInput directInput, int number)
{
// Search for Device
var devices = directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
if (devices.Count == 0 || devices[number] == null)
{
// No Device
return;
}

// Create Gamepad
joystick = new Joystick(directInput, devices[number].InstanceGuid);
//joystick.SetCooperativeLevel(game.Window.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);

// Set Axis Range for the Analog Sticks between -1000 and 1000
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
joystick.Acquire();
}


public JoystickState GetState()
{
if (joystick.Acquire().IsFailure || joystick.Poll().IsFailure)
{
state = new JoystickState();
return state;
}




state = joystick.GetCurrentState();

return state;
}

}






}

I am using the tick function to check the state of the joystick. All I am returning in the state is info from the 1st POV stick and nothing from the 2nd POV stick or the buttons.  It looks as if the information is in the non-public members for the buttons, but I am unsure of how to use the reflection to read the pressedbuttuns and releasedbuttons.

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement