Skip to content

Commit

Permalink
Merge pull request #346 from rennancockles/dev
Browse files Browse the repository at this point in the history
Amiibolink uid change mode selection
  • Loading branch information
rennancockles authored Oct 17, 2024
2 parents 5886967 + 59b6e05 commit 3b0166e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
51 changes: 49 additions & 2 deletions src/modules/rfid/amiibolink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ void Amiibolink::setup() {
return;
}

UIDMode uidMode = selectUIDMode();

displayDumpInfo();
padprintln("Searching Amiibolink Device...");

Expand All @@ -128,7 +130,7 @@ void Amiibolink::setup() {
padprintln("Amiibolink Connected");
padprintln("Sending commands...");

if (!sendCommands()) {
if (!sendCommands(uidMode)) {
displayError("Amiibolink communication error");
delay(1000);
return;
Expand Down Expand Up @@ -240,6 +242,20 @@ bool Amiibolink::checkEmulationTagType() {
}


Amiibolink::UIDMode Amiibolink::selectUIDMode() {
UIDMode uidMode;

options = {
{"UID Mode Auto", [&]() { uidMode = UIDMode_Auto; }},
{"UID Manual", [&]() { uidMode = UIDMode_Manual; }},
};
delay(200);
loopOptions(options);

return uidMode;
}


bool Amiibolink::searchDevice() {
NimBLEDevice::init("");

Expand Down Expand Up @@ -349,7 +365,10 @@ bool Amiibolink::serviceDiscovery() {
}


bool Amiibolink::sendCommands() {
bool Amiibolink::sendCommands(UIDMode uidMode) {
if (uidMode == UIDMode_Auto && !setUIDModeAuto()) return false;
else if (uidMode == UIDMode_Manual && !setUIDModeManual()) return false;

return (
cmdPreUploadDump()
&& cmdUploadDumpData()
Expand All @@ -358,6 +377,34 @@ bool Amiibolink::sendCommands() {
}


bool Amiibolink::setUIDModeAuto() {
Serial.println("Set UID Mode Auto");

uint8_t cmd0[20] = {
0x00, 0x00, 0x10, 0x03,
0xE3, 0x96, 0x51, 0xEC, 0x07, 0xE7, 0xE5, 0x54,
0x37, 0xB6, 0x13, 0x8E, 0x80, 0xC9, 0xB3, 0x09
};
if (!submitCommand(cmd0, sizeof(cmd0))) return false;

return true;
}


bool Amiibolink::setUIDModeManual() {
Serial.println("Set UID Mode Manual");

uint8_t cmd0[20] = {
0x00, 0x00, 0x10, 0x03,
0x34, 0x1F, 0x98, 0xE8, 0x46, 0x19, 0x85, 0x75,
0xE3, 0xD3, 0xE0, 0x42, 0x5D, 0x41, 0x89, 0x42
};
if (!submitCommand(cmd0, sizeof(cmd0))) return false;

return true;
}


bool Amiibolink::cmdPreUploadDump() {
Serial.println("Pre upload dump commands");

Expand Down
10 changes: 9 additions & 1 deletion src/modules/rfid/amiibolink.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Amiibolink {
String picc_type;
} PrintableUID;

enum UIDMode {
UIDMode_Auto,
UIDMode_Manual,
};

/////////////////////////////////////////////////////////////////////////////////////
// Constructor
/////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -49,14 +54,17 @@ class Amiibolink {

bool openDumpFile();
bool checkEmulationTagType();
UIDMode selectUIDMode();

bool searchDevice();
bool connectToDevice();
bool serviceDiscovery();

bool sendCommands();
bool sendCommands(UIDMode uidMode);
bool submitCommand(uint8_t *data, size_t length);

bool setUIDModeAuto();
bool setUIDModeManual();
bool cmdPreUploadDump();
bool cmdUploadDumpData();
bool cmdPostUploadDump();
Expand Down

0 comments on commit 3b0166e

Please sign in to comment.