ARM

Committer:
Toby_Chen
Date:
Sat Oct 14 12:58:38 2017 +0000
Revision:
0:f266ca250f98
TRAY+

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Toby_Chen 0:f266ca250f98 1 #include "CardList.h"
Toby_Chen 0:f266ca250f98 2
Toby_Chen 0:f266ca250f98 3 //LCD Touch Screen
Toby_Chen 0:f266ca250f98 4 #include "LCD_DISCO_F469NI.h"
Toby_Chen 0:f266ca250f98 5 #include "TS_DISCO_F469NI.h"
Toby_Chen 0:f266ca250f98 6 LCD_DISCO_F469NI lcd;
Toby_Chen 0:f266ca250f98 7
Toby_Chen 0:f266ca250f98 8 bool CardList::reg_card(int a, int b, int c, int d, CardName card ){
Toby_Chen 0:f266ca250f98 9
Toby_Chen 0:f266ca250f98 10 Card new_card(a, b, c, d, card);
Toby_Chen 0:f266ca250f98 11 _card_list.push_back(new_card);
Toby_Chen 0:f266ca250f98 12
Toby_Chen 0:f266ca250f98 13 return true;
Toby_Chen 0:f266ca250f98 14 }
Toby_Chen 0:f266ca250f98 15
Toby_Chen 0:f266ca250f98 16 CardName CardList::read_card(){
Toby_Chen 0:f266ca250f98 17 RfChip.PICC_IsNewCardPresent();// Look for new cards
Toby_Chen 0:f266ca250f98 18 RfChip.PICC_ReadCardSerial();// Select one of the cards
Toby_Chen 0:f266ca250f98 19
Toby_Chen 0:f266ca250f98 20 for(int i=0 ; i<_card_list.size() ; i++){
Toby_Chen 0:f266ca250f98 21 if( _card_list[i].UID[0] != RfChip.uid.uidByte[0] ) continue;
Toby_Chen 0:f266ca250f98 22 if( _card_list[i].UID[1] != RfChip.uid.uidByte[1] ) continue;
Toby_Chen 0:f266ca250f98 23 if( _card_list[i].UID[2] != RfChip.uid.uidByte[2] ) continue;
Toby_Chen 0:f266ca250f98 24 if( _card_list[i].UID[3] != RfChip.uid.uidByte[3] ) continue;
Toby_Chen 0:f266ca250f98 25
Toby_Chen 0:f266ca250f98 26 _card_buf = _card_list[i].type;
Toby_Chen 0:f266ca250f98 27 return _card_list[i].type;
Toby_Chen 0:f266ca250f98 28 }
Toby_Chen 0:f266ca250f98 29
Toby_Chen 0:f266ca250f98 30 return emp;
Toby_Chen 0:f266ca250f98 31 }
Toby_Chen 0:f266ca250f98 32
Toby_Chen 0:f266ca250f98 33 void CardList::print_UID(){
Toby_Chen 0:f266ca250f98 34
Toby_Chen 0:f266ca250f98 35 char text[100];
Toby_Chen 0:f266ca250f98 36
Toby_Chen 0:f266ca250f98 37 RfChip.PICC_IsNewCardPresent();// Look for new cards
Toby_Chen 0:f266ca250f98 38 RfChip.PICC_ReadCardSerial();// Select one of the cards
Toby_Chen 0:f266ca250f98 39
Toby_Chen 0:f266ca250f98 40 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"UID:", LEFT_MODE );
Toby_Chen 0:f266ca250f98 41
Toby_Chen 0:f266ca250f98 42 for(int i=0 ; i<4 ;i++ ){
Toby_Chen 0:f266ca250f98 43 sprintf(text, "%x", RfChip.uid.uidByte[i]);
Toby_Chen 0:f266ca250f98 44 lcd.DisplayStringAt( (i+1)*80, LINE(5), (uint8_t *)text, LEFT_MODE );
Toby_Chen 0:f266ca250f98 45 }
Toby_Chen 0:f266ca250f98 46 }
Toby_Chen 0:f266ca250f98 47
Toby_Chen 0:f266ca250f98 48 bool CardList::is_another_card(){
Toby_Chen 0:f266ca250f98 49 RfChip.PICC_IsNewCardPresent();// Look for new cards
Toby_Chen 0:f266ca250f98 50 RfChip.PICC_ReadCardSerial();// Select one of the cards
Toby_Chen 0:f266ca250f98 51
Toby_Chen 0:f266ca250f98 52 for(int i=0 ; i<_card_list.size() ; i++){
Toby_Chen 0:f266ca250f98 53 if( _card_list[i].UID[0] != RfChip.uid.uidByte[0] ) continue;
Toby_Chen 0:f266ca250f98 54 if( _card_list[i].UID[1] != RfChip.uid.uidByte[1] ) continue;
Toby_Chen 0:f266ca250f98 55 if( _card_list[i].UID[2] != RfChip.uid.uidByte[2] ) continue;
Toby_Chen 0:f266ca250f98 56 if( _card_list[i].UID[3] != RfChip.uid.uidByte[3] ) continue;
Toby_Chen 0:f266ca250f98 57
Toby_Chen 0:f266ca250f98 58 if( _card_buf != _card_list[i].type ) return true;
Toby_Chen 0:f266ca250f98 59 else return false;
Toby_Chen 0:f266ca250f98 60 }
Toby_Chen 0:f266ca250f98 61
Toby_Chen 0:f266ca250f98 62 return ERR;
Toby_Chen 0:f266ca250f98 63 };
Toby_Chen 0:f266ca250f98 64
Toby_Chen 0:f266ca250f98 65 Card::Card( int a, int b, int c, int d, CardName card ) {
Toby_Chen 0:f266ca250f98 66
Toby_Chen 0:f266ca250f98 67 UID[0] = a;
Toby_Chen 0:f266ca250f98 68 UID[1] = b;
Toby_Chen 0:f266ca250f98 69 UID[2] = c;
Toby_Chen 0:f266ca250f98 70 UID[3] = d;
Toby_Chen 0:f266ca250f98 71
Toby_Chen 0:f266ca250f98 72 type = card;
Toby_Chen 0:f266ca250f98 73
Toby_Chen 0:f266ca250f98 74 }