mc.mitm: mark globals as constinit, constants as constexpr and use camel case for constant variable names

This commit is contained in:
ndeadly 2023-11-16 14:33:08 +01:00
parent 503cc7c133
commit d89e0ab1a7
45 changed files with 363 additions and 370 deletions

View file

@ -19,16 +19,16 @@ namespace ams::async {
namespace {
const size_t ThreadCount = 1;
const size_t ThreadStackSize = 0x2000;
const s32 ThreadPriority = 10;
constexpr size_t ThreadCount = 1;
constexpr size_t ThreadStackSize = 0x2000;
constexpr s32 ThreadPriority = 10;
alignas(os::MemoryPageSize) u8 g_thread_stacks[ThreadCount][ThreadStackSize];
os::ThreadType g_thread_pool[ThreadCount];
alignas(os::MemoryPageSize) constinit u8 g_thread_stacks[ThreadCount][ThreadStackSize];
constinit os::ThreadType g_thread_pool[ThreadCount];
const size_t MessageBufferSize = 32;
uintptr_t g_message_buffer[MessageBufferSize];
os::MessageQueueType g_work_queue;
constexpr size_t MessageBufferSize = 32;
constinit uintptr_t g_message_buffer[MessageBufferSize];
constinit os::MessageQueueType g_work_queue;
void WorkerThreadFunc(void *) {
uintptr_t ptr;

View file

@ -20,9 +20,9 @@ namespace ams::bluetooth::ble {
namespace {
os::Mutex g_event_data_lock(false);
bluetooth::BleEventInfo g_event_info;
bluetooth::BleEventType g_current_event_type;
constinit os::SdkMutex g_event_data_lock;
constinit bluetooth::BleEventInfo g_event_info;
constinit bluetooth::BleEventType g_current_event_type;
os::SystemEvent g_system_event;
os::SystemEvent g_system_event_fwd(os::EventClearMode_AutoClear, true);

View file

@ -21,9 +21,9 @@ namespace ams::bluetooth::core {
namespace {
os::Mutex g_event_info_lock(false);
bluetooth::EventInfo g_event_info;
bluetooth::EventType g_current_event_type;
constinit os::SdkMutex g_event_info_lock;
constinit bluetooth::EventInfo g_event_info;
constinit bluetooth::EventType g_current_event_type;
os::SystemEvent g_system_event;
os::SystemEvent g_system_event_fwd(os::EventClearMode_AutoClear, true);
@ -85,17 +85,17 @@ namespace ams::bluetooth::core {
switch (event_type) {
case BtdrvEventTypeOld_InquiryDevice:
if (controller::IsAllowedDeviceClass(&event_info->inquiry_device.v1.class_of_device) && !controller::IsOfficialSwitchControllerName(event_info->inquiry_device.v1.name)) {
std::strncpy(event_info->inquiry_device.v1.name, controller::pro_controller_name, sizeof(event_info->inquiry_device.v1.name) - 1);
std::strncpy(event_info->inquiry_device.v1.name, controller::ProControllerName, sizeof(event_info->inquiry_device.v1.name) - 1);
}
break;
case BtdrvEventTypeOld_PairingPinCodeRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->pairing_pin_code_request.name)) {
std::strncpy(event_info->pairing_pin_code_request.name, controller::pro_controller_name, sizeof(event_info->pairing_pin_code_request.name) - 1);
std::strncpy(event_info->pairing_pin_code_request.name, controller::ProControllerName, sizeof(event_info->pairing_pin_code_request.name) - 1);
}
break;
case BtdrvEventTypeOld_SspRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->ssp_request.v1.name)) {
std::strncpy(event_info->ssp_request.v1.name, controller::pro_controller_name, sizeof(event_info->ssp_request.v1.name) - 1);
std::strncpy(event_info->ssp_request.v1.name, controller::ProControllerName, sizeof(event_info->ssp_request.v1.name) - 1);
}
break;
default:
@ -107,17 +107,17 @@ namespace ams::bluetooth::core {
switch (event_type) {
case BtdrvEventType_InquiryDevice:
if (controller::IsAllowedDeviceClass(&event_info->inquiry_device.v12.class_of_device) && !controller::IsOfficialSwitchControllerName(event_info->inquiry_device.v12.name)) {
std::strncpy(event_info->inquiry_device.v12.name, controller::pro_controller_name, sizeof(event_info->inquiry_device.v12.name) - 1);
std::strncpy(event_info->inquiry_device.v12.name, controller::ProControllerName, sizeof(event_info->inquiry_device.v12.name) - 1);
}
break;
case BtdrvEventType_PairingPinCodeRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->pairing_pin_code_request.name)) {
std::strncpy(event_info->pairing_pin_code_request.name, controller::pro_controller_name, sizeof(event_info->pairing_pin_code_request.name) - 1);
std::strncpy(event_info->pairing_pin_code_request.name, controller::ProControllerName, sizeof(event_info->pairing_pin_code_request.name) - 1);
}
break;
case BtdrvEventType_SspRequest:
if (!controller::IsOfficialSwitchControllerName(event_info->ssp_request.v12.name)) {
std::strncpy(event_info->ssp_request.v12.name, controller::pro_controller_name, sizeof(event_info->ssp_request.v12.name) - 1);
std::strncpy(event_info->ssp_request.v12.name, controller::ProControllerName, sizeof(event_info->ssp_request.v12.name) - 1);
}
break;
default:
@ -152,7 +152,7 @@ namespace ams::bluetooth::core {
u8 pin_length = std::strlen(pin.code);
// Reverse host address as pin code for wii devices
if (std::strncmp(event_info->pairing_pin_code_request.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) {
if (std::strncmp(event_info->pairing_pin_code_request.name, controller::WiiControllerPrefix, std::strlen(controller::WiiControllerPrefix)) == 0) {
// Fetch host adapter address
bluetooth::Address host_address;
R_ABORT_UNLESS(btdrvLegacyGetAdapterProperty(BtdrvBluetoothPropertyType_Address, &host_address, sizeof(bluetooth::Address)));
@ -170,7 +170,7 @@ namespace ams::bluetooth::core {
BtdrvPinCode pin = {"0000", 4};
// Reverse host address as pin code for wii devices
if (std::strncmp(event_info->pairing_pin_code_request.name, controller::wii_controller_prefix, std::strlen(controller::wii_controller_prefix)) == 0) {
if (std::strncmp(event_info->pairing_pin_code_request.name, controller::WiiControllerPrefix, std::strlen(controller::WiiControllerPrefix)) == 0) {
// Fetch host adapter address
BtdrvAdapterProperty property;
R_ABORT_UNLESS(btdrvGetAdapterProperty(BtdrvAdapterPropertyType_Address, &property));

View file

@ -23,15 +23,15 @@ namespace ams::bluetooth::events {
namespace {
const s32 ThreadPriority = 9;
const size_t ThreadStackSize = 0x2000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = 9;
constexpr size_t ThreadStackSize = 0x2000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
os::MultiWaitType g_manager;
os::MultiWaitHolderType g_holder_bt_core;
os::MultiWaitHolderType g_holder_bt_hid;
os::MultiWaitHolderType g_holder_bt_ble;
constinit os::MultiWaitType g_manager;
constinit os::MultiWaitHolderType g_holder_bt_core;
constinit os::MultiWaitHolderType g_holder_bt_hid;
constinit os::MultiWaitHolderType g_holder_bt_ble;
void EventHandlerThreadFunc(void *) {
os::InitializeMultiWait(&g_manager);

View file

@ -21,9 +21,9 @@ namespace ams::bluetooth::hid {
namespace {
os::Mutex g_event_info_lock(false);
bluetooth::HidEventInfo g_event_info;
bluetooth::HidEventType g_current_event_type;
constinit os::SdkMutex g_event_info_lock;
constinit bluetooth::HidEventInfo g_event_info;
constinit bluetooth::HidEventType g_current_event_type;
os::SystemEvent g_system_event;
os::SystemEvent g_system_event_fwd(os::EventClearMode_AutoClear, true);

View file

@ -23,16 +23,16 @@ namespace ams::bluetooth::hid::report {
namespace {
constexpr size_t bluetooth_sharedmem_size = 0x3000;
constexpr size_t BluetoothSharedMemorySize = 0x3000;
const s32 ThreadPriority = -11;
const size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = -11;
constexpr size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
// This is only required on fw < 7.0.0
bluetooth::HidReportEventInfo g_event_info;
bluetooth::HidEventType g_current_event_type;
constinit bluetooth::HidReportEventInfo g_event_info;
constinit bluetooth::HidEventType g_current_event_type;
os::SystemEvent g_system_event;
os::SystemEvent g_system_event_fwd(os::EventClearMode_AutoClear, true);
@ -42,12 +42,12 @@ namespace ams::bluetooth::hid::report {
os::Event g_report_read_event(os::EventClearMode_AutoClear);
os::SharedMemory g_real_bt_shmem;
os::SharedMemory g_fake_bt_shmem(bluetooth_sharedmem_size, os::MemoryPermission_ReadWrite, os::MemoryPermission_ReadWrite);
os::SharedMemory g_fake_bt_shmem(BluetoothSharedMemorySize, os::MemoryPermission_ReadWrite, os::MemoryPermission_ReadWrite);
bluetooth::CircularBuffer *g_real_buffer;
bluetooth::CircularBuffer *g_fake_buffer;
bluetooth::HidReportEventInfo g_fake_report_event_info;
constinit bluetooth::HidReportEventInfo g_fake_report_event_info;
void EventThreadFunc(void *) {
@ -120,7 +120,7 @@ namespace ams::bluetooth::hid::report {
}
Result MapRemoteSharedMemory(os::NativeHandle handle) {
g_real_bt_shmem.Attach(bluetooth_sharedmem_size, handle, true);
g_real_bt_shmem.Attach(BluetoothSharedMemorySize, handle, true);
g_real_bt_shmem.Map(os::MemoryPermission_ReadWrite);
g_real_buffer = reinterpret_cast<bluetooth::CircularBuffer *>(g_real_bt_shmem.GetMappedAddress());

View file

@ -58,10 +58,10 @@ namespace ams::mitm::bluetooth {
}
}
const s32 ThreadPriority = -11;
const size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = -11;
constexpr size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
void BtdrvMitmThreadFunction(void *) {
R_ABORT_UNLESS((g_server_manager.RegisterMitmServer<BtdrvMitmService>(PortIndex_BtdrvMitm, BtdrvMitmServiceName)));

View file

@ -25,7 +25,7 @@ namespace ams::mitm::btm {
for (unsigned int i = 0; i < count; ++i) {
auto device = &devices[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
std::strncpy(device->name, controller::ProControllerName, sizeof(device->name) - 1);
}
}
}
@ -39,7 +39,7 @@ namespace ams::mitm::btm {
for (int i = 0; i < total_out.GetValue(); ++i) {
auto device = &device_condition[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
std::strncpy(device->name, controller::ProControllerName, sizeof(device->name) - 1);
}
}
@ -53,7 +53,7 @@ namespace ams::mitm::btm {
for (int i = 0; i < total_out.GetValue(); ++i) {
auto device = &device_info[i];
if (!controller::IsOfficialSwitchControllerName(device->name)) {
std::strncpy(device->name, controller::pro_controller_name, sizeof(device->name) - 1);
std::strncpy(device->name, controller::ProControllerName, sizeof(device->name) - 1);
}
}
@ -106,7 +106,7 @@ namespace ams::mitm::btm {
for (unsigned int i = 0; i < device_info->device_count; ++i) {
auto device = &device_info->devices[i];
if (!controller::IsOfficialSwitchControllerName(device->name.name)) {
std::strncpy(device->name.name, controller::pro_controller_name, sizeof(device->name) - 1);
std::strncpy(device->name.name, controller::ProControllerName, sizeof(device->name) - 1);
}
}

View file

@ -58,10 +58,10 @@ namespace ams::mitm::btm {
}
}
const s32 ThreadPriority = 9;
const size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = 9;
constexpr size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
void BtmMitmThreadFunction(void *) {
R_ABORT_UNLESS((g_server_manager.RegisterMitmServer<BtmMitmService>(PortIndex_BtmMitm, BtmMitmServiceName)));

View file

@ -21,10 +21,10 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor_16bit = float(UINT12_MAX) / UINT16_MAX;
constexpr float stick_scale_factor_8bit = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor16Bit = float(UINT12_MAX) / UINT16_MAX;
constexpr float StickScaleFactor8Bit = float(UINT12_MAX) / UINT8_MAX;
const u16 dpad_stick_positions[] = { STICK_MIN, STICK_CENTER, STICK_MAX };
constinit const u16 DpadStickPositions[] = { STICK_MIN, STICK_CENTER, STICK_MAX };
}
@ -58,17 +58,17 @@ namespace ams::controller {
// Map dpad as left stick
m_left_stick.SetData(
dpad_stick_positions[1 + dpad_right - dpad_left],
dpad_stick_positions[1 + dpad_up - dpad_down]
DpadStickPositions[1 + dpad_right - dpad_left],
DpadStickPositions[1 + dpad_up - dpad_down]
);
} else {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor_16bit * src->input0x01_v2.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor_16bit * (UINT16_MAX - src->input0x01_v2.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor16Bit * src->input0x01_v2.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor16Bit * (UINT16_MAX - src->input0x01_v2.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor_16bit * src->input0x01_v2.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor_16bit * (UINT16_MAX - src->input0x01_v2.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor16Bit * src->input0x01_v2.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor16Bit * (UINT16_MAX - src->input0x01_v2.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01_v2.dpad == EightBitDoDPadV2_S) ||
@ -136,8 +136,8 @@ namespace ams::controller {
// Map dpad as left stick
m_left_stick.SetData(
dpad_stick_positions[1 + dpad_right - dpad_left],
dpad_stick_positions[1 + dpad_up - dpad_down]
DpadStickPositions[1 + dpad_right - dpad_left],
DpadStickPositions[1 + dpad_up - dpad_down]
);
m_buttons.A = src->input0x03_v2.buttons.B;
@ -153,12 +153,12 @@ namespace ams::controller {
}
} else {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor_8bit * src->input0x03_v3.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor_8bit * (UINT8_MAX - src->input0x03_v3.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor8Bit * src->input0x03_v3.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor8Bit * (UINT8_MAX - src->input0x03_v3.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor_8bit * src->input0x03_v3.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor_8bit * (UINT8_MAX - src->input0x03_v3.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor8Bit * src->input0x03_v3.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor8Bit * (UINT8_MAX - src->input0x03_v3.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x03_v3.dpad == EightBitDoDPadV2_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT16_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT16_MAX;
}
@ -39,12 +39,12 @@ namespace ams::controller {
void AtariController::MapInputReport0x01(const AtariReportData *src) {
m_left_stick.SetData(
static_cast<u16>( stick_scale_factor * src->input0x01.left_stick.x + 0x7ff) & UINT12_MAX,
static_cast<u16>(-stick_scale_factor * src->input0x01.left_stick.y + 0x7ff) & UINT12_MAX
static_cast<u16>( StickScaleFactor * src->input0x01.left_stick.x + 0x7ff) & UINT12_MAX,
static_cast<u16>(-StickScaleFactor * src->input0x01.left_stick.y + 0x7ff) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>( stick_scale_factor * src->input0x01.right_stick.x + 0x7ff) & UINT12_MAX,
static_cast<u16>(-stick_scale_factor * src->input0x01.right_stick.y + 0x7ff) & UINT12_MAX
static_cast<u16>( StickScaleFactor * src->input0x01.right_stick.x + 0x7ff) & UINT12_MAX,
static_cast<u16>(-StickScaleFactor * src->input0x01.right_stick.y + 0x7ff) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.buttons.dpad == AtariDPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -47,7 +47,7 @@ namespace ams::controller {
);
m_right_stick.SetData(
STICK_CENTER,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.x)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.x)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.dpad == AtGamesDPad_S) ||
@ -80,7 +80,7 @@ namespace ams::controller {
);
m_right_stick.SetData(
STICK_CENTER,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.x)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.x)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.dpad == AtGamesDPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -37,12 +37,12 @@ namespace ams::controller {
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
static_cast<u16>(StickScaleFactor * src->input0x03.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (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
static_cast<u16>(StickScaleFactor * src->input0x03.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x03.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x03.buttons.dpad == BetopDPad_S) ||

View file

@ -21,7 +21,7 @@ namespace ams::controller {
namespace {
const std::string official_npad_names[] = {
const std::string OfficialGamepadNames[] = {
"NintendoGamepad",
"Joy-Con (L)",
"Joy-Con (R)",
@ -35,12 +35,12 @@ namespace ams::controller {
"Lic2 Pro Controller",
};
constexpr auto cod_major_peripheral = 0x05;
constexpr auto cod_minor_gamepad = 0x08;
constexpr auto cod_minor_joystick = 0x04;
constexpr auto cod_minor_keyboard = 0x40;
constexpr u8 DeviceClassMajorPeripheral = 0x05;
constexpr u8 DeviceClassMinorGamepad = 0x08;
constexpr u8 DeviceClassMinorJoystick = 0x04;
constexpr u8 DeviceClassMinorKeyboard = 0x40;
os::Mutex g_controller_lock(false);
constinit os::SdkMutex g_controller_lock;
std::vector<std::shared_ptr<SwitchController>> g_controllers;
}
@ -205,12 +205,12 @@ namespace ams::controller {
}
bool IsAllowedDeviceClass(const bluetooth::DeviceClass *cod) {
return ((cod->class_of_device[1] & 0x0f) == cod_major_peripheral) &&
(((cod->class_of_device[2] & 0x0f) == cod_minor_gamepad) || ((cod->class_of_device[2] & 0x0f) == cod_minor_joystick) || ((cod->class_of_device[2] & 0x40) == cod_minor_keyboard));
return ((cod->class_of_device[1] & 0x0f) == DeviceClassMajorPeripheral) &&
(((cod->class_of_device[2] & 0x0f) == DeviceClassMinorGamepad) || ((cod->class_of_device[2] & 0x0f) == DeviceClassMinorJoystick) || ((cod->class_of_device[2] & 0x40) == DeviceClassMinorKeyboard));
}
bool IsOfficialSwitchControllerName(const std::string& name) {
for (auto n : official_npad_names) {
for (auto n : OfficialGamepadNames) {
if (name.rfind(n, 0) == 0)
return true;
}

View file

@ -45,8 +45,8 @@
namespace ams::controller {
const constexpr char* pro_controller_name = "Pro Controller";
const constexpr char* wii_controller_prefix = "Nintendo RVL";
constexpr const char ProControllerName[] = "Pro Controller";
constexpr const char WiiControllerPrefix[] = "Nintendo RVL";
enum ControllerType {
ControllerType_Switch,

View file

@ -17,12 +17,6 @@
namespace ams::controller {
u8 convert_battery_100(u8 level) {
return level ? (((level - 1) / 25) + 1) << 1 : 0;
}
u8 convert_battery_255(u8 level) {
return level ? ((level / 64) + 1) << 1 : 0;
}
}

View file

@ -18,7 +18,12 @@
namespace ams::controller {
u8 convert_battery_100(u8 level);
u8 convert_battery_255(u8 level);
constexpr u8 convert_battery_100(u8 level) {
return level ? (((level - 1) / 25) + 1) << 1 : 0;
}
constexpr u8 convert_battery_255(u8 level) {
return level ? ((level / 64) + 1) << 1 : 0;
}
}

View file

@ -21,15 +21,15 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
constexpr float AccelScaleFactor = 65535 / 16000.0f * 1000;
constexpr float GyroScaleFactor = 65535 / (13371 * 360.0f) * 1000;
constexpr u16 touchpad_width = 1920;
constexpr u16 touchpad_height = 1080;
constexpr u16 TouchpadWidth = 1920;
constexpr u16 TouchpadHeight = 1080;
const u8 player_led_flags[] = {
constinit const u8 PlayerLedFlags[] = {
// Mimic the Switch's player LEDs
0x01,
0x03,
@ -41,7 +41,7 @@ namespace ams::controller {
0x0A
};
const u8 new_player_led_flags[] = {
constinit const u8 NewPlayerLedFlags[] = {
0x04,
0x02,
0x05,
@ -52,7 +52,7 @@ namespace ams::controller {
0x07
};
const RGBColour player_led_base_colours[] = {
constinit const RGBColour PlayerLedBaseColours[] = {
// Same colours used by PS4
{0x00, 0x00, 0x04}, // blue
{0x04, 0x00, 0x00}, // red
@ -65,10 +65,10 @@ namespace ams::controller {
{0x01, 0x00, 0x03} // purple
};
constexpr u8 step = 4;
const u8 led_brightness_multipliers[] = { 0, 1, 1 * step, 2 * step, 3 * step, 4 * step, 5 * step, 6 * step, 7 * step, 8 * step };
constexpr u8 Step = 4;
constinit const u8 LedBrightnessMultipliers[] = { 0, 1, 1 * Step, 2 * Step, 3 * Step, 4 * Step, 5 * Step, 6 * Step, 7 * Step, 8 * Step };
constexpr u32 crc_seed = 0x8C36CCAE; // CRC32 of {0xa2, 0x31} bytes at beginning of output report
constexpr u32 CrcSeed = 0x8C36CCAE; // CRC32 of {0xa2, 0x31} bytes at beginning of output report
}
@ -110,16 +110,16 @@ namespace ams::controller {
if (!config->misc.dualsense_enable_player_leds) {
m_led_flags = 0x00;
} else if (fw_version < 0x0282) {
m_led_flags = player_led_flags[player_number];
m_led_flags = PlayerLedFlags[player_number];
} else {
m_led_flags = new_player_led_flags[player_number];
m_led_flags = NewPlayerLedFlags[player_number];
}
// Disable LED fade-in
m_led_flags |= 0x20;
RGBColour colour = player_led_base_colours[player_number];
u8 multiplier = led_brightness_multipliers[m_lightbar_brightness];
RGBColour colour = PlayerLedBaseColours[player_number];
u8 multiplier = LedBrightnessMultipliers[m_lightbar_brightness];
colour.r *= multiplier;
colour.g *= multiplier;
colour.b *= multiplier;
@ -146,12 +146,12 @@ namespace ams::controller {
void DualsenseController::MapInputReport0x01(const DualsenseReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
this->MapButtons(&src->input0x01.buttons);
@ -180,12 +180,12 @@ namespace ams::controller {
m_battery = static_cast<u8>(8 * (battery_level + 2) / 10) & 0x0e;
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x31.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x31.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x31.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x31.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x31.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x31.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x31.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x31.right_stick.y)) & UINT12_MAX
);
this->MapButtons(&src->input0x31.buttons);
@ -201,9 +201,9 @@ namespace ams::controller {
if (active) {
u16 x = (point->x_hi << 8) | point->x_lo;
if (x < (0.15 * touchpad_width)) {
if (x < (0.15 * TouchpadWidth)) {
m_buttons.minus = 1;
} else if (x > (0.85 * touchpad_width)) {
} else if (x > (0.85 * TouchpadWidth)) {
m_buttons.plus = 1;
} else {
m_buttons.capture = 1;
@ -213,13 +213,13 @@ namespace ams::controller {
}
if (m_enable_motion) {
s16 acc_x = -static_cast<s16>(accel_scale_factor * src->input0x31.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(accel_scale_factor * src->input0x31.acc_x / float(m_motion_calibration.acc.x_max));
s16 acc_z = static_cast<s16>(accel_scale_factor * src->input0x31.acc_y / float(m_motion_calibration.acc.y_max));
s16 acc_x = -static_cast<s16>(AccelScaleFactor * src->input0x31.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(AccelScaleFactor * src->input0x31.acc_x / float(m_motion_calibration.acc.x_max));
s16 acc_z = static_cast<s16>(AccelScaleFactor * src->input0x31.acc_y / float(m_motion_calibration.acc.y_max));
s16 vel_x = -static_cast<s16>(gyro_scale_factor * (src->input0x31.vel_z - m_motion_calibration.gyro.roll_bias) / ((m_motion_calibration.gyro.roll_max - m_motion_calibration.gyro.roll_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_y = -static_cast<s16>(gyro_scale_factor * (src->input0x31.vel_x - m_motion_calibration.gyro.pitch_bias) / ((m_motion_calibration.gyro.pitch_max - m_motion_calibration.gyro.pitch_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_z = static_cast<s16>(gyro_scale_factor * (src->input0x31.vel_y - m_motion_calibration.gyro.yaw_bias) / ((m_motion_calibration.gyro.yaw_max- m_motion_calibration.gyro.yaw_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_x = -static_cast<s16>(GyroScaleFactor * (src->input0x31.vel_z - m_motion_calibration.gyro.roll_bias) / ((m_motion_calibration.gyro.roll_max - m_motion_calibration.gyro.roll_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_y = -static_cast<s16>(GyroScaleFactor * (src->input0x31.vel_x - m_motion_calibration.gyro.pitch_bias) / ((m_motion_calibration.gyro.pitch_max - m_motion_calibration.gyro.pitch_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_z = static_cast<s16>(GyroScaleFactor * (src->input0x31.vel_y - m_motion_calibration.gyro.yaw_bias) / ((m_motion_calibration.gyro.yaw_max- m_motion_calibration.gyro.yaw_bias) / m_motion_calibration.gyro.speed_max));
m_motion_data[0].gyro_1 = vel_x;
m_motion_data[0].gyro_2 = vel_y;
@ -318,7 +318,7 @@ namespace ams::controller {
report.output0x31.data[45] = m_lightbar_colour.r;
report.output0x31.data[46] = m_lightbar_colour.g;
report.output0x31.data[47] = m_lightbar_colour.b;
report.output0x31.crc = crc32CalculateWithSeed(crc_seed, report.output0x31.data, sizeof(report.output0x31.data));
report.output0x31.crc = crc32CalculateWithSeed(CrcSeed, report.output0x31.data, sizeof(report.output0x31.data));
m_output_report.size = sizeof(report.output0x31) + sizeof(report.id);
std::memcpy(m_output_report.data, &report, m_output_report.size);

View file

@ -24,9 +24,9 @@ namespace ams::controller {
namespace {
const char *ds3_device_name = "PLAYSTATION(R)3 Controller";
constexpr u16 ds3_vendor_id = 0x054c;
constexpr u16 ds3_product_id = 0x0268;
constexpr const char Ds3DeviceName[] = "PLAYSTATION(R)3 Controller";
constexpr u16 Ds3VendorId = 0x054c;
constexpr u16 Ds3ProductId = 0x0268;
enum Dualshock3LedMode {
Dualshock3LedMode_Switch = 0,
@ -34,19 +34,19 @@ namespace ams::controller {
Dualshock3LedMode_Hybrid = 2,
};
const u8 enable_payload[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
const u8 led_config[] = { 0xff, 0x27, 0x10, 0x00, 0x32 };
const u8 player_led_patterns[] = { 0b1000, 0b1100, 0b1110, 0b1111, 0b1001, 0b0101, 0b1101, 0b0110 };
constinit const u8 EnablePayload[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
constinit const u8 LedConfig[] = { 0xff, 0x27, 0x10, 0x00, 0x32 };
constinit const u8 PlayerLedPatterns[] = { 0b1000, 0b1100, 0b1110, 0b1111, 0b1001, 0b0101, 0b1101, 0b0110 };
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000 / 113;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
constexpr float AccelScaleFactor = 65535 / 16000.0f * 1000 / 113;
alignas(os::MemoryPageSize) constinit u8 g_usb_buffer[0x1000];
const UsbHsInterfaceFilter g_interface_filter = {
constinit const UsbHsInterfaceFilter g_interface_filter = {
.Flags = UsbHsInterfaceFilterFlags_idVendor | UsbHsInterfaceFilterFlags_idProduct | UsbHsInterfaceFilterFlags_bInterfaceClass,
.idVendor = ds3_vendor_id,
.idProduct = ds3_product_id,
.idVendor = Ds3VendorId,
.idProduct = Ds3ProductId,
.bInterfaceClass = USB_CLASS_HID,
};
@ -96,16 +96,16 @@ namespace ams::controller {
device.class_of_device = {0x00, 0x05, 0x08};
device.link_key_present = false;
device.trusted_services = 0x100000;
device.vid = ds3_vendor_id;
device.pid = ds3_product_id;
device.vid = Ds3VendorId;
device.pid = Ds3ProductId;
device.sub_class = 0x08;
device.attribute_mask = 0xff;
if (hos::GetVersion() < hos::Version_13_0_0) {
std::strncpy(device.name.name, ds3_device_name, sizeof(device.name));
std::strncpy(device.name.name, Ds3DeviceName, sizeof(device.name));
}
else {
std::strncpy(device.name2, ds3_device_name, sizeof(device.name2));
std::strncpy(device.name2, Ds3DeviceName, sizeof(device.name2));
}
R_RETURN(btdrvAddPairedDeviceInfo(&device));
@ -148,7 +148,7 @@ namespace ams::controller {
}
bool Dualshock3Controller::UsbIdentify(UsbHsInterface *iface) {
return (iface->device_desc.idVendor == ds3_vendor_id) && (iface->device_desc.idProduct == ds3_product_id);
return (iface->device_desc.idVendor == Ds3VendorId) && (iface->device_desc.idProduct == Ds3ProductId);
}
Result Dualshock3Controller::UsbPair(UsbHsInterface *iface) {
@ -210,7 +210,7 @@ namespace ams::controller {
auto config = mitm::GetGlobalConfig();
switch(config->misc.dualshock3_led_mode) {
case Dualshock3LedMode_Switch:
m_led_mask = player_led_patterns[player_index];
m_led_mask = PlayerLedPatterns[player_index];
break;
case Dualshock3LedMode_Ps3:
m_led_mask = player_index < 4 ? 1 << player_index : ~(1 << player_index) & 0x0f;
@ -246,12 +246,12 @@ namespace ams::controller {
}
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = src->input0x01.buttons.dpad_down;
@ -278,9 +278,9 @@ namespace ams::controller {
m_buttons.home = src->input0x01.buttons.ps;
if (m_enable_motion) {
s16 acc_x = -static_cast<s16>(accel_scale_factor * (511 - util::SwapEndian(src->input0x01.accel_y)));
s16 acc_y = -static_cast<s16>(accel_scale_factor * (util::SwapEndian(src->input0x01.accel_x) - 511));
s16 acc_z = static_cast<s16>(accel_scale_factor * (511 - util::SwapEndian(src->input0x01.accel_z)));
s16 acc_x = -static_cast<s16>(AccelScaleFactor * (511 - util::SwapEndian(src->input0x01.accel_y)));
s16 acc_y = -static_cast<s16>(AccelScaleFactor * (util::SwapEndian(src->input0x01.accel_x) - 511));
s16 acc_z = static_cast<s16>(AccelScaleFactor * (511 - util::SwapEndian(src->input0x01.accel_z)));
m_motion_data[0].accel_x = acc_x;
m_motion_data[0].accel_y = acc_y;
@ -299,8 +299,8 @@ namespace ams::controller {
}
Result Dualshock3Controller::SendEnablePayload() {
m_output_report.size = sizeof(enable_payload);
std::memcpy(m_output_report.data, enable_payload, m_output_report.size);
m_output_report.size = sizeof(EnablePayload);
std::memcpy(m_output_report.data, EnablePayload, m_output_report.size);
R_RETURN(this->SetReport(BtdrvBluetoothHhReportType_Feature, &m_output_report));
}
@ -315,10 +315,10 @@ namespace ams::controller {
report.output0x01.data[3] = 10;
report.output0x01.data[4] = m_rumble_state.amp_motor_left;
report.output0x01.data[9] = m_led_mask << 1;
std::memcpy(&report.output0x01.data[10], led_config, sizeof(led_config));
std::memcpy(&report.output0x01.data[15], led_config, sizeof(led_config));
std::memcpy(&report.output0x01.data[20], led_config, sizeof(led_config));
std::memcpy(&report.output0x01.data[25], led_config, sizeof(led_config));
std::memcpy(&report.output0x01.data[10], LedConfig, sizeof(LedConfig));
std::memcpy(&report.output0x01.data[15], LedConfig, sizeof(LedConfig));
std::memcpy(&report.output0x01.data[20], LedConfig, sizeof(LedConfig));
std::memcpy(&report.output0x01.data[25], LedConfig, sizeof(LedConfig));
m_output_report.size = sizeof(report.output0x01) + sizeof(report.id);
std::memcpy(m_output_report.data, &report, m_output_report.size);

View file

@ -22,15 +22,15 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
constexpr float AccelScaleFactor = 65535 / 16000.0f * 1000;
constexpr float GyroScaleFactor = 65535 / (13371 * 360.0f) * 1000;
constexpr u16 touchpad_width = 1920;
constexpr u16 touchpad_height = 942;
constexpr u16 TouchpadWidth = 1920;
constexpr u16 TouchpadHeight = 942;
const RGBColour player_led_base_colours[] = {
constinit const RGBColour PlayerLedBaseColours[] = {
// Same colours used by PS4
{0x00, 0x00, 0x04}, // blue
{0x04, 0x00, 0x00}, // red
@ -43,10 +43,10 @@ namespace ams::controller {
{0x01, 0x00, 0x03} // purple
};
constexpr u8 step = 4;
const u8 led_brightness_multipliers[] = { 0, 1, 1 * step, 2 * step, 3 * step, 4 * step, 5 * step, 6 * step, 7 * step, 8 * step };
constexpr u8 Step = 4;
constinit const u8 LedBrightnessMultipliers[] = { 0, 1, 1 * Step, 2 * Step, 3 * Step, 4 * Step, 5 * Step, 6 * Step, 7 * Step, 8 * Step };
constexpr u32 crc_seed = 0xB758EC66; // CRC32 of {0xa2, 0x11} bytes at beginning of output report
constexpr u32 CrcSeed = 0xB758EC66; // CRC32 of {0xa2, 0x11} bytes at beginning of output report
}
@ -81,8 +81,8 @@ namespace ams::controller {
Result Dualshock4Controller::SetPlayerLed(u8 led_mask) {
u8 player_number;
R_TRY(LedsMaskToPlayerNumber(led_mask, &player_number));
RGBColour colour = player_led_base_colours[player_number];
u8 multiplier = led_brightness_multipliers[m_lightbar_brightness];
RGBColour colour = PlayerLedBaseColours[player_number];
u8 multiplier = LedBrightnessMultipliers[m_lightbar_brightness];
colour.r *= multiplier;
colour.g *= multiplier;
colour.b *= multiplier;
@ -109,12 +109,12 @@ namespace ams::controller {
void Dualshock4Controller::MapInputReport0x01(const Dualshock4ReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
this->MapButtons(&src->input0x01.buttons);
@ -143,12 +143,12 @@ namespace ams::controller {
m_battery = static_cast<u8>(8 * (battery_level + 2) / 10) & 0x0e;
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x11.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x11.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x11.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x11.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x11.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x11.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x11.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x11.right_stick.y)) & UINT12_MAX
);
this->MapButtons(&src->input0x11.buttons);
@ -166,9 +166,9 @@ namespace ams::controller {
if (active) {
u16 x = (point->x_hi << 8) | point->x_lo;
if (x < (0.15 * touchpad_width)) {
if (x < (0.15 * TouchpadWidth)) {
m_buttons.minus = 1;
} else if (x > (0.85 * touchpad_width)) {
} else if (x > (0.85 * TouchpadWidth)) {
m_buttons.plus = 1;
} else {
m_buttons.capture = 1;
@ -181,13 +181,13 @@ namespace ams::controller {
}
if (m_enable_motion) {
s16 acc_x = -static_cast<s16>(accel_scale_factor * src->input0x11.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(accel_scale_factor * src->input0x11.acc_x / float(m_motion_calibration.acc.x_max));
s16 acc_z = static_cast<s16>(accel_scale_factor * src->input0x11.acc_y / float(m_motion_calibration.acc.y_max));
s16 acc_x = -static_cast<s16>(AccelScaleFactor * src->input0x11.acc_z / float(m_motion_calibration.acc.z_max));
s16 acc_y = -static_cast<s16>(AccelScaleFactor * src->input0x11.acc_x / float(m_motion_calibration.acc.x_max));
s16 acc_z = static_cast<s16>(AccelScaleFactor * src->input0x11.acc_y / float(m_motion_calibration.acc.y_max));
s16 vel_x = -static_cast<s16>(gyro_scale_factor * (src->input0x11.vel_z - m_motion_calibration.gyro.roll_bias) / ((m_motion_calibration.gyro.roll_max - m_motion_calibration.gyro.roll_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_y = -static_cast<s16>(gyro_scale_factor * (src->input0x11.vel_x - m_motion_calibration.gyro.pitch_bias) / ((m_motion_calibration.gyro.pitch_max - m_motion_calibration.gyro.pitch_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_z = static_cast<s16>(gyro_scale_factor * (src->input0x11.vel_y - m_motion_calibration.gyro.yaw_bias) / ((m_motion_calibration.gyro.yaw_max- m_motion_calibration.gyro.yaw_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_x = -static_cast<s16>(GyroScaleFactor * (src->input0x11.vel_z - m_motion_calibration.gyro.roll_bias) / ((m_motion_calibration.gyro.roll_max - m_motion_calibration.gyro.roll_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_y = -static_cast<s16>(GyroScaleFactor * (src->input0x11.vel_x - m_motion_calibration.gyro.pitch_bias) / ((m_motion_calibration.gyro.pitch_max - m_motion_calibration.gyro.pitch_bias) / m_motion_calibration.gyro.speed_max));
s16 vel_z = static_cast<s16>(GyroScaleFactor * (src->input0x11.vel_y - m_motion_calibration.gyro.yaw_bias) / ((m_motion_calibration.gyro.yaw_max- m_motion_calibration.gyro.yaw_bias) / m_motion_calibration.gyro.speed_max));
m_motion_data[0].gyro_1 = vel_x;
m_motion_data[0].gyro_2 = vel_y;
@ -281,7 +281,7 @@ namespace ams::controller {
report.output0x11.data[7] = m_lightbar_colour.r;
report.output0x11.data[8] = m_lightbar_colour.g;
report.output0x11.data[9] = m_lightbar_colour.b;
report.output0x11.crc = crc32CalculateWithSeed(crc_seed, report.output0x11.data, sizeof(report.output0x11.data));
report.output0x11.crc = crc32CalculateWithSeed(CrcSeed, report.output0x11.data, sizeof(report.output0x11.data));
m_output_report.size = sizeof(report.output0x11) + sizeof(report.id);
std::memcpy(m_output_report.data, &report, m_output_report.size);

View file

@ -22,7 +22,7 @@ namespace ams::controller {
// Frequency in Hz rounded to nearest int
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md#frequency-table
const u16 rumble_freq_lut[] = {
constinit const u16 RumbleFreqLookup[] = {
0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, 0x0030, 0x0031,
0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0039, 0x003a, 0x003b,
0x003c, 0x003e, 0x003f, 0x0040, 0x0042, 0x0043, 0x0045, 0x0046, 0x0048,
@ -42,12 +42,12 @@ namespace ams::controller {
0x039d, 0x03b1, 0x03c6, 0x03db, 0x03f1, 0x0407, 0x041d, 0x0434, 0x044c,
0x0464, 0x047d, 0x0496, 0x04af, 0x04ca, 0x04e5
};
constexpr size_t rumble_freq_lut_size = sizeof(rumble_freq_lut) / sizeof(u16);
constexpr size_t RumbleFreqLookupSize = sizeof(RumbleFreqLookup) / sizeof(u16);
// Floats from dekunukem repo normalised and scaled by function used by yuzu
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md#amplitude-table
// https://github.com/yuzu-emu/yuzu/blob/d3a4a192fe26e251f521f0311b2d712f5db9918e/src/input_common/sdl/sdl_impl.cpp#L429
const float rumble_amp_lut_f[] = {
constinit const float RumbleAmpLookup[] = {
0.000000, 0.120576, 0.137846, 0.146006, 0.154745, 0.164139, 0.174246,
0.185147, 0.196927, 0.209703, 0.223587, 0.238723, 0.255268, 0.273420,
0.293398, 0.315462, 0.321338, 0.327367, 0.333557, 0.339913, 0.346441,
@ -64,7 +64,7 @@ namespace ams::controller {
0.883035, 0.895119, 0.907420, 0.919943, 0.932693, 0.945673, 0.958889,
0.972345, 0.986048, 1.000000
};
constexpr size_t rumble_amp_lut_f_size = sizeof(rumble_amp_lut_f) / sizeof(float);
constexpr size_t RumbleAmpLookupSize = sizeof(RumbleAmpLookup) / sizeof(float);
void DecodeRumbleValues(const u8 enc[], SwitchRumbleData *dec) {
u8 hi_freq_ind = 0x20 + (enc[0] >> 2) + ((enc[1] & 0x01) * 0x40) - 1;
@ -72,22 +72,22 @@ namespace ams::controller {
u8 lo_freq_ind = (enc[2] & 0x7f) - 1;
u8 lo_amp_ind = ((enc[3] - 0x40) << 1) + ((enc[2] & 0x80) >> 7);
if (!((hi_freq_ind < rumble_freq_lut_size) &&
(hi_amp_ind < rumble_amp_lut_f_size) &&
(lo_freq_ind < rumble_freq_lut_size) &&
(lo_amp_ind < rumble_amp_lut_f_size))) {
if (!((hi_freq_ind < RumbleFreqLookupSize) &&
(hi_amp_ind < RumbleAmpLookupSize) &&
(lo_freq_ind < RumbleFreqLookupSize) &&
(lo_amp_ind < RumbleAmpLookupSize))) {
std::memset(dec, 0, sizeof(SwitchRumbleData));
return;
}
dec->high_band_freq = float(rumble_freq_lut[hi_freq_ind]);
dec->high_band_amp = rumble_amp_lut_f[hi_amp_ind];
dec->low_band_freq = float(rumble_freq_lut[lo_freq_ind]);
dec->low_band_amp = rumble_amp_lut_f[lo_amp_ind];
dec->high_band_freq = float(RumbleFreqLookup[hi_freq_ind]);
dec->high_band_amp = RumbleAmpLookup[hi_amp_ind];
dec->low_band_freq = float(RumbleFreqLookup[lo_freq_ind]);
dec->low_band_amp = RumbleAmpLookup[lo_amp_ind];
}
// CRC-8 with polynomial 0x7 for NFC/IR packets
u8 crc8_lut[] = {
constinit const u8 Crc8Lookup[] = {
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
@ -111,7 +111,7 @@ namespace ams::controller {
u8 crc = 0x00;
for (size_t i = 0; i < size; ++i) {
crc = crc8_lut[crc ^ bytes[i]];
crc = Crc8Lookup[crc ^ bytes[i]];
}
return crc;
}

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -41,12 +41,12 @@ namespace ams::controller {
void GamesirController::MapInputReport0x03(const GamesirReportData *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
static_cast<u16>(StickScaleFactor * src->input0x03.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (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
static_cast<u16>(StickScaleFactor * src->input0x03.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x03.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x03.buttons.dpad == GamesirDpad2_S) ||
@ -87,12 +87,12 @@ namespace ams::controller {
void GamesirController::MapInputReport0xc4(const GamesirReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0xc4.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0xc4.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0xc4.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0xc4.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0xc4.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0xc4.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0xc4.buttons.dpad == GamesirDpad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -44,12 +44,12 @@ namespace ams::controller {
void GamestickController::MapInputReport0x03(const GamestickReportData *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
static_cast<u16>(StickScaleFactor * src->input0x03.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (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
static_cast<u16>(StickScaleFactor * src->input0x03.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x03.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x03.dpad == GamestickDPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -44,12 +44,12 @@ namespace ams::controller {
void GemboxController::MapInputReport0x07(const GemboxReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input0x07.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX + static_cast<s8>(~src->input0x07.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input0x07.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX + static_cast<s8>(~src->input0x07.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input0x07.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX + static_cast<s8>(~src->input0x07.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input0x07.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX + static_cast<s8>(~src->input0x07.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x07.dpad == GemboxDPad_S) ||

View file

@ -18,10 +18,6 @@
namespace ams::controller {
namespace {
}
void HyperkinController::ProcessInputData(const bluetooth::HidReport *report) {
auto hyperkin_report = reinterpret_cast<const HyperkinReportData *>(&report->data);

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -43,12 +43,12 @@ namespace ams::controller {
void IpegaController::MapInputReport0x07(const IpegaReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x07.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x07.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x07.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x07.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x07.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x07.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x07.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x07.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x07.buttons.dpad == IpegaDPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -37,12 +37,12 @@ namespace ams::controller {
void LanShenController::MapInputReport0x01(const LanShenReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.buttons.dpad == LanShenDPad_S) ||

View file

@ -20,8 +20,8 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
const constexpr float media_mode_stick_scale_factor = float(UINT12_MAX) / 39;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
constexpr float MediaModeStickScaleFactor = float(UINT12_MAX) / 39;
}
@ -46,12 +46,12 @@ namespace ams::controller {
void MadCatzController::MapInputReport0x01(const MadCatzReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.buttons.dpad == MadCatzDPad_S) ||
@ -93,12 +93,12 @@ namespace ams::controller {
void MadCatzController::MapInputReport0x81(const MadCatzReportData *src) {
m_left_stick.SetData(
static_cast<uint16_t>(stick_scale_factor * src->input0x81.left_stick.x) & UINT12_MAX,
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x81.left_stick.y)) & UINT12_MAX
static_cast<uint16_t>(StickScaleFactor * src->input0x81.left_stick.x) & UINT12_MAX,
static_cast<uint16_t>(StickScaleFactor * (UINT8_MAX - src->input0x81.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<uint16_t>(stick_scale_factor * src->input0x81.right_stick.x) & UINT12_MAX,
static_cast<uint16_t>(stick_scale_factor * (UINT8_MAX - src->input0x81.right_stick.y)) & UINT12_MAX
static_cast<uint16_t>(StickScaleFactor * src->input0x81.right_stick.x) & UINT12_MAX,
static_cast<uint16_t>(StickScaleFactor * (UINT8_MAX - src->input0x81.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x81.buttons.dpad == MadCatzDPad_S) ||
@ -149,8 +149,8 @@ namespace ams::controller {
void MadCatzController::MapInputReport0x83(const MadCatzReportData *src) {
m_left_stick.SetData(
std::clamp<uint16_t>(media_mode_stick_scale_factor * -src->input0x83.left_stick.x + 0x7ff, STICK_MIN, STICK_MAX),
std::clamp<uint16_t>(media_mode_stick_scale_factor * src->input0x83.left_stick.y + 0x7ff, STICK_MIN, STICK_MAX)
std::clamp<uint16_t>(MediaModeStickScaleFactor * -src->input0x83.left_stick.x + 0x7ff, STICK_MIN, STICK_MAX),
std::clamp<uint16_t>(MediaModeStickScaleFactor * src->input0x83.left_stick.y + 0x7ff, STICK_MIN, STICK_MAX)
);
m_buttons.ZR = src->input0x83.buttons.R2;

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -74,12 +74,12 @@ namespace ams::controller {
void MocuteController::MapAnalogSticks(const MocuteStickData *left_stick, const MocuteStickData *right_stick) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * left_stick->x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - left_stick->y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * left_stick->x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - left_stick->y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * right_stick->x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - right_stick->y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * right_stick->x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - right_stick->y)) & UINT12_MAX
);
}

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT16_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT16_MAX;
}
@ -39,12 +39,12 @@ namespace ams::controller {
void NvidiaShieldController::MapInputReport0x01(const NvidiaShieldReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.dpad == NvidiaShieldDPad_S) ||

View file

@ -21,7 +21,7 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT16_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT16_MAX;
}
@ -44,12 +44,12 @@ namespace ams::controller {
void OuyaController::MapInputReport0x07(const OuyaReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x07.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x07.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x07.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x07.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x07.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x07.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x07.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x07.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = src->input0x07.buttons.dpad_down;

View file

@ -21,7 +21,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -40,12 +40,12 @@ namespace ams::controller {
m_battery = convert_battery_255(src->input0x03.battery);
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
static_cast<u16>(StickScaleFactor * src->input0x03.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (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
static_cast<u16>(StickScaleFactor * src->input0x03.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x03.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x03.buttons.dpad == PowerADPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -37,12 +37,12 @@ namespace ams::controller {
void RazerController::MapInputReport0x01(const RazerReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.buttons.dpad == RazerDPad_S) ||

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -50,12 +50,12 @@ namespace ams::controller {
void SteelseriesController::MapInputReport0x01(const SteelseriesReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input0x01.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX + static_cast<s8>(~src->input0x01.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input0x01.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX + static_cast<s8>(~src->input0x01.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input0x01.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX + static_cast<s8>(~src->input0x01.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input0x01.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX + static_cast<s8>(~src->input0x01.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x01.dpad == SteelseriesDPad_S) ||
@ -133,12 +133,12 @@ namespace ams::controller {
void SteelseriesController::MapInputReport0xc4(const SteelseriesReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0xc4.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0xc4.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0xc4.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0xc4.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0xc4.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0xc4.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0xc4.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0xc4.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0xc4.dpad == SteelseriesDPad2_S) ||
@ -173,12 +173,12 @@ namespace ams::controller {
void SteelseriesController::MapMfiInputReport(const SteelseriesReportData *src) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input_mfi.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (-static_cast<s8>(~src->input_mfi.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input_mfi.left_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (-static_cast<s8>(~src->input_mfi.left_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * -static_cast<s8>(~src->input_mfi.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (-static_cast<s8>(~src->input_mfi.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
static_cast<u16>(StickScaleFactor * -static_cast<s8>(~src->input_mfi.right_stick.x + 1) + 0x7ff) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (-static_cast<s8>(~src->input_mfi.right_stick.y + 1)) + 0x7ff) & UINT12_MAX
);
m_buttons.dpad_up = src->input_mfi.buttons.dpad_up > 0;

View file

@ -21,7 +21,7 @@ namespace ams::controller {
namespace {
const u8 led_player_mappings[] = {
constinit const u8 LedPlayerMappings[] = {
SwitchPlayerNumber_Unknown, //0000
SwitchPlayerNumber_One, //0001
SwitchPlayerNumber_Unknown, //0010
@ -43,7 +43,7 @@ namespace ams::controller {
}
Result LedsMaskToPlayerNumber(u8 led_mask, u8 *player_number) {
*player_number = led_player_mappings[(led_mask & 0xf) | (led_mask >> 4)];
*player_number = LedPlayerMappings[(led_mask & 0xf) | (led_mask >> 4)];
if (*player_number == SwitchPlayerNumber_Unknown) {
return -1;
}

View file

@ -338,9 +338,7 @@ namespace ams::controller {
SwitchController(const bluetooth::Address *address, HardwareID id)
: m_address(*address)
, m_id(id)
, m_input_mutex(false)
, m_output_mutex(false) { }
, m_id(id) { }
virtual ~SwitchController() { };
@ -367,10 +365,10 @@ namespace ams::controller {
bluetooth::Address m_address;
HardwareID m_id;
os::Mutex m_input_mutex;
os::SdkMutex m_input_mutex;
bluetooth::HidReport m_input_report;
os::Mutex m_output_mutex;
os::SdkMutex m_output_mutex;
bluetooth::HidReport m_output_report;
std::queue<std::shared_ptr<HidResponse>> m_future_responses;

View file

@ -20,14 +20,14 @@ namespace ams::controller {
namespace {
constexpr size_t spi_flash_size = 0x10000;
constexpr size_t SpiFlashSize = 0x10000;
// Factory calibration data representing analog stick ranges that span the entire 12-bit data type in x and y
SwitchAnalogStickFactoryCalibration lstick_factory_calib = {0xff, 0xf7, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x08, 0x80};
SwitchAnalogStickFactoryCalibration rstick_factory_calib = {0x00, 0x08, 0x80, 0x00, 0x08, 0x80, 0xff, 0xf7, 0x7f};
constinit const SwitchAnalogStickFactoryCalibration lstick_factory_calib = { 0xff, 0xf7, 0x7f, 0x00, 0x08, 0x80, 0x00, 0x08, 0x80 };
constinit const SwitchAnalogStickFactoryCalibration rstick_factory_calib = { 0x00, 0x08, 0x80, 0x00, 0x08, 0x80, 0xff, 0xf7, 0x7f };
// Stick parameters data that produce a 12.5% inner deadzone and a 5% outer deadzone (in relation to the full 12 bit range above)
SwitchAnalogStickParameters default_stick_params = {0x0f, 0x30, 0x61, 0x00, 0x31, 0xf3, 0xd4, 0x14, 0x54, 0x41, 0x15, 0x54, 0xc7, 0x79, 0x9c, 0x33, 0x36, 0x63};
constinit const SwitchAnalogStickParameters default_stick_params = { 0x0f, 0x30, 0x61, 0x00, 0x31, 0xf3, 0xd4, 0x14, 0x54, 0x41, 0x15, 0x54, 0xc7, 0x79, 0x9c, 0x33, 0x36, 0x63 };
}
@ -94,7 +94,7 @@ namespace ams::controller {
Result VirtualSpiFlash::CreateFile(const char *path) {
// Create file representing first 64KB of SPI flash
R_TRY(fs::CreateFile(path, spi_flash_size));
R_TRY(fs::CreateFile(path, SpiFlashSize));
R_TRY(fs::OpenFile(std::addressof(m_virtual_memory_file), path, fs::OpenMode_Write));
ON_SCOPE_EXIT { fs::CloseFile(m_virtual_memory_file); };
@ -103,8 +103,8 @@ namespace ams::controller {
u8 buff[64];
std::memset(buff, 0xff, sizeof(buff));
unsigned int offset = 0;
while (offset < spi_flash_size) {
size_t write_size = std::min(static_cast<size_t>(spi_flash_size - offset), sizeof(buff));
while (offset < SpiFlashSize) {
size_t write_size = std::min(static_cast<size_t>(SpiFlashSize - offset), sizeof(buff));
R_TRY(fs::WriteFile(m_virtual_memory_file, offset, buff, write_size, fs::WriteOption::None));
offset += write_size;
}

View file

@ -22,20 +22,20 @@ namespace ams::controller {
namespace {
constexpr u8 init_data1[] = {0x55};
constexpr u8 init_data2[] = {0x00};
constinit const u8 InitData1[] = { 0x55 };
constinit const u8 InitData2[] = { 0x00 };
constexpr float nunchuck_stick_scale_factor = float(UINT12_MAX) / 0xb8;
constexpr float wiiu_scale_factor = 2.0;
constexpr float left_stick_scale_factor = float(UINT12_MAX) / 0x3f;
constexpr float right_stick_scale_factor = float(UINT12_MAX) / 0x1f;
constexpr float NunchuckStickScaleFactor = float(UINT12_MAX) / 0xb8;
constexpr float WiiUStickScaleFactor = 2.0;
constexpr float LeftStickScaleFactor = float(UINT12_MAX) / 0x3f;
constexpr float RighStickScaleFactor = float(UINT12_MAX) / 0x1f;
constexpr float accel_scale_factor = 65535 / 16000.0f * 1000;
constexpr float gyro_scale_factor = 65535 / (13371 * 360.0f) * 1000;
constexpr float AccelScaleFactor = 65535 / 16000.0f * 1000;
constexpr float GyroScaleFactor = 65535 / (13371 * 360.0f) * 1000;
const u16 dpad_stick_positions[] = { STICK_MIN, STICK_CENTER, STICK_MAX };
constinit const u16 DpadStickPositions[] = { STICK_MIN, STICK_CENTER, STICK_MAX };
float CalibrateWeightData(u16 x, u16 cal_0kg, u16 cal_17kg, u16 cal_34kg) {
constexpr float CalibrateWeightData(u16 x, u16 cal_0kg, u16 cal_17kg, u16 cal_34kg) {
x = util::SwapEndian(x);
if (x < cal_0kg) {
@ -47,7 +47,7 @@ namespace ams::controller {
}
}
float ApplyEasingFunction(float x) {
constexpr float ApplyEasingFunction(float x) {
constexpr float a = 3.0;
constexpr float s = 0.15;
@ -163,8 +163,8 @@ namespace ams::controller {
if (m_orientation == WiiControllerOrientation_Horizontal) {
// Map dpad as left stick to increase compatibility with games not supporting movement via dpad
m_left_stick.SetData(
dpad_stick_positions[1 + buttons->dpad_down - buttons->dpad_up],
dpad_stick_positions[1 + buttons->dpad_right - buttons->dpad_left]
DpadStickPositions[1 + buttons->dpad_down - buttons->dpad_up],
DpadStickPositions[1 + buttons->dpad_right - buttons->dpad_left]
);
m_buttons.A = buttons->two;
@ -209,9 +209,9 @@ namespace ams::controller {
u16 y_raw = (accel->y << 2) | (((buttons->raw[1] >> 4) & 0x1) << 1);
u16 z_raw = (accel->z << 2) | (((buttons->raw[1] >> 5) & 0x1) << 1);
s16 x = -static_cast<s16>(accel_scale_factor * (float(x_raw - m_accel_calibration.acc_x_0g) / float(m_accel_calibration.acc_x_1g - m_accel_calibration.acc_x_0g)));
s16 y = -static_cast<s16>(accel_scale_factor * (float(y_raw - m_accel_calibration.acc_y_0g) / float(m_accel_calibration.acc_y_1g - m_accel_calibration.acc_y_0g)));
s16 z = static_cast<s16>(accel_scale_factor * (float(z_raw - m_accel_calibration.acc_z_0g) / float(m_accel_calibration.acc_z_1g - m_accel_calibration.acc_z_0g)));
s16 x = -static_cast<s16>(AccelScaleFactor * (float(x_raw - m_accel_calibration.acc_x_0g) / float(m_accel_calibration.acc_x_1g - m_accel_calibration.acc_x_0g)));
s16 y = -static_cast<s16>(AccelScaleFactor * (float(y_raw - m_accel_calibration.acc_y_0g) / float(m_accel_calibration.acc_y_1g - m_accel_calibration.acc_y_0g)));
s16 z = static_cast<s16>(AccelScaleFactor * (float(z_raw - m_accel_calibration.acc_z_0g) / float(m_accel_calibration.acc_z_1g - m_accel_calibration.acc_z_0g)));
if (m_orientation == WiiControllerOrientation_Horizontal) {
m_motion_data[0].accel_x = x;
@ -268,8 +268,8 @@ namespace ams::controller {
auto extension_data = reinterpret_cast<const WiiNunchuckExtensionData *>(ext);
m_left_stick.SetData(
std::clamp<u16>(static_cast<u16>(nunchuck_stick_scale_factor * (extension_data->stick_x - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX),
std::clamp<u16>(static_cast<u16>(nunchuck_stick_scale_factor * (extension_data->stick_y - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX)
std::clamp<u16>(static_cast<u16>(NunchuckStickScaleFactor * (extension_data->stick_x - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX),
std::clamp<u16>(static_cast<u16>(NunchuckStickScaleFactor * (extension_data->stick_y - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX)
);
m_buttons.L = !extension_data->C;
@ -280,12 +280,12 @@ namespace ams::controller {
auto extension_data = reinterpret_cast<const WiiClassicControllerExtensionData *>(ext);
m_left_stick.SetData(
static_cast<u16>(left_stick_scale_factor * (extension_data->left_stick_x - 0x20) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(left_stick_scale_factor * (extension_data->left_stick_y - 0x20) + STICK_CENTER) & UINT12_MAX
static_cast<u16>(LeftStickScaleFactor * (extension_data->left_stick_x - 0x20) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(LeftStickScaleFactor * (extension_data->left_stick_y - 0x20) + STICK_CENTER) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(right_stick_scale_factor * (((extension_data->right_stick_x_43 << 3) | (extension_data->right_stick_x_21 << 1) | extension_data->right_stick_x_0) - 0x10) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(right_stick_scale_factor * (extension_data->right_stick_y - 0x10) + STICK_CENTER) & UINT12_MAX
static_cast<u16>(RighStickScaleFactor * (((extension_data->right_stick_x_43 << 3) | (extension_data->right_stick_x_21 << 1) | extension_data->right_stick_x_0) - 0x10) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(RighStickScaleFactor * (extension_data->right_stick_y - 0x10) + STICK_CENTER) & UINT12_MAX
);
m_buttons.dpad_down |= !extension_data->buttons.dpad_down;
@ -313,12 +313,12 @@ namespace ams::controller {
auto extension_data = reinterpret_cast<const WiiUProExtensionData *>(ext);
m_left_stick.SetData(
std::clamp<u16>(((wiiu_scale_factor * (extension_data->left_stick_x - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX),
std::clamp<u16>(((wiiu_scale_factor * (extension_data->left_stick_y - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX)
std::clamp<u16>(((WiiUStickScaleFactor * (extension_data->left_stick_x - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX),
std::clamp<u16>(((WiiUStickScaleFactor * (extension_data->left_stick_y - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX)
);
m_right_stick.SetData(
std::clamp<u16>(((wiiu_scale_factor * (extension_data->right_stick_x - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX),
std::clamp<u16>(((wiiu_scale_factor * (extension_data->right_stick_y - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX)
std::clamp<u16>(((WiiUStickScaleFactor * (extension_data->right_stick_x - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX),
std::clamp<u16>(((WiiUStickScaleFactor * (extension_data->right_stick_y - STICK_CENTER))) + STICK_CENTER, STICK_MIN, STICK_MAX)
);
m_buttons.dpad_down = !extension_data->buttons.dpad_down;
@ -402,9 +402,9 @@ namespace ams::controller {
u16 scale_deg_roll = 6 * (extension_data->roll_slow_mode ? m_ext_calibration.motion_plus.slow.degrees_div_6 : m_ext_calibration.motion_plus.fast.degrees_div_6);
u16 scale_deg_yaw = 6 * (extension_data->yaw_slow_mode ? m_ext_calibration.motion_plus.slow.degrees_div_6 : m_ext_calibration.motion_plus.fast.degrees_div_6);
s16 pitch = static_cast<s16>(gyro_scale_factor * (float(pitch_raw - pitch_0deg) / (float(pitch_scale - pitch_0deg) / scale_deg_pitch)));
s16 roll = -static_cast<s16>(gyro_scale_factor * (float(roll_raw - roll_0deg) / (float(roll_scale - roll_0deg) / scale_deg_roll)));
s16 yaw = -static_cast<s16>(gyro_scale_factor * (float(yaw_raw - yaw_0deg) / (float(yaw_scale - yaw_0deg) / scale_deg_yaw)));
s16 pitch = static_cast<s16>(GyroScaleFactor * (float(pitch_raw - pitch_0deg) / (float(pitch_scale - pitch_0deg) / scale_deg_pitch)));
s16 roll = -static_cast<s16>(GyroScaleFactor * (float(roll_raw - roll_0deg) / (float(roll_scale - roll_0deg) / scale_deg_roll)));
s16 yaw = -static_cast<s16>(GyroScaleFactor * (float(yaw_raw - yaw_0deg) / (float(yaw_scale - yaw_0deg) / scale_deg_yaw)));
if (m_orientation == WiiControllerOrientation_Horizontal) {
m_motion_data[0].gyro_1 = pitch;
@ -444,8 +444,8 @@ namespace ams::controller {
auto extension_data = reinterpret_cast<const WiiNunchuckPassthroughExtensionData *>(ext);
m_left_stick.SetData(
std::clamp<u16>(static_cast<u16>(nunchuck_stick_scale_factor * (extension_data->stick_x - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX),
std::clamp<u16>(static_cast<u16>(nunchuck_stick_scale_factor * (extension_data->stick_y - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX)
std::clamp<u16>(static_cast<u16>(NunchuckStickScaleFactor * (extension_data->stick_x - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX),
std::clamp<u16>(static_cast<u16>(NunchuckStickScaleFactor * (extension_data->stick_y - 0x80) + STICK_CENTER), STICK_MIN, STICK_MAX)
);
m_buttons.L = !extension_data->C;
@ -456,12 +456,12 @@ namespace ams::controller {
auto extension_data = reinterpret_cast<const WiiClassicControllerPassthroughExtensionData *>(ext);
m_left_stick.SetData(
static_cast<u16>(left_stick_scale_factor * ((extension_data->left_stick_x_51 << 1) - 0x20) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(left_stick_scale_factor * ((extension_data->left_stick_y_51 << 1) - 0x20) + STICK_CENTER) & UINT12_MAX
static_cast<u16>(LeftStickScaleFactor * ((extension_data->left_stick_x_51 << 1) - 0x20) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(LeftStickScaleFactor * ((extension_data->left_stick_y_51 << 1) - 0x20) + STICK_CENTER) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(right_stick_scale_factor * (((extension_data->right_stick_x_43 << 3) | (extension_data->right_stick_x_21 << 1) | extension_data->right_stick_x_0) - 0x10) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(right_stick_scale_factor * (extension_data->right_stick_y - 0x10) + STICK_CENTER) & UINT12_MAX
static_cast<u16>(RighStickScaleFactor * (((extension_data->right_stick_x_43 << 3) | (extension_data->right_stick_x_21 << 1) | extension_data->right_stick_x_0) - 0x10) + STICK_CENTER) & UINT12_MAX,
static_cast<u16>(RighStickScaleFactor * (extension_data->right_stick_y - 0x10) + STICK_CENTER) & UINT12_MAX
);
m_buttons.dpad_down |= !extension_data->buttons.dpad_down;
@ -826,14 +826,14 @@ namespace ams::controller {
}
Result WiiController::InitializeStandardExtension() {
R_TRY(this->WriteMemory(0x04a400f0, init_data1, sizeof(init_data1)));
R_TRY(this->WriteMemory(0x04a400fb, init_data2, sizeof(init_data2)));
R_TRY(this->WriteMemory(0x04a400f0, InitData1, sizeof(InitData1)));
R_TRY(this->WriteMemory(0x04a400fb, InitData2, sizeof(InitData2)));
R_SUCCEED();
}
Result WiiController::InitializeMotionPlus() {
R_TRY(this->WriteMemory(0x04a600f0, init_data1, sizeof(init_data1)));
R_TRY(this->WriteMemory(0x04a600f0, InitData1, sizeof(InitData1)));
// Get the MotionPlus calibration
R_TRY(this->GetMotionPlusCalibration(&m_ext_calibration.motion_plus));
@ -893,7 +893,7 @@ namespace ams::controller {
}
Result WiiController::DeactivateMotionPlus() {
R_RETURN(this->WriteMemory(0x04a400f0, init_data1, sizeof(init_data1)));
R_RETURN(this->WriteMemory(0x04a400f0, InitData1, sizeof(InitData1)));
}
Result WiiController::UpdateMotionPlusExtensionStatus(bool extension_connected) {

View file

@ -20,7 +20,7 @@ namespace ams::controller {
namespace {
constexpr float stick_scale_factor = float(UINT12_MAX) / UINT16_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT16_MAX;
}
@ -55,12 +55,12 @@ namespace ams::controller {
void XboxOneController::MapInputReport0x01(const XboxOneReportData *src, bool new_format) {
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x01.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT16_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x01.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT16_MAX - src->input0x01.right_stick.y)) & UINT12_MAX
);
m_buttons.ZR = src->input0x01.right_trigger > (m_trigger_threshold * 0x3ff);

View file

@ -21,9 +21,9 @@ namespace ams::controller {
namespace {
constexpr u8 init_packet[] = {0x20, 0x00, 0x00}; // packet to init vibration apparently
constinit const u8 InitPacket[] = { 0x20, 0x00, 0x00 }; // packet to init vibration apparently
const constexpr float stick_scale_factor = float(UINT12_MAX) / UINT8_MAX;
constexpr float StickScaleFactor = float(UINT12_MAX) / UINT8_MAX;
}
@ -32,8 +32,8 @@ namespace ams::controller {
std::scoped_lock lk(m_output_mutex);
m_output_report.size = sizeof(init_packet);
std::memcpy(m_output_report.data, init_packet, sizeof(init_packet));
m_output_report.size = sizeof(InitPacket);
std::memcpy(m_output_report.data, InitPacket, sizeof(InitPacket));
R_TRY(this->WriteDataReport(&m_output_report));
R_SUCCEED();
@ -54,12 +54,12 @@ namespace ams::controller {
m_battery = convert_battery_100(src->input0x04.battery);
m_left_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x04.left_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x04.left_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x04.left_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x04.left_stick.y)) & UINT12_MAX
);
m_right_stick.SetData(
static_cast<u16>(stick_scale_factor * src->input0x04.right_stick.x) & UINT12_MAX,
static_cast<u16>(stick_scale_factor * (UINT8_MAX - src->input0x04.right_stick.y)) & UINT12_MAX
static_cast<u16>(StickScaleFactor * src->input0x04.right_stick.x) & UINT12_MAX,
static_cast<u16>(StickScaleFactor * (UINT8_MAX - src->input0x04.right_stick.y)) & UINT12_MAX
);
m_buttons.dpad_down = (src->input0x04.buttons.dpad == XiaomiDPad_S) ||

View file

@ -48,10 +48,10 @@ namespace ams::mc {
}
}
const s32 ThreadPriority = 20;
const size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = 20;
constexpr size_t ThreadStackSize = 0x1000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
void MissionControlThreadFunction(void *) {
R_ABORT_UNLESS(g_server_manager.RegisterServer(PortIndex_MissionControl, MissionControlServiceName, MaxSessions));

View file

@ -20,11 +20,11 @@ namespace ams::mitm {
namespace {
constexpr const char *config_file_location = "sdmc:/config/MissionControl/missioncontrol.ini";
constexpr const char config_file_location[] = "sdmc:/config/MissionControl/missioncontrol.ini";
SetLanguage g_system_language;
constinit SetLanguage g_system_language;
MissionControlConfig g_global_config = {
constinit MissionControlConfig g_global_config = {
.general = {
.enable_rumble = true,
.enable_motion = true

View file

@ -111,8 +111,8 @@ namespace ams::mitm {
}
void LaunchModules() {
const s32 ThreadPriority = -7;
const size_t ThreadStackSize = 0x1000;
constexpr s32 ThreadPriority = -7;
constexpr size_t ThreadStackSize = 0x1000;
os::ThreadType init_thread;
// Allocate temporary thread stack on heap

View file

@ -19,7 +19,7 @@ namespace ams::mc {
namespace {
ncm::ProgramId g_current_program = ncm::InvalidProgramId;
constinit ncm::ProgramId g_current_program = ncm::InvalidProgramId;
os::Event g_process_switch_event(os::EventClearMode_AutoClear);
Result _GetCurrentApplicationProgramId(ncm::ProgramId *program_id) {

View file

@ -69,10 +69,10 @@ namespace ams::usb {
R_SUCCEED();
}
const s32 ThreadPriority = 9;
const size_t ThreadStackSize = 0x4000;
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
os::ThreadType g_thread;
constexpr s32 ThreadPriority = 9;
constexpr size_t ThreadStackSize = 0x4000;
alignas(os::ThreadStackAlignment) constinit u8 g_thread_stack[ThreadStackSize];
constinit os::ThreadType g_thread;
void UsbThreadFunction(void *) {
Event if_event;