Skip to content

Commit

Permalink
Xbox360W: add wrapper function to endpoint write
Browse files Browse the repository at this point in the history
  • Loading branch information
cathery committed Nov 9, 2019
1 parent 72b4e1d commit 01d20c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class Xbox360WirelessController : public IController
static void LoadConfig(const ControllerConfig *config);
virtual ControllerConfig *GetConfig();

Status OutputBuffer();
Status WriteToEndpoint(const uint8_t *buffer, size_t size);

virtual Status OutputBuffer();

bool IsControllerActive() override { return m_presence; }
};
18 changes: 11 additions & 7 deletions ControllerUSB/source/Controllers/Xbox360WirelessController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ Status Xbox360WirelessController::Initialize()
rc = OpenInterfaces();
if (S_FAILED(rc))
return rc;
/*
rc = m_outPipe->Write(reconnectPacket, sizeof(reconnectPacket));

rc = WriteToEndpoint(reconnectPacket, sizeof(reconnectPacket));
if (S_FAILED(rc))
return rc;

SetLED(XBOX360LED_TOPLEFT);
*/
return rc;
}
void Xbox360WirelessController::Exit()
Expand Down Expand Up @@ -104,7 +103,7 @@ Status Xbox360WirelessController::OpenInterfaces()
void Xbox360WirelessController::CloseInterfaces()
{
if (m_presence)
m_outPipe->Write(poweroffPacket, sizeof(poweroffPacket));
WriteToEndpoint(poweroffPacket, sizeof(poweroffPacket));

//m_device->Reset();
m_device->Close();
Expand Down Expand Up @@ -234,13 +233,13 @@ NormalizedButtonData Xbox360WirelessController::GetNormalizedButtonData()
Status Xbox360WirelessController::SetRumble(uint8_t strong_magnitude, uint8_t weak_magnitude)
{
uint8_t rumbleData[]{0x00, 0x01, 0x0F, 0xC0, 0x00, strong_magnitude, weak_magnitude, 0x00, 0x00, 0x00, 0x00, 0x00};
return m_outPipe->Write(rumbleData, sizeof(rumbleData));
return WriteToEndpoint(rumbleData, sizeof(rumbleData));
}

Status Xbox360WirelessController::SetLED(Xbox360LEDValue value)
{
uint8_t customLEDPacket[]{0x00, 0x00, 0x08, static_cast<uint8_t>(value | 0x40), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
return m_outPipe->Write(customLEDPacket, sizeof(customLEDPacket));
return WriteToEndpoint(customLEDPacket, sizeof(customLEDPacket));
}

void Xbox360WirelessController::LoadConfig(const ControllerConfig *config)
Expand All @@ -267,14 +266,19 @@ Status Xbox360WirelessController::OnControllerDisconnect()
return 0;
}

Status Xbox360WirelessController::WriteToEndpoint(const uint8_t *buffer, size_t size)
{
return m_outPipe->Write(buffer, size);
}

Status Xbox360WirelessController::OutputBuffer()
{
if (m_outputBuffer.empty())
return 1;

Status rc;
auto it = m_outputBuffer.begin();
rc = m_outPipe->Write(it->packet, it->length);
rc = WriteToEndpoint(it->packet, it->length);
m_outputBuffer.erase(it);

return rc;
Expand Down

0 comments on commit 01d20c0

Please sign in to comment.