mirror of
https://github.com/sweidac/kidsbox.git
synced 2025-07-27 19:31:54 +02:00
Adds rfid example code.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
idf_component_register(SRCS "Networking.cpp" "main.cpp" "WebInterface.cpp"
|
||||
idf_component_register(SRCS "Networking.cpp" "main.cpp" "WebInterface.cpp" "RFIDInterface.cpp"
|
||||
INCLUDE_DIRS ".")
|
||||
|
26
device/main/RFIDInterface.cpp
Normal file
26
device/main/RFIDInterface.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "RFIDInterface.hpp"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "rfid";
|
||||
|
||||
void tag_handler(uint8_t* sn) { // serial number is always 5 bytes long
|
||||
ESP_LOGI(TAG, "Tag: %#x %#x %#x %#x %#x",
|
||||
sn[0], sn[1], sn[2], sn[3], sn[4]
|
||||
);
|
||||
}
|
||||
|
||||
RFIDInterface::RFIDInterface() {
|
||||
startConfig = (rc522_start_args_t){
|
||||
.miso_io = 26,
|
||||
.mosi_io = 25,
|
||||
.sck_io = 23,
|
||||
.sda_io = 5,
|
||||
.callback = &tag_handler
|
||||
};
|
||||
}
|
||||
|
||||
void RFIDInterface::start() {
|
||||
rc522_start(startConfig);
|
||||
}
|
||||
|
14
device/main/RFIDInterface.hpp
Normal file
14
device/main/RFIDInterface.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _RFID_INTERFACE_HPP
|
||||
#define _RFID_INTERFACE_HPP
|
||||
|
||||
#include <rc522.h>
|
||||
|
||||
class RFIDInterface {
|
||||
rc522_start_args_t startConfig;
|
||||
|
||||
public:
|
||||
RFIDInterface();
|
||||
void start();
|
||||
};
|
||||
|
||||
#endif
|
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Networking.hpp"
|
||||
#include "WebInterface.hpp"
|
||||
#include "RFIDInterface.hpp"
|
||||
|
||||
extern "C" {
|
||||
void app_main();
|
||||
@@ -11,6 +12,7 @@ extern "C" {
|
||||
|
||||
Networking networking;
|
||||
WebInterface webInterface;
|
||||
RFIDInterface rfid;
|
||||
|
||||
void app_main(void) {
|
||||
initArduino();
|
||||
@@ -18,6 +20,6 @@ void app_main(void) {
|
||||
Serial.begin(115200);
|
||||
|
||||
networking.connectWifi();
|
||||
|
||||
webInterface.start();
|
||||
rfid.start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user