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
|
||||
|
||||
// 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 IRQ_RFID 34
|
||||
|
||||
|
|
@ -94,8 +94,9 @@ void playNextMp3()
|
|||
Serial.print("Now advancing to ");
|
||||
String mp3File = currentNode->getCurrentPlayingFilePath();
|
||||
Serial.println(mp3File.c_str());
|
||||
|
||||
deactivateRFID();
|
||||
audio.connecttoSD(mp3File.c_str());
|
||||
activateRFID();
|
||||
blockState = false;
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +163,9 @@ String processor(const String &var)
|
|||
|
||||
void stop()
|
||||
{
|
||||
Serial.println("stopping audio.");
|
||||
if (audio.isRunning())
|
||||
{
|
||||
Serial.println("stopping audio.");
|
||||
audio.stopSong();
|
||||
}
|
||||
}
|
||||
|
|
@ -215,35 +216,11 @@ void setup()
|
|||
/* setup the IRQ pin*/
|
||||
pinMode(IRQ_RFID, INPUT_PULLUP);
|
||||
|
||||
pinMode(CS_RFID,OUTPUT);
|
||||
pinMode(CS_SDCARD,OUTPUT);
|
||||
|
||||
|
||||
// Init MFRC522
|
||||
// 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);
|
||||
|
||||
deactivateRFID();
|
||||
|
||||
|
||||
|
||||
|
|
@ -254,11 +231,9 @@ void setup()
|
|||
|
||||
|
||||
|
||||
deactivateRFID();
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
|
||||
if (!SD.begin(D1))
|
||||
if (!SD.begin(CS_SDCARD))
|
||||
{
|
||||
Serial.println("SD initialization failed!");
|
||||
while (1)
|
||||
|
|
@ -269,21 +244,39 @@ void setup()
|
|||
rootNode.buildDirectoryTree("/");
|
||||
rootNode.printDirectoryTree();
|
||||
|
||||
|
||||
deactivateSD();
|
||||
activateRFID();
|
||||
Serial.println("RFID");
|
||||
|
||||
// clear RFID Reset
|
||||
//digitalWrite(RST_RFID, HIGH);
|
||||
// Init MFRC522
|
||||
// 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.setVolume(volume); // 0...21
|
||||
|
||||
Serial.println("Audio initialized.");
|
||||
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{ request->send_P(200, "text/html", index_html, processor); });
|
||||
|
||||
|
|
@ -311,6 +304,7 @@ void setup()
|
|||
next(); });
|
||||
|
||||
server.begin();
|
||||
Serial.println("initialization done.");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -318,24 +312,24 @@ void setup()
|
|||
void loop()
|
||||
{
|
||||
|
||||
if (newRfidInt) {
|
||||
|
||||
deactivateSD();
|
||||
activateRFID();
|
||||
deactivateRFID();
|
||||
audio.loop();
|
||||
activateRFID();
|
||||
|
||||
if(rfid.PICC_IsNewCardPresent()) {
|
||||
if (newRfidInt) {
|
||||
Serial.println("Interrupt.");
|
||||
if(rfid.PICC_IsNewCardPresent()) {
|
||||
readRFID();
|
||||
stop();
|
||||
}
|
||||
|
||||
deactivateRFID();
|
||||
activateSD();
|
||||
|
||||
|
||||
clearInt(rfid);
|
||||
newRfidInt = false;
|
||||
stop();
|
||||
|
||||
}
|
||||
|
||||
audio.loop();
|
||||
|
||||
|
||||
if (buttonPressed(BTN_START_STOP)) {
|
||||
if (audio.isRunning()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue