Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Camera_LS_Y201 Servo mbed
Fork of mbed1 by
Revision 1:547b5918a132, committed 2013-04-22
- Comitter:
- Jgreub
- Date:
- Mon Apr 22 18:38:07 2013 +0000
- Parent:
- 0:0b4164532b17
- Commit message:
- Test 2
Changed in this revision
| mbed1.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/mbed1.cpp Thu Apr 18 02:35:53 2013 +0000
+++ b/mbed1.cpp Mon Apr 22 18:38:07 2013 +0000
@@ -21,10 +21,9 @@
DigitalOut lockLED(p11); //1 = locked
//Pushbuttons
-InterruptIn lockPB(p12);
+InterruptIn lockPB(p13);
//Globals
-FILE *picture;
char signal;
int isDoorOpen;
int isDoorLocked;
@@ -39,30 +38,28 @@
/***************************************/
/* HELPER FUNCTIONS */
/***************************************/
-void servoLockDoor() {
- servo = 0;
- lockLED = 1;
-}
-void servoUnlockDoor() {
- servo = .5;
- lockLED = 0;
+inline void servoLockDoor() {servo = .5;lockLED = 1;}
+inline void servoUnlockDoor() {servo = .8;lockLED = 0;}
+inline void sendID() {pc.printf("1\n\r");}
+inline int checkLock() {return isDoorLocked;}
+inline float checkDist() {return door;}
+int i;
+
+void writePic(int done, int total, uint8_t *buf, size_t siz) {
+ pc.printf("HERE\n\r");
+ pc.printf((char*)buf);
}
-
-inline void sendID() {pc.putc('1');}
-inline int checkLock() {return isDoorLocked;}
-inline float checkDist() {return door;}
-
-void writePic(int done, int total, uint8_t *buf, size_t siz) {
- fwrite(buf, siz, 1, picture);
-}
-
-void capture() {
- cam.takePicture();
- picture = freopen("pic.jpg", "w", picture);
- cam.readJpegFileContent(writePic);
- cam.stopTakingPictures();
- fclose(picture);
+void capture(Camera_LS_Y201 *cam1) {
+ if((i=cam1->takePicture()) != 0) {
+ pc.printf("ERROR TAKEPIC = %d\n\r", i);
+ return;
+ }
+ if(cam1->readJpegFileContent(writePic) != 0) {
+ pc.printf("ERROR FILECONTENT\n\r");
+ return;
+ }
+ cam1->stopTakingPictures();
}
void lockPushed() {
@@ -77,16 +74,12 @@
isDoorLocked = 1;
sprintf(out, "USERLOCK\n\r");
}
+ pc.printf(out);
}
void sendCurrPic() {
- char buff[200];
- capture();
- picture = freopen("pic.jpg", "r", picture);
pc.printf("SENDINGPIC\n\r");
- while(fgets(buff, 200, picture)) {
- pc.printf(buff);
- }
+ capture(&cam);
pc.printf("PICSENT\n\r");
}
@@ -95,6 +88,8 @@
sprintf(out, "BREAKIN\n\r");
pc.printf(out);
sendCurrPic();
+ //ADD ALARM
+ while(1);
}
void lockDoor() {
@@ -147,25 +142,25 @@
//Switch on Buffer
switch(signal) {
- case 'Z':
+ case 'o':
sendID();
break;
- case '~':
+ case 'p':
sendFullStatus();
break;
- case 'a':
+ case 'q':
sendCheckDist();
break;
- case 'b':
+ case 'w':
sendCheckLock();
break;
- case 'c':
+ case 's':
lockDoor();
break;
- case 'd':
+ case 'x':
unlockDoor();
break;
- case 'p':
+ case 't':
sendCurrPic();
break;
default:
@@ -191,25 +186,36 @@
int DOOR_DISTANCE = door + .05;
//Setup
- lockLED = 0;
- cam.reset();
- servo = 0;
+ lockLED = 1;
+ isDoorLocked = 1;
+ servo = .5;
//Setup for freopen
- picture = fopen("pic.jpg", "w");
- fclose(picture);
+ pc.baud(9600);
+ pc.attach(&getMessage);
+ pc.printf("It is connected\n\r");
//Setup Interrupts
- pc.attach(&getMessage);
- lockPB.rise(&lockPushed);
+ lockPB.mode(PullUp);
+ wait(0.1);
+ lockPB.fall(&lockPushed);
- while(1) {
-
+ //Camera
+ wait(1);
+ pc.printf("Reseting Camera...\n\r");
+ if(cam.reset() != 0) {
+ pc.printf("RESET ERROR\n\r");
+ return 1;
+ }
+ wait(1);
+
+ while(1);// {
+ /*
//Check Door Dist and Send if needed
if(isDoorOpen) {
if(door < DOOR_DISTANCE) {
isDoorOpen = 0;
- pc.printf("DOORCLOSE");
+ pc.printf("DOORCLOSE\n\r");
}
}
else {
@@ -219,11 +225,11 @@
breakIn(); //Break In!
}
else {
- pc.printf("DOOROPEN");
+ pc.printf("DOOROPEN\n\r");
}
}
}
wait_ms(50);
-
- } // End While(1)
+ */
+ //} // End While(1)
}
\ No newline at end of file
