Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Revision:
6:dc1229224d8e
Parent:
5:41cb88f47f42
Child:
7:8ac5aee0c13e
--- a/main.h	Sun May 01 16:53:56 2016 +0000
+++ b/main.h	Mon May 02 13:47:17 2016 +0000
@@ -22,24 +22,40 @@
 @brief N5110 LCD connections
 @namespace srf02
 @brief SRF02 sensor connections
+@namespace sd
+@brief SD card connections
 @namespace pc
 @brief UART connection to PC for debugging
 @namespace led_alarm
 @brief LED to indicate status of the alarm: flashing -> setting or triggered ; constant -> set
 @namespace buzzer
-@brief indicates status of the alarm: buzzes when alarm is setting and when triggered
-@namespace zero
-@brief first button input
-@namespace one
-@brief second button input
-@namespace confirm
-@brief third button input
-@namespace read_distance
-@brief K64F fires to read distance
+@brief Indicates status of the alarm: buzzes when alarm is setting and when triggered
+@namespace button_0
+@brief First button interrupt
+@namespace button_1
+@brief Second button interrupt
+@namespace button_c
+@brief Third button interrupt
 @namespace sw2
 @brief K64F on-board switch
 @namespace sw3
 @brief K64F on-board switch
+@namespace setting_distance
+@brief This ticker fires to read the distance when the system is setting
+@namespace intruder_distance
+@brief This ticker fires to read the distance when the system is set
+@namespace alerts
+@brief This ticker fires to turn and off the led and buzzer
+@namespace pin_timeout
+@brief This ticker fires to timeout the user if they don't enter the pin within an alotted time of triggering the device
+@namespace setting_screen
+@brief This ticker fires to display the setting animation on the setting screen
+@namespace transition
+@brief This timeout transitions the system to the set state five seconds after entering the setting state
+@namespace buzz
+@brief This timeout turns off the buzzer one second after the device is set
+@namespace confirm
+@brief This timeout transitions to a screen asking the user to confirm the pin that they have just entered
 @namespace r_led
 @brief K64F on-board red LED
 @namespace g_led
@@ -69,65 +85,75 @@
 Ticker setting_screen;
 Timeout transition;
 Timeout buzz;
+Timeout confirm;
 DigitalOut r_led(LED_RED);
 DigitalOut g_led(LED_GREEN);
 DigitalOut b_led(LED_BLUE);
 
 struct State {
-    int nextState[4];  // array of next states which depend on which button was pressed
+    
+    /* array of next states which depend on which button was pressed
+       - nextState[0] ----> button_0 pressed
+       - nextState[1] ----> button_1 pressed
+       - nextState[2] ----> button_c pressed (Option 1)
+       - nextState[3] ----> button_c pressed (Option 2)
+    */
+       
+    int nextState[4];  
+    
 };
 typedef const struct State STyp;
 
+// fsm stores all nine states that 'Mobile Security System' is comprised off
 STyp fsm[9] = {
     {0,0,0,0},  // 0 - initialisation (title screen)
     {2,3,1,1},  // 1 - main menu (Set alarm or set new password)
     {2,2,4,1}, // 2 - set alarm (enter password)
     {3,3,1,1}, // 3 - set new password (enter new password)
     {4,4,4,4}, // 4 - setting calibration
-    {5,5,6,6}, // 5 - alarm activated
+    {5,6,5,5}, // 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
+    {8,8,1,1}   // 8 - alarm triggered
 };
 
-FILE *pin; // this is our file pointer
+FILE *pin; /*!< file pointer */
 
-int entered_pin[4];
-int set_pin[4];
-int index_array[4];
+int entered_pin[4]; /*!< pin user enters */ 
+int set_pin[4]; /*!< pin that is saved to SD card and this is the current pin for the system */
+int index_array[4]; /*!< array to index the reading from the SD card */
 
-int pin_counter;
-int incorrect_pin_flag;
+int pin_counter; /*!< increments to store the entered pin */
+int incorrect_pin_flag; /*!< if the entered pin doesn't match the set pin this flag is incremented to 1 */
 
-int g_current_state;
-int g_next_state;
+int g_current_state; /*!< the current state of the system */
+int g_next_state; /*!< the next state of the system  */
 
 float distance[10]; /*!< Stores 10 distance readings from SRF02 */
-float one_second_distance;
-double one_second_avg_distance;
-double initial_setting_distance;
+float one_second_distance; /*!< the total of all 10 distance readings taken in a second */
+double one_second_avg_distance; /*!< one_second_distance divided by 10 */
+double initial_setting_distance; /*!< the one_second_avg_distance calculated when in the setting state (state 4)  */
 
-int setting_distance_counter;
-int intruder_distance_counter;
-int pin_timeout_counter;
+int setting_distance_counter; /*!< increments to 10 distance readings can be stored over 1 second */
+int intruder_distance_counter; /*!< increments to 10 distance readings can be stored over 1 second */
+int pin_timeout_counter; /*!< increments to 20 to enable the 20 second timeout when the alarm is triggered */
+int setting_alarm_counter; /*!< increments in steps of five and is used for the setting screen animation */
 
-int setting_alarm_counter;
-int seconds_till_timeout;
+int seconds_till_timeout; /*!< 21 - pin_timeout_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_led_buzzer_flag; /*!< Flag in led_buzzer_isr */
-volatile int g_pin_timeout_flag;
-volatile int g_setting_screen_flag;
+volatile int g_pin_timeout_flag; /*!< Flag in pin_timeout_isr */
+volatile int g_setting_screen_flag; /*!< Flag in setting_screen_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 setting_distance_ticker_status; /*!< if the setting_distance ticker has been attached this int is equal to 1 */
 
-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  */
-
+char buffer[14]; /*!< Stores strings that are comprised of variables that are going to be displayed on the LCD */
+int length; /*!< Stores the length of strings that are comprised of variables that are going to be displayed on the LCD */
 
 
 void error(); /*!< Hangs flashing on_board LED */
@@ -138,83 +164,85 @@
 
 void init_buttons(); /*!< Set-up the three external buttons */
 
-void init_variables();
+void init_variables(); /*!< Initialises all variables to zero */
 
-void setting_distance_isr(); /*!< Interrupt that triggers when setting_distance ticker fires */
+void setting_distance_isr(); /*!< Interrupt Service Routine that triggers when setting_distance ticker fires */
 
-void intruder_distance_isr(); /*!< Interrupt that triggers when intruder_distance ticker fires */
+void intruder_distance_isr(); /*!< Interrupt Service Routine that triggers when intruder_distance ticker fires */
 
-void button_0_isr(); /*!< Interrupt that triggers when button_0 is pressed by the user */
+void button_0_isr(); /*!< Interrupt Service Routine that triggers when button_0 is pressed by the user */
+
+void button_1_isr(); /*!< Interrupt Service Routine that triggers when button_1 is pressed by the user */
 
-void button_1_isr(); /*!< Interrupt that triggers when button_1 is pressed by the user */
+void button_c_isr(); /*!< Interrupt Service Routine that triggers when button_c is pressed by the user */
 
-void button_c_isr(); /*!< Interrupt that triggers when button_c is pressed by the user */
+void led_buzzer_isr(); /*!< Interrupt Service Routine that triggers when alerts ticker fires */
 
-void led_buzzer_isr();
+void pin_timeout_isr(); /*!< Interrupt Service Routine that triggers when pin_timeout ticker fires */
 
-void pin_timeout_isr();
+void setting_screen_isr(); /*!< Interrupt Service Routine that triggers when setting_screen ticker fires */
 
-void setting_screen_isr();
+void button_0_protocol(); /*!< Protocol when button_0 is pressed */
 
-void loading_bar();
+void button_1_protocol(); /*!< Protocol when button_1 is pressed */
 
-void button_0_protocol();
+void button_c_protocol(); /*!< Protocol when button_c is pressed */
 
-void button_1_protocol();
+void timeout_protocol(); /*!< Prints timeout counter when the alarm is triggered */
 
-void button_c_protocol();
+void state_0_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 0 */
 
-void timeout_protocol();
+void state_1_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 1 */
 
-void state_0_screen();
+void state_2_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 2 */
 
-void state_1_screen();
+void state_3_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 3 */
 
-void state_2_screen();
+void state_4_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 4 */
 
-void state_3_screen();
+void state_5_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 5 */
 
-void state_4_screen();
+void state_6_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 6 */
 
-void state_5_screen();
+void state_7_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 7 */
 
-void state_6_screen();
+void state_8_screen(); /*!< Sets the screen and the necessary tickers and timeouts for state 8 */
 
-void state_7_screen();
+void screen_selection(); /*!< Calls the relevant state_X_screen() depending on the value of g_next_state */
 
-void state_8_screen();
+void setting_animation(); /*!< Prints the animation on the setting screen to the Nokia 5110 LCD */
 
-void screen_selection();
+void lcd_border(); /*!< Prints a border to the Nokia 5110 LCD  */
 
-void get_setting_distance();
+void pin_text_box(); /*!< Prints a box to the Nokia 5110 LCD for the states where a pin is required  */
 
-void get_intruder_distance();
+void get_setting_distance(); /*!< Gets the distance from the SRF02 and then increments the setting_distance_counter */
 
-void calculate_setting_distance();
+void get_intruder_distance(); /*!< Gets the distance from the SRF02 and then increments the intruder_distance_counter */
 
-void calculate_intruder_distance();
+void calculate_setting_distance(); /*!< Averages the past 10 distance readings and stores them in the initial_setting_distance */
 
-void screen_5_transition();
+void calculate_intruder_distance(); /*!< Averages the past 10 distance readings and compares this value to the initial_setting_distance to detect a potential intruder */
 
-void screen_progression();
+void screen_5_transition(); /*!< Called five seconds after the setting screen is called */
 
-void alarm_setting_buzz();
+void screen_progression(); /*!< Calls check pin to see if the entered pin is correct and from there either proceed or go back */
 
-void lcd_border();
+void alarm_setting_buzz(); /*!< Turns off buzzer one second after entering state 5 */
 
-void pin_text_box();
+void pin_confirm(); /*!< Clears the screen when a pin is entered to tell the user to press button 'C' to confirm the entered pin */
 
-void enter_pin();
+void enter_pin(); /*!< Prints '*' to the Nokia 5110 LCD when a pin is being entered */
 
-void reset_entered_pin();
+void reset_entered_pin(); /*!< Resets the entered_pin array to have elements with a value of -1 */
 
-void check_pin();
+void check_pin(); /*!< Compares the entered_pin to the set_pin */
 
-void change_pin();
+void change_pin(); /*!< Writes entered_pin to the SD card when a pin is entered in state 3 - adapted from SD card program by Dr. C.A. Evans */
 
-void read_pin();
+void read_pin(); /*!< Reads pin from the SD card to the set_pin array - adapted from SD card program by Dr. C.A. Evans */
 
-void delete_file(char filename[]);
+void delete_file(char filename[]); /*!< Deletes the old pin from the SD card - taken from SD card program by Dr. C.A. Evans */
 
 /**