diff options
| author | 2023-01-13 23:29:05 -0600 | |
|---|---|---|
| committer | 2023-01-20 00:51:45 -0600 | |
| commit | 340f15d1fa79594dbe12a6e19140ba012751b533 (patch) | |
| tree | 7a9ef54a17f927e4b8cf98dd32dd6d41c0d75201 /src/input_common/helpers/joycon_protocol/ringcon.cpp | |
| parent | core: hid: Only set the polling mode to the correct side (diff) | |
| download | yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.gz yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.tar.xz yuzu-340f15d1fa79594dbe12a6e19140ba012751b533.zip | |
input_common: Address byte review
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/ringcon.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/ringcon.cpp | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/src/input_common/helpers/joycon_protocol/ringcon.cpp b/src/input_common/helpers/joycon_protocol/ringcon.cpp index 8adad57dd..12f81309e 100644 --- a/src/input_common/helpers/joycon_protocol/ringcon.cpp +++ b/src/input_common/helpers/joycon_protocol/ringcon.cpp | |||
| @@ -11,8 +11,8 @@ RingConProtocol::RingConProtocol(std::shared_ptr<JoyconHandle> handle) | |||
| 11 | 11 | ||
| 12 | DriverResult RingConProtocol::EnableRingCon() { | 12 | DriverResult RingConProtocol::EnableRingCon() { |
| 13 | LOG_DEBUG(Input, "Enable Ringcon"); | 13 | LOG_DEBUG(Input, "Enable Ringcon"); |
| 14 | ScopedSetBlocking sb(this); | ||
| 14 | DriverResult result{DriverResult::Success}; | 15 | DriverResult result{DriverResult::Success}; |
| 15 | SetBlocking(); | ||
| 16 | 16 | ||
| 17 | if (result == DriverResult::Success) { | 17 | if (result == DriverResult::Success) { |
| 18 | result = SetReportMode(ReportMode::STANDARD_FULL_60HZ); | 18 | result = SetReportMode(ReportMode::STANDARD_FULL_60HZ); |
| @@ -30,14 +30,13 @@ DriverResult RingConProtocol::EnableRingCon() { | |||
| 30 | result = ConfigureMCU(config); | 30 | result = ConfigureMCU(config); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | SetNonBlocking(); | ||
| 34 | return result; | 33 | return result; |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | DriverResult RingConProtocol::DisableRingCon() { | 36 | DriverResult RingConProtocol::DisableRingCon() { |
| 38 | LOG_DEBUG(Input, "Disable RingCon"); | 37 | LOG_DEBUG(Input, "Disable RingCon"); |
| 38 | ScopedSetBlocking sb(this); | ||
| 39 | DriverResult result{DriverResult::Success}; | 39 | DriverResult result{DriverResult::Success}; |
| 40 | SetBlocking(); | ||
| 41 | 40 | ||
| 42 | if (result == DriverResult::Success) { | 41 | if (result == DriverResult::Success) { |
| 43 | result = EnableMCU(false); | 42 | result = EnableMCU(false); |
| @@ -45,15 +44,14 @@ DriverResult RingConProtocol::DisableRingCon() { | |||
| 45 | 44 | ||
| 46 | is_enabled = false; | 45 | is_enabled = false; |
| 47 | 46 | ||
| 48 | SetNonBlocking(); | ||
| 49 | return result; | 47 | return result; |
| 50 | } | 48 | } |
| 51 | 49 | ||
| 52 | DriverResult RingConProtocol::StartRingconPolling() { | 50 | DriverResult RingConProtocol::StartRingconPolling() { |
| 53 | LOG_DEBUG(Input, "Enable Ringcon"); | 51 | LOG_DEBUG(Input, "Enable Ringcon"); |
| 54 | bool is_connected = false; | 52 | ScopedSetBlocking sb(this); |
| 55 | DriverResult result{DriverResult::Success}; | 53 | DriverResult result{DriverResult::Success}; |
| 56 | SetBlocking(); | 54 | bool is_connected = false; |
| 57 | 55 | ||
| 58 | if (result == DriverResult::Success) { | 56 | if (result == DriverResult::Success) { |
| 59 | result = IsRingConnected(is_connected); | 57 | result = IsRingConnected(is_connected); |
| @@ -66,13 +64,13 @@ DriverResult RingConProtocol::StartRingconPolling() { | |||
| 66 | is_enabled = true; | 64 | is_enabled = true; |
| 67 | } | 65 | } |
| 68 | 66 | ||
| 69 | SetNonBlocking(); | ||
| 70 | return result; | 67 | return result; |
| 71 | } | 68 | } |
| 72 | 69 | ||
| 73 | DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { | 70 | DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { |
| 74 | LOG_DEBUG(Input, "IsRingConnected"); | 71 | LOG_DEBUG(Input, "IsRingConnected"); |
| 75 | constexpr std::size_t max_tries = 28; | 72 | constexpr std::size_t max_tries = 28; |
| 73 | constexpr u8 ring_controller_id = 0x20; | ||
| 76 | std::vector<u8> output; | 74 | std::vector<u8> output; |
| 77 | std::size_t tries = 0; | 75 | std::size_t tries = 0; |
| 78 | is_connected = false; | 76 | is_connected = false; |
| @@ -88,7 +86,7 @@ DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { | |||
| 88 | if (tries++ >= max_tries) { | 86 | if (tries++ >= max_tries) { |
| 89 | return DriverResult::NoDeviceDetected; | 87 | return DriverResult::NoDeviceDetected; |
| 90 | } | 88 | } |
| 91 | } while (output[14] != 0x59 || output[16] != 0x20); | 89 | } while (output[16] != ring_controller_id); |
| 92 | 90 | ||
| 93 | is_connected = true; | 91 | is_connected = true; |
| 94 | return DriverResult::Success; | 92 | return DriverResult::Success; |
| @@ -96,30 +94,20 @@ DriverResult RingConProtocol::IsRingConnected(bool& is_connected) { | |||
| 96 | 94 | ||
| 97 | DriverResult RingConProtocol::ConfigureRing() { | 95 | DriverResult RingConProtocol::ConfigureRing() { |
| 98 | LOG_DEBUG(Input, "ConfigureRing"); | 96 | LOG_DEBUG(Input, "ConfigureRing"); |
| 99 | constexpr std::size_t max_tries = 28; | ||
| 100 | DriverResult result{DriverResult::Success}; | ||
| 101 | std::vector<u8> output; | ||
| 102 | std::size_t tries = 0; | ||
| 103 | 97 | ||
| 104 | static constexpr std::array<u8, 37> ring_config{ | 98 | static constexpr std::array<u8, 37> ring_config{ |
| 105 | 0x06, 0x03, 0x25, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x16, 0xED, 0x34, 0x36, | 99 | 0x06, 0x03, 0x25, 0x06, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x16, 0xED, 0x34, 0x36, |
| 106 | 0x00, 0x00, 0x00, 0x0A, 0x64, 0x0B, 0xE6, 0xA9, 0x22, 0x00, 0x00, 0x04, 0x00, | 100 | 0x00, 0x00, 0x00, 0x0A, 0x64, 0x0B, 0xE6, 0xA9, 0x22, 0x00, 0x00, 0x04, 0x00, |
| 107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xA8, 0xE1, 0x34, 0x36}; | 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xA8, 0xE1, 0x34, 0x36}; |
| 108 | do { | ||
| 109 | result = SendSubCommand(SubCommand::UNKNOWN_RINGCON3, ring_config, output); | ||
| 110 | 102 | ||
| 111 | if (result != DriverResult::Success) { | 103 | const DriverResult result = SendSubCommand(SubCommand::UNKNOWN_RINGCON3, ring_config); |
| 112 | return result; | ||
| 113 | } | ||
| 114 | if (tries++ >= max_tries) { | ||
| 115 | return DriverResult::NoDeviceDetected; | ||
| 116 | } | ||
| 117 | } while (output[14] != 0x5C); | ||
| 118 | 104 | ||
| 119 | static constexpr std::array<u8, 4> ringcon_data{0x04, 0x01, 0x01, 0x02}; | 105 | if (result != DriverResult::Success) { |
| 120 | result = SendSubCommand(SubCommand::UNKNOWN_RINGCON2, ringcon_data, output); | 106 | return result; |
| 107 | } | ||
| 121 | 108 | ||
| 122 | return result; | 109 | static constexpr std::array<u8, 4> ringcon_data{0x04, 0x01, 0x01, 0x02}; |
| 110 | return SendSubCommand(SubCommand::UNKNOWN_RINGCON2, ringcon_data); | ||
| 123 | } | 111 | } |
| 124 | 112 | ||
| 125 | bool RingConProtocol::IsEnabled() const { | 113 | bool RingConProtocol::IsEnabled() const { |