1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-11-16 23:11:25 +00:00
sys-con/source/ControllerSwitch/SwitchUSBDevice.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

2019-10-31 18:00:42 +00:00
#include "SwitchUSBDevice.h"
#include <cstring> //for memset
#include "malloc.h" //for memalign
SwitchUSBDevice::SwitchUSBDevice(UsbHsInterface *interfaces, int length)
//: m_interfaces(std::vector<std::unique_ptr<IUSBInterface>>())
{
SetInterfaces(interfaces, length);
}
SwitchUSBDevice::~SwitchUSBDevice()
{
Close();
}
SwitchUSBDevice::SwitchUSBDevice()
{
}
Result SwitchUSBDevice::Open()
{
if (m_interfaces.size() != 0)
return 0;
else
return 51;
}
void SwitchUSBDevice::Close()
{
for (auto &&interface : m_interfaces)
{
interface->Close();
}
}
void SwitchUSBDevice::Reset()
{
//I'm expecting all interfaces to point to one device decsriptor
// as such resetting on any of them should do the trick
//TODO: needs testing
2019-11-02 10:39:43 +00:00
if (m_interfaces.size() != 0)
m_interfaces[0]->Reset();
2019-10-31 18:00:42 +00:00
}
void SwitchUSBDevice::SetInterfaces(UsbHsInterface *interfaces, int length)
{
if (length > 0)
2019-10-31 18:00:42 +00:00
{
m_vendorID = interfaces->device_desc.idVendor;
m_productID = interfaces->device_desc.idProduct;
m_interfaces.clear();
m_interfaces.reserve(length);
for (int i = 0; i != length; ++i)
{
m_interfaces.push_back(std::make_unique<SwitchUSBInterface>(interfaces[i]));
}
2019-10-31 18:00:42 +00:00
}
}