|
|
@ -12,7 +12,7 @@ JoyconPoller::JoyconPoller(ControllerType device_type_, JoyStickCalibration left
|
|
|
|
: device_type{device_type_}, left_stick_calibration{left_stick_calibration_},
|
|
|
|
: device_type{device_type_}, left_stick_calibration{left_stick_calibration_},
|
|
|
|
right_stick_calibration{right_stick_calibration_}, motion_calibration{motion_calibration_} {}
|
|
|
|
right_stick_calibration{right_stick_calibration_}, motion_calibration{motion_calibration_} {}
|
|
|
|
|
|
|
|
|
|
|
|
void JoyconPoller::SetCallbacks(const Joycon::JoyconCallbacks& callbacks_) {
|
|
|
|
void JoyconPoller::SetCallbacks(const JoyconCallbacks& callbacks_) {
|
|
|
|
callbacks = std::move(callbacks_);
|
|
|
|
callbacks = std::move(callbacks_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -22,13 +22,13 @@ void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& moti
|
|
|
|
memcpy(&data, buffer.data(), sizeof(InputReportActive));
|
|
|
|
memcpy(&data, buffer.data(), sizeof(InputReportActive));
|
|
|
|
|
|
|
|
|
|
|
|
switch (device_type) {
|
|
|
|
switch (device_type) {
|
|
|
|
case Joycon::ControllerType::Left:
|
|
|
|
case ControllerType::Left:
|
|
|
|
UpdateActiveLeftPadInput(data, motion_status);
|
|
|
|
UpdateActiveLeftPadInput(data, motion_status);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Joycon::ControllerType::Right:
|
|
|
|
case ControllerType::Right:
|
|
|
|
UpdateActiveRightPadInput(data, motion_status);
|
|
|
|
UpdateActiveRightPadInput(data, motion_status);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Joycon::ControllerType::Pro:
|
|
|
|
case ControllerType::Pro:
|
|
|
|
UpdateActiveProPadInput(data, motion_status);
|
|
|
|
UpdateActiveProPadInput(data, motion_status);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -47,13 +47,13 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) {
|
|
|
|
memcpy(&data, buffer.data(), sizeof(InputReportPassive));
|
|
|
|
memcpy(&data, buffer.data(), sizeof(InputReportPassive));
|
|
|
|
|
|
|
|
|
|
|
|
switch (device_type) {
|
|
|
|
switch (device_type) {
|
|
|
|
case Joycon::ControllerType::Left:
|
|
|
|
case ControllerType::Left:
|
|
|
|
UpdatePasiveLeftPadInput(data);
|
|
|
|
UpdatePasiveLeftPadInput(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Joycon::ControllerType::Right:
|
|
|
|
case ControllerType::Right:
|
|
|
|
UpdatePasiveRightPadInput(data);
|
|
|
|
UpdatePasiveRightPadInput(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case Joycon::ControllerType::Pro:
|
|
|
|
case ControllerType::Pro:
|
|
|
|
UpdatePasiveProPadInput(data);
|
|
|
|
UpdatePasiveProPadInput(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -211,13 +211,11 @@ void JoyconPoller::UpdateActiveProPadInput(const InputReportActive& input,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
|
|
|
|
void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
|
|
|
|
static constexpr std::array<Joycon::PasivePadButton, 11> left_buttons{
|
|
|
|
static constexpr std::array<PasivePadButton, 11> left_buttons{
|
|
|
|
Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X,
|
|
|
|
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
|
|
|
|
Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y,
|
|
|
|
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
|
|
|
|
Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR,
|
|
|
|
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
|
|
|
|
Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR,
|
|
|
|
PasivePadButton::Capture, PasivePadButton::StickL,
|
|
|
|
Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Capture,
|
|
|
|
|
|
|
|
Joycon::PasivePadButton::StickL,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (auto left_button : left_buttons) {
|
|
|
|
for (auto left_button : left_buttons) {
|
|
|
@ -225,16 +223,19 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
|
|
|
|
const int button = static_cast<int>(left_button);
|
|
|
|
const int button = static_cast<int>(left_button);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto [left_axis_x, left_axis_y] =
|
|
|
|
|
|
|
|
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
|
|
|
|
void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
|
|
|
|
static constexpr std::array<Joycon::PasivePadButton, 11> right_buttons{
|
|
|
|
static constexpr std::array<PasivePadButton, 11> right_buttons{
|
|
|
|
Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X,
|
|
|
|
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
|
|
|
|
Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y,
|
|
|
|
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
|
|
|
|
Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR,
|
|
|
|
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Plus,
|
|
|
|
Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR,
|
|
|
|
PasivePadButton::Home, PasivePadButton::StickR,
|
|
|
|
Joycon::PasivePadButton::Plus, Joycon::PasivePadButton::Home,
|
|
|
|
|
|
|
|
Joycon::PasivePadButton::StickR,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (auto right_button : right_buttons) {
|
|
|
|
for (auto right_button : right_buttons) {
|
|
|
@ -242,17 +243,20 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
|
|
|
|
const int button = static_cast<int>(right_button);
|
|
|
|
const int button = static_cast<int>(right_button);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto [right_axis_x, right_axis_y] =
|
|
|
|
|
|
|
|
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
|
|
|
|
void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
|
|
|
|
static constexpr std::array<Joycon::PasivePadButton, 14> pro_buttons{
|
|
|
|
static constexpr std::array<PasivePadButton, 14> pro_buttons{
|
|
|
|
Joycon::PasivePadButton::Down_A, Joycon::PasivePadButton::Right_X,
|
|
|
|
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
|
|
|
|
Joycon::PasivePadButton::Left_B, Joycon::PasivePadButton::Up_Y,
|
|
|
|
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
|
|
|
|
Joycon::PasivePadButton::SL, Joycon::PasivePadButton::SR,
|
|
|
|
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
|
|
|
|
Joycon::PasivePadButton::L_R, Joycon::PasivePadButton::ZL_ZR,
|
|
|
|
PasivePadButton::Plus, PasivePadButton::Capture, PasivePadButton::Home,
|
|
|
|
Joycon::PasivePadButton::Minus, Joycon::PasivePadButton::Plus,
|
|
|
|
PasivePadButton::StickL, PasivePadButton::StickR,
|
|
|
|
Joycon::PasivePadButton::Capture, Joycon::PasivePadButton::Home,
|
|
|
|
|
|
|
|
Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (auto pro_button : pro_buttons) {
|
|
|
|
for (auto pro_button : pro_buttons) {
|
|
|
@ -260,6 +264,15 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
|
|
|
|
const int button = static_cast<int>(pro_button);
|
|
|
|
const int button = static_cast<int>(pro_button);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
callbacks.on_button_data(button, button_status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto [left_axis_x, left_axis_y] =
|
|
|
|
|
|
|
|
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state && 0xf));
|
|
|
|
|
|
|
|
const auto [right_axis_x, right_axis_y] =
|
|
|
|
|
|
|
|
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state >> 4));
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
|
|
|
|
|
|
|
|
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const {
|
|
|
|
f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const {
|
|
|
@ -270,6 +283,30 @@ f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration ca
|
|
|
|
return value / calibration.min;
|
|
|
|
return value / calibration.min;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PasivePadStick raw_value) const {
|
|
|
|
|
|
|
|
switch (raw_value) {
|
|
|
|
|
|
|
|
case PasivePadStick::Right:
|
|
|
|
|
|
|
|
return {1.0f, 0.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::RightDown:
|
|
|
|
|
|
|
|
return {1.0f, -1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::Down:
|
|
|
|
|
|
|
|
return {0.0f, -1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::DownLeft:
|
|
|
|
|
|
|
|
return {-1.0f, -1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::Left:
|
|
|
|
|
|
|
|
return {-1.0f, 0.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::LeftUp:
|
|
|
|
|
|
|
|
return {-1.0f, 1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::Up:
|
|
|
|
|
|
|
|
return {0.0f, 1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::UpRight:
|
|
|
|
|
|
|
|
return {1.0f, 1.0f};
|
|
|
|
|
|
|
|
case PasivePadStick::Neutral:
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return {0.0f, 0.0f};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
f32 JoyconPoller::GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,
|
|
|
|
f32 JoyconPoller::GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,
|
|
|
|
AccelerometerSensitivity sensitivity) const {
|
|
|
|
AccelerometerSensitivity sensitivity) const {
|
|
|
|
const f32 value = raw * (1.0f / (cal.scale - cal.offset)) * 4;
|
|
|
|
const f32 value = raw * (1.0f / (cal.scale - cal.offset)) * 4;
|
|
|
|