kh
Dependencies: mbed PinDetect Servo
Diff: setup.cpp
- Revision:
- 2:04bbd14722bd
- Parent:
- 1:2c365f6da61d
diff -r 2c365f6da61d -r 04bbd14722bd setup.cpp --- a/setup.cpp Sat Nov 10 20:08:46 2018 +0000 +++ b/setup.cpp Mon Nov 12 23:36:11 2018 +0000 @@ -1,37 +1,53 @@ -/* -* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga -* Purpose: Controls the SETUP state of the machine -* Language: C -*/ -#include "setup.h" -#include "authentication.h" -#include "parameters.h" -#include "actuators.h" - - -DigitalIn button(p8); +/* +* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga +* Purpose: Controls the SETUP state of the machine +* Language: C +*/ +#include "setup.h" +#include "authentication.h" +#include "parameters.h" +#include "actuators.h" +#include "PinDetect.h" + + +PinDetect button(p8); + +volatile bool buttonHit = false; +bool firstTime = true; +void button_hit_callback (void) +{ + buttonHit = !buttonHit; +} +/* +* Function: setup +* -------------------- +* Calls the functions needed to setup the entry sequence for the safe. +* +* returns: the next state in the state machine +* LOCK: after entry sequence has been entered +* +*/ + + +enum states setup() +{ + printf("%d",buttonHit); + if (firstTime) { + button.mode(PullUp); + button.attach_deasserted(&button_hit_callback); + button.setSampleFrequency(); + firstTime = false; + } + if(buttonHit || checkBluetooth()) { + setEntrySequenceAttempt(); + wait(5); + lockSafe(); + wait(5); + return LOCK; + } + return SETUP; +} + + + -/* -* Function: setup -* -------------------- -* Calls the functions needed to setup the entry sequence for the safe. -* -* returns: the next state in the state machine -* LOCK: after entry sequence has been entered -* -*/ - - -enum states setup() { - if(button) { - setEntrySequenceAttempt(); - wait(5000); - lockSafe(); - wait(5000); - return LOCK; - } - return SETUP; -} - - -