2023-07-01 19:25:39 +02:00
|
|
|
#define high_baudrate
|
|
|
|
|
|
|
|
#include "Aime_Redaer.h"
|
2021-03-15 15:48:12 +01:00
|
|
|
|
|
|
|
void setup() {
|
2022-03-06 13:29:21 +01:00
|
|
|
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
|
2021-08-15 13:56:27 +02:00
|
|
|
FastLED.setBrightness(50);
|
2022-03-13 06:31:43 +01:00
|
|
|
FastLED.showColor(0);
|
2021-03-15 15:48:12 +01:00
|
|
|
nfc.begin();
|
2021-08-15 13:56:27 +02:00
|
|
|
while (!nfc.getFirmwareVersion()) {
|
2022-03-13 06:31:43 +01:00
|
|
|
FastLED.showColor(0xFF0000);
|
2021-08-15 13:56:27 +02:00
|
|
|
delay(500);
|
2022-03-13 06:31:43 +01:00
|
|
|
FastLED.showColor(0);
|
2021-08-15 13:56:27 +02:00
|
|
|
delay(500);
|
2021-03-28 15:38:32 +02:00
|
|
|
}
|
2023-07-01 19:25:39 +02:00
|
|
|
nfc.setPassiveActivationRetries(0x10);
|
2021-03-15 15:48:12 +01:00
|
|
|
nfc.SAMConfig();
|
2023-07-01 19:25:39 +02:00
|
|
|
memset(req.bytes, 0, sizeof(req.bytes));
|
|
|
|
memset(res.bytes, 0, sizeof(res.bytes));
|
2022-03-13 06:31:43 +01:00
|
|
|
|
2023-07-01 19:25:39 +02:00
|
|
|
SerialDevice.begin(baudrate);
|
|
|
|
FastLED.showColor(BootColor);
|
2021-03-15 15:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2021-10-09 19:16:03 +02:00
|
|
|
switch (packet_read()) {
|
2023-07-01 19:25:39 +02:00
|
|
|
case 0:
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_TO_NORMAL_MODE:
|
|
|
|
sys_to_normal_mode();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
case CMD_GET_FW_VERSION:
|
|
|
|
sys_get_fw_version();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
case CMD_GET_HW_VERSION:
|
|
|
|
sys_get_hw_version();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
// Card read
|
|
|
|
case CMD_START_POLLING:
|
|
|
|
nfc_start_polling();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
case CMD_STOP_POLLING:
|
|
|
|
nfc_stop_polling();
|
2022-03-12 17:02:35 +01:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
case CMD_CARD_DETECT:
|
|
|
|
nfc_card_detect();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
// MIFARE
|
|
|
|
case CMD_MIFARE_KEY_SET_A:
|
|
|
|
memcpy(KeyA, req.key, 6);
|
|
|
|
res_init();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_MIFARE_KEY_SET_B:
|
|
|
|
res_init();
|
|
|
|
memcpy(KeyB, req.key, 6);
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_MIFARE_AUTHORIZE_A:
|
|
|
|
nfc_mifare_authorize_a();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_MIFARE_AUTHORIZE_B:
|
|
|
|
nfc_mifare_authorize_b();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_MIFARE_READ:
|
|
|
|
nfc_mifare_read();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
// FeliCa
|
|
|
|
case CMD_FELICA_THROUGH:
|
|
|
|
nfc_felica_through();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
// LED
|
|
|
|
case CMD_EXT_BOARD_LED_RGB:
|
|
|
|
FastLED.showColor(CRGB(req.color_payload[0], req.color_payload[1], req.color_payload[2]));
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_EXT_BOARD_INFO:
|
|
|
|
sys_get_led_info();
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
|
|
|
case CMD_EXT_BOARD_LED_RGB_UNKNOWN:
|
2021-10-09 19:16:03 +02:00
|
|
|
break;
|
2023-07-01 19:25:39 +02:00
|
|
|
|
2021-10-09 19:16:03 +02:00
|
|
|
default:
|
2023-07-01 19:25:39 +02:00
|
|
|
res_init();
|
2021-10-09 19:16:03 +02:00
|
|
|
}
|
2023-07-01 19:25:39 +02:00
|
|
|
packet_write();
|
2021-10-09 19:16:03 +02:00
|
|
|
}
|