The purpose of this project was to create a system that would allow users to monitor a locked device using a Bluetooth device. This Bluetooth device will show the last user that unlocked the device, and also allows the user to unlock the device using the Bluetooth device. This device can be physically unlocked using a capacitive touch keypad sensor.
Dependencies: mbed Motor Servo
Fork of SerialPassthrough_LPC1768 by
Revision 8:39172c01c0f1, committed 2016-03-15
- Comitter:
- ewilliams61
- Date:
- Tue Mar 15 19:36:01 2016 +0000
- Parent:
- 7:79d0b30fedb4
- Child:
- 9:c216d7b63f92
- Commit message:
- Works :)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 15 19:14:45 2016 +0000
+++ b/main.cpp Tue Mar 15 19:36:01 2016 +0000
@@ -2,32 +2,42 @@
#include <mpr121.h>
#include <string>
#include "Shiftbrite.h"
+//Print output to pc via usb
RawSerial pc(USBTX, USBRX);
+//Print output to Bluetooth device
RawSerial dev(p9,p10);
+//LEDs
DigitalOut led1(LED1);
-DigitalOut led4(LED4);
-InterruptIn interrupt(p26);
-I2C i2c(p28, p27);
-Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
-Shiftbrite myShiftbrite(p16, p15, p11, p12, p13);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+//Interrupt for Touchpad
+InterruptIn interrupt(p26);
+//I2C for Touchpad
+I2C i2c(p28, p27);
+//Touchpad
+Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
+//Shiftbrite
+Shiftbrite myShiftbrite(p16, p15, p11, p12, p13);
+
+//Code Combinations
int code1[] = {1,1,1,1};
int code2[] = {2,2,2,2};
-int code3[] = {8,8,8,8};
+int code3[] = {8,8,8,8};//Key 4 (labeled 3) on touchpad
-volatile int input[4];
-volatile int inNdx = 0;
-bool codeIn = false;
+volatile int input[4]; //stores input values
+volatile int inNdx = 0;//to place combination in input
+bool codeIn = false; //determine if code is being entered via bluetooth
+
+//Interrupt method to read from touchpad
void fallInterrupt() {
int key_code=0;
int i = 0;
- // myShiftbrite.write(0,0,0);
- // myShiftbrite.write(0,0,255);
int value=mpr121.read(0x00);
value +=mpr121.read(0x01)<<8;
+ //output value to onboard LEDs
for (i=0; i<12; i++) {
if (((value>>i)&0x01)==1) key_code=i+1;
}
@@ -35,6 +45,7 @@
led3=(key_code>>1) & 0x01;
led2=(key_code>>2) & 0x01;
led1=(key_code>>3) & 0x01;
+ //ignore second character and input value into inputNdx
if (value > 0){
input[inNdx] = value;
inNdx++;
@@ -44,6 +55,7 @@
}
+//receive value from bluetooth device
void dev_recv()
{
string temp ="";
@@ -69,7 +81,7 @@
}
}
-
+//receive value from PC
void pc_recv()
{
led4 = !led4;
@@ -80,29 +92,34 @@
int main()
{
+ //reset Shiftbrite
myShiftbrite.write(0,0,0);
pc.baud(9600);
dev.baud(9600);
+ //Set up interrupt
interrupt.fall(&fallInterrupt);
interrupt.mode(PullUp);
-
+ //Set up read methods bluetooth and PC
pc.attach(&pc_recv, Serial::RxIrq);
dev.attach(&dev_recv, Serial::RxIrq);
+
dev.printf("Monitoring Locked Device\n");
dev.printf("To unlock the device remotely, send 'a'.\n");
while(1) {
- // sleep();
wait(5);
- pc.printf("ndx: %d\n", inNdx);
+ //If three characters have been entered, attempt to unlock
if (inNdx > 3) {
dev.printf("Attempting to Unlock\n");
codeIn = false;
bool c1 = true; bool c2 = true; bool c3 = true;
+ //check entered code against saved codes
for(int x = 0; x <= 3; x++){
+ //if no code matches, end loop
if(!(c1 | c2 | c3)) {
break;
} else {
+ //compare codes
if (code1[x] != input[x]){c1 = false;}
if (code2[x] != input[x]){c2 = false;}
if (code3[x] != input[x]){c3 = false;}
@@ -110,24 +127,24 @@
}
}
if(c1){
- //update website to say user 1 entered last
+ //Send welcome user 1 to bluetooth
dev.printf("Welcome User 1\n");
- // myShiftbrite.write(0,0,0);
myShiftbrite.write(0,255,0);
} else if(c2) {
+ //Send welcome user 2 to bluetooth
dev.printf("Welcome User 2\n");
- // myShiftbrite.write(0,0,0);
myShiftbrite.write(0,255,0);
} else if(c3) {
+ //Send welcome user 3 to bluetooth
dev.printf("Welcome User 3\n");
- // myShiftbrite.write(0,0,0);
myShiftbrite.write(0,255,0);
} else {
+ //Send welcome Try Again message to bluetooth
dev.printf("Try Again\n");
- // myShiftbrite.write(0,0,0);
myShiftbrite.write(255,0,0);
}
+ //reset indexing variable when checking is complete
inNdx = 0;
}
