Skip to content

Commit

Permalink
feat: add reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 9, 2023
1 parent 7dbe536 commit 871b1ec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/NDEFReceive/NDEFReceive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ void loop() {
nfc.stopDiscovery();
nfc.startDiscovery(mode);
}
ResetMode();
// ResetMode();
nfc.reset();
delay(500);
}

Expand Down
8 changes: 3 additions & 5 deletions examples/NDEFSend/NDEFSend.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ void setup() {

nfc.startDiscovery(mode);

nfc.setMode(nfc.mode.READER_WRITER);
Serial.println("Mode: " + String(nfc.getMode()));
nfc.setMode(nfc.mode.EMULATION);
Serial.println("Mode: " + String(nfc.getMode()));
Serial.print("Waiting for an NDEF device");
}

Expand All @@ -85,7 +81,8 @@ void loop() {
}

void checkReaders() {
Serial.print(".");
// Serial.print(".");
unsigned long startTime = millis();
if (nfc.cardModeReceive(Cmd, &CmdSize) == 0) { // Data in buffer?
if ((CmdSize >= 2) && (Cmd[0] == 0x00)) { // Expect at least two bytes
if (Cmd[1] == 0xA4) {
Expand All @@ -96,6 +93,7 @@ void checkReaders() {
Serial.print("Waiting for an NDEF device");
}
}
Serial.println("Elapsed time: " + String(millis() - startTime) + "ms");
}

void sendMessageCallback(unsigned char *pNdefRecord, unsigned short NdefRecordSize) {
Expand Down
16 changes: 14 additions & 2 deletions src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ int Electroniccats_PN7150::GetFwVersion() {
}

uint8_t Electroniccats_PN7150::configMode(uint8_t modeSE) {
unsigned mode = (modeSE == 1 ? MODE_RW : modeSE == 2 ? MODE_CARDEMU
: MODE_P2P);
// TODO: refactor modeSE to mode
unsigned mode = (modeSE == 1 ? MODE_RW : modeSE == 2 ? MODE_CARDEMU : MODE_P2P);

if (!Electroniccats_PN7150::setMode(modeSE)) {
return ERROR;
}

uint8_t Command[MAX_NCI_FRAME_SIZE];

Expand Down Expand Up @@ -1091,6 +1095,8 @@ bool Electroniccats_PN7150::cardModeReceive(unsigned char *pData, unsigned char
Serial.println("[DEBUG] cardModeReceive exec");
#endif

delay(1);

bool status = NFC_ERROR;
uint8_t Ans[MAX_NCI_FRAME_SIZE];

Expand Down Expand Up @@ -1681,3 +1687,9 @@ bool Electroniccats_PN7150::nciFactoryTestRfOn() {
bool Electroniccats_PN7150::NxpNci_FactoryTest_RfOn() {
return Electroniccats_PN7150::nciFactoryTestRfOn();
}

bool Electroniccats_PN7150::reset() {
int mode = Electroniccats_PN7150::getMode();
Electroniccats_PN7150::configMode(mode);
Electroniccats_PN7150::startDiscovery(mode);
}
1 change: 1 addition & 0 deletions src/Electroniccats_PN7150.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class Electroniccats_PN7150 : public Mode {
bool NxpNci_FactoryTest_Prbs(NxpNci_TechType_t type, NxpNci_Bitrate_t bitrate); // Deprecated, use nciFactoryTestPrbs() instead
bool nciFactoryTestRfOn();
bool NxpNci_FactoryTest_RfOn(); // Deprecated, use nciFactoryTestRfOn() instead
bool reset();
};

#endif
2 changes: 1 addition & 1 deletion src/Mode.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Mode.h"

Mode::Mode() {
this->_mode = 1;
this->_mode = mode.READER_WRITER;
}

bool Mode::setMode(int mode) {
Expand Down

0 comments on commit 871b1ec

Please sign in to comment.