summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/helpers/joycon_driver.cpp3
-rw-r--r--src/input_common/helpers/joycon_protocol/generic_functions.cpp11
-rw-r--r--src/input_common/helpers/joycon_protocol/generic_functions.h6
-rw-r--r--src/input_common/helpers/joycon_protocol/joycon_types.h1
-rw-r--r--src/input_common/helpers/stick_from_buttons.cpp9
5 files changed, 28 insertions, 2 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index 4159e5717..3775e2d35 100644
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -86,6 +86,7 @@ DriverResult JoyconDriver::InitializeDevice() {
// Get fixed joycon info
generic_protocol->GetVersionNumber(version);
+ generic_protocol->SetLowPowerMode(false);
generic_protocol->GetColor(color);
if (handle_device_type == ControllerType::Pro) {
// Some 3rd party controllers aren't pro controllers
@@ -324,6 +325,8 @@ DriverResult JoyconDriver::SetPollingMode() {
if (result != DriverResult::Success) {
LOG_ERROR(Input, "Error enabling active mode");
}
+ // Switch calls this function after enabling active mode
+ generic_protocol->TriggersElapsed();
disable_input_thread = false;
return result;
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.cpp b/src/input_common/helpers/joycon_protocol/generic_functions.cpp
index 52bb8b61a..63cfb1369 100644
--- a/src/input_common/helpers/joycon_protocol/generic_functions.cpp
+++ b/src/input_common/helpers/joycon_protocol/generic_functions.cpp
@@ -19,6 +19,17 @@ DriverResult GenericProtocol::EnableActiveMode() {
return SetReportMode(ReportMode::STANDARD_FULL_60HZ);
}
+DriverResult GenericProtocol::SetLowPowerMode(bool enable) {
+ ScopedSetBlocking sb(this);
+ const std::array<u8, 1> buffer{static_cast<u8>(enable ? 1 : 0)};
+ return SendSubCommand(SubCommand::LOW_POWER_MODE, buffer);
+}
+
+DriverResult GenericProtocol::TriggersElapsed() {
+ ScopedSetBlocking sb(this);
+ return SendSubCommand(SubCommand::TRIGGERS_ELAPSED, {});
+}
+
DriverResult GenericProtocol::GetDeviceInfo(DeviceInfo& device_info) {
ScopedSetBlocking sb(this);
std::vector<u8> output;
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.h b/src/input_common/helpers/joycon_protocol/generic_functions.h
index 239bb7dbf..424831e81 100644
--- a/src/input_common/helpers/joycon_protocol/generic_functions.h
+++ b/src/input_common/helpers/joycon_protocol/generic_functions.h
@@ -25,6 +25,12 @@ public:
/// Enables active mode. This mode will return the current status every 5-15ms
DriverResult EnableActiveMode();
+ /// Enables or disables the low power mode
+ DriverResult SetLowPowerMode(bool enable);
+
+ /// Unknown function used by the switch
+ DriverResult TriggersElapsed();
+
/**
* Sends a request to obtain the joycon firmware and mac from handle
* @returns controller device info
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h
index e2d47349f..182d2c15b 100644
--- a/src/input_common/helpers/joycon_protocol/joycon_types.h
+++ b/src/input_common/helpers/joycon_protocol/joycon_types.h
@@ -129,6 +129,7 @@ enum class SubCommand : u8 {
LOW_POWER_MODE = 0x08,
SPI_FLASH_READ = 0x10,
SPI_FLASH_WRITE = 0x11,
+ SPI_SECTOR_ERASE = 0x12,
RESET_MCU = 0x20,
SET_MCU_CONFIG = 0x21,
SET_MCU_STATE = 0x22,
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index f3a0b3419..096c23b07 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -11,6 +11,11 @@ namespace InputCommon {
class Stick final : public Common::Input::InputDevice {
public:
+ // Some games such as EARTH DEFENSE FORCE: WORLD BROTHERS
+ // do not play nicely with the theoretical maximum range.
+ // Using a value one lower from the maximum emulates real stick behavior.
+ static constexpr float MAX_RANGE = 32766.0f / 32767.0f;
+
using Button = std::unique_ptr<Common::Input::InputDevice>;
Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, Button updater_,
@@ -196,7 +201,7 @@ public:
}
void UpdateStatus() {
- const float coef = modifier_status.value ? modifier_scale : 1.0f;
+ const float coef = modifier_status.value ? modifier_scale : MAX_RANGE;
bool r = right_status;
bool l = left_status;
@@ -290,7 +295,7 @@ public:
if (down_status) {
--y;
}
- const float coef = modifier_status.value ? modifier_scale : 1.0f;
+ const float coef = modifier_status.value ? modifier_scale : MAX_RANGE;
status.x.raw_value = static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF);
status.y.raw_value = static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF);
return status;