From ca4be4283d8eec9624019f4bca88f7d1aa467f01 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Wed, 22 Mar 2023 11:09:12 -0600 Subject: android: Implement amiibo reading from nfc tag --- src/input_common/drivers/virtual_amiibo.cpp | 26 ++++++++++++++++++++++---- src/input_common/drivers/virtual_amiibo.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/drivers/virtual_amiibo.cpp b/src/input_common/drivers/virtual_amiibo.cpp index 304f4c70b..9505179c6 100644 --- a/src/input_common/drivers/virtual_amiibo.cpp +++ b/src/input_common/drivers/virtual_amiibo.cpp @@ -73,10 +73,7 @@ VirtualAmiibo::State VirtualAmiibo::GetCurrentState() const { VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(const std::string& filename) { const Common::FS::IOFile nfc_file{filename, Common::FS::FileAccessMode::Read, Common::FS::FileType::BinaryFile}; - - if (state != State::WaitingForAmiibo) { - return Info::WrongDeviceState; - } + std::vector data{}; if (!nfc_file.IsOpen()) { return Info::UnableToLoad; @@ -101,7 +98,28 @@ VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(const std::string& filename) { } file_path = filename; + return LoadAmiibo(data); +} + +VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(std::span data) { + if (state != State::WaitingForAmiibo) { + return Info::WrongDeviceState; + } + + switch (data.size_bytes()) { + case AmiiboSize: + case AmiiboSizeWithoutPassword: + nfc_data.resize(AmiiboSize); + break; + case MifareSize: + nfc_data.resize(MifareSize); + break; + default: + return Info::NotAnAmiibo; + } + state = State::AmiiboIsOpen; + memcpy(nfc_data.data(),data.data(),data.size_bytes()); SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, nfc_data}); return Info::Success; } diff --git a/src/input_common/drivers/virtual_amiibo.h b/src/input_common/drivers/virtual_amiibo.h index 488d00b31..34e97cd91 100644 --- a/src/input_common/drivers/virtual_amiibo.h +++ b/src/input_common/drivers/virtual_amiibo.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include @@ -47,6 +48,7 @@ public: State GetCurrentState() const; Info LoadAmiibo(const std::string& amiibo_file); + Info LoadAmiibo(std::span data); Info ReloadAmiibo(); Info CloseAmiibo(); -- cgit v1.2.3