Mobile Security System - Revision 1.0
Dependencies: FXOS8700Q N5110 SDFileSystem SRF02 mbed
main.h@5:41cb88f47f42, 2016-05-01 (annotated)
- Committer:
- el14dg
- Date:
- Sun May 01 16:53:56 2016 +0000
- Revision:
- 5:41cb88f47f42
- Parent:
- 4:9cac024c057c
- Child:
- 6:dc1229224d8e
setting screen implemented
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el14dg | 1:3ae4192d0c25 | 1 | /** |
el14dg | 1:3ae4192d0c25 | 2 | @file main.h |
el14dg | 1:3ae4192d0c25 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
el14dg | 1:3ae4192d0c25 | 4 | @brief Revision 1.0. |
el14dg | 1:3ae4192d0c25 | 5 | @author Daniel Gibbons |
el14dg | 1:3ae4192d0c25 | 6 | @date March 2016 |
el14dg | 1:3ae4192d0c25 | 7 | */ |
el14dg | 1:3ae4192d0c25 | 8 | |
el14dg | 1:3ae4192d0c25 | 9 | #ifndef MAIN_H |
el14dg | 1:3ae4192d0c25 | 10 | #define MAIN_H |
el14dg | 1:3ae4192d0c25 | 11 | |
el14dg | 1:3ae4192d0c25 | 12 | #define PI 3.14159265359 |
el14dg | 1:3ae4192d0c25 | 13 | |
el14dg | 1:3ae4192d0c25 | 14 | #include "mbed.h" |
el14dg | 1:3ae4192d0c25 | 15 | #include "N5110.h" |
el14dg | 1:3ae4192d0c25 | 16 | #include "SRF02.h" |
el14dg | 3:70a7b64fbd98 | 17 | #include "SDFileSystem.h" |
el14dg | 1:3ae4192d0c25 | 18 | |
el14dg | 2:e504a3cfe113 | 19 | |
el14dg | 1:3ae4192d0c25 | 20 | /** |
el14dg | 2:e504a3cfe113 | 21 | @namespace lcd |
el14dg | 2:e504a3cfe113 | 22 | @brief N5110 LCD connections |
el14dg | 1:3ae4192d0c25 | 23 | @namespace srf02 |
el14dg | 2:e504a3cfe113 | 24 | @brief SRF02 sensor connections |
el14dg | 1:3ae4192d0c25 | 25 | @namespace pc |
el14dg | 2:e504a3cfe113 | 26 | @brief UART connection to PC for debugging |
el14dg | 2:e504a3cfe113 | 27 | @namespace led_alarm |
el14dg | 2:e504a3cfe113 | 28 | @brief LED to indicate status of the alarm: flashing -> setting or triggered ; constant -> set |
el14dg | 2:e504a3cfe113 | 29 | @namespace buzzer |
el14dg | 2:e504a3cfe113 | 30 | @brief indicates status of the alarm: buzzes when alarm is setting and when triggered |
el14dg | 2:e504a3cfe113 | 31 | @namespace zero |
el14dg | 2:e504a3cfe113 | 32 | @brief first button input |
el14dg | 2:e504a3cfe113 | 33 | @namespace one |
el14dg | 2:e504a3cfe113 | 34 | @brief second button input |
el14dg | 2:e504a3cfe113 | 35 | @namespace confirm |
el14dg | 2:e504a3cfe113 | 36 | @brief third button input |
el14dg | 2:e504a3cfe113 | 37 | @namespace read_distance |
el14dg | 2:e504a3cfe113 | 38 | @brief K64F fires to read distance |
el14dg | 2:e504a3cfe113 | 39 | @namespace sw2 |
el14dg | 2:e504a3cfe113 | 40 | @brief K64F on-board switch |
el14dg | 2:e504a3cfe113 | 41 | @namespace sw3 |
el14dg | 2:e504a3cfe113 | 42 | @brief K64F on-board switch |
el14dg | 1:3ae4192d0c25 | 43 | @namespace r_led |
el14dg | 2:e504a3cfe113 | 44 | @brief K64F on-board red LED |
el14dg | 1:3ae4192d0c25 | 45 | @namespace g_led |
el14dg | 2:e504a3cfe113 | 46 | @brief K64F on-board green LED |
el14dg | 1:3ae4192d0c25 | 47 | @namespace b_led |
el14dg | 2:e504a3cfe113 | 48 | @brief K64F on-board blue LED |
el14dg | 2:e504a3cfe113 | 49 | |
el14dg | 1:3ae4192d0c25 | 50 | */ |
el14dg | 1:3ae4192d0c25 | 51 | |
el14dg | 2:e504a3cfe113 | 52 | // VCC, SCE, RST, D/C, MOSI, SCLK, LED |
el14dg | 2:e504a3cfe113 | 53 | N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3); |
el14dg | 1:3ae4192d0c25 | 54 | SRF02 srf02(I2C_SDA,I2C_SCL); |
el14dg | 3:70a7b64fbd98 | 55 | // MOSI, MISO, SCK, CS |
el14dg | 3:70a7b64fbd98 | 56 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); |
el14dg | 1:3ae4192d0c25 | 57 | Serial pc(USBTX,USBRX); |
el14dg | 2:e504a3cfe113 | 58 | PwmOut led_alarm(PTC10); |
el14dg | 2:e504a3cfe113 | 59 | PwmOut buzzer(PTC11); |
el14dg | 2:e504a3cfe113 | 60 | InterruptIn button_0(PTB23); |
el14dg | 2:e504a3cfe113 | 61 | InterruptIn button_1(PTA2); |
el14dg | 2:e504a3cfe113 | 62 | InterruptIn button_c(PTC2); |
el14dg | 2:e504a3cfe113 | 63 | InterruptIn sw2(SW2); |
el14dg | 2:e504a3cfe113 | 64 | InterruptIn sw3(SW3); |
el14dg | 3:70a7b64fbd98 | 65 | Ticker setting_distance; |
el14dg | 3:70a7b64fbd98 | 66 | Ticker intruder_distance; |
el14dg | 5:41cb88f47f42 | 67 | Ticker alerts; |
el14dg | 5:41cb88f47f42 | 68 | Ticker pin_timeout; |
el14dg | 5:41cb88f47f42 | 69 | Ticker setting_screen; |
el14dg | 3:70a7b64fbd98 | 70 | Timeout transition; |
el14dg | 5:41cb88f47f42 | 71 | Timeout buzz; |
el14dg | 1:3ae4192d0c25 | 72 | DigitalOut r_led(LED_RED); |
el14dg | 1:3ae4192d0c25 | 73 | DigitalOut g_led(LED_GREEN); |
el14dg | 1:3ae4192d0c25 | 74 | DigitalOut b_led(LED_BLUE); |
el14dg | 2:e504a3cfe113 | 75 | |
el14dg | 2:e504a3cfe113 | 76 | struct State { |
el14dg | 3:70a7b64fbd98 | 77 | int nextState[4]; // array of next states which depend on which button was pressed |
el14dg | 2:e504a3cfe113 | 78 | }; |
el14dg | 2:e504a3cfe113 | 79 | typedef const struct State STyp; |
el14dg | 2:e504a3cfe113 | 80 | |
el14dg | 2:e504a3cfe113 | 81 | STyp fsm[9] = { |
el14dg | 3:70a7b64fbd98 | 82 | {0,0,0,0}, // 0 - initialisation (title screen) |
el14dg | 5:41cb88f47f42 | 83 | {2,3,1,1}, // 1 - main menu (Set alarm or set new password) |
el14dg | 4:9cac024c057c | 84 | {2,2,4,1}, // 2 - set alarm (enter password) |
el14dg | 4:9cac024c057c | 85 | {3,3,1,1}, // 3 - set new password (enter new password) |
el14dg | 3:70a7b64fbd98 | 86 | {4,4,4,4}, // 4 - setting calibration |
el14dg | 5:41cb88f47f42 | 87 | {5,5,6,6}, // 5 - alarm activated |
el14dg | 3:70a7b64fbd98 | 88 | {6,6,1,5}, // 6 - deactivate without triggering (enter password) |
el14dg | 3:70a7b64fbd98 | 89 | {7,7,1,8}, // 7 - alarm triggered (enter password) |
el14dg | 3:70a7b64fbd98 | 90 | {8,8,1,1} // 8 - display time when alarm was triggered |
el14dg | 2:e504a3cfe113 | 91 | }; |
el14dg | 2:e504a3cfe113 | 92 | |
el14dg | 3:70a7b64fbd98 | 93 | FILE *pin; // this is our file pointer |
el14dg | 3:70a7b64fbd98 | 94 | |
el14dg | 3:70a7b64fbd98 | 95 | int entered_pin[4]; |
el14dg | 3:70a7b64fbd98 | 96 | int set_pin[4]; |
el14dg | 3:70a7b64fbd98 | 97 | int index_array[4]; |
el14dg | 3:70a7b64fbd98 | 98 | |
el14dg | 3:70a7b64fbd98 | 99 | int pin_counter; |
el14dg | 4:9cac024c057c | 100 | int incorrect_pin_flag; |
el14dg | 3:70a7b64fbd98 | 101 | |
el14dg | 2:e504a3cfe113 | 102 | int g_current_state; |
el14dg | 3:70a7b64fbd98 | 103 | int g_next_state; |
el14dg | 2:e504a3cfe113 | 104 | |
el14dg | 3:70a7b64fbd98 | 105 | float distance[10]; /*!< Stores 10 distance readings from SRF02 */ |
el14dg | 3:70a7b64fbd98 | 106 | float one_second_distance; |
el14dg | 3:70a7b64fbd98 | 107 | double one_second_avg_distance; |
el14dg | 3:70a7b64fbd98 | 108 | double initial_setting_distance; |
el14dg | 2:e504a3cfe113 | 109 | |
el14dg | 3:70a7b64fbd98 | 110 | int setting_distance_counter; |
el14dg | 3:70a7b64fbd98 | 111 | int intruder_distance_counter; |
el14dg | 5:41cb88f47f42 | 112 | int pin_timeout_counter; |
el14dg | 5:41cb88f47f42 | 113 | |
el14dg | 5:41cb88f47f42 | 114 | int setting_alarm_counter; |
el14dg | 5:41cb88f47f42 | 115 | int seconds_till_timeout; |
el14dg | 3:70a7b64fbd98 | 116 | |
el14dg | 3:70a7b64fbd98 | 117 | volatile int g_setting_distance_flag; /*!< Flag in setting_distance_isr */ |
el14dg | 3:70a7b64fbd98 | 118 | volatile int g_intruder_distance_flag; /*!< Flag in intruder_distance_isr */ |
el14dg | 5:41cb88f47f42 | 119 | volatile int g_led_buzzer_flag; /*!< Flag in led_buzzer_isr */ |
el14dg | 5:41cb88f47f42 | 120 | volatile int g_pin_timeout_flag; |
el14dg | 5:41cb88f47f42 | 121 | volatile int g_setting_screen_flag; |
el14dg | 2:e504a3cfe113 | 122 | volatile int g_button_0_flag; /*!< Flag in button_0_isr */ |
el14dg | 2:e504a3cfe113 | 123 | volatile int g_button_1_flag; /*!< Flag in button_1_isr */ |
el14dg | 2:e504a3cfe113 | 124 | volatile int g_button_c_flag; /*!< Flag in button_c_isr */ |
el14dg | 2:e504a3cfe113 | 125 | |
el14dg | 3:70a7b64fbd98 | 126 | int setting_distance_ticker_status; |
el14dg | 3:70a7b64fbd98 | 127 | |
el14dg | 2:e504a3cfe113 | 128 | char buffer[14]; /*!< Stores any string that is going to be displayed on the LCD */ |
el14dg | 2:e504a3cfe113 | 129 | int length; /*!< Stores the length of any string that is going to be displayed on the LCD */ |
el14dg | 1:3ae4192d0c25 | 130 | |
el14dg | 1:3ae4192d0c25 | 131 | |
el14dg | 2:e504a3cfe113 | 132 | |
el14dg | 2:e504a3cfe113 | 133 | void error(); /*!< Hangs flashing on_board LED */ |
el14dg | 2:e504a3cfe113 | 134 | |
el14dg | 2:e504a3cfe113 | 135 | void init_serial(); /*!< Set-up the serial port */ |
el14dg | 2:e504a3cfe113 | 136 | |
el14dg | 2:e504a3cfe113 | 137 | void init_K64F(); /*!< Set-up the on-board LEDs and switches */ |
el14dg | 2:e504a3cfe113 | 138 | |
el14dg | 2:e504a3cfe113 | 139 | void init_buttons(); /*!< Set-up the three external buttons */ |
el14dg | 2:e504a3cfe113 | 140 | |
el14dg | 5:41cb88f47f42 | 141 | void init_variables(); |
el14dg | 5:41cb88f47f42 | 142 | |
el14dg | 3:70a7b64fbd98 | 143 | void setting_distance_isr(); /*!< Interrupt that triggers when setting_distance ticker fires */ |
el14dg | 3:70a7b64fbd98 | 144 | |
el14dg | 3:70a7b64fbd98 | 145 | void intruder_distance_isr(); /*!< Interrupt that triggers when intruder_distance ticker fires */ |
el14dg | 2:e504a3cfe113 | 146 | |
el14dg | 2:e504a3cfe113 | 147 | void button_0_isr(); /*!< Interrupt that triggers when button_0 is pressed by the user */ |
el14dg | 2:e504a3cfe113 | 148 | |
el14dg | 2:e504a3cfe113 | 149 | void button_1_isr(); /*!< Interrupt that triggers when button_1 is pressed by the user */ |
el14dg | 1:3ae4192d0c25 | 150 | |
el14dg | 2:e504a3cfe113 | 151 | void button_c_isr(); /*!< Interrupt that triggers when button_c is pressed by the user */ |
el14dg | 2:e504a3cfe113 | 152 | |
el14dg | 5:41cb88f47f42 | 153 | void led_buzzer_isr(); |
el14dg | 5:41cb88f47f42 | 154 | |
el14dg | 5:41cb88f47f42 | 155 | void pin_timeout_isr(); |
el14dg | 5:41cb88f47f42 | 156 | |
el14dg | 5:41cb88f47f42 | 157 | void setting_screen_isr(); |
el14dg | 5:41cb88f47f42 | 158 | |
el14dg | 5:41cb88f47f42 | 159 | void loading_bar(); |
el14dg | 4:9cac024c057c | 160 | |
el14dg | 3:70a7b64fbd98 | 161 | void button_0_protocol(); |
el14dg | 3:70a7b64fbd98 | 162 | |
el14dg | 3:70a7b64fbd98 | 163 | void button_1_protocol(); |
el14dg | 3:70a7b64fbd98 | 164 | |
el14dg | 3:70a7b64fbd98 | 165 | void button_c_protocol(); |
el14dg | 2:e504a3cfe113 | 166 | |
el14dg | 5:41cb88f47f42 | 167 | void timeout_protocol(); |
el14dg | 5:41cb88f47f42 | 168 | |
el14dg | 2:e504a3cfe113 | 169 | void state_0_screen(); |
el14dg | 2:e504a3cfe113 | 170 | |
el14dg | 2:e504a3cfe113 | 171 | void state_1_screen(); |
el14dg | 2:e504a3cfe113 | 172 | |
el14dg | 5:41cb88f47f42 | 173 | void state_2_screen(); |
el14dg | 3:70a7b64fbd98 | 174 | |
el14dg | 3:70a7b64fbd98 | 175 | void state_3_screen(); |
el14dg | 2:e504a3cfe113 | 176 | |
el14dg | 2:e504a3cfe113 | 177 | void state_4_screen(); |
el14dg | 2:e504a3cfe113 | 178 | |
el14dg | 2:e504a3cfe113 | 179 | void state_5_screen(); |
el14dg | 2:e504a3cfe113 | 180 | |
el14dg | 5:41cb88f47f42 | 181 | void state_6_screen(); |
el14dg | 5:41cb88f47f42 | 182 | |
el14dg | 5:41cb88f47f42 | 183 | void state_7_screen(); |
el14dg | 5:41cb88f47f42 | 184 | |
el14dg | 2:e504a3cfe113 | 185 | void state_8_screen(); |
el14dg | 2:e504a3cfe113 | 186 | |
el14dg | 2:e504a3cfe113 | 187 | void screen_selection(); |
el14dg | 1:3ae4192d0c25 | 188 | |
el14dg | 3:70a7b64fbd98 | 189 | void get_setting_distance(); |
el14dg | 3:70a7b64fbd98 | 190 | |
el14dg | 3:70a7b64fbd98 | 191 | void get_intruder_distance(); |
el14dg | 3:70a7b64fbd98 | 192 | |
el14dg | 3:70a7b64fbd98 | 193 | void calculate_setting_distance(); |
el14dg | 3:70a7b64fbd98 | 194 | |
el14dg | 3:70a7b64fbd98 | 195 | void calculate_intruder_distance(); |
el14dg | 3:70a7b64fbd98 | 196 | |
el14dg | 3:70a7b64fbd98 | 197 | void screen_5_transition(); |
el14dg | 3:70a7b64fbd98 | 198 | |
el14dg | 4:9cac024c057c | 199 | void screen_progression(); |
el14dg | 4:9cac024c057c | 200 | |
el14dg | 5:41cb88f47f42 | 201 | void alarm_setting_buzz(); |
el14dg | 5:41cb88f47f42 | 202 | |
el14dg | 5:41cb88f47f42 | 203 | void lcd_border(); |
el14dg | 5:41cb88f47f42 | 204 | |
el14dg | 5:41cb88f47f42 | 205 | void pin_text_box(); |
el14dg | 5:41cb88f47f42 | 206 | |
el14dg | 4:9cac024c057c | 207 | void enter_pin(); |
el14dg | 4:9cac024c057c | 208 | |
el14dg | 5:41cb88f47f42 | 209 | void reset_entered_pin(); |
el14dg | 5:41cb88f47f42 | 210 | |
el14dg | 4:9cac024c057c | 211 | void check_pin(); |
el14dg | 4:9cac024c057c | 212 | |
el14dg | 3:70a7b64fbd98 | 213 | void change_pin(); |
el14dg | 3:70a7b64fbd98 | 214 | |
el14dg | 3:70a7b64fbd98 | 215 | void read_pin(); |
el14dg | 3:70a7b64fbd98 | 216 | |
el14dg | 3:70a7b64fbd98 | 217 | void delete_file(char filename[]); |
el14dg | 3:70a7b64fbd98 | 218 | |
el14dg | 1:3ae4192d0c25 | 219 | /** |
el14dg | 2:e504a3cfe113 | 220 | |
el14dg | 1:3ae4192d0c25 | 221 | */ |
el14dg | 1:3ae4192d0c25 | 222 | |
el14dg | 1:3ae4192d0c25 | 223 | #endif |