Kamis, 09 Februari 2017

raspberry PI Fingerprint


https://www.sparkfun.com/products/11792
https://github.com/the-AjK/GT-511C3
https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=84572
http://devnotes.fabioluiz.de/spring-boot-libfprint
http://sergeplay.blogspot.co.id/2016/01/cheap-usb-fingerprint-reader-from.html

sudo apt-get install libfprint


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <libfprint/fprint.h>

struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
{
   struct fp_dscv_dev *ddev = discovered_devs[0];
   struct fp_driver *drv;
   if (!ddev)
      return NULL;
 
   drv = fp_dscv_dev_get_driver(ddev);
   printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
   return ddev;
}

struct fp_print_data *enroll(struct fp_dev *dev) {
   struct fp_print_data *enrolled_print = NULL;
   int r;

   printf("You will need to successfully scan your finger %d times to "
      "complete the process.\n", fp_dev_get_nr_enroll_stages(dev));

   do {
      struct fp_img *img = NULL;
 
      sleep(1);
      printf("\nScan your finger now.\n");

      r = fp_enroll_finger_img(dev, &enrolled_print, &img);
      if (img) {
         fp_img_save_to_file(img, "enrolled.pgm");
         printf("Wrote scanned image to enrolled.pgm\n");
         fp_img_free(img);
      }
      if (r < 0) {
         printf("Enroll failed with error %d\n", r);
         return NULL;
      }

      switch (r) {
      case FP_ENROLL_COMPLETE:
         printf("Enroll complete!\n");
         break;
      case FP_ENROLL_FAIL:
         printf("Enroll failed, something wen't wrong :(\n");
         return NULL;
      case FP_ENROLL_PASS:
         printf("Enroll stage passed. Yay!\n");
         break;
      case FP_ENROLL_RETRY:
         printf("Didn't quite catch that. Please try again.\n");
         break;
      case FP_ENROLL_RETRY_TOO_SHORT:
         printf("Your swipe was too short, please try again.\n");
         break;
      case FP_ENROLL_RETRY_CENTER_FINGER:
         printf("Didn't catch that, please center your finger on the "
            "sensor and try again.\n");
         break;
      case FP_ENROLL_RETRY_REMOVE_FINGER:
         printf("Scan failed, please remove your finger and then try "
            "again.\n");
         break;
      }
   } while (r != FP_ENROLL_COMPLETE);

   if (!enrolled_print) {
      fprintf(stderr, "Enroll complete but no print?\n");
      return NULL;
   }

   printf("Enrollment completed!\n\n");
   return enrolled_print;
}

int main(void)
{
   int r = 1;
   struct fp_dscv_dev *ddev;
   struct fp_dscv_dev **discovered_devs;
   struct fp_dev *dev;
   struct fp_print_data *data;

   printf("This program will enroll your right index finger, "
      "unconditionally overwriting any right-index print that was enrolled "
      "previously. If you want to continue, press enter, otherwise hit "
      "Ctrl+C\n");
   getchar();

   r = fp_init();
   if (r < 0) {
      fprintf(stderr, "Failed to initialize libfprint\n");
      exit(1);
   }
   fp_set_debug(3);

   discovered_devs = fp_discover_devs();
   if (!discovered_devs) {
      fprintf(stderr, "Could not discover devices\n");
      goto out;
   }

   ddev = discover_device(discovered_devs);
   if (!ddev) {
      fprintf(stderr, "No devices detected.\n");
      goto out;
   }

   dev = fp_dev_open(ddev);
   fp_dscv_devs_free(discovered_devs);
   if (!dev) {
      fprintf(stderr, "Could not open device.\n");
      goto out;
   }

   printf("Opened device. It's now time to enroll your finger.\n\n");
   data = enroll(dev);
   if (!data)
      goto out_close;

   r = fp_print_data_save(data, RIGHT_INDEX);
   if (r < 0)
      fprintf(stderr, "Data save failed, code %d\n", r);

   fp_print_data_free(data);
out_close:
   fp_dev_close(dev);
out:
   fp_exit();
   return r;
}

===========

Cheap USB fingerprint reader (from Laptop) works with Raspberry Pi

sudo apt-get install libpam-fprintd

And then testing:

> sudo fprintd-enroll 
Using device /net/reactivated/Fprint/Device/0
Enrolling right-index-finger finger.
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-completed

> sudo fprintd-verify
Using device /net/reactivated/Fprint/Device/0
Listing enrolled fingers:
 - #0: right-index-finger
Verify result: verify-match (done)