diff --git a/btdrv-mitm/source/controllers/controller_management.cpp b/btdrv-mitm/source/controllers/controller_management.cpp index 987ab96..176d57f 100644 --- a/btdrv-mitm/source/controllers/controller_management.cpp +++ b/btdrv-mitm/source/controllers/controller_management.cpp @@ -69,6 +69,12 @@ namespace ams::controller { } } + for (auto hwId : XiaomiController::hardware_ids) { + if ( (device->vid == hwId.vid) && (device->pid == hwId.pid) ) { + return ControllerType_Xiaomi; + } + } + // Handle the case where joycons have been assigned random hardware ids when paired via rails if (IsJoyCon(device->name)) { return ControllerType_Switch;; diff --git a/btdrv-mitm/source/controllers/controller_management.hpp b/btdrv-mitm/source/controllers/controller_management.hpp index afcfe22..4e3fe56 100644 --- a/btdrv-mitm/source/controllers/controller_management.hpp +++ b/btdrv-mitm/source/controllers/controller_management.hpp @@ -21,6 +21,7 @@ #include "dualshock4_controller.hpp" #include "xbox_one_controller.hpp" #include "ouya_controller.hpp" +#include "xiaomi_controller.hpp" namespace ams::controller { @@ -33,6 +34,7 @@ namespace ams::controller { ControllerType_Dualshock4, ControllerType_XboxOne, ControllerType_Ouya, + ControllerType_Xiaomi, ControllerType_Unknown, }; diff --git a/btdrv-mitm/source/controllers/xiaomi_controller.cpp b/btdrv-mitm/source/controllers/xiaomi_controller.cpp new file mode 100644 index 0000000..b32efb1 --- /dev/null +++ b/btdrv-mitm/source/controllers/xiaomi_controller.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2020 ndeadly + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "xiaomi_controller.hpp" +#include + +namespace ams::controller { + + void XiaomiController::ConvertReportFormat(const bluetooth::HidReport *in_report, bluetooth::HidReport *out_report) { + auto xiaomi_report = reinterpret_cast(&in_report->data); + auto switch_report = reinterpret_cast(&out_report->data); + + switch(xiaomi_report->id) { + default: + break; + } + + out_report->size = sizeof(SwitchInputReport0x30) + 1; + switch_report->id = 0x30; + switch_report->input0x30.conn_info = 0x0; + switch_report->input0x30.battery = m_battery | m_charging; + switch_report->input0x30.timer = os::ConvertToTimeSpan(os::GetSystemTick()).GetMilliSeconds() & 0xff; + } + +} diff --git a/btdrv-mitm/source/controllers/xiaomi_controller.hpp b/btdrv-mitm/source/controllers/xiaomi_controller.hpp new file mode 100644 index 0000000..7a32530 --- /dev/null +++ b/btdrv-mitm/source/controllers/xiaomi_controller.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2020 ndeadly + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#include "emulated_switch_controller.hpp" + +namespace ams::controller { + + struct XiaomiReportData{ + uint8_t id; + } __attribute__((packed)); + + class XiaomiController : public EmulatedSwitchController { + + public: + static constexpr const HardwareID hardware_ids[] = { + {0x2717, 0x3144} // Xiaomi Mi Controller + }; + + XiaomiController(const bluetooth::Address *address) + : EmulatedSwitchController(address) { }; + + void ConvertReportFormat(const bluetooth::HidReport *in_report, bluetooth::HidReport *out_report); + + private: + + }; + +}