mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-25 05:40:22 +00:00
mc.mitm: add support for betop 2585n2 controller
This commit is contained in:
parent
f2e348325a
commit
d83763d38b
4 changed files with 180 additions and 0 deletions
77
mc_mitm/source/controllers/betop_controller.cpp
Normal file
77
mc_mitm/source/controllers/betop_controller.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2023 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "betop_controller.hpp"
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
namespace {
|
||||
|
||||
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
|
||||
}
|
||||
|
||||
void BetopController::ProcessInputData(const bluetooth::HidReport *report) {
|
||||
auto betop_report = reinterpret_cast<const BetopReportData *>(&report->data);
|
||||
|
||||
switch(betop_report->id) {
|
||||
case 0x03:
|
||||
this->MapInputReport0x03(betop_report); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BetopController::MapInputReport0x03(const BetopReportData *src) {
|
||||
m_left_stick.SetData(
|
||||
static_cast<u16>(stick_scale_factor * src->input0x03.left_stick.x) & UINT12_MAX,
|
||||
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x03.left_stick.y)) & UINT12_MAX
|
||||
);
|
||||
m_right_stick.SetData(
|
||||
static_cast<u16>(stick_scale_factor * src->input0x03.right_stick.x) & UINT12_MAX,
|
||||
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x03.right_stick.y)) & UINT12_MAX
|
||||
);
|
||||
|
||||
m_buttons.dpad_down = (src->input0x03.buttons.dpad == BetopDPad_S) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_SE) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_SW);
|
||||
m_buttons.dpad_up = (src->input0x03.buttons.dpad == BetopDPad_N) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_NE) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_NW);
|
||||
m_buttons.dpad_right = (src->input0x03.buttons.dpad == BetopDPad_E) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_NE) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_SE);
|
||||
m_buttons.dpad_left = (src->input0x03.buttons.dpad == BetopDPad_W) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_NW) ||
|
||||
(src->input0x03.buttons.dpad == BetopDPad_SW);
|
||||
|
||||
m_buttons.A = src->input0x03.buttons.B;
|
||||
m_buttons.B = src->input0x03.buttons.A;
|
||||
m_buttons.X = src->input0x03.buttons.Y;
|
||||
m_buttons.Y = src->input0x03.buttons.X;
|
||||
|
||||
m_buttons.R = src->input0x03.buttons.R1;
|
||||
m_buttons.ZR = src->input0x03.buttons.R2;
|
||||
m_buttons.L = src->input0x03.buttons.L1;
|
||||
m_buttons.ZL = src->input0x03.buttons.L2;
|
||||
|
||||
m_buttons.minus = src->input0x03.buttons.select;
|
||||
m_buttons.plus = src->input0x03.buttons.start;
|
||||
|
||||
m_buttons.home = src->input0x03.buttons.home;
|
||||
}
|
||||
|
||||
}
|
92
mc_mitm/source/controllers/betop_controller.hpp
Normal file
92
mc_mitm/source/controllers/betop_controller.hpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2023 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 BetopDPadDirection {
|
||||
BetopDPad_N,
|
||||
BetopDPad_NE,
|
||||
BetopDPad_E,
|
||||
BetopDPad_SE,
|
||||
BetopDPad_S,
|
||||
BetopDPad_SW,
|
||||
BetopDPad_W,
|
||||
BetopDPad_NW,
|
||||
BetopDPad_Released = 0x0f
|
||||
};
|
||||
|
||||
struct BetopStickData {
|
||||
u8 x;
|
||||
u8 y;
|
||||
} PACKED;
|
||||
|
||||
struct BetopButtonData {
|
||||
u8 dpad;
|
||||
|
||||
u8 A : 1;
|
||||
u8 B : 1;
|
||||
u8 : 1;
|
||||
u8 X : 1;
|
||||
u8 Y : 1;
|
||||
u8 : 1;
|
||||
u8 L1 : 1;
|
||||
u8 R1 : 1;
|
||||
|
||||
u8 L2 : 1;
|
||||
u8 R2 : 1;
|
||||
u8 select : 1;
|
||||
u8 start : 1;
|
||||
u8 home : 1;
|
||||
u8 : 0;
|
||||
} PACKED;
|
||||
|
||||
struct BetopInputReport0x03 {
|
||||
u8 unk0;
|
||||
BetopButtonData buttons;
|
||||
BetopStickData left_stick;
|
||||
BetopStickData right_stick;
|
||||
u8 left_trigger;
|
||||
u8 right_trigger;
|
||||
u8 unk1;
|
||||
} PACKED;
|
||||
|
||||
struct BetopReportData {
|
||||
u8 id;
|
||||
union {
|
||||
BetopInputReport0x03 input0x03;
|
||||
};
|
||||
} PACKED;
|
||||
|
||||
class BetopController final : public EmulatedSwitchController {
|
||||
|
||||
public:
|
||||
static constexpr const HardwareID hardware_ids[] = {
|
||||
{0x20bc, 0x5501} // Betop 2585N2
|
||||
};
|
||||
|
||||
BetopController(const bluetooth::Address *address, HardwareID id)
|
||||
: EmulatedSwitchController(address, id) { }
|
||||
|
||||
void ProcessInputData(const bluetooth::HidReport *report) override;
|
||||
|
||||
private:
|
||||
void MapInputReport0x03(const BetopReportData *src);
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -180,6 +180,12 @@ namespace ams::controller {
|
|||
}
|
||||
}
|
||||
|
||||
for (auto hwId : BetopController::hardware_ids) {
|
||||
if ( (device->vid == hwId.vid) && (device->pid == hwId.pid) ) {
|
||||
return ControllerType_Betop;
|
||||
}
|
||||
}
|
||||
|
||||
return ControllerType_Unknown;
|
||||
}
|
||||
|
||||
|
@ -275,6 +281,9 @@ namespace ams::controller {
|
|||
case ControllerType_Hyperkin:
|
||||
controller = std::make_shared<HyperkinController>(address, id);
|
||||
break;
|
||||
case ControllerType_Betop:
|
||||
controller = std::make_shared<BetopController>(address, id);
|
||||
break;
|
||||
default:
|
||||
controller = std::make_shared<UnknownController>(address, id);
|
||||
break;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "lanshen_controller.hpp"
|
||||
#include "atgames_controller.hpp"
|
||||
#include "hyperkin_controller.hpp"
|
||||
#include "betop_controller.hpp"
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
|
@ -70,6 +71,7 @@ namespace ams::controller {
|
|||
ControllerType_LanShen,
|
||||
ControllerType_AtGames,
|
||||
ControllerType_Hyperkin,
|
||||
ControllerType_Betop,
|
||||
ControllerType_Unknown,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue