kh

Dependencies:   mbed PinDetect Servo

Files at this revision

API Documentation at this revision

Comitter:
Sayak97
Date:
Mon Nov 12 23:36:11 2018 +0000
Parent:
1:2c365f6da61d
Child:
3:2f7a7e2cd49e
Commit message:
ss

Changed in this revision

.mbed Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
actuators.cpp Show annotated file Show diff for this revision Revisions of this file
actuators.h Show annotated file Show diff for this revision Revisions of this file
authentication.cpp Show annotated file Show diff for this revision Revisions of this file
authentication.h Show annotated file Show diff for this revision Revisions of this file
lock.cpp Show annotated file Show diff for this revision Revisions of this file
lock.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
open.cpp Show annotated file Show diff for this revision Revisions of this file
open.h Show annotated file Show diff for this revision Revisions of this file
parameters.h Show annotated file Show diff for this revision Revisions of this file
powerManagement.cpp Show annotated file Show diff for this revision Revisions of this file
powerManagement.h Show annotated file Show diff for this revision Revisions of this file
setup.cpp Show annotated file Show diff for this revision Revisions of this file
setup.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.mbed	Mon Nov 12 23:36:11 2018 +0000
@@ -0,0 +1,2 @@
+ROOT=.
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Mon Nov 12 23:36:11 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/README.md	Sat Nov 10 20:08:46 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-# devilsafe
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Mon Nov 12 23:36:11 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- a/actuators.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/actuators.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -5,11 +5,11 @@
 */
 #include "actuators.h"
 #include "parameters.h"
-#include "mbed.h"
+#include "Servo.h"
 
 
-PwmOut rcServo1(p23); // pwm, fwd, rev
-PwmOut rcServo2(p24); // pwm, fwd, rev
+Servo rcServo1(p23); // pwm
+Servo rcServo2(p24); // pwm
 
 /*
 * Function:  turnsRcServosRight
@@ -19,6 +19,7 @@
 *
 */
 void turnsRcServosRight() {
+	printf("I entered turnsRCServoRight");
 	rcServo1 = 1.0f;
 	rcServo2 = 1.0f;
 }
@@ -31,8 +32,8 @@
 *
 */
 void turnsRcServosLeft() {
-	rcServo1 = -1.0f;
-	rcServo2 = -1.0f;
+	rcServo1 = 0.0f;
+	rcServo2 = 0.0f;
 }
 
 
@@ -55,4 +56,3 @@
 }
 
 
-
--- a/actuators.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/actuators.h	Mon Nov 12 23:36:11 2018 +0000
@@ -1,41 +1,42 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls the actuators of the safe
-* Language:  NBC
-*/
-
-/*
-* Function:  turnsRcServosRight
-* --------------------
-*  Turns the servos to the right
-*
-*
-*/
-void turnsRcServosRight() ;
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the actuators of the safe
+* Language:  NBC
+*/
+
+/*
+* Function:  turnsRcServosRight
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosRight() ;
+
+/*
+* Function:  urnsRcServosLeft
+* --------------------
+*  Turns the servos to the right
+*
+*
+*/
+void turnsRcServosLeft() ;
+
+
+/*
+* Function:  openSafe
+* --------------------
+*  Opens the safe
+*/
+void openSafe() ;
+
+/*
+* Function:  lockSafe
+* --------------------
+*  Locks the safe
+*/
+void lockSafe() ;
+
+
+
 
-/*
-* Function:  urnsRcServosLeft
-* --------------------
-*  Turns the servos to the right
-*
-*
-*/
-void turnsRcServosLeft() ;
-
-
-/*
-* Function:  openSafe
-* --------------------
-*  Opens the safe
-*/
-void openSafe() ;
-
-/*
-* Function:  lockSafe
-* --------------------
-*  Locks the safe
-*/
-void lockSafe() ;
-
-
-
--- a/authentication.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/authentication.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -18,13 +18,15 @@
 int entryNum4;
 
 
-Serial blue(p28,p27);
-
 AnalogIn pot1(p18);
 AnalogIn pot2(p18);
 AnalogIn pot3(p20);
 AnalogIn pot4(p20);
 
+bool bluetoothCode = false;
+bool bluetoothSetup = false;
+Serial blue(p28,p27);
+
 /*
 * Function: setEntrySequence
 * --------------------
@@ -47,10 +49,14 @@
 *
 */
 bool CorrectEntrySequenceAttempt() {
-	p1 = float(pot1) * 10;
-	p2 = float(pot2) * 10;
-	p3 = float(pot3) * 10;
-	p4 = float(pot4) * 10;
+	if (bluetoothCode) {
+		return true;
+
+	}
+	p1 = float(pot1) * 6;
+	p2 = float(pot2) * 6;
+	p3 = float(pot3) * 6;
+	p4 = float(pot4) * 6;
 
 	return (checkPot(p1,entryNum1) && checkPot(p2,entryNum2) && checkPot(p3,entryNum3) && checkPot(p3,entryNum3));
 }
@@ -60,20 +66,43 @@
 
 }
 
+bool checkBluetooth() {
+	if (bluetoothSetup) {
+		bluetoothSetup = false;
+		return true;
+	}
+	return false;
+}
+
 
 
 /*
-* Function:  bluetooth
+* Function:  parse_bluetooth
 * --------------------
 *  bluetooth stuff EDIT LATER
 *
 *  returns:
 *
 */
-void bluetooth() {
-
+void parse_bluetooth()
+{
+    switch (blue.getc()) {
+        case 'o':
+            bluetoothCode  = true;
+            break;
+        case 'l':
+            bluetoothCode = false;
+            break;
+        case 's':
+			bluetoothSetup = true;
+			break;
+    }
+    
 }
 
+void start_bluetooth() {
+	 blue.attach(&parse_bluetooth, Serial::RxIrq);	
+}
 
 /*
 * Function:  sdCard
@@ -87,3 +116,4 @@
 
 }
 
+
--- a/authentication.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/authentication.h	Mon Nov 12 23:36:11 2018 +0000
@@ -22,6 +22,7 @@
 
 bool checkPot(int p1, int p2);
 
+bool checkBluetooth();
 
 
 /*
@@ -32,8 +33,9 @@
 *  returns:
 *
 */
-void bluetooth();
+void parse_bluetooth();
 
+void start_bluetooth();
 
 /*
 * Function:  sdCard
@@ -45,3 +47,4 @@
 */
 void sdCard();
 
+
--- a/lock.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/lock.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -1,40 +1,41 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls the LOCK state of the machine
-* Language: C
-*/
-#include "lock.h"
-#include "authentication.h"
-#include "actuators.h"
-#include "powerManagement.h"
-#include "parameters.h"
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the LOCK state of the machine
+* Language: C
+*/
+#include "lock.h"
+#include "authentication.h"
+#include "actuators.h"
+#include "powerManagement.h"
+#include "parameters.h"
+
+/*
+* Function:  lock
+* --------------------
+*  Locks safe
+*
+*  returns: the next state in the state machine
+*  Open: After it has been locked
+*
+*/
+enum states lock() {
+	if(authenticateLock()) {
+		openSafe();
+		wait(5);
+		return OPEN;
+	} else {
+		return LOCK;
+	}
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticateLock() {
+    return CorrectEntrySequenceAttempt();
+}
 
-/*
-* Function:  lock
-* --------------------
-*  Locks safe
-*
-*  returns: the next state in the state machine
-*  Open: After it has been locked
-*
-*/
-enum states lock() {
-	if(authenticateLock()) {
-		openSafe();
-		wait(5000);
-		return OPEN;
-	} else {
-		return LOCK;
-	}
-}
-
-/*
-* Function: authenticate
-* ----------------------------
-*  Checks whether a cup was found through the sonar sensor
-*
-*  returns: true if cup found else false
-*/
-bool authenticateLock() {
-    return CorrectEntrySequenceAttempt();
-}
--- a/lock.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/lock.h	Mon Nov 12 23:36:11 2018 +0000
@@ -1,25 +1,26 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls the LOCK state of the machine
-* Language: C
-*/
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the LOCK state of the machine
+* Language: C
+*/
+
+/*
+* Function:  lock
+* --------------------
+*  Locks safe
+*
+*  returns: the next state in the state machine
+*  Open: After it has been locked
+*
+*/
+enum states lock();
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticateLock();
 
-/*
-* Function:  lock
-* --------------------
-*  Locks safe
-*
-*  returns: the next state in the state machine
-*  Open: After it has been locked
-*
-*/
-enum states lock();
-
-/*
-* Function: authenticate
-* ----------------------------
-*  Checks whether a cup was found through the sonar sensor
-*
-*  returns: true if cup found else false
-*/
-bool authenticateLock();
--- a/main.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/main.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -6,10 +6,13 @@
 #include "open.h"
 #include "lock.h"
 #include "setup.h"
-#include "sleep.h"
 #include "parameters.h"
+#include "authentication.h"
 
 
+
+enum states state = SETUP;
+
 /*
 * Function:  SafeStateMachine
 * --------------------
@@ -18,11 +21,8 @@
 *
 *
 */
-void SafeStateMachine() {
-
-
-    enum states state = SETUP;
-
+void SafeStateMachine()
+{
     while (1) {
         switch (state) {
         case OPEN:/*state in which the the case is open*/
@@ -37,12 +37,15 @@
         default:
             state = lock();
         }
+        wait(.5);
     }
 }
 
 int main() {
+    start_bluetooth();
     SafeStateMachine();
 }
 
 
 
+
--- a/mbed.bld	Sat Nov 10 20:08:46 2018 +0000
+++ b/mbed.bld	Mon Nov 12 23:36:11 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
--- a/open.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/open.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -1,42 +1,43 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls the OPEN state of the machine
-* Language:  C
-*/
-#include "open.h"
-#include "authentication.h"
-#include "actuators.h"
-#include "parameters.h"
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the OPEN state of the machine
+* Language:  C
+*/
+#include "open.h"
+#include "authentication.h"
+#include "actuators.h"
+#include "parameters.h"
+
+/*
+* Function:  OPEN
+* --------------------
+*  Calls the functions needed to for the open state
+*
+*
+*  returns: the next state in the state machine
+*  LOCK: if closed properly
+*  ALARM: if cup is not found after searching in a full circle
+*
+*/
+enum states open() {
+    if (authenticateOpen()) {
+        return OPEN;
+    } else {
+        lockSafe();
+        wait(5);
+        return LOCK;
+    }
+}
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticateOpen() {
+    return CorrectEntrySequenceAttempt();
+}
+
 
-/*
-* Function:  OPEN
-* --------------------
-*  Calls the functions needed to for the open state
-*
-*
-*  returns: the next state in the state machine
-*  LOCK: if closed properly
-*  ALARM: if cup is not found after searching in a full circle
-*
-*/
-enum states open() {
-    if (authenticateOpen()) {
-        return OPEN;
-    } else {
-        lockSafe();
-        wait(5000);
-        return LOCK;
-    }
-}
-
-/*
-* Function: authenticate
-* ----------------------------
-*  Checks whether a cup was found through the sonar sensor
-*
-*  returns: true if cup found else false
-*/
-bool authenticateOpen() {
-    return CorrectEntrySequenceAttempt();
-}
-
--- a/open.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/open.h	Mon Nov 12 23:36:11 2018 +0000
@@ -1,27 +1,28 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls the OPEN state of the machine
-* Language:  C
-*/
-/*
-* Function:  OPEN
-* --------------------
-*  Calls the functions needed to for the open state
-*
-*
-*  returns: the next state in the state machine
-*  LOCK: if closed properly
-*  ALARM: if cup is not found after searching in a full circle
-*
-*/
-enum states open();
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls the OPEN state of the machine
+* Language:  C
+*/
+/*
+* Function:  OPEN
+* --------------------
+*  Calls the functions needed to for the open state
+*
+*
+*  returns: the next state in the state machine
+*  LOCK: if closed properly
+*  ALARM: if cup is not found after searching in a full circle
+*
+*/
+enum states open();
+
+/*
+* Function: authenticate
+* ----------------------------
+*  Checks whether a cup was found through the sonar sensor
+*
+*  returns: true if cup found else false
+*/
+bool authenticateOpen();
+
 
-/*
-* Function: authenticate
-* ----------------------------
-*  Checks whether a cup was found through the sonar sensor
-*
-*  returns: true if cup found else false
-*/
-bool authenticateOpen();
-
--- a/parameters.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/parameters.h	Mon Nov 12 23:36:11 2018 +0000
@@ -1,10 +1,11 @@
-#include "mbed.h"
-/*
- * Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga 
- * Purpose: Controls the parameters of the safe
- * Language:  C
- */
-enum states{OPEN, LOCK, SETUP};/*Name of the states in the Safe Cups State Machine*/
-#define  maxFailedAtttemps 6; /*number of max failed attemps entered before alarm is thrown*/
+#include "mbed.h"
+/*
+ * Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga 
+ * Purpose: Controls the parameters of the safe
+ * Language:  C
+ */
+enum states{OPEN, LOCK, SETUP};/*Name of the states in the Safe Cups State Machine*/
+#define  maxFailedAtttemps 6; /*number of max failed attemps entered before alarm is thrown*/
+
+
 
-
--- a/powerManagement.cpp	Sat Nov 10 20:08:46 2018 +0000
+++ b/powerManagement.cpp	Mon Nov 12 23:36:11 2018 +0000
@@ -1,31 +1,32 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls Input and Output Data
-* Language: C
-*/
-#include "powerManagement.h"
-#include "parameters.h"
-
-int batteryLevels;
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+#include "powerManagement.h"
+#include "parameters.h"
+
+int batteryLevels;
+
+/*
+* Function: powerSavingMode
+* --------------------
+*  Controls what is on while the safe is on this mode
+*/
+void powerSavingMode() {
+//however we decide to implement 
+}
+
+/*
+* Function: getBatteryLevels
+* --------------------
+*  Get the battery level for the safe
+*
+*  returns: the battery level for the safe
+*
+*/
+int getBatteryLevels() {
+	//EDIT LATER maybe have it send a notification in the future
+	return batteryLevels;
+}
 
-/*
-* Function: powerSavingMode
-* --------------------
-*  Controls what is on while the safe is on this mode
-*/
-void powerSavingMode() {
-//however we decide to implement 
-}
-
-/*
-* Function: getBatteryLevels
-* --------------------
-*  Get the battery level for the safe
-*
-*  returns: the battery level for the safe
-*
-*/
-int getBatteryLevels() {
-	//EDIT LATER maybe have it send a notification in the future
-	return batteryLevels;
-}
--- a/powerManagement.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/powerManagement.h	Mon Nov 12 23:36:11 2018 +0000
@@ -1,22 +1,23 @@
-/*
-* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
-* Purpose: Controls Input and Output Data
-* Language: C
-*/
+/*
+* Authors: Group 4 Adam Elghor, Brian Kaplan, Sayak Chatterjee, Moraa Onwonga
+* Purpose: Controls Input and Output Data
+* Language: C
+*/
+
+/*
+* Function: powerSavingMode
+* --------------------
+*  Controls what is on while the safe is on this mode
+*/
+void powerSavingMode();
+
+/*
+* Function: getBatteryLevels
+* --------------------
+*  Get the battery level for the safe
+*
+*  returns: the battery level for the safe
+*
+*/
+int getBatteryLevels();
 
-/*
-* Function: powerSavingMode
-* --------------------
-*  Controls what is on while the safe is on this mode
-*/
-void powerSavingMode();
-
-/*
-* Function: getBatteryLevels
-* --------------------
-*  Get the battery level for the safe
-*
-*  returns: the battery level for the safe
-*
-*/
-int getBatteryLevels();
--- 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;
-}
-
-
-
--- a/setup.h	Sat Nov 10 20:08:46 2018 +0000
+++ b/setup.h	Mon Nov 12 23:36:11 2018 +0000
@@ -16,5 +16,3 @@
 
 
 enum states setup();
-
-