2020-08-25 19:23:38 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2020-08-26 18:52:47 +00:00
|
|
|
#include "wii_controller.hpp"
|
2020-06-02 21:24:40 +00:00
|
|
|
#include <switch.h>
|
2020-08-24 20:40:44 +00:00
|
|
|
#include <stratosphere.hpp>
|
2020-08-26 18:52:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstring>
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-11 11:43:21 +00:00
|
|
|
namespace ams::controller {
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-08-11 23:06:05 +00:00
|
|
|
namespace {
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
constexpr uint8_t init_data1[] = {0x55};
|
|
|
|
constexpr uint8_t init_data2[] = {0x00};
|
|
|
|
|
|
|
|
constexpr float nunchuck_stick_scale_factor = float(UINT12_MAX) / 0xb8;
|
2020-09-14 00:46:40 +00:00
|
|
|
constexpr float wiiu_scale_factor = 1.5;
|
2020-08-26 18:52:47 +00:00
|
|
|
constexpr float left_stick_scale_factor = float(UINT12_MAX) / 0x3f;
|
|
|
|
constexpr float right_stick_scale_factor = float(UINT12_MAX) / 0x1f;
|
2020-08-11 23:06:05 +00:00
|
|
|
|
|
|
|
}
|
2020-08-11 23:14:50 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::Initialize(void) {
|
|
|
|
R_TRY(this->SetReportMode(0x31));
|
|
|
|
|
|
|
|
return this->QueryStatus();
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::UpdateControllerState(const bluetooth::HidReport *report) {
|
|
|
|
auto wii_report = reinterpret_cast<const WiiReportData *>(&report->data);
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
switch(wii_report->id) {
|
2020-07-30 20:04:15 +00:00
|
|
|
case 0x20: // status
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x20(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x21: // memory read
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x21(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x22: // ack
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x22(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x30:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x30(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x31:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x31(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x32:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x32(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case 0x34:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->HandleInputReport0x34(wii_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x20(const WiiReportData *src) {
|
2020-07-30 20:04:15 +00:00
|
|
|
if (!src->input0x20.extension_connected) {
|
|
|
|
m_extension = WiiExtensionController_None;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x31);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
else if (src->input0x20.extension_connected && (m_extension == WiiExtensionController_None)) {
|
|
|
|
// Initialise extension
|
2020-08-26 18:52:47 +00:00
|
|
|
this->WriteMemory(0x04a400f0, init_data1, sizeof(init_data1));
|
|
|
|
this->WriteMemory(0x04a400fb, init_data2, sizeof(init_data2));
|
2020-07-30 20:04:15 +00:00
|
|
|
|
|
|
|
// Read extension type
|
2020-08-26 18:52:47 +00:00
|
|
|
this->ReadMemory(0x04a400fa, 6);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 23:02:47 +00:00
|
|
|
m_battery = (src->input0x20.battery / 52) << 1;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x21(const WiiReportData *src) {
|
2020-08-26 18:52:47 +00:00
|
|
|
uint16_t read_addr = util::SwapBytes(src->input0x21.address);
|
2020-07-30 20:04:15 +00:00
|
|
|
|
|
|
|
if (read_addr == 0x00fa) {
|
2020-08-14 22:33:37 +00:00
|
|
|
// Identify extension controller by ID
|
2020-08-26 18:52:47 +00:00
|
|
|
uint64_t extension_id = (util::SwapBytes(*reinterpret_cast<const uint64_t *>(&src->input0x21.data)) >> 16);
|
2020-08-14 22:33:37 +00:00
|
|
|
|
2020-07-30 20:04:15 +00:00
|
|
|
switch (extension_id) {
|
2020-08-14 22:33:37 +00:00
|
|
|
case 0x0000A4200000ULL:
|
|
|
|
case 0xFF00A4200000ULL:
|
2020-07-30 20:04:15 +00:00
|
|
|
m_extension = WiiExtensionController_Nunchuck;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x32);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
2020-08-14 22:33:37 +00:00
|
|
|
case 0x0000A4200101ULL:
|
2020-07-30 20:04:15 +00:00
|
|
|
m_extension = WiiExtensionController_Classic;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x32);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
2020-08-14 22:33:37 +00:00
|
|
|
case 0x0100A4200101ULL:
|
2020-07-30 20:04:15 +00:00
|
|
|
m_extension = WiiExtensionController_ClassicPro;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x32);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
2020-08-14 22:33:37 +00:00
|
|
|
case 0x0000a4200120ULL:
|
2020-07-30 20:04:15 +00:00
|
|
|
m_extension = WiiExtensionController_WiiUPro;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x34);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
2020-09-24 00:40:33 +00:00
|
|
|
case 0x0000a4200111ULL:
|
|
|
|
m_extension = WiiExtensionController_TaTaCon;
|
|
|
|
this->SetReportMode(0x32);
|
|
|
|
break;
|
2020-07-30 20:04:15 +00:00
|
|
|
default:
|
|
|
|
m_extension = WiiExtensionController_Unsupported;
|
2020-08-26 18:52:47 +00:00
|
|
|
this->SetReportMode(0x31);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-03 15:50:07 +00:00
|
|
|
|
|
|
|
this->ClearControllerState();
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x22(const WiiReportData *src) {
|
2020-08-26 18:52:47 +00:00
|
|
|
;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x30(const WiiReportData *src) {
|
|
|
|
this->MapButtonsHorizontalOrientation(&src->input0x30.buttons);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x31(const WiiReportData *src) {
|
|
|
|
this->MapButtonsHorizontalOrientation(&src->input0x31.buttons);
|
2020-07-30 20:04:15 +00:00
|
|
|
|
|
|
|
// Todo: Accelerometer data
|
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x32(const WiiReportData *src) {
|
2020-08-14 22:33:37 +00:00
|
|
|
if ((m_extension == WiiExtensionController_Nunchuck)
|
|
|
|
|| (m_extension == WiiExtensionController_Classic)
|
2020-09-24 00:40:33 +00:00
|
|
|
|| (m_extension == WiiExtensionController_ClassicPro)
|
|
|
|
|| (m_extension == WiiExtensionController_TaTaCon)) {
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapButtonsVerticalOrientation(&src->input0x32.buttons);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapExtensionBytes(src->input0x32.extension);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::HandleInputReport0x34(const WiiReportData *src) {
|
2020-08-14 22:33:37 +00:00
|
|
|
if ((m_extension == WiiExtensionController_Nunchuck)
|
|
|
|
|| (m_extension == WiiExtensionController_Classic)
|
|
|
|
|| (m_extension == WiiExtensionController_ClassicPro)) {
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapButtonsVerticalOrientation(&src->input0x34.buttons);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapExtensionBytes(src->input0x34.extension);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapButtonsHorizontalOrientation(const WiiButtonData *buttons) {
|
|
|
|
m_buttons.dpad_down = buttons->dpad_left;
|
|
|
|
m_buttons.dpad_up = buttons->dpad_right;
|
|
|
|
m_buttons.dpad_right = buttons->dpad_down;
|
|
|
|
m_buttons.dpad_left = buttons->dpad_up;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.A = buttons->two;
|
|
|
|
m_buttons.B = buttons->one;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.R = buttons->A;
|
|
|
|
m_buttons.L = buttons->B;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.minus = buttons->minus;
|
|
|
|
m_buttons.plus = buttons->plus;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.home = buttons->home;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapButtonsVerticalOrientation(const WiiButtonData *buttons) {
|
|
|
|
m_buttons.dpad_down = buttons->dpad_down;
|
|
|
|
m_buttons.dpad_up = buttons->dpad_up;
|
|
|
|
m_buttons.dpad_right = buttons->dpad_right;
|
|
|
|
m_buttons.dpad_left = buttons->dpad_left;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.A = buttons->A;
|
|
|
|
m_buttons.B = buttons->B;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
|
|
|
// Not the best mapping but at least most buttons are mapped to something when nunchuck is connected.
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.R = buttons->one;
|
|
|
|
m_buttons.ZR = buttons->two;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.minus = buttons->minus;
|
|
|
|
m_buttons.plus = buttons->plus;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.home = buttons->home;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapExtensionBytes(const uint8_t ext[]) {
|
2020-07-30 20:04:15 +00:00
|
|
|
switch(m_extension) {
|
|
|
|
case WiiExtensionController_Nunchuck:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapNunchuckExtension(ext);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case WiiExtensionController_Classic:
|
|
|
|
case WiiExtensionController_ClassicPro:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapClassicControllerExtension(ext);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
|
|
|
case WiiExtensionController_WiiUPro:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapWiiUProControllerExtension(ext);
|
2020-07-30 20:04:15 +00:00
|
|
|
break;
|
2020-09-24 00:40:33 +00:00
|
|
|
case WiiExtensionController_TaTaCon:
|
2020-10-03 15:22:21 +00:00
|
|
|
this->MapTaTaConExtension(ext);
|
2020-09-24 00:40:33 +00:00
|
|
|
break;
|
2020-07-30 20:04:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapNunchuckExtension(const uint8_t ext[]) {
|
2020-07-30 20:04:15 +00:00
|
|
|
auto extension = reinterpret_cast<const WiiNunchuckExtensionData *>(ext);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
this->PackStickData(&m_left_stick,
|
2020-08-26 18:52:47 +00:00
|
|
|
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_x - 0x80) + STICK_ZERO), 0, 0xfff),
|
|
|
|
std::clamp<uint16_t>(static_cast<uint16_t>(nunchuck_stick_scale_factor * (extension->stick_y - 0x80) + STICK_ZERO), 0, 0xfff)
|
2020-07-30 20:04:15 +00:00
|
|
|
);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.L = !extension->C;
|
|
|
|
m_buttons.ZL = !extension->Z;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapClassicControllerExtension(const uint8_t ext[]) {
|
|
|
|
this->PackStickData(&m_left_stick,
|
2020-08-26 18:52:47 +00:00
|
|
|
static_cast<uint16_t>(left_stick_scale_factor * ((ext[0] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff,
|
|
|
|
static_cast<uint16_t>(left_stick_scale_factor * ((ext[1] & 0x3f) - 0x20) + STICK_ZERO) & 0xfff
|
2020-07-30 20:04:15 +00:00
|
|
|
);
|
2020-10-03 15:22:21 +00:00
|
|
|
this->PackStickData(&m_right_stick,
|
2020-08-26 18:52:47 +00:00
|
|
|
static_cast<uint16_t>(right_stick_scale_factor * ((((ext[0] >> 3) & 0x18) | ((ext[1] >> 5) & 0x06) | ((ext[2] >> 7) & 0x01)) - 0x10) + STICK_ZERO) & 0xfff,
|
|
|
|
static_cast<uint16_t>(right_stick_scale_factor * ((ext[2] & 0x1f) - 0x10) + STICK_ZERO) & 0xfff
|
2020-07-30 20:04:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
auto buttons = reinterpret_cast<const WiiClassicControllerButtonData *>(&ext[4]);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.dpad_down = !buttons->dpad_down;
|
|
|
|
m_buttons.dpad_up = !buttons->dpad_up;
|
|
|
|
m_buttons.dpad_right = !buttons->dpad_right;
|
|
|
|
m_buttons.dpad_left = !buttons->dpad_left;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.A = !buttons->A;
|
|
|
|
m_buttons.B = !buttons->B;
|
|
|
|
m_buttons.X = !buttons->X;
|
|
|
|
m_buttons.Y = !buttons->Y;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.L = !buttons->L;
|
|
|
|
m_buttons.ZL = !buttons->ZL;
|
|
|
|
m_buttons.R = !buttons->R;
|
|
|
|
m_buttons.ZR = !buttons->ZR;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.minus = !buttons->minus;
|
|
|
|
m_buttons.plus = !buttons->plus;
|
2020-06-09 20:39:30 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.home = !buttons->home;
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapWiiUProControllerExtension(const uint8_t ext[]) {
|
2020-07-30 20:04:15 +00:00
|
|
|
auto extension = reinterpret_cast<const WiiUProExtensionData *>(ext);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
this->PackStickData(&m_left_stick,
|
2020-09-14 00:46:40 +00:00
|
|
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
|
|
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->left_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
2020-07-30 20:04:15 +00:00
|
|
|
);
|
2020-10-03 15:22:21 +00:00
|
|
|
this->PackStickData(&m_right_stick,
|
2020-09-14 00:46:40 +00:00
|
|
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_x - STICK_ZERO))) + STICK_ZERO, 0, 0xfff),
|
|
|
|
std::clamp<uint16_t>(((wiiu_scale_factor * (extension->right_stick_y - STICK_ZERO))) + STICK_ZERO, 0, 0xfff)
|
2020-07-30 20:04:15 +00:00
|
|
|
);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.dpad_down = !extension->buttons.dpad_down;
|
|
|
|
m_buttons.dpad_up = !extension->buttons.dpad_up;
|
|
|
|
m_buttons.dpad_right = !extension->buttons.dpad_right;
|
|
|
|
m_buttons.dpad_left = !extension->buttons.dpad_left;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.A = !extension->buttons.A;
|
|
|
|
m_buttons.B = !extension->buttons.B;
|
|
|
|
m_buttons.X = !extension->buttons.X;
|
|
|
|
m_buttons.Y = !extension->buttons.Y;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.R = !extension->buttons.R;
|
|
|
|
m_buttons.ZR = !extension->buttons.ZR;
|
|
|
|
m_buttons.L = !extension->buttons.L;
|
|
|
|
m_buttons.ZL = !extension->buttons.ZL;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.minus = !extension->buttons.minus;
|
|
|
|
m_buttons.plus = !extension->buttons.plus;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.lstick_press = !extension->buttons.lstick_press;
|
|
|
|
m_buttons.rstick_press = !extension->buttons.rstick_press;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.home = !extension->buttons.home;
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
void WiiController::MapTaTaConExtension(const uint8_t ext[]) {
|
2020-09-24 00:40:33 +00:00
|
|
|
auto extension = reinterpret_cast<const TaTaConExtensionData *>(ext);
|
|
|
|
|
2020-10-03 15:22:21 +00:00
|
|
|
m_buttons.X = !extension->R_rim;
|
|
|
|
m_buttons.Y = !extension->R_center;
|
|
|
|
m_buttons.dpad_up = !extension->L_rim;
|
|
|
|
m_buttons.dpad_right = !extension->L_center;
|
2020-09-24 00:40:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::WriteMemory(uint32_t write_addr, const uint8_t *data, uint8_t size) {
|
|
|
|
s_output_report.size = sizeof(WiiOutputReport0x16) + 1;
|
|
|
|
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);
|
|
|
|
report_data->id = 0x16;
|
|
|
|
report_data->output0x16.address = ams::util::SwapBytes(write_addr);
|
|
|
|
report_data->output0x16.size = size;
|
|
|
|
std::memcpy(&report_data->output0x16.data, data, size);
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::ReadMemory(uint32_t read_addr, uint16_t size) {
|
|
|
|
s_output_report.size = sizeof(WiiOutputReport0x17) + 1;
|
|
|
|
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);
|
|
|
|
report_data->id = 0x17;
|
|
|
|
report_data->output0x17.address = ams::util::SwapBytes(read_addr);
|
|
|
|
report_data->output0x17.size = ams::util::SwapBytes(size);
|
2020-07-11 18:30:17 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::SetReportMode(uint8_t mode) {
|
|
|
|
s_output_report.size = sizeof(WiiOutputReport0x12) + 1;
|
|
|
|
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);
|
|
|
|
report_data->id = 0x12;
|
|
|
|
report_data->output0x12._unk = 0;
|
|
|
|
report_data->output0x12.report_mode = mode;
|
2020-07-11 18:30:17 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::QueryStatus(void) {
|
|
|
|
s_output_report.size = sizeof(WiiOutputReport0x15) + 1;
|
|
|
|
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);
|
|
|
|
report_data->id = 0x15;
|
|
|
|
report_data->output0x15._unk = 0;
|
2020-07-11 18:30:17 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
2020-07-27 17:42:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
Result WiiController::SetPlayerLed(uint8_t led_mask) {
|
|
|
|
s_output_report.size = sizeof(WiiOutputReport0x15) + 1;
|
|
|
|
auto report_data = reinterpret_cast<WiiReportData *>(s_output_report.data);
|
|
|
|
report_data->id = 0x11;
|
2020-10-12 22:10:22 +00:00
|
|
|
report_data->output0x11.leds = (led_mask << 4) & 0xf0;
|
2020-07-30 20:04:15 +00:00
|
|
|
|
2020-08-26 18:52:47 +00:00
|
|
|
return bluetooth::hid::report::SendHidReport(&m_address, &s_output_report);
|
2020-07-30 20:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
}
|