1
0
mirror of synced 2024-11-28 01:20:59 +01:00

分开定义不同单片机的串口和针脚;修复 SystemCode 大小端反转的问题。

This commit is contained in:
Sucareto 2021-11-20 23:48:38 +08:00
parent 1eb01e389f
commit d5bf4658b0
3 changed files with 357 additions and 329 deletions

View File

@ -1,5 +1,17 @@
//#define SerialDevice SerialUSB //32u4,samd21
#define SerialDevice Serial //esp8266
#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO)
#pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO"
#define SerialDevice SerialUSB
#define DATA_PIN A3
#elif defined(ARDUINO_ESP8266_NODEMCU_ESP12E)
#pragma message "当前的开发板是 NODEMCU_ESP12E"
#define SerialDevice Serial
#define DATA_PIN D5
#else
#error "未经测试的开发板,请检查串口和阵脚定义"
#endif
//#define high_baudrate
#define M2F //取消注释此行将默认密钥的mifare模拟为felica
#include "cmd.h"

2
cmd.h
View File

@ -1,6 +1,5 @@
#include "FastLED.h"
#define NUM_LEDS 6
#define DATA_PIN D5//14
CRGB leds[NUM_LEDS];
#include <Wire.h>
@ -208,6 +207,7 @@ static void sg_nfc_cmd_radio_on() {
}
if (nfc.felica_Polling(systemCode, requestCode, felica.IDm, felica.PMm, &felica.SystemCode, 200)) {
cardtype = 0x20;
felica.SystemCode = felica.SystemCode >> 8 | felica.SystemCode << 8;
return;
}
#ifdef M2F

View File

@ -2,8 +2,20 @@
#include <PN532_I2C.h>
#include <PN532.h>
//#define SerialDevice SerialUSB //32u4,samd21
#define SerialDevice Serial //esp8266
#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO)
#pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO"
#define SerialDevice SerialUSB
#define DATA_PIN A3
#elif defined(ARDUINO_ESP8266_NODEMCU_ESP12E)
#pragma message "当前的开发板是 NODEMCU_ESP12E"
#define SerialDevice Serial
#define DATA_PIN D5
#else
#error "未经测试的开发板,请检查串口和阵脚定义"
#endif
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
@ -46,7 +58,8 @@ void loop() {
delay(2000);
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL) && nfc.mifareclassic_AuthenticateBlock(uid, uL, 1, 1, AimeKey)) {
SerialDevice.print("Aime card!UID Value:");
SerialDevice.println("Aime card!");
SerialDevice.print("UID Value:");
nfc.PrintHex(uid, uL);
SerialDevice.print("Block 2 Data:");
if (nfc.mifareclassic_ReadDataBlock(2, card.block)) {
@ -55,7 +68,8 @@ void loop() {
return;
}
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL) && nfc.mifareclassic_AuthenticateBlock(uid, uL, 1, 0, BanaKey)) {
SerialDevice.println("Banapassport card!UID Value:");
SerialDevice.println("Banapassport card!");
SerialDevice.print("UID Value:");
nfc.PrintHex(uid, uL);
SerialDevice.print("Block 2 Data:");
if (nfc.mifareclassic_ReadDataBlock(2, card.block)) {
@ -74,7 +88,8 @@ void loop() {
return;
}
if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uL)) {
SerialDevice.println("Unknown key Mifare.UID Value:");
SerialDevice.println("Unknown key Mifare.");
SerialDevice.print("UID Value:");
nfc.PrintHex(uid, uL);
return;
}
@ -86,6 +101,7 @@ void loop() {
SerialDevice.print("PMm:");
nfc.PrintHex(card.PMm, 8);
SerialDevice.print("SystemCode:");
card.SystemCode = card.SystemCode >> 8 | card.SystemCode << 8;
nfc.PrintHex(card.System_Code, 2);
return;
}