Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Embed: (wiki syntax)

« Back to documentation index

main.h File Reference

main.h File Reference

Header file containing functions prototypes, defines and global variables. More...

Go to the source code of this file.

Namespaces

namespace  lcd
 

N5110 LCD connections.


namespace  srf02
 

SRF02 sensor connections.


namespace  i2c
 

K64F I2C connections for FXOS8700Q on-board Accelerometer.


namespace  acc
 

K64F FXOS8700Q on-board Accelerometer connections.


namespace  sd
 

SD card connections.


namespace  pc
 

UART connection to PC for debugging.


namespace  led_alarm
 

LED to indicate status of the alarm: flashing -> setting or triggered ; constant -> set.


namespace  buzzer
 

Indicates status of the alarm: buzzes when alarm is setting and when triggered.


namespace  button_0
 

First button interrupt.


namespace  button_1
 

Second button interrupt.


namespace  button_c
 

Third button interrupt.


namespace  sw2
 

K64F on-board switch.


namespace  sw3
 

K64F on-board switch.


namespace  setting_distance
 

This ticker fires to read the distance when the system is setting.


namespace  intruder_distance
 

This ticker fires to read the distance when the system is set.


namespace  alerts
 

This ticker fires to turn and off the led and buzzer.


namespace  pin_timeout
 

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
 

This ticker fires to display the setting animation on the setting screen.


namespace  accelerometer
 

This ticker fires whilst in the setting screen to get accelerometer data.


namespace  transition
 

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
 

This timeout transitions the system to the menu if the device is moved in the setting state.


namespace  buzz
 

This timeout turns off the buzzer one second after the device is set.


namespace  confirm
 

This timeout transitions to a screen asking the user to confirm the pin that they have just entered.


namespace  r_led
 

K64F on-board red LED.


namespace  g_led
 

K64F on-board green LED.


namespace  b_led
 

K64F on-board blue LED.


Functions

void error ()
 Initialisation Functions.
void init_serial ()
void init_K64F ()
void init_buttons ()
void init_variables ()
void setting_distance_isr ()
 Interrupt Service Routines (ISRs)
void intruder_distance_isr ()
void button_0_isr ()
void button_1_isr ()
void button_c_isr ()
void led_buzzer_isr ()
void acc_isr ()
void pin_timeout_isr ()
void setting_screen_isr ()
void button_0_protocol ()
 Button Functions.
void button_1_protocol ()
void button_c_protocol ()
void state_0_screen ()
 State Functions.
void state_1_screen ()
void state_2_screen ()
void state_3_screen ()
void state_4_screen ()
void state_5_screen ()
void state_6_screen ()
void state_7_screen ()
void state_8_screen ()
void lcd_border ()
void pin_text_box ()
void screen_progression ()
void screen_selection ()
void setting_animation ()
 Screen Animation Functions.
void timeout_protocol ()
void get_setting_distance ()
 Read Distance Functions.
void get_intruder_distance ()
void calculate_setting_distance ()
void calculate_intruder_distance ()
void screen_5_transition ()
 Timeout Functions.
void pin_confirm ()
void state_1_transition ()
void alarm_setting_buzz ()
void get_axis_data ()
 Accelerometer Functions.
void compare_axis_data ()
void device_tampered_protocol ()
void enter_pin ()
 Pin Functions.
void reset_entered_pin ()
void check_pin ()
void change_pin ()
void read_pin ()
void delete_file (char filename[])

Variables

FILE * pin
int entered_pin [4]
int set_pin [4]
int index_array [4]
int pin_counter
int incorrect_pin_flag
float acc_X
float acc_Y
float acc_Z
float setting_acc_X
float setting_acc_Y
float setting_acc_Z
int g_current_state
int g_next_state
float distance [10]
float one_second_distance
double one_second_avg_distance
double initial_setting_distance
int setting_distance_counter
int intruder_distance_counter
int pin_timeout_counter
int setting_alarm_counter
int seconds_till_timeout
volatile int g_setting_distance_flag
volatile int g_intruder_distance_flag
volatile int g_button_0_flag
volatile int g_button_1_flag
volatile int g_button_c_flag
volatile int g_led_buzzer_flag
volatile int g_acc_flag
volatile int g_pin_timeout_flag
volatile int g_setting_screen_flag
char buffer [14]
int length

Detailed Description

Header file containing functions prototypes, defines and global variables.

Revision 1.0.

Author:
Daniel Gibbons
Date:
May 2016

Definition in file main.h.


Function Documentation

void acc_isr (  )

Interrupt Service Routine that triggers when accelerometer ticker fires

Definition at line 256 of file main.cpp.

void alarm_setting_buzz (  )

Turns off buzzer one second after entering state 5

Definition at line 1141 of file main.cpp.

void button_0_isr (  )

Interrupt Service Routine that triggers when button_0 is pressed by the user

Definition at line 232 of file main.cpp.

void button_0_protocol (  )

Button Functions.

Protocol when button_0 is pressed

Definition at line 276 of file main.cpp.

void button_1_isr (  )

Interrupt Service Routine that triggers when button_1 is pressed by the user

Definition at line 238 of file main.cpp.

void button_1_protocol (  )

Protocol when button_1 is pressed

Definition at line 345 of file main.cpp.

void button_c_isr (  )

Interrupt Service Routine that triggers when button_c is pressed by the user

Definition at line 244 of file main.cpp.

void button_c_protocol (  )

Protocol when button_c is pressed

Definition at line 414 of file main.cpp.

void calculate_intruder_distance (  )

Averages the past 10 distance readings and compares this value to the initial_setting_distance to detect a potential intruder

Definition at line 1047 of file main.cpp.

void calculate_setting_distance (  )

Averages the past 10 distance readings and stores them in the initial_setting_distance

Definition at line 1026 of file main.cpp.

void change_pin (  )

Writes entered_pin to the SD card when a pin is entered in state 3 - adapted from 2545_SD_Card Example by Dr. C.A. Evans

Definition at line 1316 of file main.cpp.

void check_pin (  )

Compares the entered_pin to the set_pin

Definition at line 1298 of file main.cpp.

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

Definition at line 1159 of file main.cpp.

void delete_file ( char  filename[] )

Deletes the old pin from the SD card - taken from 2545_SD_Card Example by Dr. C.A. Evans

Definition at line 1376 of file main.cpp.

void device_tampered_protocol (  )

If the device is moved whilst in the setting state this function is called to stop the alarm from setting

Definition at line 1221 of file main.cpp.

void enter_pin (  )

Pin Functions.

Prints '*' to the Nokia 5110 LCD when a pin is being entered

Definition at line 1253 of file main.cpp.

void error (  )

Initialisation Functions.

Hangs flashing on_board LED

void get_axis_data (  )

Accelerometer Functions.

Gets the accelerometer data from the K64F on_board accelerometer and stores them in acc_X, acc_Y and acc_Z

Definition at line 1150 of file main.cpp.

void get_intruder_distance (  )

Gets the distance from the SRF02 and then increments the intruder_distance_counter

Definition at line 1009 of file main.cpp.

void get_setting_distance (  )

Read Distance Functions.

Gets the distance from the SRF02 and then increments the setting_distance_counter

Definition at line 993 of file main.cpp.

void init_buttons (  )

Set-up the three external buttons

Definition at line 176 of file main.cpp.

void init_K64F (  )

Set-up the on-board LEDs and switches

Definition at line 162 of file main.cpp.

void init_serial (  )

Set-up the serial port

Definition at line 156 of file main.cpp.

void init_variables (  )

Initialises all variables to zero

Definition at line 190 of file main.cpp.

void intruder_distance_isr (  )

Interrupt Service Routine that triggers when intruder_distance ticker fires

Definition at line 226 of file main.cpp.

void lcd_border (  )

Prints a border to the Nokia 5110 LCD

Definition at line 762 of file main.cpp.

void led_buzzer_isr (  )

Interrupt Service Routine that triggers when alerts ticker fires

Definition at line 250 of file main.cpp.

void pin_confirm (  )

Clears the screen when a pin is entered to tell the user to press button 'C' to confirm the entered pin

Definition at line 1107 of file main.cpp.

void pin_text_box (  )

Prints a box to the Nokia 5110 LCD for the states where a pin is required

Definition at line 770 of file main.cpp.

void pin_timeout_isr (  )

Interrupt Service Routine that triggers when pin_timeout ticker fires

Definition at line 262 of file main.cpp.

void read_pin (  )

Reads pin from the SD card to the set_pin array - adapted from 2545_SD_Card Example by Dr. C.A. Evans

Definition at line 1352 of file main.cpp.

void reset_entered_pin (  )

Resets the entered_pin array to have elements with a value of -1

Definition at line 1286 of file main.cpp.

void screen_5_transition (  )

Timeout Functions.

Called five seconds after the setting screen is called

Definition at line 1095 of file main.cpp.

void screen_progression (  )

Calls check pin to see if the entered pin is correct and from there either proceed or go back

Definition at line 796 of file main.cpp.

void screen_selection (  )

Calls the relevant state_X_screen() depending on the value of g_next_state

Definition at line 844 of file main.cpp.

void setting_animation (  )

Screen Animation Functions.

Prints the animation on the setting screen to the Nokia 5110 LCD

Definition at line 907 of file main.cpp.

void setting_distance_isr (  )

Interrupt Service Routines (ISRs)

Interrupt Service Routine that triggers when setting_distance ticker fires

Definition at line 220 of file main.cpp.

void setting_screen_isr (  )

Interrupt Service Routine that triggers when setting_screen ticker fires

Definition at line 268 of file main.cpp.

void state_0_screen (  )

State Functions.

Sets the screen and the necessary tickers and timeouts for state 0

Definition at line 454 of file main.cpp.

void state_1_screen (  )

Sets the screen and the necessary tickers and timeouts for state 1

Definition at line 478 of file main.cpp.

void state_1_transition (  )

Sends the user back to state 1 if the device is tampered in the setting state

Definition at line 1129 of file main.cpp.

void state_2_screen (  )

Sets the screen and the necessary tickers and timeouts for state 2

Definition at line 520 of file main.cpp.

void state_3_screen (  )

Sets the screen and the necessary tickers and timeouts for state 3

Definition at line 544 of file main.cpp.

void state_4_screen (  )

Sets the screen and the necessary tickers and timeouts for state 4

Definition at line 568 of file main.cpp.

void state_5_screen (  )

Sets the screen and the necessary tickers and timeouts for state 5

Definition at line 620 of file main.cpp.

void state_6_screen (  )

Sets the screen and the necessary tickers and timeouts for state 6

Definition at line 664 of file main.cpp.

void state_7_screen (  )

Sets the screen and the necessary tickers and timeouts for state 7

Definition at line 695 of file main.cpp.

void state_8_screen (  )

Sets the screen and the necessary tickers and timeouts for state 8

Definition at line 729 of file main.cpp.

void timeout_protocol (  )

Prints timeout counter when the alarm is triggered

Definition at line 949 of file main.cpp.


Variable Documentation

float acc_X

Current x-axis reading from the accelerometer

Definition at line 142 of file main.h.

float acc_Y

Current y-axis reading from the accelerometer

Definition at line 143 of file main.h.

float acc_Z

Current z-axis reading from the accelerometer

Definition at line 144 of file main.h.

char buffer[14]

Stores strings that are comprised of variables that are going to be displayed on the LCD

Definition at line 174 of file main.h.

float distance[10]

Stores 10 distance readings from SRF02

Definition at line 152 of file main.h.

int entered_pin[4]

Pin user enters

Definition at line 135 of file main.h.

volatile int g_acc_flag

Flag in acc_isr

Definition at line 170 of file main.h.

volatile int g_button_0_flag

Flag in button_0_isr

Definition at line 166 of file main.h.

volatile int g_button_1_flag

Flag in button_1_isr

Definition at line 167 of file main.h.

volatile int g_button_c_flag

Flag in button_c_isr

Definition at line 168 of file main.h.

The current state of the system

Definition at line 149 of file main.h.

Flag in intruder_distance_isr

Definition at line 165 of file main.h.

volatile int g_led_buzzer_flag

Flag in led_buzzer_isr

Definition at line 169 of file main.h.

The next state of the system

Definition at line 150 of file main.h.

volatile int g_pin_timeout_flag

Flag in pin_timeout_isr

Definition at line 171 of file main.h.

Flag in setting_distance_isr

Definition at line 164 of file main.h.

volatile int g_setting_screen_flag

Flag in setting_screen_isr

Definition at line 172 of file main.h.

If the entered pin doesn't match the set pin this flag is incremented to 1

Definition at line 140 of file main.h.

int index_array[4]

Array to index the reading from the SD card

Definition at line 137 of file main.h.

The one_second_avg_distance calculated when in the setting state (state 4)

Definition at line 155 of file main.h.

increments to 10 distance readings can be stored over 1 second

Definition at line 158 of file main.h.

int length

Stores the length of strings that are comprised of variables that are going to be displayed on the LCD

Definition at line 175 of file main.h.

one_second_distance divided by 10

Definition at line 154 of file main.h.

The total of all 10 distance readings taken in a second

Definition at line 153 of file main.h.

FILE* pin

File pointer

Definition at line 133 of file main.h.

Increments to store the entered pin

Definition at line 139 of file main.h.

increments to 20 to enable the 20 second timeout when the alarm is triggered

Definition at line 159 of file main.h.

21 - pin_timeout_counter

Definition at line 162 of file main.h.

int set_pin[4]

Pin that is saved to SD card and this is the current pin for the system

Definition at line 136 of file main.h.

X-axis reading from the accelerometer when setting screen is initialised

Definition at line 145 of file main.h.

Y-axis reading from the accelerometer when setting screen is initialised

Definition at line 146 of file main.h.

Z-axis reading from the accelerometer when setting screen is initialised

Definition at line 147 of file main.h.

increments in steps of five and is used for the setting screen animation

Definition at line 160 of file main.h.

increments to 10 distance readings can be stored over 1 second

Definition at line 157 of file main.h.