Main
user.h@2:8441bd03d9bc, 2015-12-08 (annotated)
- Committer:
- chinetion
- Date:
- Tue Dec 08 18:33:16 2015 +0000
- Revision:
- 2:8441bd03d9bc
- Parent:
- 0:57b3f673b395
last
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chinetion | 0:57b3f673b395 | 1 | #include "eeprom.h" |
chinetion | 0:57b3f673b395 | 2 | #include "mbed.h" |
chinetion | 0:57b3f673b395 | 3 | class USER{ |
chinetion | 0:57b3f673b395 | 4 | public: |
chinetion | 0:57b3f673b395 | 5 | USER(PinName,PinName,uint8_t); |
chinetion | 0:57b3f673b395 | 6 | void save(uint32_t ,char*,char* ,char*); |
chinetion | 0:57b3f673b395 | 7 | void rfid(int8_t ,char *); |
chinetion | 0:57b3f673b395 | 8 | void pass(int8_t ,char *); |
chinetion | 0:57b3f673b395 | 9 | void time(int8_t ,char *); |
chinetion | 0:57b3f673b395 | 10 | void savepos(char); |
chinetion | 0:57b3f673b395 | 11 | char getpos(); |
chinetion | 0:57b3f673b395 | 12 | void savenum(char); |
chinetion | 0:57b3f673b395 | 13 | char getnum(); |
chinetion | 2:8441bd03d9bc | 14 | void saveprice(int32_t); |
chinetion | 2:8441bd03d9bc | 15 | int32_t getprice(); |
chinetion | 0:57b3f673b395 | 16 | private: |
chinetion | 0:57b3f673b395 | 17 | EEPROM rom; |
chinetion | 0:57b3f673b395 | 18 | }; |
chinetion | 0:57b3f673b395 | 19 | USER::USER(PinName sda,PinName scl,uint8_t adr):rom(sda,scl,adr){} |
chinetion | 0:57b3f673b395 | 20 | void USER::save(uint32_t id,char *rfid,char *pass,char *time){ |
chinetion | 0:57b3f673b395 | 21 | uint32_t _id = id/2*((id-1)*96); |
chinetion | 0:57b3f673b395 | 22 | rom.write(_id,rfid,16);wait_ms(10); |
chinetion | 0:57b3f673b395 | 23 | rom.write(_id+32,pass,4);wait_ms(10); |
chinetion | 0:57b3f673b395 | 24 | rom.write(_id+32+32,time,6);wait_ms(10); |
chinetion | 0:57b3f673b395 | 25 | |
chinetion | 0:57b3f673b395 | 26 | } |
chinetion | 0:57b3f673b395 | 27 | void USER::savepos(char pos){ |
chinetion | 0:57b3f673b395 | 28 | rom.write(1000,pos);wait_ms(10); |
chinetion | 0:57b3f673b395 | 29 | } |
chinetion | 0:57b3f673b395 | 30 | char USER::getpos(){ |
chinetion | 0:57b3f673b395 | 31 | int8_t pos; |
chinetion | 0:57b3f673b395 | 32 | rom.read(1000,pos);wait_ms(10); |
chinetion | 0:57b3f673b395 | 33 | return (char)pos; |
chinetion | 0:57b3f673b395 | 34 | } |
chinetion | 0:57b3f673b395 | 35 | void USER::savenum(char pos){ |
chinetion | 0:57b3f673b395 | 36 | rom.write(1005,pos);wait_ms(10); |
chinetion | 0:57b3f673b395 | 37 | } |
chinetion | 0:57b3f673b395 | 38 | char USER::getnum(){ |
chinetion | 0:57b3f673b395 | 39 | int8_t pos; |
chinetion | 0:57b3f673b395 | 40 | rom.read(1005,pos);wait_ms(10); |
chinetion | 0:57b3f673b395 | 41 | return (char)pos; |
chinetion | 0:57b3f673b395 | 42 | } |
chinetion | 2:8441bd03d9bc | 43 | void USER::saveprice(int32_t price){ |
chinetion | 2:8441bd03d9bc | 44 | rom.write(1010,price);wait_ms(10); |
chinetion | 2:8441bd03d9bc | 45 | } |
chinetion | 2:8441bd03d9bc | 46 | int32_t USER::getprice(){ |
chinetion | 2:8441bd03d9bc | 47 | int32_t price; |
chinetion | 2:8441bd03d9bc | 48 | rom.read(1010,price);wait_ms(10); |
chinetion | 2:8441bd03d9bc | 49 | return price; |
chinetion | 2:8441bd03d9bc | 50 | } |
chinetion | 0:57b3f673b395 | 51 | void USER::rfid(int8_t id,char *rfid){ |
chinetion | 0:57b3f673b395 | 52 | uint32_t _id = id/2*((id-1)*96); |
chinetion | 0:57b3f673b395 | 53 | rom.read(_id,rfid,16); |
chinetion | 0:57b3f673b395 | 54 | wait_ms(10); |
chinetion | 0:57b3f673b395 | 55 | } |
chinetion | 0:57b3f673b395 | 56 | void USER::pass(int8_t id,char *pass){ |
chinetion | 0:57b3f673b395 | 57 | uint32_t _id = id/2*((id-1)*96); |
chinetion | 0:57b3f673b395 | 58 | rom.read(_id+32,pass,4); |
chinetion | 0:57b3f673b395 | 59 | wait_ms(10); |
chinetion | 0:57b3f673b395 | 60 | } |
chinetion | 0:57b3f673b395 | 61 | void USER::time(int8_t id,char *time){ |
chinetion | 0:57b3f673b395 | 62 | uint32_t _id = id/2*((id-1)*96); |
chinetion | 0:57b3f673b395 | 63 | rom.read(_id+32+32,time,6); |
chinetion | 0:57b3f673b395 | 64 | wait_ms(10); |
chinetion | 0:57b3f673b395 | 65 | } |