Add FeliCa toggle button

This commit is contained in:
Laura Hausmann 2023-04-22 03:08:11 +02:00
parent de6a15b128
commit 9b2818f11b
Signed by: zotan
GPG key ID: D044E84C5BE01605
5 changed files with 35 additions and 16 deletions

View file

@ -45,9 +45,11 @@ private:
Adafruit_PN532* pn532;
uint8_t uid[16];
uint8_t uidLength;
uint8_t mode = 0;
unsigned long timer = 0;
public:
static volatile int irq;
static volatile bool toggleMode;
static uint8_t mode;
explicit PN532Reader(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss);
bool canHaveUnstableIdentifier() override;
bool isNewCardPresent() override;

View file

@ -30,6 +30,7 @@
#define PIN_BUZZER 19
#define PIN_OLED_SDA 21
#define PIN_OLED_SCL 22
#define PIN_INTERRUPT_FELICA 5
#define PIN_INTERRUPT_TRANSACT 26
#define PIN_INTERRUPT_BALANCE 25
#define PIN_INTERRUPT_LINK 33

View file

@ -44,6 +44,13 @@ void IRAM_ATTR PN532_IRQ() {
PN532Reader::irq++;
}
void IRAM_ATTR FeliCaInterruptHandler() {
if (PN532Reader::toggleMode || scanstate != SCANSTATE_ACTIVE || digitalRead(PIN_INTERRUPT_FELICA)) {
return;
}
PN532Reader::toggleMode = true;
}
void IRAM_ATTR TransactInterruptHandler() {
if (interruptFired || state != STATE_IDLE || digitalRead(PIN_INTERRUPT_TRANSACT)) {
return;
@ -126,6 +133,7 @@ void setup() {
pinMode(PIN_INTERRUPT_IRQ_PN532, INPUT_PULLUP);
pinMode(PIN_INTERRUPT_TRANSACT, INPUT_PULLUP);
pinMode(PIN_INTERRUPT_BALANCE, INPUT_PULLUP);
pinMode(PIN_INTERRUPT_FELICA, INPUT_PULLUP);
pinMode(PIN_INTERRUPT_CANCEL, INPUT_PULLUP);
pinMode(PIN_INTERRUPT_LINK, INPUT_PULLUP);
@ -148,6 +156,7 @@ void setup() {
attachInterrupt(PIN_INTERRUPT_IRQ_PN532, PN532_IRQ, FALLING);
attachInterrupt(PIN_INTERRUPT_TRANSACT, TransactInterruptHandler, FALLING);
attachInterrupt(PIN_INTERRUPT_BALANCE, BalanceInterruptHandler, FALLING);
attachInterrupt(PIN_INTERRUPT_FELICA, FeliCaInterruptHandler, FALLING);
attachInterrupt(PIN_INTERRUPT_CANCEL, CancelInterruptHandler, FALLING);
attachInterrupt(PIN_INTERRUPT_LINK, LinkInterruptHandler, FALLING);
}

View file

@ -8,6 +8,7 @@
#include "utils.h"
#include "vars.h"
#include "oled.h"
#include "readers.h"
OLED::OLED(U8G2 u8g2) {
this->u8g2 = std::move(u8g2);
@ -85,6 +86,9 @@ void OLED::drawLogo(e_logo logo) {
case LOGO_CONTACTLESS:
drawLogoBitmap( contactless_width, contactless_height, contactless_bits);
break;
case LOGO_FELICA:
drawLogoBitmap( felica_width, felica_height, felica_bits);
break;
case LOGO_MATECARD:
drawLogoBitmap(matecard_width, matecard_height, matecard_bits, 5);
u8g2.setFont(u8g2_font_bpixeldouble_tr);
@ -130,7 +134,10 @@ void OLED::updateOLED(e_state state, const String& statusText, const String& sta
case STATE_BALANCE_CARDSCAN:
case STATE_LINK_CARD_SCAN:
case STATE_LINK_CARD_RESCAN:
drawLogo(LOGO_CONTACTLESS);
if (PN532Reader::mode == PN532_MIFARE_ISO14443A)
drawLogo(LOGO_CONTACTLESS);
else
drawLogo(LOGO_FELICA);
break;
case STATE_RESULT_SUCCESS:
drawLogo(LOGO_SUCCESS);

View file

@ -4,6 +4,9 @@
#include "vars.h"
volatile int PN532Reader::irq = 0;
volatile bool PN532Reader::toggleMode = false;
uint8_t PN532Reader::mode = 0;
PN532Reader::PN532Reader(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {
pn532 = new Adafruit_PN532(ss, new SPIClass(HSPI));
@ -12,7 +15,7 @@ PN532Reader::PN532Reader(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {
void PN532Reader::begin() {
pn532->begin();
irq = 0;
mode = PN532_FELICA_424;
mode = PN532_MIFARE_ISO14443A;
pn532->startPassiveTargetIDDetection(mode);
}
@ -27,7 +30,7 @@ void PN532Reader::cycleMode() {
}
else {
mode = PN532_MIFARE_ISO14443A;
Serial.println("Mode is now MIFARE");
Serial.println("Mode is now NFC-A");
}
pn532->startPassiveTargetIDDetection(mode);
@ -41,24 +44,21 @@ bool PN532Reader::isNewCardPresent() {
if (irq > 1)
return true;
//cycleMode();
if (toggleMode) {
if (millis() - timer > 500) {
cycleMode();
timer = millis();
}
toggleMode = false;
}
return false;
}
String PN532Reader::getCardUid() {
if (mode == PN532_MIFARE_ISO14443A) {
Serial.println("Reading MIFARE UID");
Serial.println("Reading NFC-A UID");
pn532->readDetectedPassiveTargetID(uid, &uidLength);
uint8_t felica_idm[16];
uint8_t felica_length;
Serial.println("Checking if a FeliCa card is present as well");
this->end();
pn532->begin();
if (pn532->readPassiveTargetID(PN532_FELICA_424, felica_idm, &felica_length, 500)) {
memcpy(uid, felica_idm, felica_length);
uidLength = felica_length;
}
}
else {
Serial.println("Reading FeliCa IDm");