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
main.cpp
- Committer:
- ewilliams61
- Date:
- 2016-03-15
- Revision:
- 7:79d0b30fedb4
- Parent:
- 6:0398d0fcc8cc
- Child:
- 8:39172c01c0f1
File content as of revision 7:79d0b30fedb4:
#include "mbed.h" #include <mpr121.h> #include <string> #include "Shiftbrite.h" RawSerial pc(USBTX, USBRX); RawSerial dev(p9,p10); 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); int code1[] = {1,1,1,1}; int code2[] = {2,2,2,2}; int code3[] = {8,8,8,8}; volatile int input[4]; volatile int inNdx = 0; bool codeIn = false; 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; for (i=0; i<12; i++) { if (((value>>i)&0x01)==1) key_code=i+1; } led4=key_code & 0x01; led3=(key_code>>1) & 0x01; led2=(key_code>>2) & 0x01; led1=(key_code>>3) & 0x01; if (value > 0){ input[inNdx] = value; inNdx++; } } void dev_recv() { string temp =""; led1 = !led1; while(dev.readable()) { //pc.putc(dev.getc()); if(!codeIn){ if(dev.getc() == 'a'){ dev.printf("Send code 4 digit code.\n"); inNdx = 0; codeIn = true; // myShiftbrite.write(0,0,255); } else {dev.printf("Command not recognized");} } else { // pc.printf("BT entered: %c\n", dev.getc()); input[inNdx] = dev.getc() - '0'; if(input[inNdx] > -1){ dev.printf("Just entered: %d", input[inNdx]); inNdx++;} //break; } } } void pc_recv() { led4 = !led4; while(pc.readable()) { dev.putc(pc.getc()); } } int main() { myShiftbrite.write(0,0,0); pc.baud(9600); dev.baud(9600); interrupt.fall(&fallInterrupt); interrupt.mode(PullUp); 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 (inNdx > 3) { dev.printf("Attempting to Unlock\n"); codeIn = false; bool c1 = true; bool c2 = true; bool c3 = true; for(int x = 0; x <= 3; x++){ if(!(c1 | c2 | c3)) { break; } else { if (code1[x] != input[x]){c1 = false;} if (code2[x] != input[x]){c2 = false;} if (code3[x] != input[x]){c3 = false;} } } if(c1){ //update website to say user 1 entered last dev.printf("Welcome User 1\n"); // myShiftbrite.write(0,0,0); myShiftbrite.write(0,255,0); } else if(c2) { dev.printf("Welcome User 2\n"); // myShiftbrite.write(0,0,0); myShiftbrite.write(0,255,0); } else if(c3) { dev.printf("Welcome User 3\n"); // myShiftbrite.write(0,0,0); myShiftbrite.write(0,255,0); } else { dev.printf("Try Again\n"); // myShiftbrite.write(0,0,0); myShiftbrite.write(255,0,0); } inNdx = 0; } } }