diff --git a/Arduino-Aime-Reader.ino b/Arduino-Aime-Reader.ino index ef3be0c..e2f1e7a 100644 --- a/Arduino-Aime-Reader.ino +++ b/Arduino-Aime-Reader.ino @@ -1,3 +1,5 @@ +#include "cmd.h" + #if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO) #pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO" #define SerialDevice SerialUSB @@ -7,6 +9,7 @@ #pragma message "当前的开发板是 NODEMCU_ESP12E" #define SerialDevice Serial #define LED_PIN D5 +//#define SwitchBaudPIN D4 //修改波特率按钮 #elif defined(ARDUINO_NodeMCU_32S) #pragma message "当前的开发板是 NodeMCU_32S" @@ -17,40 +20,45 @@ #error "未经测试的开发板,请检查串口和阵脚定义" #endif -#define high_baudrate//high_baudrate=true -#include "cmd.h" +bool high_baudrate = true;//high_baudrate=true void setup() { -#ifdef high_baudrate - SerialDevice.begin(115200); -#else - SerialDevice.begin(38400); -#endif - SerialDevice.setTimeout(0); FastLED.addLeds(leds, NUM_LEDS); FastLED.setBrightness(50); - FastLED.clear(); - FastLED.show(); + FastLED.showColor(0); nfc.begin(); while (!nfc.getFirmwareVersion()) { - fill_solid(leds, NUM_LEDS, 0xFF0000); - FastLED.show(); + FastLED.showColor(0xFF0000); delay(500); - fill_solid(leds, NUM_LEDS, 0x000000); - FastLED.show(); + FastLED.showColor(0); delay(500); } nfc.setPassiveActivationRetries(0x10);//设定等待次数 nfc.SAMConfig(); memset(&req, 0, sizeof(req.bytes)); memset(&res, 0, sizeof(res.bytes)); - fill_solid(leds, NUM_LEDS, 0xFFD700); - FastLED.show(); + + SerialDevice.begin(high_baudrate ? 115200 : 38400); + FastLED.showColor(high_baudrate ? 0x0000FF : 0x00FF00); + +#ifdef SwitchBaudPIN +#pragma message "已启用波特率切换功能" + pinMode(SwitchBaudPIN, INPUT_PULLUP); +#endif } void loop() { SerialCheck(); packet_write(); +#ifdef SwitchBaudPIN + if (!digitalRead(SwitchBaudPIN)) { + high_baudrate = !high_baudrate; + SerialDevice.flush(); + SerialDevice.begin(high_baudrate ? 115200 : 38400); + FastLED.showColor(high_baudrate ? 0x0000FF : 0x00FF00); + delay(2000); + } +#endif } static uint8_t len, r, checksum; diff --git a/cmd.h b/cmd.h index 141504a..be087f2 100644 --- a/cmd.h +++ b/cmd.h @@ -33,10 +33,10 @@ enum { //FELICA_ENCAP FELICA_CMD_POLL = 0x00, + FELICA_CMD_NDA_06 = 0x06, + FELICA_CMD_NDA_08 = 0x08, FELICA_CMD_GET_SYSTEM_CODE = 0x0C, FELICA_CMD_NDA_A4 = 0xA4, - FELICA_CMD_NDA_06 = 0x06,//测试中,作用未知 - FELICA_CMD_NDA_08 = 0x08,//测试中,作用未知 }; typedef union packet_req { @@ -134,8 +134,7 @@ static void sg_nfc_cmd_reset() { //重置读卡器 res.status = 3; return; } - fill_solid(leds, NUM_LEDS, 0xFFFF00); - FastLED.show(); + FastLED.showColor(0xFF0000); } static void sg_nfc_cmd_get_fw_version() { @@ -166,8 +165,7 @@ static void sg_nfc_cmd_mifare_set_key_bana() { static void sg_led_cmd_reset() { sg_res_init(); - FastLED.clear(); - FastLED.show(); + FastLED.showColor(0); } static void sg_led_cmd_get_info() { @@ -177,11 +175,7 @@ static void sg_led_cmd_get_info() { } static void sg_led_cmd_set_color() { - uint8_t r = req.color_payload[0]; - uint8_t g = req.color_payload[1]; - uint8_t b = req.color_payload[2]; - fill_solid(leds, NUM_LEDS, CRGB(r, g, b)); - FastLED.show(); + FastLED.showColor(CRGB(req.color_payload[0], req.color_payload[1], req.color_payload[2])); } static void sg_nfc_cmd_radio_on() {