No Description

zfm20.cxx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Author: Jon Trulson <jtrulson@ics.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <unistd.h>
  25. #include <iostream>
  26. #include <signal.h>
  27. #include "zfm20.h"
  28. using namespace std;
  29. using namespace upm;
  30. int main (int argc, char **argv)
  31. {
  32. //! [Interesting]
  33. // Instantiate a ZFM20 Fingerprint reader on UART 0
  34. upm::ZFM20* fp = new upm::ZFM20(0);
  35. // make sure port is initialized properly. 57600 baud is the default.
  36. if (!fp->setupTty(B57600))
  37. {
  38. cerr << "Failed to setup tty port parameters" << endl;
  39. return 1;
  40. }
  41. // first, set the default password and address
  42. fp->setPassword(ZFM20_DEFAULT_PASSWORD);
  43. fp->setAddress(ZFM20_DEFAULT_ADDRESS);
  44. // now verify the password. If this fails, any other commands
  45. // will be ignored, so we just bail.
  46. if (fp->verifyPassword())
  47. {
  48. cout << "Password verified." << endl;
  49. }
  50. else
  51. {
  52. cerr << "Password verification failed." << endl;
  53. return 1;
  54. }
  55. // how many valid stored templates (fingerprints) do we have?
  56. cout << "Total stored templates: " << fp->getNumTemplates() << endl;
  57. cout << endl;
  58. // now spin waiting for a fingerprint to successfully image
  59. cout << "Waiting for finger print..." << endl;
  60. while (fp->generateImage() == ZFM20::ERR_NO_FINGER)
  61. ;
  62. // in theory, we have an image
  63. cout << "Image captured, converting..." << endl;
  64. uint8_t rv;
  65. if ((rv = fp->image2Tz(1)) != ZFM20::ERR_OK)
  66. {
  67. cerr << "Image conversion failed with error code " << int(rv) <<endl;
  68. return 1;
  69. }
  70. cout << "Image conversion succeeded." << endl;
  71. cout << "Searching database..." << endl;
  72. uint16_t id = 0;
  73. uint16_t score = 0;
  74. // we search for a print matching slot 1, where we shored our last
  75. // converted fingerprint
  76. if ((rv = fp->search(1, &id, &score)) != ZFM20::ERR_OK)
  77. {
  78. if (rv == ZFM20::ERR_FP_NOTFOUND)
  79. {
  80. cout << "Finger Print not found" << endl;
  81. return 0;
  82. }
  83. else
  84. {
  85. cerr << "Search failed with error code " << int(rv) <<endl;
  86. return 1;
  87. }
  88. }
  89. cout << "Fingerprint found!" << endl;
  90. cout << "ID: " << int(id) << ", Score: " << int(score) << endl;
  91. //! [Interesting]
  92. delete fp;
  93. return 0;
  94. }