Hopefully fix windows!

This commit is contained in:
Jordan Woyak 2013-02-11 05:30:51 -06:00
parent 7a053d0f07
commit c267be2682
2 changed files with 18 additions and 5 deletions

View File

@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <regex> #include <regex>
#include <algorithm>
#include <unordered_set> #include <unordered_set>
#include <windows.h> #include <windows.h>
@ -379,6 +380,14 @@ int Wiimote::IORead(unsigned char* buf)
int Wiimote::IOWrite(const u8* buf, int len) int Wiimote::IOWrite(const u8* buf, int len)
{ {
u8 big_buf[MAX_PAYLOAD];
if (len < MAX_PAYLOAD)
{
std::copy(buf, buf + len, big_buf);
std::fill(big_buf + len, big_buf + MAX_PAYLOAD, 0);
buf = big_buf;
}
DWORD bytes = 0; DWORD bytes = 0;
switch (stack) switch (stack)
{ {
@ -386,7 +395,7 @@ int Wiimote::IOWrite(const u8* buf, int len)
{ {
// Try to auto-detect the stack type // Try to auto-detect the stack type
auto i = WriteFile(dev_handle, buf + 1, 22, &bytes, &hid_overlap); auto i = WriteFile(dev_handle, buf + 1, MAX_PAYLOAD - 1, &bytes, &hid_overlap);
if (i) if (i)
{ {
// Bluesoleil will always return 1 here, even if it's not connected // Bluesoleil will always return 1 here, even if it's not connected
@ -433,7 +442,7 @@ int Wiimote::IOWrite(const u8* buf, int len)
break; break;
} }
case MSBT_STACK_BLUESOLEIL: case MSBT_STACK_BLUESOLEIL:
return WriteFile(dev_handle, buf + 1, 22, &bytes, &hid_overlap); return WriteFile(dev_handle, buf + 1, MAX_PAYLOAD - 1, &bytes, &hid_overlap);
break; break;
} }

View File

@ -249,15 +249,19 @@ bool Wiimote::Prepare(int _index)
{ {
index = _index; index = _index;
// core buttons, no continuous reporting
u8 const mode_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_CMD_REPORT_TYPE, 0, 0x30};
// Set the active LEDs. // Set the active LEDs.
u8 const led_report[] = {HID_TYPE_SET_REPORT, WM_CMD_LED, u8(WIIMOTE_LED_1 << index)}; u8 const led_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_CMD_LED, u8(WIIMOTE_LED_1 << index)};
// Rumble briefly // Rumble briefly
u8 rumble_report[] = {HID_TYPE_SET_REPORT, WM_CMD_RUMBLE, 1}; u8 rumble_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_CMD_RUMBLE, 1};
// TODO: request status and check for sane response? // TODO: request status and check for sane response?
return (IOWrite(led_report, sizeof(led_report)) return (IOWrite(mode_report, sizeof(mode_report))
&& IOWrite(led_report, sizeof(led_report))
&& IOWrite(rumble_report, sizeof(rumble_report)) && IOWrite(rumble_report, sizeof(rumble_report))
&& (rumble_report[2] = 0, SLEEP(200), IOWrite(rumble_report, sizeof(rumble_report)))); && (rumble_report[2] = 0, SLEEP(200), IOWrite(rumble_report, sizeof(rumble_report))));
} }