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:39:32 2016 +0000
Parent:
8:9b41712fd2c3
Child:
10:c3556e27e576
Commit message:
user_id to int done

Changed in this revision

MEM.h Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MEM.h	Mon Apr 25 01:39:32 2016 +0000
@@ -0,0 +1,105 @@
+#ifndef MEM_H
+#define MEM_H
+
+#include "mbed.h"
+
+#define MEM_START_ADDR      0
+#define MEM_PAGE_OFFSET     (1 << 8)
+#define MEM_SECTOR_OFFSET   (1 << 12)
+
+// Chip Manufacturer Info
+typedef struct {
+    int manuf_id;
+    int mem_type;
+    int mem_size;
+} FLASH_MEM_INFO;
+
+// Supported Commands
+struct FLASH_MEM_CMD {
+    static const int WREN         = 0x06;  // Set Write Enable Latch
+    static const int WRDI         = 0x04;  // Reset Write Enable Latch
+    static const int RDSR         = 0x05;  // Read Status Register
+    static const int WRSR         = 0x01;  // Write Status Register
+    static const int READ         = 0x03;  // Read Data from Memory Array
+    static const int FAST_READ    = 0x0B;  // Read Data from Memory Array (with dummy cycles)
+    static const int PROGRAM      = 0x02;  // Program Data Into Memory Array
+    static const int SECTOR_ERASE = 0x20;  // Erase 1 4KB Sector in Memory
+    static const int BLOCK_ERASE  = 0x52;  // Erase 1 64KB Block in Memory
+    static const int CHIP_ERASE   = 0x60;  // Erase Entire Memory Array
+    static const int RDID         = 0x9F;  // Read Manufacturer and Product ID
+};
+
+// Memory Operations Status
+enum MEM_STATUS {
+    FAIL    = 0,
+    SUCCESS,
+    BUSY,
+    READY,
+};
+
+
+class MEM_DEVICE
+{
+    SPI *dev;
+
+public:
+     /**
+     * Constructor
+     *
+     * @param mosi MOSI pin for SPI
+     * @param miso MISO pin for SPI
+     * @param sck  clock pin for SPI
+     * @param cs Chip Select pin
+     */
+     MEM_DEVICE(PinName mosi, PinName miso, PinName sck, PinName cs);
+     
+     
+     /**
+     * Destructor
+     */
+     ~MEM_DEVICE();
+     
+     /**
+     * Set mode and number of bits to use
+     *
+     * @param databits number data bits
+     * @param mode SPI mode to use (0, 1, 2, 3)
+     */
+     void format(int databits, int mode);
+    
+     /**
+     * Read multiple consecutive bytes from memory device
+     *
+     * @param startAddr address where to start reading from
+     * @param numOfBytes number of consecutive bytes to read
+     * @param destBuffer buffer where to copy bytes to
+     * @return status of the read operation (FAIL or SUCCESS)
+     */
+     MEM_STATUS read_bytes(int startAddr, int numOfBytes, char *destBuffer);
+
+     /**
+     * Write multiple consecutive bytes to memory device
+     *
+     * @param startAddr address where to start writing to
+     * @param numOfBytes number of consecutive bytes to write
+     * @param srcBuffer buffer where to write from
+     * @return status of the write operation (FAIL or SUCCESS)
+     */
+     MEM_STATUS write_bytes(int startAddr, int numOfBytes, char *srcBuffer);
+     
+     /**
+     * Clears the entire flash memory
+     *
+     * @return status of the clear operation (FAIL or SUCCESS)
+     */
+     MEM_STATUS erase();
+    
+    /**
+     * Reads the status of the memory device
+     *
+     * @return status of the operation (FAIL, BUSY, READY)
+     */
+     MEM_STATUS read_status();
+};
+
+#endif
\ No newline at end of file
--- a/lib.cpp	Mon Apr 25 01:18:04 2016 +0000
+++ b/lib.cpp	Mon Apr 25 01:39:32 2016 +0000
@@ -193,3 +193,12 @@
     lcd->text_height(4);
     lcd->text_string(text, 1, 4, FONT_7X8, BLUE);
 }
+
+int id_to_int(char *user_id, int size)
+{
+    int val = 0;
+    for (int i = 0; i < size; i++) {
+        val += 10 * val + (user_id[i] - '0');
+    }
+    return val;
+}
--- a/lib.h	Mon Apr 25 01:18:04 2016 +0000
+++ b/lib.h	Mon Apr 25 01:39:32 2016 +0000
@@ -12,4 +12,5 @@
 bool speech_enroll(char *user_id, Serial *android);
 void buzzer(PwmOut *speaker, int seconds);
 void failure_display(uLCD_4DGL *lcd, char *text);
-void success_display(uLCD_4DGL *lcd, char *text);
\ No newline at end of file
+void success_display(uLCD_4DGL *lcd, char *text);
+int id_to_int(char *user_id, int size);
\ No newline at end of file
--- a/main.cpp	Mon Apr 25 01:18:04 2016 +0000
+++ b/main.cpp	Mon Apr 25 01:39:32 2016 +0000
@@ -2,19 +2,17 @@
 #include "lib.h"
 
 Serial mag_card(p13, p14);
-Serial pc(USBTX, USBRX);
+Serial android(USBTX, USBRX);
+FPScanner fp(p9, p10);
+uLCD_4DGL lcd(p28, p27, p30);
+PwmOut speaker(p21);
+
+// Flash Memory
+SPI spi(p5, p6, p7); // MOSI, MISO, CLK
+DigitalOut cs(p20);  // Chip Select
 
 
 int main()
 {
-    char card_data[250];
-    int bytes_read;
-    int hash;
-
-    while (true) {
-        read_mag_card(&mag_card, card_data, &bytes_read);
-        hash = hashcode(card_data, bytes_read);
-        pc.printf("Bytes read: %d\n\rHash Code: %d\n\r", bytes_read, hash);
-        wait(2);        
-    }
+   
 }