kh

Dependencies:   mbed PinDetect Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers setup.cpp Source File

setup.cpp

00001 /*
00002 * Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
00003 * Purpose: Controls the SETUP state of the machine
00004 * Language: C
00005 */
00006 #include "setup.h"
00007 #include "authentication.h"
00008 #include "parameters.h"
00009 #include "actuators.h"
00010 #include "PinDetect.h"
00011 
00012 
00013 PinDetect button(p8);
00014 
00015 volatile bool buttonHit = false;
00016 bool firstTime = true;
00017 void button_hit_callback (void)
00018 {
00019     buttonHit = !buttonHit;
00020 }
00021 /*
00022 * Function:  setup
00023 * --------------------
00024 *  Calls the functions needed to setup the entry sequence for the safe.
00025 *
00026 *  returns: the next state in the state machine
00027 *  LOCK: after entry sequence has been entered
00028 *
00029 */
00030 
00031 
00032 enum states setup()
00033 {
00034     printf("%d",buttonHit);
00035     if (firstTime) {
00036         button.mode(PullUp);
00037         button.attach_deasserted(&button_hit_callback);
00038         button.setSampleFrequency();
00039         firstTime = false;
00040     }
00041     if(buttonHit || checkBluetooth()) {
00042         setEntrySequenceAttempt();
00043         wait(5);
00044         lockSafe();
00045         wait(5);
00046         return LOCK;
00047     }
00048     return SETUP;
00049 }
00050 
00051 
00052 
00053