From b6dc2a2772daef37d796a817cbc56e0e0f60afda Mon Sep 17 00:00:00 2001 From: Sucareto <28331534+Sucareto@users.noreply.github.com> Date: Sun, 13 Mar 2022 13:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=81=AF=E5=85=89=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=9B=E6=B7=BB=E5=8A=A0=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E4=BF=AE=E6=94=B9=E6=B3=A2=E7=89=B9=E7=8E=87?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Arduino-Aime-Reader.ino | 40 ++++++++++++++++++++++++---------------- cmd.h | 16 +++++----------- 2 files changed, 29 insertions(+), 27 deletions(-) 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() {