Trung Nguyen / Mbed 2 deprecated FINAL_PROJECT_4180

Dependencies:   mbed

Fork of FINAL_PROJECT_4180 by Gedeon Nyengele

Files at this revision

API Documentation at this revision

Comitter:
nyengele
Date:
Mon Apr 25 01:57:10 2016 +0000
Parent:
9:48e93bcd1d5c
Child:
11:1d7021c0739d
Commit message:
added some additional helpers for hash tables;

Changed in this revision

lib.cpp Show annotated file Show diff for this revision Revisions of this file
lib.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/lib.cpp	Mon Apr 25 01:39:32 2016 +0000
+++ b/lib.cpp	Mon Apr 25 01:57:10 2016 +0000
@@ -202,3 +202,20 @@
     }
     return val;
 }
+
+void add_to_table(HASH_RECORD *table, int ind, int user_id, int hash)
+{
+    HASH_RECORD rec = {user_id, hash};
+    table[ind] = rec;
+}
+
+bool contain_hash(HASH_RECORD *table, int table_size, int user_id, int hash)
+{
+    for (int i = 0; i < table_size; i++) {
+        HASH_RECORD h = table[i];
+        if (h.user_id == user_id && h.hash == hash) {
+            return false;
+        }
+    }
+    return false;
+}
--- a/lib.h	Mon Apr 25 01:39:32 2016 +0000
+++ b/lib.h	Mon Apr 25 01:57:10 2016 +0000
@@ -2,6 +2,11 @@
 #include "FPScanner.h"
 #include "uLCD_4DGL.h"
 
+typedef struct{
+    int user_id;
+    int hash;
+} HASH_RECORD;
+
 int hashcode(const char *data, int size);
 void read_mag_card(Serial *device, char *dest, int *size);
 bool fp_enroll(FPScanner *fp);
@@ -13,4 +18,6 @@
 void buzzer(PwmOut *speaker, int seconds);
 void failure_display(uLCD_4DGL *lcd, char *text);
 void success_display(uLCD_4DGL *lcd, char *text);
-int id_to_int(char *user_id, int size);
\ No newline at end of file
+int id_to_int(char *user_id, int size);
+void add_to_table(HASH_RECORD *table, int ind, int user_id, int hash);
+bool contain_hash(HASH_RECORD *table, int table_size, int user_id, int hash);
\ No newline at end of file
--- a/main.cpp	Mon Apr 25 01:39:32 2016 +0000
+++ b/main.cpp	Mon Apr 25 01:57:10 2016 +0000
@@ -11,6 +11,9 @@
 SPI spi(p5, p6, p7); // MOSI, MISO, CLK
 DigitalOut cs(p20);  // Chip Select
 
+// hash table
+const int MAX_ENTRIES = 100;
+HASH_RECORD records[MAX_ENTRIES];
 
 int main()
 {