mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-26 14:20:21 +00:00
bluetooth-mitm: add support for lanshen x1pro controller
This commit is contained in:
parent
f5a1ef2ff3
commit
9e476ea9fd
4 changed files with 183 additions and 1 deletions
|
@ -159,7 +159,13 @@ namespace ams::controller {
|
|||
if ( (device->vid == hwId.vid) && (device->pid == hwId.pid) ) {
|
||||
return ControllerType_ICade;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto hwId : LanShenController::hardware_ids) {
|
||||
if ( (device->vid == hwId.vid) && (device->pid == hwId.pid) ) {
|
||||
return ControllerType_LanShen;
|
||||
}
|
||||
}
|
||||
|
||||
return ControllerType_Unknown;
|
||||
}
|
||||
|
@ -242,6 +248,9 @@ namespace ams::controller {
|
|||
case ControllerType_ICade:
|
||||
g_controllers.push_back(std::make_unique<ICadeController>(address));
|
||||
break;
|
||||
case ControllerType_LanShen:
|
||||
g_controllers.push_back(std::make_unique<LanShenController>(address));
|
||||
break;
|
||||
default:
|
||||
g_controllers.push_back(std::make_unique<UnknownController>(address));
|
||||
break;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "mocute_controller.hpp"
|
||||
#include "razer_controller.hpp"
|
||||
#include "icade_controller.hpp"
|
||||
#include "lanshen_controller.hpp"
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
|
@ -62,6 +63,7 @@ namespace ams::controller {
|
|||
ControllerType_Mocute,
|
||||
ControllerType_Razer,
|
||||
ControllerType_ICade,
|
||||
ControllerType_LanShen,
|
||||
ControllerType_Unknown,
|
||||
};
|
||||
|
||||
|
|
79
mc_mitm/source/controllers/lanshen_controller.cpp
Normal file
79
mc_mitm/source/controllers/lanshen_controller.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 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 "lanshen_controller.hpp"
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
namespace ams::controller {
|
||||
|
||||
namespace {
|
||||
|
||||
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
|
||||
|
||||
}
|
||||
|
||||
void LanShenController::UpdateControllerState(const bluetooth::HidReport *report) {
|
||||
auto LanShen_report = reinterpret_cast<const LanShenReportData *>(&report->data);
|
||||
|
||||
switch(LanShen_report->id) {
|
||||
case 0x01:
|
||||
this->HandleInputReport0x01(LanShen_report);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LanShenController::HandleInputReport0x01(const LanShenReportData *src) {
|
||||
m_left_stick = this->PackStickData(
|
||||
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
|
||||
);
|
||||
m_right_stick = this->PackStickData(
|
||||
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 == LanShenDPad_S) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_SE) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_SW);
|
||||
m_buttons.dpad_up = (src->input0x01.buttons.dpad == LanShenDPad_N) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_NE) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_NW);
|
||||
m_buttons.dpad_right = (src->input0x01.buttons.dpad == LanShenDPad_E) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_NE) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_SE);
|
||||
m_buttons.dpad_left = (src->input0x01.buttons.dpad == LanShenDPad_W) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_NW) ||
|
||||
(src->input0x01.buttons.dpad == LanShenDPad_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;
|
||||
}
|
||||
|
||||
}
|
92
mc_mitm/source/controllers/lanshen_controller.hpp
Normal file
92
mc_mitm/source/controllers/lanshen_controller.hpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 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 LanShenDPadDirection {
|
||||
LanShenDPad_N,
|
||||
LanShenDPad_NE,
|
||||
LanShenDPad_E,
|
||||
LanShenDPad_SE,
|
||||
LanShenDPad_S,
|
||||
LanShenDPad_SW,
|
||||
LanShenDPad_W,
|
||||
LanShenDPad_NW,
|
||||
LanShenDPad_Released = 0x0f
|
||||
};
|
||||
|
||||
struct LanShenStickData {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct LanShenButtonData {
|
||||
uint8_t dpad;
|
||||
|
||||
uint8_t A : 1;
|
||||
uint8_t B : 1;
|
||||
uint8_t : 1;
|
||||
uint8_t X : 1;
|
||||
uint8_t Y : 1;
|
||||
uint8_t : 1;
|
||||
uint8_t L1 : 1;
|
||||
uint8_t R1 : 1;
|
||||
|
||||
uint8_t L2 : 1;
|
||||
uint8_t R2 : 1;
|
||||
uint8_t : 1;
|
||||
uint8_t start : 1;
|
||||
uint8_t : 1;
|
||||
uint8_t L3 : 1;
|
||||
uint8_t R3 : 1;
|
||||
uint8_t : 1;
|
||||
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct LanShenInputReport0x01{
|
||||
LanShenStickData left_stick;
|
||||
LanShenStickData right_stick;
|
||||
LanShenButtonData buttons;
|
||||
uint8_t _unk[4];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct LanShenReportData {
|
||||
uint8_t id;
|
||||
union {
|
||||
LanShenInputReport0x01 input0x01;
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
class LanShenController : public EmulatedSwitchController {
|
||||
|
||||
public:
|
||||
static constexpr const HardwareID hardware_ids[] = {
|
||||
{0x0079, 0x181c} // LanShen X1Pro
|
||||
};
|
||||
|
||||
LanShenController(const bluetooth::Address *address)
|
||||
: EmulatedSwitchController(address) { };
|
||||
|
||||
void UpdateControllerState(const bluetooth::HidReport *report);
|
||||
|
||||
private:
|
||||
void HandleInputReport0x01(const LanShenReportData *src);
|
||||
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue