mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-26 14:20:21 +00:00
Merge branch 'feature/mad-catz-C.T.R.L.R-support' into develop
This commit is contained in:
commit
e8505d190c
4 changed files with 203 additions and 0 deletions
|
@ -122,6 +122,12 @@ namespace ams::controller {
|
|||
}
|
||||
}
|
||||
|
||||
for (auto hwId : MadCatzController::hardware_ids) {
|
||||
if ( (device->vid == hwId.vid) && (device->pid == hwId.pid) ) {
|
||||
return ControllerType_MadCatz;
|
||||
}
|
||||
}
|
||||
|
||||
return ControllerType_Unknown;
|
||||
}
|
||||
|
||||
|
@ -190,6 +196,9 @@ namespace ams::controller {
|
|||
case ControllerType_PowerA:
|
||||
g_controllers.push_back(std::make_unique<PowerAController>(address));
|
||||
break;
|
||||
case ControllerType_MadCatz:
|
||||
g_controllers.push_back(std::make_unique<MadCatzController>(address));
|
||||
break;
|
||||
default:
|
||||
g_controllers.push_back(std::make_unique<UnknownController>(address));
|
||||
break;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "nvidia_shield_controller.hpp"
|
||||
#include "8bitdo_controller.hpp"
|
||||
#include "powera_controller.hpp"
|
||||
#include "mad_catz_controller.hpp"
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
|
@ -51,6 +52,7 @@ namespace ams::controller {
|
|||
ControllerType_NvidiaShield,
|
||||
ControllerType_8BitDo,
|
||||
ControllerType_PowerA,
|
||||
ControllerType_MadCatz,
|
||||
ControllerType_Unknown,
|
||||
};
|
||||
|
||||
|
|
89
bluetooth-mitm/source/controllers/mad_catz_controller.cpp
Normal file
89
bluetooth-mitm/source/controllers/mad_catz_controller.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "mad_catz_controller.hpp"
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
namespace {
|
||||
|
||||
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
|
||||
}
|
||||
|
||||
void MadCatzController::UpdateControllerState(const bluetooth::HidReport *report) {
|
||||
auto madcatz_report = reinterpret_cast<const MadCatzReportData *>(&report->data);
|
||||
|
||||
switch(madcatz_report->id) {
|
||||
case 0x01:
|
||||
this->HandleInputReport0x01(madcatz_report);
|
||||
break;
|
||||
case 0x02:
|
||||
this->HandleInputReport0x02(madcatz_report);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MadCatzController::HandleInputReport0x01(const MadCatzReportData *src) {
|
||||
this->PackStickData(&m_left_stick,
|
||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.left_stick.x) & 0xfff,
|
||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & 0xfff
|
||||
);
|
||||
this->PackStickData(&m_right_stick,
|
||||
static_cast<uint16_t>(stick_scale_factor * src->input0x01.right_stick.x) & 0xfff,
|
||||
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & 0xfff
|
||||
);
|
||||
|
||||
m_buttons.dpad_down = (src->input0x01.buttons.dpad == MadCatzDPad_S) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_SE) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_SW);
|
||||
m_buttons.dpad_up = (src->input0x01.buttons.dpad == MadCatzDPad_N) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_NE) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_NW);
|
||||
m_buttons.dpad_right = (src->input0x01.buttons.dpad == MadCatzDPad_E) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_NE) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_SE);
|
||||
m_buttons.dpad_left = (src->input0x01.buttons.dpad == MadCatzDPad_W) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_NW) ||
|
||||
(src->input0x01.buttons.dpad == MadCatzDPad_SW);
|
||||
|
||||
m_buttons.A = src->input0x01.buttons.B;
|
||||
m_buttons.B = src->input0x01.buttons.A;
|
||||
m_buttons.X = src->input0x01.buttons.Y;
|
||||
m_buttons.Y = src->input0x01.buttons.X;
|
||||
|
||||
m_buttons.R = src->input0x01.buttons.R1;
|
||||
m_buttons.ZR = src->input0x01.buttons.R2;
|
||||
m_buttons.L = src->input0x01.buttons.L1;
|
||||
m_buttons.ZL = src->input0x01.buttons.L2;
|
||||
|
||||
m_buttons.minus = src->input0x01.buttons.select;
|
||||
m_buttons.plus = src->input0x01.buttons.start;
|
||||
|
||||
m_buttons.lstick_press = src->input0x01.buttons.L3;
|
||||
m_buttons.rstick_press = src->input0x01.buttons.R3;
|
||||
|
||||
m_buttons.home = src->input0x01.buttons.home;
|
||||
}
|
||||
|
||||
void MadCatzController::HandleInputReport0x02(const MadCatzReportData *src) {
|
||||
// Media buttons
|
||||
}
|
||||
|
||||
}
|
103
bluetooth-mitm/source/controllers/mad_catz_controller.hpp
Normal file
103
bluetooth-mitm/source/controllers/mad_catz_controller.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include "emulated_switch_controller.hpp"
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
enum MadCatzDPadDirection {
|
||||
MadCatzDPad_Released,
|
||||
MadCatzDPad_N,
|
||||
MadCatzDPad_NE,
|
||||
MadCatzDPad_E,
|
||||
MadCatzDPad_SE,
|
||||
MadCatzDPad_S,
|
||||
MadCatzDPad_SW,
|
||||
MadCatzDPad_W,
|
||||
MadCatzDPad_NW
|
||||
};
|
||||
|
||||
struct MadCatzStickData {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct MadCatzButtonData {
|
||||
uint8_t X : 1;
|
||||
uint8_t A : 1;
|
||||
uint8_t B : 1;
|
||||
uint8_t Y : 1;
|
||||
uint8_t L1 : 1;
|
||||
uint8_t R1 : 1;
|
||||
uint8_t L2 : 1;
|
||||
uint8_t R2 : 1;
|
||||
|
||||
uint8_t select : 1;
|
||||
uint8_t start : 1;
|
||||
uint8_t L3 : 1;
|
||||
uint8_t R3 : 1;
|
||||
uint8_t home : 1;
|
||||
uint8_t : 0;
|
||||
|
||||
uint8_t dpad;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct MadCatzInputReport0x01{
|
||||
MadCatzButtonData buttons;
|
||||
MadCatzStickData left_stick;
|
||||
MadCatzStickData right_stick;
|
||||
uint8_t left_trigger;
|
||||
uint8_t right_trigger;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct MadCatzInputReport0x02{
|
||||
uint8_t : 2;
|
||||
uint8_t volume_up : 1;
|
||||
uint8_t volume_down : 1;
|
||||
uint8_t play : 1;
|
||||
uint8_t forward : 1;
|
||||
uint8_t rewind : 1;
|
||||
uint8_t : 0;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct MadCatzReportData {
|
||||
uint8_t id;
|
||||
union {
|
||||
MadCatzInputReport0x01 input0x01;
|
||||
MadCatzInputReport0x02 input0x02;
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
class MadCatzController : public EmulatedSwitchController {
|
||||
|
||||
public:
|
||||
static constexpr const HardwareID hardware_ids[] = {
|
||||
{0x0738, 0x5266} // Mad Catz C.T.R.L.R
|
||||
};
|
||||
|
||||
MadCatzController(const bluetooth::Address *address)
|
||||
: EmulatedSwitchController(address) { };
|
||||
|
||||
void UpdateControllerState(const bluetooth::HidReport *report);
|
||||
|
||||
private:
|
||||
void HandleInputReport0x01(const MadCatzReportData *src);
|
||||
void HandleInputReport0x02(const MadCatzReportData *src);
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue