Made Xbox360Controller and Xbox360WirelessController endian clean
This commit is contained in:
parent
dd569f0fa4
commit
30c3084398
2 changed files with 79 additions and 3 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "helper.hpp"
|
||||
#include "options.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
#include "unpack.hpp"
|
||||
#include "usb_helper.hpp"
|
||||
|
||||
Xbox360Controller::Xbox360Controller(libusb_device* dev,
|
||||
|
@ -149,8 +150,44 @@ Xbox360Controller::parse(uint8_t* data, int len, XboxGenericMsg* msg_out)
|
|||
}
|
||||
else if (len == 20 && data[0] == 0x00 && data[1] == 0x14)
|
||||
{
|
||||
msg_out->type = XBOX_MSG_XBOX360;
|
||||
memcpy(&msg_out->xbox360, data, sizeof(Xbox360Msg));
|
||||
msg_out->type = XBOX_MSG_XBOX360;
|
||||
Xbox360Msg& msg = msg_out->xbox360;
|
||||
|
||||
msg.type = data[0];
|
||||
msg.length = data[1];
|
||||
|
||||
msg.dpad_up = unpack::bit(data+2, 0);
|
||||
msg.dpad_down = unpack::bit(data+2, 1);
|
||||
msg.dpad_left = unpack::bit(data+2, 2);
|
||||
msg.dpad_right = unpack::bit(data+2, 3);
|
||||
|
||||
msg.start = unpack::bit(data+2, 4);
|
||||
msg.back = unpack::bit(data+2, 5);
|
||||
msg.thumb_l = unpack::bit(data+2, 6);
|
||||
msg.thumb_r = unpack::bit(data+2, 7);
|
||||
|
||||
msg.lb = unpack::bit(data+3, 0);
|
||||
msg.rb = unpack::bit(data+3, 1);
|
||||
msg.guide = unpack::bit(data+3, 2);
|
||||
msg.dummy1 = unpack::bit(data+3, 3);
|
||||
|
||||
msg.a = unpack::bit(data+3, 4);
|
||||
msg.b = unpack::bit(data+3, 5);
|
||||
msg.x = unpack::bit(data+3, 6);
|
||||
msg.y = unpack::bit(data+3, 7);
|
||||
|
||||
msg.lt = data[4];
|
||||
msg.rt = data[5];
|
||||
|
||||
msg.x1 = unpack::int16le(data+6);
|
||||
msg.y1 = unpack::int16le(data+8);
|
||||
|
||||
msg.x2 = unpack::int16le(data+10);
|
||||
msg.y2 = unpack::int16le(data+12);
|
||||
|
||||
msg.dummy2 = unpack::int32le(data+14);
|
||||
msg.dummy3 = unpack::int16le(data+18);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "helper.hpp"
|
||||
#include "raise_exception.hpp"
|
||||
#include "unpack.hpp"
|
||||
#include "usb_helper.hpp"
|
||||
#include "xboxmsg.hpp"
|
||||
|
||||
|
@ -134,7 +135,45 @@ Xbox360WirelessController::parse(uint8_t* data, int len, XboxGenericMsg* msg_out
|
|||
else if (data[0] == 0x00 && data[1] == 0x01 && data[2] == 0x00 && data[3] == 0xf0 && data[4] == 0x00 && data[5] == 0x13)
|
||||
{ // Event message
|
||||
msg_out->type = XBOX_MSG_XBOX360;
|
||||
memcpy(&msg_out->xbox360, data+4, sizeof(Xbox360Msg));
|
||||
Xbox360Msg& msg = msg_out->xbox360;
|
||||
|
||||
uint8_t* ptr = data+4;
|
||||
|
||||
msg.type = ptr[0];
|
||||
msg.length = ptr[1];
|
||||
|
||||
msg.dpad_up = unpack::bit(ptr+2, 0);
|
||||
msg.dpad_down = unpack::bit(ptr+2, 1);
|
||||
msg.dpad_left = unpack::bit(ptr+2, 2);
|
||||
msg.dpad_right = unpack::bit(ptr+2, 3);
|
||||
|
||||
msg.start = unpack::bit(ptr+2, 4);
|
||||
msg.back = unpack::bit(ptr+2, 5);
|
||||
msg.thumb_l = unpack::bit(ptr+2, 6);
|
||||
msg.thumb_r = unpack::bit(ptr+2, 7);
|
||||
|
||||
msg.lb = unpack::bit(ptr+3, 0);
|
||||
msg.rb = unpack::bit(ptr+3, 1);
|
||||
msg.guide = unpack::bit(ptr+3, 2);
|
||||
msg.dummy1 = unpack::bit(ptr+3, 3);
|
||||
|
||||
msg.a = unpack::bit(ptr+3, 4);
|
||||
msg.b = unpack::bit(ptr+3, 5);
|
||||
msg.x = unpack::bit(ptr+3, 6);
|
||||
msg.y = unpack::bit(ptr+3, 7);
|
||||
|
||||
msg.lt = ptr[4];
|
||||
msg.rt = ptr[5];
|
||||
|
||||
msg.x1 = unpack::int16le(ptr+6);
|
||||
msg.y1 = unpack::int16le(ptr+8);
|
||||
|
||||
msg.x2 = unpack::int16le(ptr+10);
|
||||
msg.y2 = unpack::int16le(ptr+12);
|
||||
|
||||
msg.dummy2 = unpack::int32le(ptr+14);
|
||||
msg.dummy3 = unpack::int16le(ptr+18);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0x13)
|
||||
|
|
Loading…
Add table
Reference in a new issue