wip rfid
This commit is contained in:
parent
eb0d631ea2
commit
18fbc91859
96
src/main.cpp
96
src/main.cpp
|
|
@ -17,7 +17,7 @@
|
||||||
#include <MFRC522.h>//RFID Reader
|
#include <MFRC522.h>//RFID Reader
|
||||||
|
|
||||||
// define pins for RFID
|
// define pins for RFID
|
||||||
#define CS_RFID 32
|
#define CS_RFID 32// SIC, tried 4 and 32 but only this worked!
|
||||||
#define RST_RFID 33
|
#define RST_RFID 33
|
||||||
#define IRQ_RFID 34
|
#define IRQ_RFID 34
|
||||||
|
|
||||||
|
|
@ -94,8 +94,9 @@ void playNextMp3()
|
||||||
Serial.print("Now advancing to ");
|
Serial.print("Now advancing to ");
|
||||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||||
Serial.println(mp3File.c_str());
|
Serial.println(mp3File.c_str());
|
||||||
|
deactivateRFID();
|
||||||
audio.connecttoSD(mp3File.c_str());
|
audio.connecttoSD(mp3File.c_str());
|
||||||
|
activateRFID();
|
||||||
blockState = false;
|
blockState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,9 +163,9 @@ String processor(const String &var)
|
||||||
|
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
Serial.println("stopping audio.");
|
|
||||||
if (audio.isRunning())
|
if (audio.isRunning())
|
||||||
{
|
{
|
||||||
|
Serial.println("stopping audio.");
|
||||||
audio.stopSong();
|
audio.stopSong();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,35 +216,11 @@ void setup()
|
||||||
/* setup the IRQ pin*/
|
/* setup the IRQ pin*/
|
||||||
pinMode(IRQ_RFID, INPUT_PULLUP);
|
pinMode(IRQ_RFID, INPUT_PULLUP);
|
||||||
|
|
||||||
|
pinMode(CS_RFID,OUTPUT);
|
||||||
|
pinMode(CS_SDCARD,OUTPUT);
|
||||||
|
|
||||||
|
|
||||||
// Init MFRC522
|
deactivateRFID();
|
||||||
// Init SPI bus
|
|
||||||
SPI.begin();
|
|
||||||
rfid.PCD_Init();
|
|
||||||
/*
|
|
||||||
* Allow the ... irq to be propagated to the IRQ pin
|
|
||||||
* For test purposes propagate the IdleIrq and loAlert
|
|
||||||
*/
|
|
||||||
rfid.PCD_WriteRegister(rfid.ComIEnReg, 0xA0);
|
|
||||||
|
|
||||||
newRfidInt = false; //interrupt flag
|
|
||||||
|
|
||||||
attachInterrupt(IRQ_RFID, rfid_interrupt, FALLING);
|
|
||||||
|
|
||||||
do { //clear a spourious interrupt at start
|
|
||||||
;
|
|
||||||
} while (!newRfidInt);
|
|
||||||
newRfidInt = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//switch off RFID Reader:
|
|
||||||
//pinMode(RST_RFID, OUTPUT);
|
|
||||||
//digitalWrite(RST_RFID, LOW);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -254,11 +231,9 @@ void setup()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deactivateRFID();
|
|
||||||
|
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
|
|
||||||
if (!SD.begin(D1))
|
if (!SD.begin(CS_SDCARD))
|
||||||
{
|
{
|
||||||
Serial.println("SD initialization failed!");
|
Serial.println("SD initialization failed!");
|
||||||
while (1)
|
while (1)
|
||||||
|
|
@ -269,21 +244,39 @@ void setup()
|
||||||
rootNode.buildDirectoryTree("/");
|
rootNode.buildDirectoryTree("/");
|
||||||
rootNode.printDirectoryTree();
|
rootNode.printDirectoryTree();
|
||||||
|
|
||||||
|
|
||||||
|
deactivateSD();
|
||||||
|
activateRFID();
|
||||||
Serial.println("RFID");
|
Serial.println("RFID");
|
||||||
|
|
||||||
// clear RFID Reset
|
// Init MFRC522
|
||||||
//digitalWrite(RST_RFID, HIGH);
|
// Init SPI bus
|
||||||
|
SPI.begin(-1,-1,-1,CS_RFID);
|
||||||
|
rfid.PCD_Init(CS_RFID, RST_RFID);
|
||||||
|
if (rfid.PCD_PerformSelfTest()) {
|
||||||
|
Serial.println("RFID OK");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allow the ... irq to be propagated to the IRQ pin
|
||||||
|
* For test purposes propagate the IdleIrq and loAlert
|
||||||
|
*/
|
||||||
|
//rfid.PCD_WriteRegister(rfid.ComIEnReg, 0xA0);
|
||||||
|
attachInterrupt(IRQ_RFID, rfid_interrupt, FALLING);
|
||||||
|
|
||||||
activateRFID();
|
do { //clear a spourious interrupt at start
|
||||||
|
;
|
||||||
|
} while (!newRfidInt);
|
||||||
|
newRfidInt = false; //interrupt flag
|
||||||
|
} else {
|
||||||
|
Serial.println("RFID Self Test failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// printDirectoryTree(&rootNode, 0);
|
|
||||||
|
|
||||||
// printDirectory(root, 0);
|
|
||||||
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||||
audio.setVolume(volume); // 0...21
|
audio.setVolume(volume); // 0...21
|
||||||
|
|
||||||
|
Serial.println("Audio initialized.");
|
||||||
|
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{ request->send_P(200, "text/html", index_html, processor); });
|
{ request->send_P(200, "text/html", index_html, processor); });
|
||||||
|
|
||||||
|
|
@ -311,6 +304,7 @@ void setup()
|
||||||
next(); });
|
next(); });
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
Serial.println("initialization done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -318,24 +312,24 @@ void setup()
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (newRfidInt) {
|
deactivateRFID();
|
||||||
|
audio.loop();
|
||||||
deactivateSD();
|
activateRFID();
|
||||||
activateRFID();
|
|
||||||
|
|
||||||
if(rfid.PICC_IsNewCardPresent()) {
|
if (newRfidInt) {
|
||||||
|
Serial.println("Interrupt.");
|
||||||
|
if(rfid.PICC_IsNewCardPresent()) {
|
||||||
readRFID();
|
readRFID();
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivateRFID();
|
|
||||||
activateSD();
|
|
||||||
|
|
||||||
clearInt(rfid);
|
clearInt(rfid);
|
||||||
newRfidInt = false;
|
newRfidInt = false;
|
||||||
stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
audio.loop();
|
|
||||||
|
|
||||||
if (buttonPressed(BTN_START_STOP)) {
|
if (buttonPressed(BTN_START_STOP)) {
|
||||||
if (audio.isRunning()) {
|
if (audio.isRunning()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue