2020-07-11 19:11:13 +00:00
|
|
|
#pragma once
|
|
|
|
#include "switchcontroller.hpp"
|
|
|
|
|
|
|
|
namespace ams::controller {
|
|
|
|
|
2020-08-18 21:47:44 +00:00
|
|
|
inline bool bdcmp(const bluetooth::Address *addr1, const bluetooth::Address *addr2) {
|
|
|
|
return std::memcmp(addr1, addr2, sizeof(bluetooth::Address)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void packStickData(SwitchStickData *stick, uint16_t x, uint16_t y) {
|
|
|
|
*stick = (SwitchStickData){
|
|
|
|
static_cast<uint8_t>(x & 0xff),
|
|
|
|
static_cast<uint8_t>((x >> 8) | ((y & 0xff) << 4)),
|
|
|
|
static_cast<uint8_t>((y >> 4) & 0xff)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-17 21:17:02 +00:00
|
|
|
class EmulatedSwitchController : public SwitchController {
|
2020-07-11 19:11:13 +00:00
|
|
|
|
|
|
|
public:
|
2020-08-17 21:17:02 +00:00
|
|
|
EmulatedSwitchController(ControllerType type, const bluetooth::Address *address)
|
2020-08-18 21:47:44 +00:00
|
|
|
: SwitchController(type, address)
|
|
|
|
, m_charging(false)
|
|
|
|
, m_battery(BATTERY_MAX) { };
|
2020-07-11 19:11:13 +00:00
|
|
|
|
2020-08-24 20:47:27 +00:00
|
|
|
Result handleIncomingReport(const bluetooth::HidReport *report);
|
2020-08-25 00:05:19 +00:00
|
|
|
Result handleOutgoingReport(const bluetooth::HidReport *report);
|
2020-07-11 19:11:13 +00:00
|
|
|
|
2020-07-27 17:42:40 +00:00
|
|
|
protected:
|
2020-08-24 20:47:27 +00:00
|
|
|
virtual void convertReportFormat(const bluetooth::HidReport *inReport, bluetooth::HidReport *outReport) {};
|
|
|
|
|
|
|
|
virtual Result setVibration(void) { return ams::ResultSuccess(); };
|
|
|
|
virtual Result setPlayerLed(u8 led_mask) { return ams::ResultSuccess(); };
|
2020-07-11 19:11:13 +00:00
|
|
|
|
2020-07-27 17:42:40 +00:00
|
|
|
Result handleSubCmdReport(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdRequestDeviceInfo(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSpiFlashRead(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSpiFlashWrite(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSpiSectorErase(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSetInputReportMode(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdTriggersElapsedTime(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSetShipPowerState(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSetMcuConfig(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSetMcuState(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdSetPlayerLeds(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdEnableImu(const bluetooth::HidReport *report);
|
|
|
|
Result subCmdEnableVibration(const bluetooth::HidReport *report);
|
|
|
|
|
2020-08-17 22:14:19 +00:00
|
|
|
Result fakeSubCmdResponse(const u8 response[], size_t size);
|
|
|
|
|
2020-08-18 21:47:44 +00:00
|
|
|
bool m_charging;
|
|
|
|
uint8_t m_battery;
|
2020-07-27 17:42:40 +00:00
|
|
|
bluetooth::HidReport m_inputReport;
|
|
|
|
bluetooth::HidReport m_outputReport;
|
2020-07-11 19:11:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|