Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Revision:
8:8a3d1c07bdec
Parent:
7:8ac5aee0c13e
Child:
9:a5614f53d435
diff -r 8ac5aee0c13e -r 8a3d1c07bdec main.h
--- a/main.h	Mon May 02 14:28:32 2016 +0000
+++ b/main.h	Tue May 03 09:51:02 2016 +0000
@@ -14,6 +14,7 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "SRF02.h"
+#include "FXOS8700Q.h"
 #include "SDFileSystem.h"
 
 
@@ -22,6 +23,10 @@
 @brief N5110 LCD connections
 @namespace srf02
 @brief SRF02 sensor connections
+@namespace i2c
+@brief K64F I2C connections for FXOS8700Q on-board Accelerometer
+@namespace acc
+@brief K64F FXOS8700Q on-board Accelerometer connections
 @namespace sd
 @brief SD card connections
 @namespace pc
@@ -50,8 +55,12 @@
 @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 accelerometer
+@brief This ticker fires whilst in the setting screen to get accelerometer data
 @namespace transition
-@brief This timeout transitions the system to the set state five seconds after entering the setting state
+@brief This timeout transitions the system to the set state, five seconds after entering the setting state, or to the menu if the device is moved in the setting state
+@namespace tamper_transition
+@brief This timeout transitions the system  to the menu if the device is moved in the setting state
 @namespace buzz
 @brief This timeout turns off the buzzer one second after the device is set
 @namespace confirm
@@ -68,6 +77,8 @@
 //         VCC, SCE, RST, D/C, MOSI, SCLK, LED
 N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3);
 SRF02 srf02(I2C_SDA,I2C_SCL);
+I2C i2c(PTE25, PTE24);
+FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);
 //              MOSI, MISO, SCK, CS
 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); 
 Serial pc(USBTX,USBRX);
@@ -83,7 +94,9 @@
 Ticker alerts;
 Ticker pin_timeout;
 Ticker setting_screen;
+Ticker accelerometer;
 Timeout transition;
+Timeout tamper_transition;
 Timeout buzz;
 Timeout confirm;
 DigitalOut r_led(LED_RED);
@@ -117,22 +130,29 @@
     {8,8,1,1}   // 8 - alarm triggered
 };
 
-FILE *pin; /*!< file pointer */
+FILE *pin; /*!< File pointer */
 
-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 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; /*!< 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 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 */
+float acc_X; /*!< Current x-axis reading from the accelerometer */
+float acc_Y; /*!< Current y-axis reading from the accelerometer */
+float acc_Z; /*!< Current z-axis reading from the accelerometer */
+float setting_acc_X; /*!< X-axis reading from the accelerometer when setting screen is initialised */
+float setting_acc_Y; /*!< Y-axis reading from the accelerometer when setting screen is initialised */
+float setting_acc_Z; /*!< Z-axis reading from the accelerometer when setting screen is initialised */
 
-int g_current_state; /*!< the current state of the system */
-int g_next_state; /*!< the next state of the system  */
+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; /*!< the total of all 10 distance readings taken in a second */
+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)  */
+double initial_setting_distance; /*!< The one_second_avg_distance calculated when in the setting state (state 4)  */
 
 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 */
@@ -143,14 +163,13 @@
 
 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; /*!< 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; /*!< if the setting_distance ticker has been attached this int is equal to 1 */
+volatile int g_led_buzzer_flag; /*!< Flag in led_buzzer_isr */
+volatile int g_acc_flag; /*!< Flag in acc_isr */
+volatile int g_pin_timeout_flag; /*!< Flag in pin_timeout_isr */
+volatile int g_setting_screen_flag; /*!< Flag in setting_screen_isr */
 
 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 */
@@ -182,6 +201,8 @@
 
 void led_buzzer_isr(); /*!< Interrupt Service Routine that triggers when alerts ticker fires */
 
+void acc_isr(); /*!< Interrupt Service Routine that triggers when accelerometer ticker fires */
+
 void pin_timeout_isr(); /*!< Interrupt Service Routine that triggers when pin_timeout ticker fires */
 
 void setting_screen_isr(); /*!< Interrupt Service Routine that triggers when setting_screen ticker fires */
@@ -218,6 +239,8 @@
 
 void pin_text_box(); /*!< Prints a box to the Nokia 5110 LCD for the states where a pin is required  */
 
+void screen_progression(); /*!< Calls check pin to see if the entered pin is correct and from there either proceed or go back */
+
 void screen_selection(); /*!< Calls the relevant state_X_screen() depending on the value of g_next_state */
 
 // Screen Animation Functions
@@ -240,13 +263,23 @@
 
 void screen_5_transition(); /*!< Called five seconds after the setting screen is called */
 
-void screen_progression(); /*!< Calls check pin to see if the entered pin is correct and from there either proceed or go back */
+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 device_tampered(); /*!< Sends the user back to state 1 if the device is tampered in the setting state */
 
 void alarm_setting_buzz(); /*!< Turns off buzzer one second after entering state 5 */
 
+// Accelerometer Function
+
+void get_axis_data(); /*!< Gets the accelerometer data from the K64F on_board accelerometer and stores them in acc_X, acc_Y and acc_Z */
+
+void compare_axis_data(); /*!< Compares the accelerometer data from the K64F on-board accelerometer with the stored values of setting_acc_X, setting_acc_Y and setting_acc_Z */ 
+
+void device_tampered_protocol(); /*!< If the device is moved whilst in the setting state this function is called */
+
 // Pin Functions
 
-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(); /*!< Prints '*' to the Nokia 5110 LCD when a pin is being entered */