Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Revision:
3:70a7b64fbd98
Parent:
2:e504a3cfe113
Child:
4:9cac024c057c
--- a/main.h	Sat Apr 02 13:50:00 2016 +0000
+++ b/main.h	Fri Apr 15 07:45:23 2016 +0000
@@ -14,6 +14,7 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "SRF02.h"
+#include "SDFileSystem.h"
 
 
 /**  
@@ -51,49 +52,68 @@
 //         VCC, SCE, RST, D/C, MOSI, SCLK, LED
 N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3);
 SRF02 srf02(I2C_SDA,I2C_SCL);
+//              MOSI, MISO, SCK, CS
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); 
 Serial pc(USBTX,USBRX);
 PwmOut led_alarm(PTC10);
 PwmOut buzzer(PTC11);
 InterruptIn button_0(PTB23);
 InterruptIn button_1(PTA2);
 InterruptIn button_c(PTC2);
-Ticker read_distance;
-
 InterruptIn sw2(SW2);
 InterruptIn sw3(SW3);
+Ticker setting_distance;
+Ticker intruder_distance;
+Timeout transition;
 DigitalOut r_led(LED_RED);
 DigitalOut g_led(LED_GREEN);
 DigitalOut b_led(LED_BLUE);
 
 struct State {
-    int nextState[3];  // array of next states which depend on which button was pressed
+    int nextState[4];  // array of next states which depend on which button was pressed
 };
 typedef const struct State STyp;
 
 STyp fsm[9] = {
-    {0,0,0},  // 0 - initialisation (title screen)
-    {2,1,3},  // 1 - main menu (Set alarm or set new password)
-    {2,2,4}, // 2 - set alarm
-    {3,3,1}, // 3 - set new password
-    {4,4,5}, // 4 - setting calibration
-    {7,5,6}, // 5 - alarm activated
-    {6,6,1}, // 6 - deactivate without triggering (enter password)
-    {7,7,1}, // 7 - alarm triggered (enter password)
-    {8,8,1}   // 8 - display time when alarm was triggered
+    {0,0,0,0},  // 0 - initialisation (title screen)
+    {2,1,3,3},  // 1 - main menu (Set alarm or set new password)
+    {2,2,4,1}, // 2 - set alarm
+    {3,3,1,1}, // 3 - set new password
+    {4,4,4,4}, // 4 - setting calibration
+    {7,5,6,6}, // 5 - alarm activated
+    {6,6,1,5}, // 6 - deactivate without triggering (enter password)
+    {7,7,1,8}, // 7 - alarm triggered (enter password)
+    {8,8,1,1}   // 8 - display time when alarm was triggered
 };
 
+FILE *pin; // this is our file pointer
+
+int entered_pin[4];
+int set_pin[4];
+int index_array[4];
+
+int pin_counter;
+
 int g_current_state;
+int g_next_state;
 
-int distance[10]; /*!< Stores 10 distance readings from SRF02 */
-int one_second_distance = 0;
-float one_second_avg_distance = 0;
-int read_distance_counter = 0;
+float distance[10]; /*!< Stores 10 distance readings from SRF02 */
+float one_second_distance;
+double one_second_avg_distance;
+double initial_setting_distance;
 
-volatile int g_read_distance_flag; /*!< Flag in read_distance_isr */
+int setting_distance_counter;
+int intruder_distance_counter;
+
+volatile int g_setting_distance_flag; /*!< Flag in setting_distance_isr */
+volatile int g_intruder_distance_flag; /*!< Flag in intruder_distance_isr */
 volatile int g_button_0_flag; /*!< Flag in button_0_isr */
 volatile int g_button_1_flag; /*!< Flag in button_1_isr */
 volatile int g_button_c_flag; /*!< Flag in button_c_isr */
 
+int setting_distance_ticker_status;
+int intruder_distance_ticker_status;
+
 char buffer[14]; /*!< Stores any string that is going to be displayed on the LCD */
 int length; /*!< Stores the length of any string that is going to be displayed on the LCD  */
 
@@ -107,7 +127,9 @@
 
 void init_buttons(); /*!< Set-up the three external buttons */
 
-void read_distance_isr(); /*!< Interrupt that triggers when read_distance ticker fires */
+void setting_distance_isr(); /*!< Interrupt that triggers when setting_distance ticker fires */
+
+void intruder_distance_isr(); /*!< Interrupt that triggers when intruder_distance ticker fires */
 
 void button_0_isr(); /*!< Interrupt that triggers when button_0 is pressed by the user */
 
@@ -115,13 +137,19 @@
 
 void button_c_isr(); /*!< Interrupt that triggers when button_c is pressed by the user */
 
-void get_distance(); /*!< Gets the average distance in cm from the last 10 readings from the SRF02 */
+void button_0_protocol();
+
+void button_1_protocol();
+
+void button_c_protocol();
 
 void state_0_screen();
 
 void state_1_screen();
 
-void state_2_3_6_7_screen();
+void state_2_6_7_screen();
+
+void state_3_screen();
 
 void state_4_screen();
 
@@ -131,6 +159,22 @@
 
 void screen_selection();
 
+void get_setting_distance();
+
+void get_intruder_distance();
+
+void calculate_setting_distance();
+
+void calculate_intruder_distance();
+
+void screen_5_transition();
+
+void change_pin();
+
+void read_pin();
+
+void delete_file(char filename[]);
+
 /**
 
 */