Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'real-wiimote-minor-fixes'
  • Loading branch information
jordan-woyak committed Apr 6, 2013
2 parents 8a21096 + c32e2f3 commit 5336882
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 151 deletions.
9 changes: 5 additions & 4 deletions Source/Core/Common/Src/FifoQueue.h
Expand Up @@ -36,15 +36,16 @@ class FifoQueue
return (0 == m_size);
}

const T& Front() const
T& Front() const
{
return *m_read_ptr->current;
}

void Push(const T& t)
template <typename Arg>
void Push(Arg&& t)
{
// create the element, add it to the queue
m_write_ptr->current = new T(t);
m_write_ptr->current = new T(std::forward<Arg>(t));
// set the next pointer to a new element ptr
// then advance the write pointer
m_write_ptr = m_write_ptr->next = new ElementPtr();
Expand All @@ -67,7 +68,7 @@ class FifoQueue
if (Empty())
return false;

t = Front();
t = std::move(Front());
Pop();

return true;
Expand Down
14 changes: 5 additions & 9 deletions Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -707,10 +707,10 @@ void Wiimote::Update()
std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
if (g_wiimotes[m_index])
{
Report rpt = g_wiimotes[m_index]->ProcessReadQueue();
const u8 *real_data = rpt.first;
if (real_data)
const Report& rpt = g_wiimotes[m_index]->ProcessReadQueue();
if (!rpt.empty())
{
const u8 *real_data = rpt.data();
switch (real_data[1])
{
// use data reports
Expand Down Expand Up @@ -770,13 +770,9 @@ void Wiimote::Update()
// copy over report from real-wiimote
if (-1 == rptf_size)
{
memcpy(data, real_data, rpt.second);
rptf_size = rpt.second;
std::copy(rpt.begin(), rpt.end(), data);
rptf_size = rpt.size();
}

if (real_data != g_wiimotes[m_index]->\
m_last_data_report.first)
delete[] real_data;
}
}
}
Expand Down
74 changes: 28 additions & 46 deletions Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp
Expand Up @@ -370,73 +370,55 @@ bool Wiimote::IsConnected() const
// zero = error
int Wiimote::IORead(u8* buf)
{
// used below for a warning
*buf = 0;
// Add data report indicator byte (here, 0xa1)
buf[0] = 0xa1;
// Used below for a warning
buf[1] = 0;

DWORD bytes;
DWORD bytes = 0;
ResetEvent(hid_overlap_read.hEvent);
if (!ReadFile(dev_handle, buf, MAX_PAYLOAD - 1, &bytes, &hid_overlap_read))
if (!ReadFile(dev_handle, buf + 1, MAX_PAYLOAD - 1, &bytes, &hid_overlap_read))
{
auto const err = GetLastError();
auto const read_err = GetLastError();

if (ERROR_IO_PENDING == err)
if (ERROR_IO_PENDING == read_err)
{
auto const r = WaitForSingleObject(hid_overlap_read.hEvent, WIIMOTE_DEFAULT_TIMEOUT);
if (WAIT_TIMEOUT == r)
auto const wait_result = WaitForSingleObject(hid_overlap_read.hEvent, WIIMOTE_DEFAULT_TIMEOUT);
if (WAIT_TIMEOUT == wait_result)
{
// Timeout - cancel and continue
if (*buf)
WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem (timeout is %i ms).",
WIIMOTE_DEFAULT_TIMEOUT);

CancelIo(dev_handle);
bytes = -1;
}
else if (WAIT_FAILED == r)
else if (WAIT_FAILED == wait_result)
{
WARN_LOG(WIIMOTE, "A wait error occurred on reading from Wiimote %i.", index + 1);
bytes = 0;
CancelIo(dev_handle);
}
else if (WAIT_OBJECT_0 == r)

if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, TRUE))
{
if (!GetOverlappedResult(dev_handle, &hid_overlap_read, &bytes, TRUE))
auto const overlapped_err = GetLastError();

if (ERROR_OPERATION_ABORTED == overlapped_err)
{
WARN_LOG(WIIMOTE, "GetOverlappedResult failed on Wiimote %i.", index + 1);
bytes = 0;
if (buf[1] != 0)
WARN_LOG(WIIMOTE, "Packet ignored. This may indicate a problem (timeout is %i ms).",
WIIMOTE_DEFAULT_TIMEOUT);

return -1;
}

WARN_LOG(WIIMOTE, "GetOverlappedResult error %d on Wiimote %i.", overlapped_err, index + 1);
return 0;
}
else
{
bytes = 0;
}
}
else if (ERROR_HANDLE_EOF == err)
{
// Remote disconnect
bytes = 0;
}
else if (ERROR_DEVICE_NOT_CONNECTED == err)
{
// Remote disconnect
bytes = 0;
}
else
{
bytes = 0;
WARN_LOG(WIIMOTE, "ReadFile error %d on Wiimote %i.", read_err, index + 1);
return 0;
}
}

if (bytes > 0)
{
// Move the data over one, so we can add back in data report indicator byte (here, 0xa1)
std::copy_n(buf, MAX_PAYLOAD - 1, buf + 1);
buf[0] = 0xa1;

// TODO: is this really needed?
bytes = MAX_PAYLOAD;
}

return bytes;
return bytes + 1;
}

int Wiimote::IOWrite(const u8* buf, int len)
Expand Down

0 comments on commit 5336882

Please sign in to comment.