diff --git a/NFC.c b/NFC.c index b2b89d7..980b241 100644 --- a/NFC.c +++ b/NFC.c @@ -1,4 +1,72 @@ #include #include "NFC.h" #include "Mfrc522.h" +void NFCInit(){ + RC522_init(BIT6, BIT7); + /* + * Setting antenna gain to maximum (7) can read cards up to approximately 5cm. + * Default can read cards up to approximately 1cm. + * */ + RC522_setAntennaGain(7); // TODO fine tuning + //TODO LED +} + +//NFCNummer return serienummer van de NFC-tag +uchar NFCAvailable(){ //is er een kaart en is het leesbaar? serienummer + uchar str[5]; + if(RC522_request(PICC_REQALL, str) == MI_OK){ + if(RC522_anticoll(str) == MI_OK){ // controleert of de kaart reageert + /* Select card to be active */ + uchar l = RC522_selectTag(str); + uchar Colour = NFCRead (0 , 1 , 0 , str); + uchar Direction = NFCRead (2 , 0 , 9 , str); + RGBLed_update (Colour); + switch (Direction){ + case 'S': + return 0b00; // stop = 00 + case 'D': + return 0b11; // vooruit = 11 + case 'L': + return 0b10; // 10= Links + case 'R': + return 0b01; // 01 = rechts + + + } + + } + } +} + +//uchar* NFCTestConnection (uchar* TagType); //communiceren met de eerst gedetecteerde kaart +//uchar* NFCActive(); //NFC tag communicatie controleren + +// controleren of we de kaart kunnen "authenticaten" en De vervallen NFCActive +//uchar NFCAuthenticate (uchar* NFCNummer); +//sector*4 + block formule of (sector << 2) | block +uchar NFCRead (uchar sector, uchar block, uchar byte, uchar* str){ + /* See if we can authenticate to read */ + uchar recvData[18]; + block = (sector << 2) | block; + uchar keyA[6] = {0xBA, 0xBE, 0xBA, 0xBE, 0xBA, 0xBE}; + if(RC522_auth(PICC_AUTHENT1A, block, keyA, str) == MI_OK){ + + /* See if we can actually read data from the card. (block 1) */ + if(RC522_readBlock(block, recvData) == MI_OK){ + return recvData[byte]; + /* Color data is in block 1 of sector 0 */ + } + + /* Stop authentication */ + RC522_stopCrypto(); + } + +} // controle of de data kan worden gelezen + +//stuur richting door pls + +// byte van de NFCRead doorsturen naar RGBLed_update +uchar RGBLed_update (uchar Colour){ + return 0; +} diff --git a/NFC.h b/NFC.h index bb45360..e604fe6 100644 --- a/NFC.h +++ b/NFC.h @@ -10,23 +10,8 @@ #include "typedefExtention.h" -//NFCNummer return serienummer van de NFC-tag -uchar* NFCAvailable(); //is er een kaart en is het leesbaar? serienummer - -//uchar* NFCTestConnection (uchar* TagType); //communiceren met de eerst gedetecteerde kaart -//uchar* NFCActive(); //NFC tag communicatie controleren - -// controleren of we de kaart kunnen "authenticaten" en De vervallen NFCActive -//uchar NFCAuthenticate (uchar* NFCNummer); -//sector*4 + block formule of (sector << 2) | block -uchar NFCRead (uchar sector,uchar block,uchar byte); // controle of de data kan worden gelezen - -//stuur richting door pls - -// byte van de NFCRead doorsturen naar RGBLed_update -uchar RGBLed_update (uchar Colour); - -char NFCCheck(); // ongeldige dat in de min en geldige data is positief +void NFCInit(); +uchar NFCAvailable(); #endif diff --git a/main.c b/main.c index d632721..80b5c33 100644 --- a/main.c +++ b/main.c @@ -50,7 +50,10 @@ int main(void) SPIInit(); MDInit(); MCInit(); - //NFCInit(); + NFCInit(); + while (1){ + uchar NFCAvailable(); + } return 0; }