2020-05-29 11:14:16 +02:00

73 lines
2.4 KiB
C

#include <msp430.h>
#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;
}