Mobile Security System - Revision 1.0

Dependencies:   FXOS8700Q N5110 SDFileSystem SRF02 mbed

Committer:
el14dg
Date:
Mon May 02 14:28:32 2016 +0000
Revision:
7:8ac5aee0c13e
Parent:
6:dc1229224d8e
Child:
8:8a3d1c07bdec
Formatted Code.; ; Still need to investigate RTC and Accelerometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el14dg 6:dc1229224d8e 1 /* ELEC2645 Project */
el14dg 2:e504a3cfe113 2
el14dg 1:3ae4192d0c25 3 #include "main.h"
el14dg 0:12ae42019e9f 4
el14dg 0:12ae42019e9f 5 int main()
el14dg 0:12ae42019e9f 6 {
el14dg 6:dc1229224d8e 7
el14dg 6:dc1229224d8e 8 init_serial(); // set up UART connection with PC for debugging
el14dg 6:dc1229224d8e 9 init_K64F(); // set up K64F on board LEDs and switches
el14dg 6:dc1229224d8e 10 init_buttons(); // set up the three external buttons
el14dg 6:dc1229224d8e 11 init_variables(); // initialise all variables to 0
el14dg 6:dc1229224d8e 12 lcd.init(); // initialise the Nokia 5110 LCD
el14dg 3:70a7b64fbd98 13
el14dg 6:dc1229224d8e 14 read_pin(); // read current pin from the SD card to the set_pin array
el14dg 6:dc1229224d8e 15
el14dg 6:dc1229224d8e 16 buzzer.period(1.0/500.0); // set the buzzer period - 500 Hz
el14dg 6:dc1229224d8e 17
el14dg 6:dc1229224d8e 18 buzzer.write(0.5); // duty cycle = 0.5 ----> Square Wave
el14dg 6:dc1229224d8e 19
el14dg 6:dc1229224d8e 20 wait(2); // wait two seconds to allow LCD to initialise
el14dg 6:dc1229224d8e 21
el14dg 6:dc1229224d8e 22 screen_selection(); // initial screen
el14dg 2:e504a3cfe113 23
el14dg 2:e504a3cfe113 24 wait(4);
el14dg 2:e504a3cfe113 25
el14dg 3:70a7b64fbd98 26 g_next_state = 1;
el14dg 6:dc1229224d8e 27
el14dg 6:dc1229224d8e 28 screen_selection(); // menu screen
el14dg 6:dc1229224d8e 29
el14dg 5:41cb88f47f42 30 g_current_state = 1;
el14dg 3:70a7b64fbd98 31
el14dg 3:70a7b64fbd98 32
el14dg 0:12ae42019e9f 33 while (1) {
el14dg 0:12ae42019e9f 34
el14dg 3:70a7b64fbd98 35
el14dg 6:dc1229224d8e 36 if (g_button_0_flag) { // if button_0 is pressed
el14dg 3:70a7b64fbd98 37
el14dg 3:70a7b64fbd98 38 pc.printf("g_button_0_flag = %d \n", g_button_0_flag);
el14dg 2:e504a3cfe113 39
el14dg 2:e504a3cfe113 40 g_button_0_flag = 0;
el14dg 2:e504a3cfe113 41
el14dg 3:70a7b64fbd98 42 button_0_protocol();
el14dg 2:e504a3cfe113 43
el14dg 0:12ae42019e9f 44 }
el14dg 3:70a7b64fbd98 45
el14dg 6:dc1229224d8e 46 if (g_button_1_flag) { // if button_1 is pressed
el14dg 3:70a7b64fbd98 47
el14dg 3:70a7b64fbd98 48 pc.printf("g_button_1_flag = %d \n", g_button_1_flag);
el14dg 2:e504a3cfe113 49
el14dg 2:e504a3cfe113 50 g_button_1_flag = 0;
el14dg 6:dc1229224d8e 51
el14dg 3:70a7b64fbd98 52 button_1_protocol();
el14dg 0:12ae42019e9f 53
el14dg 2:e504a3cfe113 54 }
el14dg 2:e504a3cfe113 55
el14dg 6:dc1229224d8e 56 if (g_button_c_flag) { // if button_c is pressed
el14dg 3:70a7b64fbd98 57
el14dg 3:70a7b64fbd98 58 pc.printf("g_button_c_flag = %d \n", g_button_c_flag);
el14dg 2:e504a3cfe113 59
el14dg 2:e504a3cfe113 60 g_button_c_flag = 0;
el14dg 5:41cb88f47f42 61
el14dg 3:70a7b64fbd98 62 button_c_protocol();
el14dg 5:41cb88f47f42 63
el14dg 3:70a7b64fbd98 64 }
el14dg 3:70a7b64fbd98 65
el14dg 6:dc1229224d8e 66 if (g_setting_distance_flag) { // state 4 - initial setting distance
el14dg 3:70a7b64fbd98 67
el14dg 3:70a7b64fbd98 68 g_setting_distance_flag = 0;
el14dg 3:70a7b64fbd98 69
el14dg 3:70a7b64fbd98 70 get_setting_distance();
el14dg 3:70a7b64fbd98 71
el14dg 3:70a7b64fbd98 72 }
el14dg 3:70a7b64fbd98 73
el14dg 6:dc1229224d8e 74 if (g_intruder_distance_flag) { // state 5 - current distance compared to initial setting distance
el14dg 3:70a7b64fbd98 75
el14dg 3:70a7b64fbd98 76 g_setting_distance_flag = 0;
el14dg 3:70a7b64fbd98 77
el14dg 3:70a7b64fbd98 78 get_intruder_distance();
el14dg 3:70a7b64fbd98 79
el14dg 5:41cb88f47f42 80 }
el14dg 6:dc1229224d8e 81
el14dg 6:dc1229224d8e 82 if (g_setting_screen_flag) { // state 4 loading bar and percentage animation
el14dg 6:dc1229224d8e 83
el14dg 5:41cb88f47f42 84 g_setting_screen_flag = 0;
el14dg 6:dc1229224d8e 85
el14dg 6:dc1229224d8e 86 setting_animation();
el14dg 3:70a7b64fbd98 87
el14dg 6:dc1229224d8e 88 }
el14dg 6:dc1229224d8e 89
el14dg 6:dc1229224d8e 90 if (g_led_buzzer_flag) { // toggles LED and buzzer
el14dg 5:41cb88f47f42 91
el14dg 5:41cb88f47f42 92 g_led_buzzer_flag = 0;
el14dg 3:70a7b64fbd98 93
el14dg 5:41cb88f47f42 94 led_alarm = !led_alarm;
el14dg 6:dc1229224d8e 95
el14dg 5:41cb88f47f42 96 if (buzzer == 0) {
el14dg 6:dc1229224d8e 97
el14dg 5:41cb88f47f42 98 buzzer = 0.5;
el14dg 6:dc1229224d8e 99
el14dg 5:41cb88f47f42 100 }
el14dg 6:dc1229224d8e 101
el14dg 5:41cb88f47f42 102 else {
el14dg 6:dc1229224d8e 103
el14dg 5:41cb88f47f42 104 buzzer = 0;
el14dg 6:dc1229224d8e 105
el14dg 6:dc1229224d8e 106 }
el14dg 0:12ae42019e9f 107
el14dg 2:e504a3cfe113 108 }
el14dg 3:70a7b64fbd98 109
el14dg 6:dc1229224d8e 110 if (g_pin_timeout_flag) { // state 7 - 20 second timeout
el14dg 3:70a7b64fbd98 111
el14dg 5:41cb88f47f42 112 g_pin_timeout_flag = 0;
el14dg 3:70a7b64fbd98 113
el14dg 5:41cb88f47f42 114 timeout_protocol();
el14dg 6:dc1229224d8e 115
el14dg 5:41cb88f47f42 116 }
el14dg 6:dc1229224d8e 117
el14dg 3:70a7b64fbd98 118 if (g_next_state != g_current_state) {
el14dg 6:dc1229224d8e 119
el14dg 5:41cb88f47f42 120 pc.printf("TRANSITION \n");
el14dg 3:70a7b64fbd98 121
el14dg 6:dc1229224d8e 122 screen_selection(); // the screen is determined by the value of g_next_state
el14dg 6:dc1229224d8e 123
el14dg 5:41cb88f47f42 124 g_current_state = g_next_state;
el14dg 6:dc1229224d8e 125
el14dg 5:41cb88f47f42 126 pc.printf("Current State = %d \n",g_current_state);
el14dg 6:dc1229224d8e 127
el14dg 3:70a7b64fbd98 128 }
el14dg 3:70a7b64fbd98 129
el14dg 6:dc1229224d8e 130
el14dg 3:70a7b64fbd98 131
el14dg 3:70a7b64fbd98 132 if (g_current_state == 4) {
el14dg 6:dc1229224d8e 133
el14dg 6:dc1229224d8e 134 if (setting_distance_ticker_status == 0) { // if the setting_distance ticker has not been attached
el14dg 3:70a7b64fbd98 135
el14dg 3:70a7b64fbd98 136 setting_distance_ticker_status = 1;
el14dg 3:70a7b64fbd98 137
el14dg 3:70a7b64fbd98 138 setting_distance.attach(&setting_distance_isr,0.1);
el14dg 6:dc1229224d8e 139
el14dg 3:70a7b64fbd98 140 }
el14dg 3:70a7b64fbd98 141
el14dg 3:70a7b64fbd98 142 }
el14dg 3:70a7b64fbd98 143
el14dg 3:70a7b64fbd98 144 if (g_current_state == 5) {
el14dg 3:70a7b64fbd98 145
el14dg 6:dc1229224d8e 146 intruder_distance.attach(&intruder_distance_isr,0.1);
el14dg 3:70a7b64fbd98 147
el14dg 3:70a7b64fbd98 148 }
el14dg 6:dc1229224d8e 149
el14dg 4:9cac024c057c 150 else {
el14dg 6:dc1229224d8e 151
el14dg 3:70a7b64fbd98 152 intruder_distance.detach();
el14dg 6:dc1229224d8e 153
el14dg 6:dc1229224d8e 154 }
el14dg 6:dc1229224d8e 155
el14dg 3:70a7b64fbd98 156
el14dg 2:e504a3cfe113 157 sleep();
el14dg 6:dc1229224d8e 158
el14dg 2:e504a3cfe113 159
el14dg 0:12ae42019e9f 160 }
el14dg 2:e504a3cfe113 161
el14dg 0:12ae42019e9f 162 }
el14dg 0:12ae42019e9f 163
el14dg 2:e504a3cfe113 164
el14dg 7:8ac5aee0c13e 165 // Initialisation Functions
el14dg 7:8ac5aee0c13e 166
el14dg 0:12ae42019e9f 167 void init_serial()
el14dg 0:12ae42019e9f 168 {
el14dg 2:e504a3cfe113 169 // Ensure terminal software matches
el14dg 3:70a7b64fbd98 170 pc.baud(115200);
el14dg 0:12ae42019e9f 171 }
el14dg 0:12ae42019e9f 172
el14dg 0:12ae42019e9f 173 void init_K64F()
el14dg 0:12ae42019e9f 174 {
el14dg 6:dc1229224d8e 175 // on-board LEDs are active-low, so they are set high to turn them off.
el14dg 0:12ae42019e9f 176 r_led = 1;
el14dg 0:12ae42019e9f 177 g_led = 1;
el14dg 0:12ae42019e9f 178 b_led = 1;
el14dg 0:12ae42019e9f 179
el14dg 0:12ae42019e9f 180 // since the on-board switches have external pull-ups, we should disable the internal pull-down
el14dg 0:12ae42019e9f 181 // resistors that are enabled by default using InterruptIn
el14dg 0:12ae42019e9f 182 sw2.mode(PullNone);
el14dg 0:12ae42019e9f 183 sw3.mode(PullNone);
el14dg 0:12ae42019e9f 184
el14dg 0:12ae42019e9f 185 }
el14dg 2:e504a3cfe113 186
el14dg 2:e504a3cfe113 187 void init_buttons()
el14dg 2:e504a3cfe113 188 {
el14dg 6:dc1229224d8e 189 // all external buttons trigger the relevant ISR when the voltage at the K64F pin falls
el14dg 2:e504a3cfe113 190 button_0.fall(&button_0_isr);
el14dg 2:e504a3cfe113 191 button_1.fall(&button_1_isr);
el14dg 2:e504a3cfe113 192 button_c.fall(&button_c_isr);
el14dg 2:e504a3cfe113 193
el14dg 6:dc1229224d8e 194 // enable the internal pull-down resistors
el14dg 2:e504a3cfe113 195 button_0.mode(PullDown);
el14dg 2:e504a3cfe113 196 button_1.mode(PullDown);
el14dg 2:e504a3cfe113 197 button_c.mode(PullDown);
el14dg 2:e504a3cfe113 198
el14dg 2:e504a3cfe113 199 }
el14dg 2:e504a3cfe113 200
el14dg 5:41cb88f47f42 201 void init_variables()
el14dg 5:41cb88f47f42 202 {
el14dg 5:41cb88f47f42 203
el14dg 5:41cb88f47f42 204 one_second_distance = 0;
el14dg 5:41cb88f47f42 205 one_second_avg_distance = 0;
el14dg 5:41cb88f47f42 206 initial_setting_distance = 0;
el14dg 5:41cb88f47f42 207
el14dg 5:41cb88f47f42 208 pin_counter = 0;
el14dg 5:41cb88f47f42 209 incorrect_pin_flag = 0;
el14dg 5:41cb88f47f42 210
el14dg 5:41cb88f47f42 211 setting_distance_counter = 0;
el14dg 5:41cb88f47f42 212 intruder_distance_counter = 0;
el14dg 5:41cb88f47f42 213
el14dg 5:41cb88f47f42 214 g_button_0_flag = 0;
el14dg 5:41cb88f47f42 215 g_button_1_flag = 0;
el14dg 5:41cb88f47f42 216 g_button_c_flag = 0;
el14dg 5:41cb88f47f42 217 g_setting_distance_flag = 0;
el14dg 5:41cb88f47f42 218 g_intruder_distance_flag = 0;
el14dg 5:41cb88f47f42 219 g_pin_timeout_flag = 0;
el14dg 5:41cb88f47f42 220
el14dg 5:41cb88f47f42 221 setting_distance_ticker_status = 0;
el14dg 5:41cb88f47f42 222
el14dg 5:41cb88f47f42 223 g_current_state = 0;
el14dg 5:41cb88f47f42 224
el14dg 6:dc1229224d8e 225 reset_entered_pin();
el14dg 6:dc1229224d8e 226
el14dg 5:41cb88f47f42 227 }
el14dg 5:41cb88f47f42 228
el14dg 7:8ac5aee0c13e 229 // Interrupt Service Routines (ISRs)
el14dg 7:8ac5aee0c13e 230
el14dg 3:70a7b64fbd98 231 void setting_distance_isr()
el14dg 2:e504a3cfe113 232 {
el14dg 3:70a7b64fbd98 233 g_setting_distance_flag = 1;
el14dg 3:70a7b64fbd98 234
el14dg 3:70a7b64fbd98 235 }
el14dg 3:70a7b64fbd98 236
el14dg 3:70a7b64fbd98 237 void intruder_distance_isr()
el14dg 3:70a7b64fbd98 238 {
el14dg 3:70a7b64fbd98 239 g_intruder_distance_flag = 1;
el14dg 2:e504a3cfe113 240
el14dg 2:e504a3cfe113 241 }
el14dg 2:e504a3cfe113 242
el14dg 2:e504a3cfe113 243 void button_0_isr()
el14dg 2:e504a3cfe113 244 {
el14dg 2:e504a3cfe113 245 g_button_0_flag = 1;
el14dg 2:e504a3cfe113 246
el14dg 2:e504a3cfe113 247 }
el14dg 2:e504a3cfe113 248
el14dg 2:e504a3cfe113 249 void button_1_isr()
el14dg 2:e504a3cfe113 250 {
el14dg 2:e504a3cfe113 251 g_button_1_flag = 1;
el14dg 2:e504a3cfe113 252
el14dg 2:e504a3cfe113 253 }
el14dg 2:e504a3cfe113 254
el14dg 2:e504a3cfe113 255 void button_c_isr()
el14dg 2:e504a3cfe113 256 {
el14dg 2:e504a3cfe113 257 g_button_c_flag = 1;
el14dg 2:e504a3cfe113 258
el14dg 2:e504a3cfe113 259 }
el14dg 2:e504a3cfe113 260
el14dg 7:8ac5aee0c13e 261 void led_buzzer_isr()
el14dg 7:8ac5aee0c13e 262 {
el14dg 7:8ac5aee0c13e 263 g_led_buzzer_flag = 1;
el14dg 7:8ac5aee0c13e 264
el14dg 7:8ac5aee0c13e 265 }
el14dg 7:8ac5aee0c13e 266
el14dg 5:41cb88f47f42 267 void pin_timeout_isr()
el14dg 5:41cb88f47f42 268 {
el14dg 5:41cb88f47f42 269 g_pin_timeout_flag = 1;
el14dg 5:41cb88f47f42 270
el14dg 5:41cb88f47f42 271 }
el14dg 5:41cb88f47f42 272
el14dg 7:8ac5aee0c13e 273 void setting_screen_isr()
el14dg 5:41cb88f47f42 274 {
el14dg 7:8ac5aee0c13e 275 g_setting_screen_flag = 1;
el14dg 6:dc1229224d8e 276
el14dg 7:8ac5aee0c13e 277 }
el14dg 6:dc1229224d8e 278
el14dg 7:8ac5aee0c13e 279 // Button Functions
el14dg 5:41cb88f47f42 280
el14dg 3:70a7b64fbd98 281 void button_0_protocol()
el14dg 2:e504a3cfe113 282 {
el14dg 6:dc1229224d8e 283
el14dg 6:dc1229224d8e 284 // states 2, 3, 6 and 7 require a pin to be entered
el14dg 6:dc1229224d8e 285
el14dg 3:70a7b64fbd98 286 if (g_current_state == 2) {
el14dg 3:70a7b64fbd98 287
el14dg 6:dc1229224d8e 288 if (pin_counter < 4) { // entered_pin has four elements
el14dg 3:70a7b64fbd98 289
el14dg 3:70a7b64fbd98 290 entered_pin[pin_counter] = 0;
el14dg 3:70a7b64fbd98 291
el14dg 3:70a7b64fbd98 292 pin_counter++;
el14dg 3:70a7b64fbd98 293
el14dg 3:70a7b64fbd98 294 }
el14dg 5:41cb88f47f42 295
el14dg 6:dc1229224d8e 296 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 297
el14dg 3:70a7b64fbd98 298 }
el14dg 3:70a7b64fbd98 299
el14dg 3:70a7b64fbd98 300 else if (g_current_state == 3) {
el14dg 3:70a7b64fbd98 301
el14dg 6:dc1229224d8e 302 if (pin_counter < 4) { // entered_pin has four elements
el14dg 3:70a7b64fbd98 303
el14dg 3:70a7b64fbd98 304 entered_pin[pin_counter] = 0;
el14dg 3:70a7b64fbd98 305
el14dg 3:70a7b64fbd98 306 pin_counter++;
el14dg 3:70a7b64fbd98 307
el14dg 3:70a7b64fbd98 308 }
el14dg 5:41cb88f47f42 309
el14dg 6:dc1229224d8e 310 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 311
el14dg 3:70a7b64fbd98 312 }
el14dg 2:e504a3cfe113 313
el14dg 3:70a7b64fbd98 314 else if (g_current_state == 6) {
el14dg 3:70a7b64fbd98 315
el14dg 6:dc1229224d8e 316 if (pin_counter < 4) { // entered_pin has four elements
el14dg 6:dc1229224d8e 317
el14dg 6:dc1229224d8e 318 entered_pin[pin_counter] = 0;
el14dg 6:dc1229224d8e 319
el14dg 6:dc1229224d8e 320 pin_counter++;
el14dg 6:dc1229224d8e 321
el14dg 6:dc1229224d8e 322 }
el14dg 6:dc1229224d8e 323
el14dg 6:dc1229224d8e 324 enter_pin(); // prints '*' to the LCD
el14dg 6:dc1229224d8e 325
el14dg 6:dc1229224d8e 326 }
el14dg 6:dc1229224d8e 327
el14dg 6:dc1229224d8e 328 else if (g_current_state == 7) { // entered_pin has four elements
el14dg 6:dc1229224d8e 329
el14dg 3:70a7b64fbd98 330 if (pin_counter < 4) {
el14dg 3:70a7b64fbd98 331
el14dg 3:70a7b64fbd98 332 entered_pin[pin_counter] = 0;
el14dg 3:70a7b64fbd98 333
el14dg 3:70a7b64fbd98 334 pin_counter++;
el14dg 3:70a7b64fbd98 335
el14dg 3:70a7b64fbd98 336 }
el14dg 5:41cb88f47f42 337
el14dg 6:dc1229224d8e 338 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 339
el14dg 3:70a7b64fbd98 340 }
el14dg 3:70a7b64fbd98 341
el14dg 3:70a7b64fbd98 342 else {
el14dg 2:e504a3cfe113 343
el14dg 6:dc1229224d8e 344 g_next_state = fsm[g_current_state].nextState[0]; // filters through fsm to find the next state
el14dg 3:70a7b64fbd98 345
el14dg 3:70a7b64fbd98 346 }
el14dg 3:70a7b64fbd98 347
el14dg 3:70a7b64fbd98 348 }
el14dg 3:70a7b64fbd98 349
el14dg 3:70a7b64fbd98 350 void button_1_protocol()
el14dg 3:70a7b64fbd98 351 {
el14dg 3:70a7b64fbd98 352
el14dg 6:dc1229224d8e 353 // states 2, 3, 6 and 7 require a pin to be entered
el14dg 6:dc1229224d8e 354
el14dg 3:70a7b64fbd98 355 if (g_current_state == 2) {
el14dg 3:70a7b64fbd98 356
el14dg 6:dc1229224d8e 357 if (pin_counter < 4) { // entered_pin has four elements
el14dg 3:70a7b64fbd98 358
el14dg 3:70a7b64fbd98 359 entered_pin[pin_counter] = 1;
el14dg 3:70a7b64fbd98 360
el14dg 3:70a7b64fbd98 361 pin_counter++;
el14dg 3:70a7b64fbd98 362
el14dg 3:70a7b64fbd98 363 }
el14dg 5:41cb88f47f42 364
el14dg 6:dc1229224d8e 365 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 366
el14dg 3:70a7b64fbd98 367 }
el14dg 3:70a7b64fbd98 368
el14dg 3:70a7b64fbd98 369 else if (g_current_state == 3) {
el14dg 3:70a7b64fbd98 370
el14dg 6:dc1229224d8e 371 if (pin_counter < 4) { // entered_pin has four elements
el14dg 2:e504a3cfe113 372
el14dg 3:70a7b64fbd98 373 entered_pin[pin_counter] = 1;
el14dg 3:70a7b64fbd98 374
el14dg 3:70a7b64fbd98 375 pin_counter++;
el14dg 3:70a7b64fbd98 376
el14dg 3:70a7b64fbd98 377 }
el14dg 5:41cb88f47f42 378
el14dg 6:dc1229224d8e 379 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 380
el14dg 3:70a7b64fbd98 381 }
el14dg 3:70a7b64fbd98 382
el14dg 3:70a7b64fbd98 383 else if (g_current_state == 6) {
el14dg 3:70a7b64fbd98 384
el14dg 6:dc1229224d8e 385 if (pin_counter < 4) { // entered_pin has four elements
el14dg 3:70a7b64fbd98 386
el14dg 3:70a7b64fbd98 387 entered_pin[pin_counter] = 1;
el14dg 2:e504a3cfe113 388
el14dg 3:70a7b64fbd98 389 pin_counter++;
el14dg 3:70a7b64fbd98 390
el14dg 3:70a7b64fbd98 391 }
el14dg 5:41cb88f47f42 392
el14dg 6:dc1229224d8e 393 enter_pin(); // prints '*' to the LCD
el14dg 3:70a7b64fbd98 394
el14dg 3:70a7b64fbd98 395 }
el14dg 3:70a7b64fbd98 396
el14dg 3:70a7b64fbd98 397 else if (g_current_state == 7) {
el14dg 3:70a7b64fbd98 398
el14dg 6:dc1229224d8e 399 if (pin_counter < 4) { // entered_pin has four elements
el14dg 3:70a7b64fbd98 400
el14dg 3:70a7b64fbd98 401 entered_pin[pin_counter] = 1;
el14dg 3:70a7b64fbd98 402
el14dg 3:70a7b64fbd98 403 pin_counter++;
el14dg 2:e504a3cfe113 404
el14dg 2:e504a3cfe113 405 }
el14dg 5:41cb88f47f42 406
el14dg 6:dc1229224d8e 407 enter_pin(); // prints '*' to the LCD
el14dg 5:41cb88f47f42 408
el14dg 3:70a7b64fbd98 409 }
el14dg 3:70a7b64fbd98 410
el14dg 3:70a7b64fbd98 411 else {
el14dg 3:70a7b64fbd98 412
el14dg 6:dc1229224d8e 413 g_next_state = fsm[g_current_state].nextState[1]; // filters through fsm to find the next state
el14dg 3:70a7b64fbd98 414
el14dg 3:70a7b64fbd98 415 }
el14dg 3:70a7b64fbd98 416
el14dg 3:70a7b64fbd98 417 }
el14dg 3:70a7b64fbd98 418
el14dg 3:70a7b64fbd98 419 void button_c_protocol()
el14dg 3:70a7b64fbd98 420 {
el14dg 3:70a7b64fbd98 421
el14dg 6:dc1229224d8e 422 // states 2, 3, 6 and 7 require a pin to be entered
el14dg 6:dc1229224d8e 423 // the screen only progresses if the correct pin is entered
el14dg 6:dc1229224d8e 424
el14dg 3:70a7b64fbd98 425 if (g_current_state == 2) {
el14dg 3:70a7b64fbd98 426
el14dg 4:9cac024c057c 427 screen_progression();
el14dg 3:70a7b64fbd98 428
el14dg 3:70a7b64fbd98 429 }
el14dg 3:70a7b64fbd98 430
el14dg 3:70a7b64fbd98 431 else if (g_current_state == 3) {
el14dg 3:70a7b64fbd98 432
el14dg 4:9cac024c057c 433 screen_progression();
el14dg 3:70a7b64fbd98 434
el14dg 3:70a7b64fbd98 435 }
el14dg 3:70a7b64fbd98 436
el14dg 3:70a7b64fbd98 437 else if (g_current_state == 6) {
el14dg 3:70a7b64fbd98 438
el14dg 4:9cac024c057c 439 screen_progression();
el14dg 2:e504a3cfe113 440
el14dg 3:70a7b64fbd98 441 }
el14dg 3:70a7b64fbd98 442
el14dg 3:70a7b64fbd98 443 else if (g_current_state == 7) {
el14dg 3:70a7b64fbd98 444
el14dg 4:9cac024c057c 445 screen_progression();
el14dg 3:70a7b64fbd98 446
el14dg 3:70a7b64fbd98 447 }
el14dg 3:70a7b64fbd98 448
el14dg 3:70a7b64fbd98 449 else {
el14dg 3:70a7b64fbd98 450
el14dg 6:dc1229224d8e 451 g_next_state = fsm[g_current_state].nextState[2]; // filters through fsm to find the next state
el14dg 3:70a7b64fbd98 452
el14dg 3:70a7b64fbd98 453 }
el14dg 2:e504a3cfe113 454
el14dg 3:70a7b64fbd98 455 }
el14dg 3:70a7b64fbd98 456
el14dg 7:8ac5aee0c13e 457 // State Functions
el14dg 3:70a7b64fbd98 458
el14dg 2:e504a3cfe113 459 void state_0_screen()
el14dg 2:e504a3cfe113 460 {
el14dg 2:e504a3cfe113 461 lcd.clear();
el14dg 2:e504a3cfe113 462
el14dg 6:dc1229224d8e 463 // print the screen
el14dg 6:dc1229224d8e 464
el14dg 5:41cb88f47f42 465 lcd.printString("Mobile",27,1);
el14dg 6:dc1229224d8e 466
el14dg 5:41cb88f47f42 467 lcd.printString("Security",18,2);
el14dg 2:e504a3cfe113 468
el14dg 5:41cb88f47f42 469 lcd.printString("System",27,3);
el14dg 6:dc1229224d8e 470
el14dg 5:41cb88f47f42 471 lcd_border();
el14dg 6:dc1229224d8e 472
el14dg 6:dc1229224d8e 473 // set LED and buzzer
el14dg 6:dc1229224d8e 474
el14dg 6:dc1229224d8e 475 led_alarm = 0;
el14dg 6:dc1229224d8e 476
el14dg 5:41cb88f47f42 477 buzzer.write(0.0);
el14dg 6:dc1229224d8e 478
el14dg 2:e504a3cfe113 479 lcd.refresh();
el14dg 2:e504a3cfe113 480
el14dg 2:e504a3cfe113 481 }
el14dg 2:e504a3cfe113 482
el14dg 2:e504a3cfe113 483 void state_1_screen()
el14dg 2:e504a3cfe113 484 {
el14dg 2:e504a3cfe113 485 lcd.clear();
el14dg 2:e504a3cfe113 486
el14dg 6:dc1229224d8e 487 // print the screen
el14dg 6:dc1229224d8e 488
el14dg 2:e504a3cfe113 489 lcd.printString("Set Alarm",15,1);
el14dg 2:e504a3cfe113 490
el14dg 2:e504a3cfe113 491 lcd.printString("Set New Pin",9,4);
el14dg 6:dc1229224d8e 492
el14dg 5:41cb88f47f42 493 lcd_border();
el14dg 6:dc1229224d8e 494
el14dg 5:41cb88f47f42 495 for (int i = 0; i < WIDTH; i++) {
el14dg 6:dc1229224d8e 496
el14dg 5:41cb88f47f42 497 lcd.setPixel(i,24);
el14dg 6:dc1229224d8e 498
el14dg 6:dc1229224d8e 499 }
el14dg 6:dc1229224d8e 500
el14dg 6:dc1229224d8e 501 // detach tickers
el14dg 6:dc1229224d8e 502
el14dg 6:dc1229224d8e 503 pin_timeout.detach();
el14dg 6:dc1229224d8e 504
el14dg 5:41cb88f47f42 505 alerts.detach();
el14dg 6:dc1229224d8e 506
el14dg 6:dc1229224d8e 507 // set LED and buzzer
el14dg 6:dc1229224d8e 508
el14dg 6:dc1229224d8e 509 led_alarm = 0;
el14dg 6:dc1229224d8e 510
el14dg 5:41cb88f47f42 511 buzzer.write(0);
el14dg 6:dc1229224d8e 512
el14dg 6:dc1229224d8e 513 // reset counter
el14dg 6:dc1229224d8e 514
el14dg 5:41cb88f47f42 515 pin_timeout_counter = 0;
el14dg 6:dc1229224d8e 516
el14dg 2:e504a3cfe113 517 lcd.refresh();
el14dg 2:e504a3cfe113 518
el14dg 2:e504a3cfe113 519 }
el14dg 2:e504a3cfe113 520
el14dg 5:41cb88f47f42 521 void state_2_screen()
el14dg 2:e504a3cfe113 522 {
el14dg 2:e504a3cfe113 523 lcd.clear();
el14dg 2:e504a3cfe113 524
el14dg 6:dc1229224d8e 525 // print the screen
el14dg 6:dc1229224d8e 526
el14dg 2:e504a3cfe113 527 lcd.printString("Enter 4 Digit",3,1);
el14dg 2:e504a3cfe113 528
el14dg 2:e504a3cfe113 529 lcd.printString("Pin Below",15,2);
el14dg 6:dc1229224d8e 530
el14dg 5:41cb88f47f42 531 pin_text_box();
el14dg 6:dc1229224d8e 532
el14dg 5:41cb88f47f42 533 lcd_border();
el14dg 6:dc1229224d8e 534
el14dg 6:dc1229224d8e 535 // set the LED and buzzer
el14dg 6:dc1229224d8e 536
el14dg 6:dc1229224d8e 537 led_alarm = 0;
el14dg 6:dc1229224d8e 538
el14dg 5:41cb88f47f42 539 buzzer.write(0.0);
el14dg 6:dc1229224d8e 540
el14dg 2:e504a3cfe113 541 lcd.refresh();
el14dg 2:e504a3cfe113 542
el14dg 2:e504a3cfe113 543 }
el14dg 2:e504a3cfe113 544
el14dg 3:70a7b64fbd98 545 void state_3_screen()
el14dg 3:70a7b64fbd98 546 {
el14dg 3:70a7b64fbd98 547 lcd.clear();
el14dg 3:70a7b64fbd98 548
el14dg 6:dc1229224d8e 549 // print the screen
el14dg 6:dc1229224d8e 550
el14dg 3:70a7b64fbd98 551 lcd.printString("Enter New 4",9,1);
el14dg 3:70a7b64fbd98 552
el14dg 3:70a7b64fbd98 553 lcd.printString("Digit Pin",15,2);
el14dg 6:dc1229224d8e 554
el14dg 5:41cb88f47f42 555 pin_text_box();
el14dg 3:70a7b64fbd98 556
el14dg 5:41cb88f47f42 557 lcd_border();
el14dg 6:dc1229224d8e 558
el14dg 6:dc1229224d8e 559 // set the LED and buzzer
el14dg 6:dc1229224d8e 560
el14dg 6:dc1229224d8e 561 led_alarm = 0;
el14dg 6:dc1229224d8e 562
el14dg 5:41cb88f47f42 563 buzzer.write(0.0);
el14dg 6:dc1229224d8e 564
el14dg 3:70a7b64fbd98 565 lcd.refresh();
el14dg 3:70a7b64fbd98 566
el14dg 3:70a7b64fbd98 567 }
el14dg 3:70a7b64fbd98 568
el14dg 2:e504a3cfe113 569 void state_4_screen()
el14dg 2:e504a3cfe113 570 {
el14dg 2:e504a3cfe113 571 lcd.clear();
el14dg 2:e504a3cfe113 572
el14dg 6:dc1229224d8e 573 // print the screen
el14dg 6:dc1229224d8e 574
el14dg 2:e504a3cfe113 575 lcd.printString("Setting",21,1);
el14dg 6:dc1229224d8e 576
el14dg 5:41cb88f47f42 577 lcd_border();
el14dg 6:dc1229224d8e 578
el14dg 6:dc1229224d8e 579 lcd.drawRect(0,20,84,5,0); // blank setting bar
el14dg 6:dc1229224d8e 580
el14dg 6:dc1229224d8e 581 lcd.printString("0%",41,4); // 0% of setting complete
el14dg 6:dc1229224d8e 582
el14dg 6:dc1229224d8e 583 // reset counter
el14dg 6:dc1229224d8e 584
el14dg 5:41cb88f47f42 585 setting_alarm_counter = 0;
el14dg 6:dc1229224d8e 586
el14dg 6:dc1229224d8e 587 // set LED and buzzer
el14dg 6:dc1229224d8e 588
el14dg 5:41cb88f47f42 589 led_alarm = 0;
el14dg 6:dc1229224d8e 590
el14dg 5:41cb88f47f42 591 buzzer.write(0.0);
el14dg 6:dc1229224d8e 592
el14dg 6:dc1229224d8e 593 // attach tickers
el14dg 6:dc1229224d8e 594
el14dg 5:41cb88f47f42 595 alerts.attach(&led_buzzer_isr,0.5);
el14dg 6:dc1229224d8e 596
el14dg 6:dc1229224d8e 597 setting_screen.attach(&setting_screen_isr,0.3);
el14dg 2:e504a3cfe113 598
el14dg 2:e504a3cfe113 599 lcd.refresh();
el14dg 2:e504a3cfe113 600
el14dg 2:e504a3cfe113 601 }
el14dg 2:e504a3cfe113 602
el14dg 2:e504a3cfe113 603 void state_5_screen()
el14dg 2:e504a3cfe113 604 {
el14dg 2:e504a3cfe113 605 lcd.clear();
el14dg 2:e504a3cfe113 606
el14dg 6:dc1229224d8e 607 // print the screen
el14dg 6:dc1229224d8e 608
el14dg 2:e504a3cfe113 609 lcd.printString("Alarm Set",15,1);
el14dg 2:e504a3cfe113 610
el14dg 2:e504a3cfe113 611 lcd.printString("DEACTIVATE?",9,4);
el14dg 6:dc1229224d8e 612
el14dg 5:41cb88f47f42 613 lcd_border();
el14dg 6:dc1229224d8e 614
el14dg 5:41cb88f47f42 615 for (int i = 0; i < WIDTH; i++) {
el14dg 6:dc1229224d8e 616
el14dg 5:41cb88f47f42 617 lcd.setPixel(i,20);
el14dg 6:dc1229224d8e 618
el14dg 6:dc1229224d8e 619 }
el14dg 6:dc1229224d8e 620
el14dg 6:dc1229224d8e 621 // detach tickers
el14dg 6:dc1229224d8e 622
el14dg 5:41cb88f47f42 623 alerts.detach();
el14dg 6:dc1229224d8e 624
el14dg 5:41cb88f47f42 625 setting_screen.detach();
el14dg 6:dc1229224d8e 626
el14dg 6:dc1229224d8e 627 // set LED and buzzer
el14dg 6:dc1229224d8e 628
el14dg 5:41cb88f47f42 629 led_alarm = 1;
el14dg 6:dc1229224d8e 630
el14dg 5:41cb88f47f42 631 buzzer.write(0.5);
el14dg 6:dc1229224d8e 632
el14dg 6:dc1229224d8e 633 // turn off buzzer after 1 second
el14dg 6:dc1229224d8e 634
el14dg 5:41cb88f47f42 635 buzz.attach(&alarm_setting_buzz,1);
el14dg 5:41cb88f47f42 636
el14dg 5:41cb88f47f42 637 lcd.refresh();
el14dg 6:dc1229224d8e 638
el14dg 5:41cb88f47f42 639 }
el14dg 5:41cb88f47f42 640
el14dg 5:41cb88f47f42 641 void state_6_screen()
el14dg 5:41cb88f47f42 642 {
el14dg 5:41cb88f47f42 643 lcd.clear();
el14dg 5:41cb88f47f42 644
el14dg 6:dc1229224d8e 645 // print the screen
el14dg 6:dc1229224d8e 646
el14dg 5:41cb88f47f42 647 lcd.printString("DEACTIVATE",12,1);
el14dg 5:41cb88f47f42 648
el14dg 5:41cb88f47f42 649 lcd.printString("Enter Pin",15,2);
el14dg 6:dc1229224d8e 650
el14dg 5:41cb88f47f42 651 lcd_border();
el14dg 6:dc1229224d8e 652
el14dg 5:41cb88f47f42 653 pin_text_box();
el14dg 6:dc1229224d8e 654
el14dg 6:dc1229224d8e 655 // set the LED and buzzer
el14dg 6:dc1229224d8e 656
el14dg 5:41cb88f47f42 657 led_alarm = 0;
el14dg 6:dc1229224d8e 658
el14dg 5:41cb88f47f42 659 buzzer.write(0.0);
el14dg 6:dc1229224d8e 660
el14dg 6:dc1229224d8e 661 // attach ticker
el14dg 6:dc1229224d8e 662
el14dg 5:41cb88f47f42 663 alerts.attach(&led_buzzer_isr,0.5);
el14dg 5:41cb88f47f42 664
el14dg 5:41cb88f47f42 665 lcd.refresh();
el14dg 5:41cb88f47f42 666
el14dg 5:41cb88f47f42 667 }
el14dg 5:41cb88f47f42 668
el14dg 5:41cb88f47f42 669 void state_7_screen()
el14dg 5:41cb88f47f42 670 {
el14dg 5:41cb88f47f42 671 lcd.clear();
el14dg 5:41cb88f47f42 672
el14dg 6:dc1229224d8e 673 // print the screen
el14dg 6:dc1229224d8e 674
el14dg 5:41cb88f47f42 675 lcd.printString("INTRUDER",18,1);
el14dg 5:41cb88f47f42 676
el14dg 5:41cb88f47f42 677 lcd.printString("Enter Pin",15,2);
el14dg 6:dc1229224d8e 678
el14dg 5:41cb88f47f42 679 lcd_border();
el14dg 6:dc1229224d8e 680
el14dg 6:dc1229224d8e 681 lcd.drawRect(1,30,15,10,0);
el14dg 6:dc1229224d8e 682
el14dg 5:41cb88f47f42 683 pin_text_box();
el14dg 6:dc1229224d8e 684
el14dg 6:dc1229224d8e 685 // set the LED and buzzer
el14dg 6:dc1229224d8e 686
el14dg 5:41cb88f47f42 687 led_alarm = 0;
el14dg 6:dc1229224d8e 688
el14dg 5:41cb88f47f42 689 buzzer.write(0.0);
el14dg 6:dc1229224d8e 690
el14dg 6:dc1229224d8e 691 // attach tickers
el14dg 6:dc1229224d8e 692
el14dg 5:41cb88f47f42 693 alerts.attach(&led_buzzer_isr,0.5);
el14dg 6:dc1229224d8e 694
el14dg 5:41cb88f47f42 695 pin_timeout.attach(&pin_timeout_isr,1);
el14dg 2:e504a3cfe113 696
el14dg 2:e504a3cfe113 697 lcd.refresh();
el14dg 2:e504a3cfe113 698
el14dg 2:e504a3cfe113 699 }
el14dg 2:e504a3cfe113 700
el14dg 2:e504a3cfe113 701 void state_8_screen()
el14dg 2:e504a3cfe113 702 {
el14dg 2:e504a3cfe113 703 lcd.clear();
el14dg 2:e504a3cfe113 704
el14dg 6:dc1229224d8e 705 // print the screen
el14dg 6:dc1229224d8e 706
el14dg 2:e504a3cfe113 707 lcd.printString("ALARM",27,1);
el14dg 2:e504a3cfe113 708
el14dg 2:e504a3cfe113 709 lcd.printString("TRIGGERED",15,2);
el14dg 6:dc1229224d8e 710
el14dg 5:41cb88f47f42 711 lcd.printString("Menu?",27,4);
el14dg 6:dc1229224d8e 712
el14dg 5:41cb88f47f42 713 lcd_border();
el14dg 6:dc1229224d8e 714
el14dg 6:dc1229224d8e 715 // set the LED and buzzer
el14dg 6:dc1229224d8e 716
el14dg 5:41cb88f47f42 717 led_alarm = 0;
el14dg 6:dc1229224d8e 718
el14dg 5:41cb88f47f42 719 buzzer.write(0.0);
el14dg 6:dc1229224d8e 720
el14dg 6:dc1229224d8e 721 // detach tickers
el14dg 6:dc1229224d8e 722
el14dg 5:41cb88f47f42 723 alerts.detach();
el14dg 6:dc1229224d8e 724
el14dg 5:41cb88f47f42 725 pin_timeout.detach();
el14dg 6:dc1229224d8e 726
el14dg 6:dc1229224d8e 727 // attach ticker
el14dg 6:dc1229224d8e 728
el14dg 5:41cb88f47f42 729 alerts.attach(&led_buzzer_isr,0.2);
el14dg 2:e504a3cfe113 730
el14dg 2:e504a3cfe113 731 lcd.refresh();
el14dg 2:e504a3cfe113 732 }
el14dg 2:e504a3cfe113 733
el14dg 7:8ac5aee0c13e 734 void lcd_border()
el14dg 7:8ac5aee0c13e 735 {
el14dg 7:8ac5aee0c13e 736 lcd.drawRect(0,0,83,47,0);
el14dg 7:8ac5aee0c13e 737
el14dg 7:8ac5aee0c13e 738 lcd.drawRect(1,1,81,45,0);
el14dg 7:8ac5aee0c13e 739
el14dg 7:8ac5aee0c13e 740 }
el14dg 7:8ac5aee0c13e 741
el14dg 7:8ac5aee0c13e 742 void pin_text_box()
el14dg 7:8ac5aee0c13e 743 {
el14dg 7:8ac5aee0c13e 744 lcd.drawRect(15,30,15,10,0); // transparent box, just outline
el14dg 7:8ac5aee0c13e 745 lcd.drawRect(29,30,15,10,0); // transparent box, just outline
el14dg 7:8ac5aee0c13e 746 lcd.drawRect(43,30,15,10,0); // transparent box, just outline
el14dg 7:8ac5aee0c13e 747 lcd.drawRect(57,30,15,10,0); // transparent boox, just outline
el14dg 7:8ac5aee0c13e 748
el14dg 7:8ac5aee0c13e 749 }
el14dg 7:8ac5aee0c13e 750
el14dg 2:e504a3cfe113 751 void screen_selection()
el14dg 2:e504a3cfe113 752 {
el14dg 6:dc1229224d8e 753
el14dg 6:dc1229224d8e 754 reset_entered_pin(); // re-set each element of the entered pin array to -1
el14dg 3:70a7b64fbd98 755
el14dg 3:70a7b64fbd98 756 if (g_next_state == 0) {
el14dg 2:e504a3cfe113 757
el14dg 2:e504a3cfe113 758 state_0_screen();
el14dg 2:e504a3cfe113 759
el14dg 2:e504a3cfe113 760 }
el14dg 3:70a7b64fbd98 761
el14dg 3:70a7b64fbd98 762 else if (g_next_state == 1) {
el14dg 2:e504a3cfe113 763
el14dg 2:e504a3cfe113 764 state_1_screen();
el14dg 2:e504a3cfe113 765
el14dg 2:e504a3cfe113 766 }
el14dg 2:e504a3cfe113 767
el14dg 3:70a7b64fbd98 768 else if (g_next_state == 2) {
el14dg 2:e504a3cfe113 769
el14dg 5:41cb88f47f42 770 state_2_screen();
el14dg 2:e504a3cfe113 771
el14dg 2:e504a3cfe113 772 }
el14dg 2:e504a3cfe113 773
el14dg 3:70a7b64fbd98 774 else if (g_next_state == 3) {
el14dg 2:e504a3cfe113 775
el14dg 3:70a7b64fbd98 776 state_3_screen();
el14dg 2:e504a3cfe113 777
el14dg 2:e504a3cfe113 778 }
el14dg 2:e504a3cfe113 779
el14dg 3:70a7b64fbd98 780 else if (g_next_state == 4) {
el14dg 2:e504a3cfe113 781
el14dg 2:e504a3cfe113 782 state_4_screen();
el14dg 2:e504a3cfe113 783
el14dg 2:e504a3cfe113 784 }
el14dg 2:e504a3cfe113 785
el14dg 3:70a7b64fbd98 786 else if (g_next_state == 5) {
el14dg 2:e504a3cfe113 787
el14dg 2:e504a3cfe113 788 state_5_screen();
el14dg 2:e504a3cfe113 789
el14dg 2:e504a3cfe113 790 }
el14dg 2:e504a3cfe113 791
el14dg 3:70a7b64fbd98 792 else if (g_next_state == 6) {
el14dg 2:e504a3cfe113 793
el14dg 5:41cb88f47f42 794 state_6_screen();
el14dg 2:e504a3cfe113 795
el14dg 2:e504a3cfe113 796 }
el14dg 2:e504a3cfe113 797
el14dg 3:70a7b64fbd98 798 else if (g_next_state == 7) {
el14dg 2:e504a3cfe113 799
el14dg 5:41cb88f47f42 800 state_7_screen();
el14dg 2:e504a3cfe113 801
el14dg 2:e504a3cfe113 802 }
el14dg 2:e504a3cfe113 803
el14dg 2:e504a3cfe113 804 else {
el14dg 2:e504a3cfe113 805
el14dg 2:e504a3cfe113 806 state_8_screen();
el14dg 2:e504a3cfe113 807
el14dg 2:e504a3cfe113 808 }
el14dg 6:dc1229224d8e 809
el14dg 2:e504a3cfe113 810 }
el14dg 3:70a7b64fbd98 811
el14dg 7:8ac5aee0c13e 812 // Screen Animation Functions
el14dg 7:8ac5aee0c13e 813
el14dg 7:8ac5aee0c13e 814 void setting_animation()
el14dg 7:8ac5aee0c13e 815 {
el14dg 7:8ac5aee0c13e 816 setting_alarm_counter = setting_alarm_counter + 5; // increment setting_alarm_counter in steps of five
el14dg 7:8ac5aee0c13e 817
el14dg 7:8ac5aee0c13e 818 if (setting_alarm_counter < 101) {
el14dg 7:8ac5aee0c13e 819
el14dg 7:8ac5aee0c13e 820 lcd.drawRect(0,20,setting_alarm_counter,5,1); // prints the loading bar to the LCD
el14dg 7:8ac5aee0c13e 821
el14dg 7:8ac5aee0c13e 822 // format how the percentage is displayed depending on its value
el14dg 7:8ac5aee0c13e 823 if (setting_alarm_counter < 10) {
el14dg 7:8ac5aee0c13e 824
el14dg 7:8ac5aee0c13e 825 length = sprintf(buffer,"0%d%%",setting_alarm_counter);
el14dg 7:8ac5aee0c13e 826
el14dg 7:8ac5aee0c13e 827 }
el14dg 7:8ac5aee0c13e 828
el14dg 7:8ac5aee0c13e 829 else {
el14dg 7:8ac5aee0c13e 830
el14dg 7:8ac5aee0c13e 831 length = sprintf(buffer,"%d%%",setting_alarm_counter);
el14dg 7:8ac5aee0c13e 832
el14dg 7:8ac5aee0c13e 833 }
el14dg 7:8ac5aee0c13e 834
el14dg 7:8ac5aee0c13e 835 if (length <= 14) { // if length of string will fit on the screen ( WIDTH = 6 * 24 = 84 pixels )
el14dg 7:8ac5aee0c13e 836
el14dg 7:8ac5aee0c13e 837 if (setting_alarm_counter < 100) {
el14dg 7:8ac5aee0c13e 838
el14dg 7:8ac5aee0c13e 839 lcd.printString(buffer,33,4);
el14dg 7:8ac5aee0c13e 840
el14dg 7:8ac5aee0c13e 841 }
el14dg 7:8ac5aee0c13e 842
el14dg 7:8ac5aee0c13e 843 else {
el14dg 7:8ac5aee0c13e 844
el14dg 7:8ac5aee0c13e 845 lcd.printString(buffer,30,4); // this string is four characters long and is therefore shifted to the left of the screen
el14dg 7:8ac5aee0c13e 846
el14dg 7:8ac5aee0c13e 847 }
el14dg 7:8ac5aee0c13e 848
el14dg 7:8ac5aee0c13e 849 }
el14dg 7:8ac5aee0c13e 850
el14dg 7:8ac5aee0c13e 851 lcd.refresh(); // refresh screen
el14dg 7:8ac5aee0c13e 852
el14dg 7:8ac5aee0c13e 853 }
el14dg 7:8ac5aee0c13e 854 }
el14dg 7:8ac5aee0c13e 855
el14dg 7:8ac5aee0c13e 856 void timeout_protocol()
el14dg 7:8ac5aee0c13e 857 {
el14dg 7:8ac5aee0c13e 858
el14dg 7:8ac5aee0c13e 859 pin_timeout_counter++;
el14dg 7:8ac5aee0c13e 860
el14dg 7:8ac5aee0c13e 861 seconds_till_timeout = 21 - pin_timeout_counter; // timeout counts down from 20
el14dg 7:8ac5aee0c13e 862
el14dg 7:8ac5aee0c13e 863 if (seconds_till_timeout == 0) { // if 20 seconds passes
el14dg 7:8ac5aee0c13e 864
el14dg 7:8ac5aee0c13e 865 g_next_state = 8;
el14dg 7:8ac5aee0c13e 866
el14dg 7:8ac5aee0c13e 867 pin_timeout_counter = 0;
el14dg 7:8ac5aee0c13e 868
el14dg 7:8ac5aee0c13e 869 }
el14dg 7:8ac5aee0c13e 870
el14dg 7:8ac5aee0c13e 871 else { // less than 20 seconds has passed
el14dg 7:8ac5aee0c13e 872
el14dg 7:8ac5aee0c13e 873 // These if statements manage the formatting of the number of seconds remaining
el14dg 7:8ac5aee0c13e 874
el14dg 7:8ac5aee0c13e 875 if (seconds_till_timeout >= 10) {
el14dg 7:8ac5aee0c13e 876
el14dg 7:8ac5aee0c13e 877 length = sprintf(buffer,"%d",seconds_till_timeout);
el14dg 7:8ac5aee0c13e 878
el14dg 7:8ac5aee0c13e 879 }
el14dg 7:8ac5aee0c13e 880
el14dg 7:8ac5aee0c13e 881 else {
el14dg 7:8ac5aee0c13e 882
el14dg 7:8ac5aee0c13e 883 length = sprintf(buffer,"0%d",seconds_till_timeout);
el14dg 7:8ac5aee0c13e 884
el14dg 7:8ac5aee0c13e 885 }
el14dg 7:8ac5aee0c13e 886
el14dg 7:8ac5aee0c13e 887 // if the length of the formatted string will fit on the screen print it ( WIDTH = 14 * 6 = 84 pixels )
el14dg 7:8ac5aee0c13e 888
el14dg 7:8ac5aee0c13e 889 if (length <= 14)
el14dg 7:8ac5aee0c13e 890 lcd.printString(buffer,3,4);
el14dg 7:8ac5aee0c13e 891
el14dg 7:8ac5aee0c13e 892 lcd.refresh();
el14dg 7:8ac5aee0c13e 893
el14dg 7:8ac5aee0c13e 894 }
el14dg 7:8ac5aee0c13e 895
el14dg 7:8ac5aee0c13e 896 }
el14dg 7:8ac5aee0c13e 897
el14dg 7:8ac5aee0c13e 898 // Read Distance Functions
el14dg 7:8ac5aee0c13e 899
el14dg 7:8ac5aee0c13e 900 void get_setting_distance()
el14dg 7:8ac5aee0c13e 901 {
el14dg 7:8ac5aee0c13e 902 distance[setting_distance_counter] = srf02.getDistanceCm(); // distance array stores 10 distance readings
el14dg 7:8ac5aee0c13e 903
el14dg 7:8ac5aee0c13e 904 setting_distance_counter++;
el14dg 7:8ac5aee0c13e 905
el14dg 7:8ac5aee0c13e 906 if (setting_distance_counter == 10) { // if distance array has 10 new readings (arrays are zero indexed)
el14dg 7:8ac5aee0c13e 907
el14dg 7:8ac5aee0c13e 908 setting_distance.detach();
el14dg 7:8ac5aee0c13e 909
el14dg 7:8ac5aee0c13e 910 calculate_setting_distance(); // find the average of the 10 distance readings
el14dg 7:8ac5aee0c13e 911
el14dg 7:8ac5aee0c13e 912 }
el14dg 7:8ac5aee0c13e 913
el14dg 7:8ac5aee0c13e 914 }
el14dg 7:8ac5aee0c13e 915
el14dg 7:8ac5aee0c13e 916 void get_intruder_distance()
el14dg 7:8ac5aee0c13e 917 {
el14dg 7:8ac5aee0c13e 918
el14dg 7:8ac5aee0c13e 919 distance[intruder_distance_counter] = srf02.getDistanceCm(); // distance array stores 10 distance readings
el14dg 7:8ac5aee0c13e 920
el14dg 7:8ac5aee0c13e 921 intruder_distance_counter++;
el14dg 7:8ac5aee0c13e 922
el14dg 7:8ac5aee0c13e 923 if (intruder_distance_counter == 10) { // if distance array has 10 new readings (arrays are zero indexed)
el14dg 7:8ac5aee0c13e 924
el14dg 7:8ac5aee0c13e 925 intruder_distance.detach();
el14dg 7:8ac5aee0c13e 926
el14dg 7:8ac5aee0c13e 927 calculate_intruder_distance(); // find the average of the 10 distance readings
el14dg 7:8ac5aee0c13e 928
el14dg 7:8ac5aee0c13e 929 }
el14dg 7:8ac5aee0c13e 930
el14dg 7:8ac5aee0c13e 931 }
el14dg 7:8ac5aee0c13e 932
el14dg 7:8ac5aee0c13e 933 void calculate_setting_distance()
el14dg 7:8ac5aee0c13e 934 {
el14dg 7:8ac5aee0c13e 935
el14dg 7:8ac5aee0c13e 936 for (int i = 0; i < 10; i++) {
el14dg 7:8ac5aee0c13e 937
el14dg 7:8ac5aee0c13e 938 one_second_distance = one_second_distance + distance[i]; // add all 10 readings together
el14dg 7:8ac5aee0c13e 939
el14dg 7:8ac5aee0c13e 940 }
el14dg 7:8ac5aee0c13e 941
el14dg 7:8ac5aee0c13e 942 initial_setting_distance = (one_second_distance / 10);
el14dg 7:8ac5aee0c13e 943
el14dg 7:8ac5aee0c13e 944 pc.printf("Initial Setting Distance = %.2f cm\n",initial_setting_distance);
el14dg 7:8ac5aee0c13e 945
el14dg 7:8ac5aee0c13e 946 setting_distance_counter = 0;
el14dg 7:8ac5aee0c13e 947
el14dg 7:8ac5aee0c13e 948 one_second_distance = 0;
el14dg 7:8ac5aee0c13e 949
el14dg 7:8ac5aee0c13e 950 transition.attach(&screen_5_transition,5); // transition to the set screen in five seconds
el14dg 7:8ac5aee0c13e 951
el14dg 7:8ac5aee0c13e 952 }
el14dg 7:8ac5aee0c13e 953
el14dg 7:8ac5aee0c13e 954 void calculate_intruder_distance()
el14dg 7:8ac5aee0c13e 955 {
el14dg 7:8ac5aee0c13e 956
el14dg 7:8ac5aee0c13e 957 for (int i = 0; i < 10; i++) {
el14dg 7:8ac5aee0c13e 958
el14dg 7:8ac5aee0c13e 959 one_second_distance = one_second_distance + distance[i]; // add all 10 distance readings together
el14dg 7:8ac5aee0c13e 960
el14dg 7:8ac5aee0c13e 961 }
el14dg 7:8ac5aee0c13e 962
el14dg 7:8ac5aee0c13e 963 one_second_avg_distance = one_second_distance / 10;
el14dg 7:8ac5aee0c13e 964
el14dg 7:8ac5aee0c13e 965 pc.printf("Intruder Distance = %.2f cm\n",one_second_avg_distance);
el14dg 7:8ac5aee0c13e 966
el14dg 7:8ac5aee0c13e 967 intruder_distance_counter = 0;
el14dg 7:8ac5aee0c13e 968
el14dg 7:8ac5aee0c13e 969 one_second_distance = 0;
el14dg 7:8ac5aee0c13e 970
el14dg 7:8ac5aee0c13e 971
el14dg 7:8ac5aee0c13e 972 if (one_second_avg_distance > (1.1*initial_setting_distance)) { // if the current average distance is 10% greater than the initial_setting_distance set off the alarm
el14dg 7:8ac5aee0c13e 973
el14dg 7:8ac5aee0c13e 974 g_next_state = 7;
el14dg 7:8ac5aee0c13e 975
el14dg 7:8ac5aee0c13e 976 g_current_state = 7;
el14dg 7:8ac5aee0c13e 977
el14dg 7:8ac5aee0c13e 978 screen_selection();
el14dg 7:8ac5aee0c13e 979
el14dg 7:8ac5aee0c13e 980 }
el14dg 7:8ac5aee0c13e 981
el14dg 7:8ac5aee0c13e 982 else if (one_second_avg_distance < (0.9 * initial_setting_distance)) { // if the current average distance is 10% smaller than the initial_setting_distance set off the alarm
el14dg 7:8ac5aee0c13e 983
el14dg 7:8ac5aee0c13e 984 g_next_state = 7;
el14dg 7:8ac5aee0c13e 985
el14dg 7:8ac5aee0c13e 986 g_current_state = 7;
el14dg 7:8ac5aee0c13e 987
el14dg 7:8ac5aee0c13e 988 screen_selection();
el14dg 7:8ac5aee0c13e 989
el14dg 7:8ac5aee0c13e 990 }
el14dg 7:8ac5aee0c13e 991
el14dg 7:8ac5aee0c13e 992 else { // if the current distance is within 10% of the initial_setting_distance carry on reading distance
el14dg 7:8ac5aee0c13e 993
el14dg 7:8ac5aee0c13e 994 intruder_distance.attach(&intruder_distance_isr,0.1);
el14dg 7:8ac5aee0c13e 995
el14dg 7:8ac5aee0c13e 996 }
el14dg 7:8ac5aee0c13e 997
el14dg 7:8ac5aee0c13e 998 }
el14dg 7:8ac5aee0c13e 999
el14dg 7:8ac5aee0c13e 1000 // Timeout Functions
el14dg 7:8ac5aee0c13e 1001
el14dg 3:70a7b64fbd98 1002 void screen_5_transition()
el14dg 3:70a7b64fbd98 1003 {
el14dg 4:9cac024c057c 1004 g_next_state = 5;
el14dg 6:dc1229224d8e 1005
el14dg 6:dc1229224d8e 1006 screen_selection(); // sets the LCD to screen 5
el14dg 3:70a7b64fbd98 1007
el14dg 3:70a7b64fbd98 1008 g_current_state = 5;
el14dg 6:dc1229224d8e 1009
el14dg 6:dc1229224d8e 1010 setting_distance_ticker_status = 0; // setting_distance ticker is off
el14dg 3:70a7b64fbd98 1011
el14dg 6:dc1229224d8e 1012 intruder_distance.attach(&intruder_distance_isr,0.1); // start reading distance to detect potential intruder
el14dg 6:dc1229224d8e 1013
el14dg 3:70a7b64fbd98 1014 }
el14dg 3:70a7b64fbd98 1015
el14dg 6:dc1229224d8e 1016 void screen_progression()
el14dg 4:9cac024c057c 1017 {
el14dg 6:dc1229224d8e 1018 if (g_current_state == 3) { // set new pin state
el14dg 6:dc1229224d8e 1019
el14dg 6:dc1229224d8e 1020 if (pin_counter > 3) { // if a four digit pin has been entered
el14dg 6:dc1229224d8e 1021
el14dg 6:dc1229224d8e 1022 change_pin(); // save entered_pin to the SD card
el14dg 6:dc1229224d8e 1023
el14dg 6:dc1229224d8e 1024 read_pin(); // read the pin from the SD card to the set_pin array
el14dg 6:dc1229224d8e 1025
el14dg 4:9cac024c057c 1026 g_next_state = fsm[g_current_state].nextState[2];
el14dg 6:dc1229224d8e 1027
el14dg 4:9cac024c057c 1028 }
el14dg 6:dc1229224d8e 1029
el14dg 4:9cac024c057c 1030 else {
el14dg 6:dc1229224d8e 1031
el14dg 4:9cac024c057c 1032 g_next_state = fsm[g_current_state].nextState[3];
el14dg 6:dc1229224d8e 1033
el14dg 4:9cac024c057c 1034 }
el14dg 6:dc1229224d8e 1035
el14dg 6:dc1229224d8e 1036 }
el14dg 6:dc1229224d8e 1037
el14dg 6:dc1229224d8e 1038 else { // if the current state is either 2, 6 or 7
el14dg 6:dc1229224d8e 1039
el14dg 6:dc1229224d8e 1040 check_pin(); // sets incorrect_pin_flag to 1 if entered pin doesn't match set_pin
el14dg 6:dc1229224d8e 1041
el14dg 4:9cac024c057c 1042 if (incorrect_pin_flag == 1) {
el14dg 6:dc1229224d8e 1043
el14dg 4:9cac024c057c 1044 incorrect_pin_flag = 0;
el14dg 6:dc1229224d8e 1045
el14dg 6:dc1229224d8e 1046 g_next_state = fsm[g_current_state].nextState[3]; // go to previous state or alarm triggered state
el14dg 6:dc1229224d8e 1047
el14dg 4:9cac024c057c 1048 pc.printf("g_next_state = %d\n",g_next_state);
el14dg 6:dc1229224d8e 1049
el14dg 4:9cac024c057c 1050 }
el14dg 6:dc1229224d8e 1051
el14dg 4:9cac024c057c 1052 else {
el14dg 6:dc1229224d8e 1053
el14dg 6:dc1229224d8e 1054 g_next_state = fsm[g_current_state].nextState[2]; // proceed
el14dg 6:dc1229224d8e 1055
el14dg 4:9cac024c057c 1056 pc.printf("g_next_state = %d\n",g_next_state);
el14dg 6:dc1229224d8e 1057
el14dg 4:9cac024c057c 1058 }
el14dg 6:dc1229224d8e 1059
el14dg 4:9cac024c057c 1060 }
el14dg 6:dc1229224d8e 1061
el14dg 6:dc1229224d8e 1062 }
el14dg 5:41cb88f47f42 1063
el14dg 5:41cb88f47f42 1064 void alarm_setting_buzz()
el14dg 5:41cb88f47f42 1065 {
el14dg 6:dc1229224d8e 1066
el14dg 6:dc1229224d8e 1067 buzzer.write(0.0); // turn off buzzer
el14dg 6:dc1229224d8e 1068
el14dg 6:dc1229224d8e 1069 }
el14dg 6:dc1229224d8e 1070
el14dg 7:8ac5aee0c13e 1071 // Pin Functions
el14dg 7:8ac5aee0c13e 1072
el14dg 6:dc1229224d8e 1073 void pin_confirm()
el14dg 6:dc1229224d8e 1074 {
el14dg 6:dc1229224d8e 1075 lcd.clear();
el14dg 6:dc1229224d8e 1076
el14dg 6:dc1229224d8e 1077 lcd_border();
el14dg 6:dc1229224d8e 1078
el14dg 6:dc1229224d8e 1079 lcd.printString("Press C",24,1);
el14dg 6:dc1229224d8e 1080
el14dg 6:dc1229224d8e 1081 lcd.printString("to",36,2);
el14dg 6:dc1229224d8e 1082
el14dg 6:dc1229224d8e 1083 lcd.printString("Confirm",24,3);
el14dg 7:8ac5aee0c13e 1084
el14dg 7:8ac5aee0c13e 1085 if (g_current_state == 7) {
el14dg 7:8ac5aee0c13e 1086
el14dg 7:8ac5aee0c13e 1087 lcd.drawRect(1,30,15,10,0);
el14dg 7:8ac5aee0c13e 1088
el14dg 7:8ac5aee0c13e 1089 }
el14dg 6:dc1229224d8e 1090
el14dg 6:dc1229224d8e 1091 lcd.refresh();
el14dg 6:dc1229224d8e 1092
el14dg 6:dc1229224d8e 1093 }
el14dg 5:41cb88f47f42 1094
el14dg 4:9cac024c057c 1095 void enter_pin()
el14dg 4:9cac024c057c 1096 {
el14dg 6:dc1229224d8e 1097
el14dg 6:dc1229224d8e 1098 // current value of the pin_counter determines where '*' is printed
el14dg 6:dc1229224d8e 1099
el14dg 4:9cac024c057c 1100 if (pin_counter == 1) {
el14dg 6:dc1229224d8e 1101
el14dg 5:41cb88f47f42 1102 lcd.printString("*",20,4);
el14dg 6:dc1229224d8e 1103
el14dg 4:9cac024c057c 1104 }
el14dg 6:dc1229224d8e 1105
el14dg 4:9cac024c057c 1106 else if (pin_counter == 2) {
el14dg 6:dc1229224d8e 1107
el14dg 4:9cac024c057c 1108 lcd.printString("*",34,4);
el14dg 6:dc1229224d8e 1109
el14dg 4:9cac024c057c 1110 }
el14dg 6:dc1229224d8e 1111
el14dg 4:9cac024c057c 1112 else if (pin_counter == 3) {
el14dg 6:dc1229224d8e 1113
el14dg 5:41cb88f47f42 1114 lcd.printString("*",48,4);
el14dg 6:dc1229224d8e 1115
el14dg 4:9cac024c057c 1116 }
el14dg 6:dc1229224d8e 1117
el14dg 4:9cac024c057c 1118 else if (pin_counter == 4) {
el14dg 6:dc1229224d8e 1119
el14dg 5:41cb88f47f42 1120 lcd.printString("*",62,4);
el14dg 6:dc1229224d8e 1121
el14dg 6:dc1229224d8e 1122 confirm.attach(&pin_confirm,0.5); // 'Press C to Confirm' screen
el14dg 6:dc1229224d8e 1123
el14dg 6:dc1229224d8e 1124 }
el14dg 6:dc1229224d8e 1125
el14dg 6:dc1229224d8e 1126 }
el14dg 4:9cac024c057c 1127
el14dg 7:8ac5aee0c13e 1128 void reset_entered_pin()
el14dg 7:8ac5aee0c13e 1129 {
el14dg 7:8ac5aee0c13e 1130 for (int i = 0; i < 4; i++) {
el14dg 7:8ac5aee0c13e 1131
el14dg 7:8ac5aee0c13e 1132 entered_pin[i] = -1;
el14dg 7:8ac5aee0c13e 1133
el14dg 7:8ac5aee0c13e 1134 }
el14dg 7:8ac5aee0c13e 1135
el14dg 7:8ac5aee0c13e 1136 pin_counter = 0;
el14dg 7:8ac5aee0c13e 1137
el14dg 7:8ac5aee0c13e 1138 }
el14dg 7:8ac5aee0c13e 1139
el14dg 4:9cac024c057c 1140 void check_pin()
el14dg 4:9cac024c057c 1141 {
el14dg 4:9cac024c057c 1142 for (int i = 0; i < 4; i++) {
el14dg 6:dc1229224d8e 1143
el14dg 6:dc1229224d8e 1144 if (entered_pin[i] != set_pin[i]) { // if any element of entered_pin doesn't match set_pin
el14dg 6:dc1229224d8e 1145
el14dg 4:9cac024c057c 1146 pc.printf("entered pin doesn't match set pin...");
el14dg 6:dc1229224d8e 1147
el14dg 4:9cac024c057c 1148 incorrect_pin_flag = 1;
el14dg 6:dc1229224d8e 1149
el14dg 4:9cac024c057c 1150 break;
el14dg 6:dc1229224d8e 1151
el14dg 4:9cac024c057c 1152 }
el14dg 6:dc1229224d8e 1153
el14dg 4:9cac024c057c 1154 }
el14dg 6:dc1229224d8e 1155
el14dg 5:41cb88f47f42 1156 }
el14dg 5:41cb88f47f42 1157
el14dg 3:70a7b64fbd98 1158 void change_pin()
el14dg 3:70a7b64fbd98 1159 {
el14dg 3:70a7b64fbd98 1160 delete_file("/sd/test.txt");
el14dg 3:70a7b64fbd98 1161
el14dg 3:70a7b64fbd98 1162 pin = fopen("/sd/test.txt", "a");
el14dg 3:70a7b64fbd98 1163
el14dg 3:70a7b64fbd98 1164 if (pin == NULL) { // if it can't open the file then print error message
el14dg 3:70a7b64fbd98 1165
el14dg 3:70a7b64fbd98 1166 pc.printf("Error! Unable to open file!\n");
el14dg 3:70a7b64fbd98 1167
el14dg 3:70a7b64fbd98 1168 }
el14dg 3:70a7b64fbd98 1169
el14dg 3:70a7b64fbd98 1170 else {
el14dg 3:70a7b64fbd98 1171
el14dg 4:9cac024c057c 1172 pc.printf("Writing to file....\n");
el14dg 3:70a7b64fbd98 1173
el14dg 3:70a7b64fbd98 1174 for(int i = 0; i < 4; i++) {
el14dg 3:70a7b64fbd98 1175
el14dg 6:dc1229224d8e 1176 int pin_element = entered_pin[i];; // pin_element takes on the value of each element in the entered_pin array
el14dg 3:70a7b64fbd98 1177
el14dg 6:dc1229224d8e 1178 fprintf(pin, "%d,%d\n",i,pin_element); // pin element is printed to SD card file (CSV)
el14dg 3:70a7b64fbd98 1179 }
el14dg 3:70a7b64fbd98 1180
el14dg 3:70a7b64fbd98 1181 for(int i = 0; i < 4; i++) {
el14dg 3:70a7b64fbd98 1182
el14dg 6:dc1229224d8e 1183 pc.printf("[%d] %d\n",i,entered_pin[i]); // print to PC for debugging purposes
el14dg 3:70a7b64fbd98 1184 }
el14dg 3:70a7b64fbd98 1185
el14dg 3:70a7b64fbd98 1186 pc.printf("Done.\n");
el14dg 3:70a7b64fbd98 1187
el14dg 6:dc1229224d8e 1188 fclose(pin); // close the file after writing
el14dg 3:70a7b64fbd98 1189
el14dg 3:70a7b64fbd98 1190 }
el14dg 3:70a7b64fbd98 1191
el14dg 3:70a7b64fbd98 1192 }
el14dg 3:70a7b64fbd98 1193
el14dg 3:70a7b64fbd98 1194 void read_pin()
el14dg 3:70a7b64fbd98 1195 {
el14dg 3:70a7b64fbd98 1196 pin = fopen("/sd/test.txt", "r");
el14dg 6:dc1229224d8e 1197
el14dg 3:70a7b64fbd98 1198 int i = 0;
el14dg 3:70a7b64fbd98 1199
el14dg 3:70a7b64fbd98 1200 pc.printf("Reading into set_pin array...\n");
el14dg 3:70a7b64fbd98 1201
el14dg 6:dc1229224d8e 1202 while (fscanf(pin, "%d,%d",&index_array[i],&set_pin[i]) != EOF) { // EOF ---> End of File
el14dg 3:70a7b64fbd98 1203 i++; // read data into array and increment index
el14dg 3:70a7b64fbd98 1204 }
el14dg 3:70a7b64fbd98 1205
el14dg 6:dc1229224d8e 1206 fclose(pin); // close the file after reading
el14dg 3:70a7b64fbd98 1207
el14dg 3:70a7b64fbd98 1208 for(int i = 0; i < 4 ; i++) {
el14dg 3:70a7b64fbd98 1209
el14dg 6:dc1229224d8e 1210 pc.printf("[%d] %d\n",i,set_pin[i]); // print to PC for debugging purposes
el14dg 3:70a7b64fbd98 1211
el14dg 3:70a7b64fbd98 1212 }
el14dg 6:dc1229224d8e 1213
el14dg 3:70a7b64fbd98 1214 pc.printf("Done.\n");
el14dg 6:dc1229224d8e 1215
el14dg 3:70a7b64fbd98 1216 }
el14dg 6:dc1229224d8e 1217
el14dg 3:70a7b64fbd98 1218 void delete_file(char filename[])
el14dg 3:70a7b64fbd98 1219 {
el14dg 3:70a7b64fbd98 1220 pc.printf("Deleting file '%s'...",filename);
el14dg 6:dc1229224d8e 1221
el14dg 3:70a7b64fbd98 1222 FILE *fp = fopen(filename, "r"); // try and open file
el14dg 6:dc1229224d8e 1223
el14dg 3:70a7b64fbd98 1224 if (fp != NULL) { // if it does open...
el14dg 6:dc1229224d8e 1225
el14dg 3:70a7b64fbd98 1226 fclose(fp); // close it
el14dg 6:dc1229224d8e 1227
el14dg 6:dc1229224d8e 1228 remove(filename); // delete the file
el14dg 6:dc1229224d8e 1229
el14dg 3:70a7b64fbd98 1230 pc.printf("Done!\n");
el14dg 6:dc1229224d8e 1231
el14dg 3:70a7b64fbd98 1232 }
el14dg 6:dc1229224d8e 1233
el14dg 6:dc1229224d8e 1234 // if it can't be opened, it doesn't exist and can't be deleted
el14dg 6:dc1229224d8e 1235
el14dg 6:dc1229224d8e 1236 }