1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-10-02 20:52:02 +00:00
sys-con/SwitchUSB/source/SwitchUSBDevice.cpp
2019-10-31 21:00:42 +03:00

59 lines
1.2 KiB
C++

#include "SwitchUSBDevice.h"
#include "libnxFix.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
for (auto &&interface : m_interfaces)
{
interface->Reset();
}
//if (m_interfaces.size() != 0)
//m_interfaces[0]->Reset();
}
void SwitchUSBDevice::SetInterfaces(UsbHsInterface *interfaces, int length)
{
m_interfaces.clear();
m_interfaces.reserve(length);
for (int i = 0; i != length; ++i)
{
m_interfaces.push_back(std::make_unique<SwitchUSBInterface>(interfaces[i]));
}
}