Moraa Onwonga / Mbed 2 deprecated Safe_Of_the_Gods

Dependencies:   mbed Servo PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers authentication.cpp Source File

authentication.cpp

00001 /*
00002 * Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
00003 * Purpose: Controls Input and Output Data
00004 * Language: C++
00005 */
00006 #include "authentication.h"
00007 #include "parameters.h"
00008 
00009 int p1;
00010 int p2;
00011 int p3;
00012 int p4;
00013 
00014 int entryNum1;
00015 int entryNum2;
00016 int entryNum3;
00017 int entryNum4;
00018 
00019 
00020 AnalogIn pot1(p15);
00021 AnalogIn pot2(p16);
00022 AnalogIn pot3(p18);
00023 AnalogIn pot4(p19);
00024 
00025 bool bluetoothCode = false;
00026 bool bluetoothSetup = false;
00027 Serial blue(p28,p27);
00028 Serial pc(USBTX, USBRX);
00029 
00030 /*
00031 * Function: setEntrySequence
00032 * --------------------
00033 *  Reads in user's entry sequence attempt
00034 */
00035 void setEntrySequenceAttempt() {
00036     entryNum1 = float(pot1) * 6;
00037     entryNum2 = float(pot2) * 6;
00038     entryNum3 = float(pot3) * 6;
00039     entryNum4 = float(pot4) * 6;
00040 }
00041 
00042 /*
00043 * Function:  CorrectEntrySequenceAttempt
00044 * --------------------
00045 *  Checks whether the user's entry sequence attempt is correct
00046 *
00047 *  returns: true if the entry sequence attempt from the user matches
00048 *  the set entry sequence otherwise false
00049 *
00050 */
00051 bool CorrectEntrySequenceAttempt() {
00052     if (bluetoothCode) {
00053         return true;
00054 
00055     }
00056     p1 = float(pot1) * 6;
00057     p2 = float(pot2) * 6;
00058     p3 = float(pot3) * 6;
00059     p4 = float(pot4) * 6;
00060 
00061     return (checkPot(p1,entryNum1) && checkPot(p2,entryNum2) && checkPot(p3,entryNum3) && checkPot(p3,entryNum3));
00062 }
00063 
00064 void printPotValues() {
00065     pc.printf("pot1 is %f", pot1);
00066     
00067 }
00068 
00069 bool checkPot(int p1, int p2) {
00070     return (p2 - p1) < 2 && (p1 - p2) > -2;
00071 
00072 }
00073 
00074 bool checkBluetooth() {
00075     if (bluetoothSetup) {
00076         bluetoothSetup = false;
00077         return true;
00078     }
00079     return false;
00080 }
00081 
00082 
00083 
00084 /*
00085 * Function:  parse_bluetooth
00086 * --------------------
00087 *  bluetooth stuff EDIT LATER
00088 *
00089 *  returns:
00090 *
00091 */
00092 void parse_bluetooth()
00093 {
00094     switch (blue.getc()) {
00095         case 'o':
00096             bluetoothCode  = true;
00097             break;
00098         case 'l':
00099             bluetoothCode = false;
00100             break;
00101         case 's':
00102             bluetoothSetup = true;
00103             break;
00104     }
00105     
00106 }
00107 
00108 void start_bluetooth() {
00109      blue.attach(&parse_bluetooth, Serial::RxIrq);  
00110 }
00111 
00112 
00113 
00114