/*--------------------------------------------------------------------------- * * USB Biopod 3500 User Program - version 0.1.1 * * Micah Villmow, Michael A. Smith * Summer 2005 * Copyright 2005 - Michael A. Smith and Micah Villmow - All Rights Reserved * Purpose: To test the USB Biopod * *--------------------------------------------------------------------------*/ #ifndef _BIOPOD_UP_UI_H_ #define _BIOPOD_UP_UI_H_ #include "../biopod/biopod.h" /* for biopod functionality */ #include /* for file ops (open, close) */ #include /* for our beloved ioctl's */ /*--------------------------------------------------------------------------- * * WW WW WW W WW WWWW WW WW * WW WW W WW WW W WW * WWW WW WW WWW WW WWW W WW WW W W WW WW WWW * WW W WW WW W WW W WW W W WW W WW WWWW W WW WW WW W * WW W WW WW W WW W WW W W WW W WW WW WW WW WW WW WW W * WWW WW WW WWW WW WWW WWWW WW WW WWW WW WW WW W * WW * WW * *--------------------------------------------------------------------------*/ /* Constants */ #define DEVICE biopod_fd #define DEVICE_LOC "/dev/biopod0" #define OPEN_MODE O_RDONLY /* stuff to simplify (or obfuscate?) code */ #define weAreNoLongerGoingToUseTheDevice \ if (theDeviceIsAlreadyOpen) close(DEVICE) #define informUserThatWeCannotUseTheDevice #define weAreNowGoingToUseTheDevice weAreCurrentlyUsingTheDevice = true #define weAreDoneUsingTheDeviceForNow weAreCurrentlyUsingTheDevice = false #define stopTheDeviceFromDoingWhateverItIsDoing ioctl(DEVICE, BIOPOD_IOCSTOP) #define initializeTheDevice ioctl(DEVICE, BIOPOD_IOCSTART); ioctl(DEVICE, BIOPOD_IOCDEFAULT) #define putScanOfDeviceIn(x) ioctl(DEVICE, BIOPOD_IOCGIMAGE, &(*x)) #define getFingerprint putScanOfDeviceIn(&image) #define useTheDeviceToInitializeImage(x) ioctl(DEVICE, BIOPOD_IOCQIMAGE, (x)) #define console(x) fprintf(stderr, x ); fprintf(stderr, "\n") #define weAre(x) statusDisplay->setText(x); console(x) #define weAre2(x, y) fprintf(stderr, x, y ); fprintf(stderr, "\n") #define weAre3(x, y, z) fprintf(stderr, x, y, z ); fprintf(stderr, "\n") #define weAreDoingNothing weAre("Idle...") /* Global Data Members */ int biopod_fd; bool theDeviceIsAlreadyOpen; bool weAreCurrentlyUsingTheDevice; biopod_image image; QPixmap *pixmap; /* Member Functions */ bool biopodUP::ableToDisplayFingerprint() { if (pixmap->paintingActive()) return false; if (pixmap->loadFromData(image.data, image.num_rows * image.num_cols, "pgm", QPixmap::Mono)) { weAre("Not able to display fingerprint") ; return false; } fingerprintDisplay->setPixmap(*pixmap); fingerprintDisplay->repaint(); return true; } bool biopodUP::notAbleToOpenTheDevice() { weAre("Openining device..."); if (!(DEVICE = open(DEVICE_LOC, OPEN_MODE))) { weAre("Unable to open device."); return true; } initializeTheDevice; weAre("Device has been initialized"); theDeviceIsAlreadyOpen = true; return false; } bool biopodUP::weAreAbleToCreateAndInitializeImage(biopod_image *im) { if ((!im) || (!(im = (biopod_image *)malloc(sizeof(*im))))) { weAre("Unable to create image"); return false; } //weAre("Using the device to initialize image"); //useTheDeviceToInitializeImage(im); image.num_rows = image.num_cols = 128; weAre3("Image: (%d, %d)", im->num_rows, im->num_cols); image.data = (matrix_data_t *) malloc(sizeof(matrix_data_t) * image.num_cols * image.num_rows); if (!(image.data)) return false; return true; } void biopodUP::freeImage(biopod_image *im) { if ((im) && (im->data)) free(im->data); } bool biopodUP::weAreAbleToCreateAndInitializeAllDataMembers() { if (!theDeviceIsAlreadyOpen) { weAre("Device isn't open, cannot initialize"); return false; } if (weAreAbleToCreateAndInitializeImage(&image)) { pixmap = new QPixmap(image.num_cols, image.num_rows, -1, QPixmap::DefaultOptim); weAre("Initialization of data members done"); return true; } return false; } void biopodUP::freeAllDataMembers() { /* apparently not necessary */ //freeImage(image); } bool biopodUP::weCannotUseTheDevice() { weAre("Checking device..."); if (!((theDeviceIsAlreadyOpen) || (!notAbleToOpenTheDevice()))) { weAre("Unable to use the device"); return true; } if (weAreAbleToCreateAndInitializeAllDataMembers()) { weAre("Able to use the device"); return false; } weAre("Unable to use the device"); return true; } /* Interceptor for all "close" events */ void biopodUP::closeEvent( QCloseEvent * ) { fileExit(); } /* really closes the application */ void biopodUP::fileExit() { weAre("Exiting..."); if (theDeviceIsAlreadyOpen) { stopBiopodScan(); weAreNoLongerGoingToUseTheDevice; freeAllDataMembers(); } QApplication::exit(0); } /* Try Enrolling a fingerprint */ void biopodUP::tryToEnrollFingerprint() { if (weCannotUseTheDevice()) informUserThatWeCannotUseTheDevice; else { weAreNowGoingToUseTheDevice; weAreDoneUsingTheDeviceForNow; } weAreDoingNothing; } /* Try continuously scanning from the Biopod (for demo purposes)*/ void biopodUP::tryToShowBiopodScan() { if (weCannotUseTheDevice()) informUserThatWeCannotUseTheDevice; else { weAreNowGoingToUseTheDevice; while (weAreCurrentlyUsingTheDevice) { weAre("Getting fingerprint"); getFingerprint; /* for (int r = 0; r < image.num_rows; r++) { for (int c = 0; c < image.num_cols; c++) fprintf(stderr, "Image[%d][%d]=%d ", r, c, int((image.data)[(r*image.num_cols)+c])); fprintf(stderr, "\n"); } */ if (ableToDisplayFingerprint()) { //weAre("Displaying Fingerprint..."); } else { weAre("Not Displaying Fingerprint"); } sleep(2); } weAreDoneUsingTheDeviceForNow; } weAreDoingNothing; } /* Try identifying a scanned fingerprint */ void biopodUP::tryToIdentifyFingerprint() { if (weCannotUseTheDevice()) informUserThatWeCannotUseTheDevice; else { weAreNowGoingToUseTheDevice; weAreDoneUsingTheDeviceForNow; } weAreDoingNothing; } /* Halt any scanning from the Biopod */ void biopodUP::stopBiopodScan() { weAre("Stopping all device actions..."); if (weAreCurrentlyUsingTheDevice) { stopTheDeviceFromDoingWhateverItIsDoing; weAreDoneUsingTheDeviceForNow; } weAreDoingNothing; } /* called at application load */ void biopodUP::init() { theDeviceIsAlreadyOpen = false; weAreCurrentlyUsingTheDevice = false; weAre("Welcome to BiopodUP!"); } /* called at application close */ void biopodUP::destroy() { /* nothing to do */ } /*--------------------------------------------------------------------------*/ #endif /* end defining _BIOPOD_UP_UI_H_*/