Same library as tosihisa, but with extensions for SetTemplate, DeleteAllIDs, and SendData.
Dependents: GT511C3_demo GT511C3 IOTProjectCodeDavidBruce15597305
Fork of GT511C3 by
Diff: GT511C3.cpp
- Revision:
- 1:aa0bd9bd1c56
- Parent:
- 0:90c64cb9db58
- Child:
- 2:8fa6daf39d91
diff -r 90c64cb9db58 -r aa0bd9bd1c56 GT511C3.cpp --- a/GT511C3.cpp Fri Jan 03 16:00:00 2014 +0000 +++ b/GT511C3.cpp Tue Dec 01 18:13:20 2015 +0000 @@ -105,6 +105,32 @@ return 0; } +int GT511C3::SendData(unsigned char *data,unsigned long size) +{ + const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 }; + unsigned short sum = 0; + int i; + + for(i = 0;i < 4;i++){ + while(!writeable()); + putc(fixedbuf[i]); + sum += fixedbuf[i]; + } + + for(i = 0;i < size;i++){ + while(!writeable()); + putc(data[i]); + sum += data[i]; + } + + while(!writeable()); + putc((unsigned char)(sum & 0xff)); + while(!writeable()); + putc((unsigned char)((sum >> 8) & 0xff)); + + return 0; +} + int GT511C3::RecvData(unsigned char *data,unsigned long size) { const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 }; @@ -335,6 +361,30 @@ return -1; } +int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size) +{ + unsigned long Parameter = 0xFFFF0000 | ID; + unsigned short Response = 0; + int sts = 0; + + sts = SendRecv(CMD_DeleteID,&Parameter,&Response); + + if ((sts != 0) || (Response != CMD_Ack)) + return -1; + + sts = SendData(data, size); + + if (sts != 0) + return -1; + + sts = RecvResponse(&Parameter, &Response); + + if ((sts != 0) || (Response != CMD_Ack)) + return -1; + + return 0; +} + int GT511C3::DeleteID(int ID) { unsigned long Parameter = ID; @@ -346,3 +396,15 @@ return 0; return -1; } + +int GT511C3::DeleteAllIDs() +{ + unsigned long Parameter = 0; + unsigned short Response = 0; + int sts = 0; + + sts = SendRecv(CMD_DeleteAll,&Parameter,&Response); + if((sts == 0) && (Response == CMD_Ack)) + return 0; + return -1; +}