Skip to content

Commit

Permalink
优化灯光处理逻辑;添加运行时修改波特率功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
Sucareto committed Mar 13, 2022
1 parent 9ded22e commit b6dc2a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
40 changes: 24 additions & 16 deletions Arduino-Aime-Reader.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "cmd.h"

#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO)
#pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO"
#define SerialDevice SerialUSB
Expand All @@ -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"
Expand All @@ -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<WS2812B, LED_PIN, GRB>(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;
Expand Down
16 changes: 5 additions & 11 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit b6dc2a2

Please sign in to comment.