Raspberry-pi – Why does GamePad.getCurrentReading () does not work?

I created a UWP application that utilizes the Windows.Gaming.Input namespace, but when I deploy to a Raspberry Pi 2 B running Windows 10 IoT Core, Gamepad.GetCurrentReading() The method returns the default instance of GamepadReading. (ie everything is 0)

Debugging on my local machine seems to work. Is there any other way to run this API on my device?

P.S. I noticed that one of the samples uses HidDevice, so I will use it as an alternative at the same time.

< /div>

This is my (incomplete) solution. It is a direct replacement for the Gamepad class.

class HidGamepad
{
static readonly List _gamepads = new List();
GamepadReading _currentReading;

static HidGamepad()
{
var deviceSelector = HidDevice.GetDeviceSelector(0x01, 0x05);
var watcher = DeviceInformation.CreateWatcher(deviceSelector);
watcher.Added += HandleAdded;
watcher.Start() ;
}

private HidGamepad(HidDevice device)
{
device.InputReportReceived += HandleInputReportRecieved;
}

public static event EventHandler GamepadAdded;

public static IReadOnlyList Gamepads
=> _gamepads;

public GamepadReading GetCurrentReading()
=> _currentReadin g;

static async void HandleAdded(DeviceWatcher sender, DeviceInformation args)
{
var hidDevice = await HidDevice.FromIdAsync(args.Id, FileAccessMode.Read);
if (hidDevice == null) return;

var gamepad = new HidGamepad(hidDevice);
_gamepads.Add(gamepad);
GamepadAdded?.Invoke(null, gamepad );
}

void HandleInputReportRecieved(
HidDevice sender, HidInputReportReceivedEventArgs args)
{
var leftThumbstickX = args.Report.GetNumericControl(0x01, 0x30) .Value;
var leftThumbstickY = args.Report.GetNumericControl(0x01, 0x31).Value;

_currentReading = new GamepadReading
{
LeftThumbstickX = (leftThumbstickX-32768 ) / 32768.0,
LeftThumbstickY = (leftThumbstickY-32768) / -32768.0
};
}
}

Me Created a UWP application that utilizes the Windows.Gaming.Input namespace, But when I deploy to Raspberry Pi 2 B running Windows 10 IoT Core, the Gamepad.GetCurrentReading() method returns the default instance of GamepadReading. (i.e. everything is 0)

On my local Debugging on the machine seems to work. Is there any other way to run this API on my device?

P.S. I noticed that one of the samples uses HidDevice, so I will use it as an alternative at the same time.

This Is my (incomplete) workaround. It is a direct replacement for the Gamepad class.

class HidGamepad
{
static readonly List _gamepads = new List();
GamepadReading _currentReading;

static HidGamepad()
{
var deviceSelector = HidDevice.GetDeviceSelector(0x01 , 0x05);
var watcher = DeviceInformation.CreateWatcher(deviceSelector);
watcher.Added += HandleAdded;
watcher.Start();
}

private HidGamepad(HidDevice device)
{
device.InputReportReceived += HandleInputReportRecieved;
}

public static event EventHandler GamepadAdded;

public static IReadOnlyList Gamepads
=> _gamepads;

public GamepadReading GetCurrentReading()
=> _currentReading;

static async void HandleAdded(Device Watcher sender, DeviceInformation args)
{
var hidDevice = await HidDevice.FromIdAsync(args.Id, FileAccessMode.Read);
if (hidDevice == null) return;
< br /> var gamepad = new HidGamepad(hidDevice);
_gamepads.Add(gamepad);
GamepadAdded?.Invoke(null, gamepad);
}

void HandleInputReportRecieved(
HidDevice sender, HidInputReportReceivedEventArgs args)
{
var leftThumbstickX = args.Report.GetNumericControl(0x01, 0x30).Value;
var leftThumbstickY = args.Report.GetNumericControl (0x01, 0x31).Value;

_currentReading = new GamepadReading
{
LeftThumbstickX = (leftThumbstickX-32768) / 32768.0,
LeftThumbstickY = (leftThumbstickY-32768) / -32768.0
};
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1719 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.