mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-26 14:20:21 +00:00
btdrv-mitm: begin adding virtual hdl controller code
This commit is contained in:
parent
396b1a0268
commit
d591d7b2b8
9 changed files with 188 additions and 0 deletions
|
@ -5,6 +5,7 @@ namespace controller {
|
|||
|
||||
BluetoothController::BluetoothController(ControllerType type, const BluetoothAddress *address) : m_type(type), m_address(*address) {
|
||||
m_switchController = (type == ControllerType_Joycon) || (type == ControllerType_SwitchPro);
|
||||
m_virtualController = nullptr;
|
||||
}
|
||||
|
||||
const BluetoothAddress& BluetoothController::address(void) const {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include <switch.h>
|
||||
|
||||
#include "virtualcontroller.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
struct HardwareID {
|
||||
|
@ -34,7 +37,9 @@ namespace controller {
|
|||
|
||||
BluetoothAddress m_address;
|
||||
ControllerType m_type;
|
||||
|
||||
bool m_switchController;
|
||||
std::unique_ptr<VirtualController> m_virtualController;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "dualshock4.hpp"
|
||||
#include "../btdrv_mitm_logging.hpp"
|
||||
|
||||
#include "hdlsvirtualcontroller.hpp"
|
||||
|
||||
|
||||
namespace controller {
|
||||
|
||||
|
@ -13,6 +15,11 @@ namespace controller {
|
|||
|
||||
}
|
||||
|
||||
Dualshock4Controller::Dualshock4Controller(const BluetoothAddress *address)
|
||||
: BluetoothController(ControllerType_Dualshock4, address) {
|
||||
m_virtualController = std::make_unique<HdlsVirtualController>();
|
||||
}
|
||||
|
||||
Result Dualshock4Controller::initialize(void) {
|
||||
BTDRV_LOG_FMT("Dualshock4Controller::initialize");
|
||||
return BluetoothController::initialize();
|
||||
|
|
84
btdrv-mitm/source/controllers/hdlsvirtualcontroller.cpp
Normal file
84
btdrv-mitm/source/controllers/hdlsvirtualcontroller.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <cstring>
|
||||
#include "hdlsvirtualcontroller.hpp"
|
||||
|
||||
#include "../btdrv_mitm_logging.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
HdlsVirtualController::HdlsVirtualController() {
|
||||
BTDRV_LOG_FMT("HdlsVirtualController() called");
|
||||
m_handle = INVALID_HANDLE;
|
||||
|
||||
std::memset(&m_device, 0, sizeof(HiddbgHdlsDeviceInfo));
|
||||
m_device.deviceType = HidDeviceType_FullKey3;
|
||||
m_device.npadInterfaceType = NpadInterfaceType_Bluetooth;
|
||||
// Set official pro controller colours
|
||||
m_device.singleColorBody = RGBA8_MAXALPHA(45, 45, 45);
|
||||
m_device.singleColorButtons = RGBA8_MAXALPHA(230, 230, 230);
|
||||
m_device.colorLeftGrip = RGBA8_MAXALPHA(70, 70, 70);
|
||||
m_device.colorRightGrip = RGBA8_MAXALPHA(70, 70, 70);
|
||||
|
||||
std::memset(&m_state, 0, sizeof(HiddbgHdlsState));
|
||||
m_state.batteryCharge = 4;
|
||||
|
||||
this->connect();
|
||||
}
|
||||
|
||||
HdlsVirtualController::~HdlsVirtualController() {
|
||||
BTDRV_LOG_FMT("~HdlsVirtualController() called");
|
||||
this->disconnect();
|
||||
}
|
||||
|
||||
Result HdlsVirtualController::connect(void) {
|
||||
BTDRV_LOG_FMT("Connecting Hdls virtual device");
|
||||
//return hiddbgAttachHdlsVirtualDevice(&m_handle, &m_device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result HdlsVirtualController::disconnect(void) {
|
||||
BTDRV_LOG_FMT("Disconnecting Hdls virtual device");
|
||||
//return hiddbgDetachHdlsVirtualDevice(m_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result HdlsVirtualController::setState(const SwitchProGamepadState* state) {
|
||||
if (m_handle != INVALID_HANDLE) {
|
||||
m_state.buttons = 0;
|
||||
|
||||
m_state.buttons |= state->A ? KEY_A : 0;
|
||||
m_state.buttons |= state->B ? KEY_B : 0;
|
||||
m_state.buttons |= state->X ? KEY_X : 0;
|
||||
m_state.buttons |= state->Y ? KEY_Y : 0;
|
||||
|
||||
m_state.buttons |= state->dpad_down ? KEY_DDOWN : 0;
|
||||
m_state.buttons |= state->dpad_up ? KEY_DUP : 0;
|
||||
m_state.buttons |= state->dpad_right ? KEY_DRIGHT : 0;
|
||||
m_state.buttons |= state->dpad_left ? KEY_DLEFT : 0;
|
||||
|
||||
m_state.buttons |= state->L ? KEY_L : 0;
|
||||
m_state.buttons |= state->ZL ? KEY_ZL : 0;
|
||||
m_state.buttons |= state->lstick_press ? KEY_LSTICK : 0;
|
||||
|
||||
m_state.buttons |= state->R ? KEY_R : 0;
|
||||
m_state.buttons |= state->ZR ? KEY_ZR : 0;
|
||||
m_state.buttons |= state->rstick_press ? KEY_RSTICK : 0;
|
||||
|
||||
m_state.buttons |= state->minus ? KEY_MINUS : 0;
|
||||
m_state.buttons |= state->plus ? KEY_PLUS : 0;
|
||||
m_state.buttons |= state->capture ? KEY_CAPTURE : 0;
|
||||
m_state.buttons |= state->home ? KEY_HOME : 0;
|
||||
|
||||
m_state.joysticks[JOYSTICK_LEFT].dx = state->left_stick.dx;
|
||||
m_state.joysticks[JOYSTICK_LEFT].dy = state->left_stick.dy;
|
||||
|
||||
m_state.joysticks[JOYSTICK_RIGHT].dx = state->right_stick.dx;
|
||||
m_state.joysticks[JOYSTICK_RIGHT].dy = state->right_stick.dy;
|
||||
|
||||
//return hiddbgSetHdlsState(m_handle, &m_state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
25
btdrv-mitm/source/controllers/hdlsvirtualcontroller.hpp
Normal file
25
btdrv-mitm/source/controllers/hdlsvirtualcontroller.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
#include "virtualcontroller.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
class HdlsVirtualController : public VirtualController {
|
||||
|
||||
public:
|
||||
HdlsVirtualController();
|
||||
~HdlsVirtualController();
|
||||
|
||||
Result connect(void);
|
||||
Result disconnect(void);
|
||||
Result setState(const SwitchProGamepadState* state);
|
||||
|
||||
private:
|
||||
uint64_t m_handle;
|
||||
HiddbgHdlsDeviceInfo m_device;
|
||||
HiddbgHdlsState m_state;
|
||||
};
|
||||
|
||||
|
||||
}
|
48
btdrv-mitm/source/controllers/virtualcontroller.hpp
Normal file
48
btdrv-mitm/source/controllers/virtualcontroller.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
namespace controller {
|
||||
|
||||
struct SwitchProGamepadState {
|
||||
|
||||
uint8_t Y : 1;
|
||||
uint8_t X : 1;
|
||||
uint8_t B : 1;
|
||||
uint8_t A : 1;
|
||||
uint8_t : 2; // SR, SL (Right Joy)
|
||||
uint8_t R : 1;
|
||||
uint8_t ZR : 1;
|
||||
|
||||
uint8_t minus : 1;
|
||||
uint8_t plus : 1;
|
||||
uint8_t rstick_press : 1;
|
||||
uint8_t lstick_press : 1;
|
||||
uint8_t home : 1;
|
||||
uint8_t capture : 1;
|
||||
uint8_t : 0;
|
||||
|
||||
uint8_t dpad_down : 1;
|
||||
uint8_t dpad_up : 1;
|
||||
uint8_t dpad_right : 1;
|
||||
uint8_t dpad_left : 1;
|
||||
uint8_t : 2; // SR, SL (Left Joy)
|
||||
uint8_t L : 1;
|
||||
uint8_t ZL : 1;
|
||||
|
||||
JoystickPosition left_stick;
|
||||
JoystickPosition right_stick;
|
||||
};
|
||||
|
||||
class VirtualController {
|
||||
|
||||
public:
|
||||
virtual ~VirtualController() {};
|
||||
|
||||
virtual Result connect(void) = 0;
|
||||
virtual Result disconnect(void) = 0;
|
||||
virtual Result setState(const SwitchProGamepadState* state) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -1,7 +1,13 @@
|
|||
#include "wiimote.hpp"
|
||||
#include "hdlsvirtualcontroller.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
WiimoteController::WiimoteController(const BluetoothAddress *address)
|
||||
: WiiController(ControllerType_Wiimote, address) {
|
||||
m_virtualController = std::make_unique<HdlsVirtualController>();
|
||||
}
|
||||
|
||||
void WiimoteController::convertReportFormat(const HidReport *inReport, HidReport *outReport) {
|
||||
auto wiiData = reinterpret_cast<const WiimoteReportData *>(&inReport->data);
|
||||
auto switchData = reinterpret_cast<SwitchReportData *>(&outReport->data);
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
|
||||
#include <vapours.hpp>
|
||||
#include "wiiupro.hpp"
|
||||
#include "hdlsvirtualcontroller.hpp"
|
||||
|
||||
#include "../btdrv_mitm_logging.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
WiiUProController::WiiUProController(const BluetoothAddress *address)
|
||||
: WiiController(ControllerType_WiiUPro, address) {
|
||||
m_virtualController = std::make_unique<HdlsVirtualController>();
|
||||
}
|
||||
|
||||
Result WiiUProController::initialize(void) {
|
||||
WiiController::initialize();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <cmath>
|
||||
|
||||
#include "xboxone.hpp"
|
||||
#include "hdlsvirtualcontroller.hpp"
|
||||
|
||||
namespace controller {
|
||||
|
||||
|
@ -11,6 +12,11 @@ namespace controller {
|
|||
|
||||
}
|
||||
|
||||
XboxOneController::XboxOneController(const BluetoothAddress *address)
|
||||
: BluetoothController(ControllerType_XboxOne, address) {
|
||||
m_virtualController = std::make_unique<HdlsVirtualController>();
|
||||
}
|
||||
|
||||
void XboxOneController::convertReportFormat(const HidReport *inReport, HidReport *outReport) {
|
||||
auto xboxData = reinterpret_cast<const XboxOneReportData *>(&inReport->data);
|
||||
auto switchData = reinterpret_cast<SwitchReportData *>(&outReport->data);
|
||||
|
|
Loading…
Reference in a new issue