Coordinator v2
Dependencies: NerfUSXbee PinDetect EthernetInterface JSON MFRC522 WebSocketClient mbed-rtos mbed
includes/Rfid.hpp@2:019d8848cf7e, 2017-04-11 (annotated)
- Committer:
- Ismael Balafrej
- Date:
- Tue Apr 11 12:40:05 2017 -0400
- Revision:
- 2:019d8848cf7e
- Child:
- 3:501120a68c11
Final version without allies/enemies
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ismael Balafrej |
2:019d8848cf7e | 1 | #include "ports.hpp" |
Ismael Balafrej |
2:019d8848cf7e | 2 | #include "MFRC522.h" |
Ismael Balafrej |
2:019d8848cf7e | 3 | #include "serverEvents.hpp" |
Ismael Balafrej |
2:019d8848cf7e | 4 | |
Ismael Balafrej |
2:019d8848cf7e | 5 | class Rfid |
Ismael Balafrej |
2:019d8848cf7e | 6 | { |
Ismael Balafrej |
2:019d8848cf7e | 7 | public: |
Ismael Balafrej |
2:019d8848cf7e | 8 | Thread rfid_thread; |
Ismael Balafrej |
2:019d8848cf7e | 9 | |
Ismael Balafrej |
2:019d8848cf7e | 10 | Rfid(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset) : RfChip(mosi, miso, sclk, cs, reset) |
Ismael Balafrej |
2:019d8848cf7e | 11 | { |
Ismael Balafrej |
2:019d8848cf7e | 12 | RfChip.PCD_Init(); |
Ismael Balafrej |
2:019d8848cf7e | 13 | rfid_thread = Thread(osPriorityNormal, 850); |
Ismael Balafrej |
2:019d8848cf7e | 14 | rfid_thread.start(this, &Rfid::read_rfid); |
Ismael Balafrej |
2:019d8848cf7e | 15 | } |
Ismael Balafrej |
2:019d8848cf7e | 16 | |
Ismael Balafrej |
2:019d8848cf7e | 17 | void read_rfid() |
Ismael Balafrej |
2:019d8848cf7e | 18 | { |
Ismael Balafrej |
2:019d8848cf7e | 19 | ServerEvent event; |
Ismael Balafrej |
2:019d8848cf7e | 20 | strcpy(event.event, "gun"); |
Ismael Balafrej |
2:019d8848cf7e | 21 | while(1) |
Ismael Balafrej |
2:019d8848cf7e | 22 | { |
Ismael Balafrej |
2:019d8848cf7e | 23 | if (RfChip.PICC_IsNewCardPresent() && RfChip.PICC_ReadCardSerial()) |
Ismael Balafrej |
2:019d8848cf7e | 24 | { |
Ismael Balafrej |
2:019d8848cf7e | 25 | for (uint8_t i = 0; i < RfChip.uid.size; i++) |
Ismael Balafrej |
2:019d8848cf7e | 26 | { |
Ismael Balafrej |
2:019d8848cf7e | 27 | itoa(RfChip.uid.uidByte[i], &(event.data.rfid_code[i]), 10); |
Ismael Balafrej |
2:019d8848cf7e | 28 | } |
Ismael Balafrej |
2:019d8848cf7e | 29 | event.data.rfid_code[RfChip.uid.size] = '\0'; |
Ismael Balafrej |
2:019d8848cf7e | 30 | //toPc("RFID received, sending event name: %s, size: %i", event.event, RfChip.uid.size); |
Ismael Balafrej |
2:019d8848cf7e | 31 | websocket_message_send(event); |
Ismael Balafrej |
2:019d8848cf7e | 32 | } |
Ismael Balafrej |
2:019d8848cf7e | 33 | Thread::wait(500); |
Ismael Balafrej |
2:019d8848cf7e | 34 | } |
Ismael Balafrej |
2:019d8848cf7e | 35 | } |
Ismael Balafrej |
2:019d8848cf7e | 36 | |
Ismael Balafrej |
2:019d8848cf7e | 37 | private: |
Ismael Balafrej |
2:019d8848cf7e | 38 | MFRC522 RfChip; |
Ismael Balafrej |
2:019d8848cf7e | 39 | |
Ismael Balafrej |
2:019d8848cf7e | 40 | }; |