3
0
Fork 0
forked from suyu/suyu

input_common: Make amiibo scanning less demanding

This commit is contained in:
german77 2023-05-13 00:04:18 -06:00
parent 9c739f1506
commit ac531aa15f
3 changed files with 13 additions and 4 deletions

View file

@ -394,6 +394,7 @@ enum class DriverResult {
InvalidHandle, InvalidHandle,
NotSupported, NotSupported,
Disabled, Disabled,
Delayed,
Unknown, Unknown,
}; };

View file

@ -72,6 +72,11 @@ DriverResult NfcProtocol::StartNFCPollingMode() {
} }
DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) { DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) {
if (update_counter++ < AMIIBO_UPDATE_DELAY) {
return DriverResult::Delayed;
}
update_counter = 0;
LOG_DEBUG(Input, "Start NFC pooling Mode"); LOG_DEBUG(Input, "Start NFC pooling Mode");
ScopedSetBlocking sb(this); ScopedSetBlocking sb(this);
DriverResult result{DriverResult::Success}; DriverResult result{DriverResult::Success};
@ -87,7 +92,7 @@ DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) {
result = WaitUntilNfcIsReady(); result = WaitUntilNfcIsReady();
} }
if (result == DriverResult::Success) { if (result == DriverResult::Success) {
result = StartPolling(tag_data); result = StartPolling(tag_data, 7);
} }
if (result == DriverResult::Success) { if (result == DriverResult::Success) {
result = GetAmiiboData(data); result = GetAmiiboData(data);
@ -129,9 +134,8 @@ DriverResult NfcProtocol::WaitUntilNfcIsReady() {
return DriverResult::Success; return DriverResult::Success;
} }
DriverResult NfcProtocol::StartPolling(TagFoundData& data) { DriverResult NfcProtocol::StartPolling(TagFoundData& data, std::size_t timeout_limit) {
LOG_DEBUG(Input, "Start Polling for tag"); LOG_DEBUG(Input, "Start Polling for tag");
constexpr std::size_t timeout_limit = 7;
MCUCommandResponse output{}; MCUCommandResponse output{};
std::size_t tries = 0; std::size_t tries = 0;

View file

@ -32,6 +32,9 @@ public:
bool IsEnabled() const; bool IsEnabled() const;
private: private:
// Number of times the function will be delayed until it outputs valid data
static constexpr std::size_t AMIIBO_UPDATE_DELAY = 15;
struct TagFoundData { struct TagFoundData {
u8 type; u8 type;
std::vector<u8> uuid; std::vector<u8> uuid;
@ -39,7 +42,7 @@ private:
DriverResult WaitUntilNfcIsReady(); DriverResult WaitUntilNfcIsReady();
DriverResult StartPolling(TagFoundData& data); DriverResult StartPolling(TagFoundData& data, std::size_t timeout_limit = 1);
DriverResult ReadTag(const TagFoundData& data); DriverResult ReadTag(const TagFoundData& data);
@ -56,6 +59,7 @@ private:
NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const;
bool is_enabled{}; bool is_enabled{};
std::size_t update_counter{};
}; };
} // namespace InputCommon::Joycon } // namespace InputCommon::Joycon