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: mbed-src FATFileSystem1515 SDFileSystem1515 Camera_LS_Y201_CANSAT
Fork of CANSAT_CAMERA_servo by
Revision 2:248e3594ca61, committed 2015-09-09
- Comitter:
- Hagrass
- Date:
- Wed Sep 09 16:45:37 2015 +0000
- Parent:
- 1:71734a321e31
- Child:
- 3:ff47827160f8
- Commit message:
- cansat3
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Wed Sep 09 16:45:37 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/Hagrass/code/Servo/#0789028dbbc3
--- a/extlib/FATFileSystem.lib Wed Feb 09 23:04:04 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
--- a/extlib/SDFileSystem.lib Wed Feb 09 23:04:04 2011 +0000 +++ b/extlib/SDFileSystem.lib Wed Sep 09 16:45:37 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25 +https://developer.mbed.org/users/Hagrass/code/SDFileSystem1515/#8248299ce3a9
--- a/main.cpp Wed Feb 09 23:04:04 2011 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/**
- * =============================================================================
- * LS-Y201 - Test program. (Version 0.0.2)
- * =============================================================================
- * Copyright (c) 2010-2011 Shinichiro Nakamura (CuBeatSystems)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- * =============================================================================
- */
-#include "mbed.h"
-#include "Camera_LS_Y201.h"
-#include "SDFileSystem.h"
-
-#define DEBMSG printf
-#define NEWLINE() printf("\r\n")
-
-#define USE_SDCARD 0
-
-#if USE_SDCARD
-#define FILENAME "/sd/IMG_%04d.jpg"
-SDFileSystem fs(p5, p6, p7, p8, "sd");
-#else
-#define FILENAME "/local/IMG_%04d.jpg"
-LocalFileSystem fs("local");
-#endif
-Camera_LS_Y201 cam1(p13, p14);
-
-typedef struct work {
- FILE *fp;
-} work_t;
-
-work_t work;
-
-/**
- * Callback function for readJpegFileContent.
- *
- * @param buf A pointer to a buffer.
- * @param siz A size of the buffer.
- */
-void callback_func(int done, int total, uint8_t *buf, size_t siz) {
- fwrite(buf, siz, 1, work.fp);
-
- static int n = 0;
- int tmp = done * 100 / total;
- if (n != tmp) {
- n = tmp;
- DEBMSG("Writing...: %3d%%", n);
- NEWLINE();
- }
-}
-
-/**
- * Capture.
- *
- * @param cam A pointer to a camera object.
- * @param filename The file name.
- *
- * @return Return 0 if it succeed.
- */
-int capture(Camera_LS_Y201 *cam, char *filename) {
- /*
- * Take a picture.
- */
- if (cam->takePicture() != 0) {
- return -1;
- }
- DEBMSG("Captured.");
- NEWLINE();
-
- /*
- * Open file.
- */
- work.fp = fopen(filename, "wb");
- if (work.fp == NULL) {
- return -2;
- }
-
- /*
- * Read the content.
- */
- DEBMSG("%s", filename);
- NEWLINE();
- if (cam->readJpegFileContent(callback_func) != 0) {
- fclose(work.fp);
- return -3;
- }
- fclose(work.fp);
-
- /*
- * Stop taking pictures.
- */
- cam->stopTakingPictures();
-
- return 0;
-}
-
-/**
- * Entry point.
- */
-int main(void) {
- DEBMSG("Camera module");
- NEWLINE();
- DEBMSG("Resetting...");
- NEWLINE();
- wait(1);
-
- if (cam1.reset() == 0) {
- DEBMSG("Reset OK.");
- NEWLINE();
- } else {
- DEBMSG("Reset fail.");
- NEWLINE();
- error("Reset fail.");
- }
- wait(1);
-
- int cnt = 0;
- while (1) {
- char fname[64];
- snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
- int r = capture(&cam1, fname);
- if (r == 0) {
- DEBMSG("[%04d]:OK.", cnt);
- NEWLINE();
- } else {
- DEBMSG("[%04d]:NG. (code=%d)", cnt, r);
- NEWLINE();
- error("Failure.");
- }
- cnt++;
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main2.cpp Wed Sep 09 16:45:37 2015 +0000
@@ -0,0 +1,321 @@
+ #include "mbed.h"
+#include "Camera_LS_Y201.h"
+#include "SDFileSystem.h"
+#include "Servo.h"
+
+Servo myservo(p23);
+//#include "FATFileSystem.h"
+Serial xbee(p28,p27);
+Serial pc(USBTX,USBRX);
+//FILE *p1;
+
+ #define DEBMSG pc.printf
+#define NEWLINE() pc.printf("\r\n")
+
+#define USE_SDCARD 0
+
+#if USE_SDCARD
+#define FILENAME "/sd/IMG_%04d.jpg"
+SDFileSystem fs(p5, p6, p7, p8, "sd");
+#else
+#define FILENAME "/local/IMG_%04d.jpg"
+LocalFileSystem fs("local");
+#endif
+Camera_LS_Y201 cam1(p17, p18);
+
+typedef struct work {
+ FILE *fp;
+} work_t;
+
+work_t work;
+
+
+
+ uint8_t send[16] = {
+ 0x56,
+ 0x00,
+ 0x32,
+ 0x0C,
+ 0x00,
+ 0x0A,
+ 0x00,
+ 0x00,
+ 0x00, // MH
+ 0x00, // ML
+ 0x00,
+ 0x00,
+ 0x00, // KH
+ 0x00, // KL
+ 0x00, // XX
+ 0x00 // XX
+ };
+
+ uint16_t x = 10; // Interval time. XX XX * 0.01m[sec]
+ bool end = true;
+ uint16_t m = 0; // Staring address.
+ /*
+ * Get the data size.
+ */
+uint8_t body[16000];
+uint16_t k = sizeof(body);
+ int siz_done = 0;
+ int siz_total = 0;
+ int cnt = 0;
+ int z;
+//////////////////////////////////////////
+void callback_func(int done, int total, uint8_t *buf, size_t siz) {
+
+ // fwrite(buf, siz, 1, work.fp);
+
+for(int i=0;i<siz;i++)
+{
+//xbee.printf("%x",buf[i]);
+fprintf(work.fp,"%c",buf[i]);
+ }
+
+ static int n = 0;
+ int tmp = done * 100 / total;
+ if (n != tmp) {
+ n = tmp;
+ DEBMSG("Writ%3d%%", n);
+ NEWLINE();
+ }
+}
+
+
+
+////////////////////////////////////////////
+
+
+
+
+ void readdJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz)) {
+
+
+
+if(m==0)
+{
+z=sizeof(body);
+ }
+
+ //if (r != NoError) {
+ // return r;
+ //}
+
+
+ send[8] = (m >> 8) & 0xff;
+ send[9] = (m >> 0) & 0xff;
+ send[12] = (k >> 8) & 0xff;
+ send[13] = (k >> 0) & 0xff;
+ send[14] = (x >> 8) & 0xff;
+ send[15] = (x >> 0) & 0xff;
+ /*
+ * Send a command.
+ */
+ cam1.sendBytes(send, sizeof(send), 200 * 1000) ;
+ // printf("sended header");
+ // return SendError;
+
+ /*
+ * Read the header of the response.
+ */
+ uint8_t header[5];
+ cam1.recvBytes(header, sizeof(header), 2 * 1000 * 1000);
+ // return RecvError;
+ //printf("recved header");
+ /*
+ * Check the response and fetch an image data.
+ */
+
+ if ((header[0] == 0x76)
+ && (header[1] == 0x00)
+ && (header[2] == 0x32)
+ && (header[3] == 0x00)
+ && (header[4] == 0x00)) {
+
+ cam1.recvBytes(body, z, 2 * 1000 * 1000); //{
+ //return RecvError;
+ // }
+ // printf("saved");
+
+ siz_done += z;
+
+ if (func != NULL) {
+ if (siz_done > siz_total) {
+ z=sizeof(body)-siz_done+siz_total+3;
+ siz_done = siz_total;
+
+
+ }
+ func(siz_done, siz_total, body, z);
+ }
+ for (int i = 1; i < z; i++) {
+ if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9)) {
+ end = true;
+ //printf("saved%d",i);
+ }
+ }
+ } //else {
+ // return UnexpectedReply;
+ //}
+ /*
+ * Read the footer of the response.
+ */
+ uint8_t footer[5];
+ cam1.recvBytes(footer, sizeof(footer), 2 * 1000 * 1000);// {
+ // return RecvError;
+ //}
+
+ m += z;
+
+ // return NoError;
+}
+
+//////////////////
+/**
+ * Capture.
+ *
+ * @param cam A pointer to a camera object.
+ * @param filename The file name.
+ *
+ * @return Return 0 if it succeed.
+ */
+ float p=0.1;//////////////servo
+ int flag=1;///////////////servo
+int capture(Camera_LS_Y201 *cam, char *filename) {
+ /*
+ * Take a picture.
+ */
+if(end==true)
+{
+ ///////////////////////////////////////////servo
+ myservo = p;
+ //pc.printf("hhhhhhh%fhhhh",p);
+ if (flag==1)
+ {
+ p+=0.1;
+ }
+ else
+ {
+ p-=0.1;
+ }
+ if(p>0.9)
+
+ {
+ flag=0;
+ }
+
+ if(p<0.1)
+ {
+ flag=1;
+ }
+
+ //////////////////////////////////////////servo
+ if (cam->takePicture() != 0) {
+ return -1;
+ }
+ cam1.readJpegFileSize(&siz_total);
+// printf("%d",siz_total);
+ siz_done = 0;
+
+
+ DEBMSG("Captured.");
+ NEWLINE();
+ work.fp = fopen(filename, "wb");
+ //p1= fopen("/sd/IMG_11111.txt", "wb");
+ if (work.fp == NULL) {
+ return -2;
+ }
+
+ /*
+ * Read the content.
+ */
+ DEBMSG("%s", filename);
+ NEWLINE();
+end=false;
+}
+ /*
+ * Open file.
+ */
+
+ readdJpegFileContent(callback_func);
+ // fclose(work.fp);
+ //return -3;
+
+
+
+ /*
+ * Stop taking pictures.
+ */
+ if(end== true)
+ {
+ fclose(work.fp);
+ cam->stopTakingPictures();
+
+DEBMSG("[%04d]:OK.", cnt);
+ NEWLINE();
+m=0;
+cnt++;
+//wait(1);
+//xbee.printf("saved");
+}
+ return 0;
+}
+////////////////////////////
+/////////////////////////
+
+/////////////////////////////////////////////////////
+int main(void) {
+
+ xbee.baud(115200);
+ pc.baud(115200);
+
+DEBMSG("Camera module");
+ NEWLINE();
+ DEBMSG("Resetting...");
+ NEWLINE();
+ wait(1);
+
+ if (cam1.reset() == 0) {
+ DEBMSG("Reset OK.");
+ NEWLINE();
+ } else {
+ DEBMSG("Reset fail.");
+ NEWLINE();
+ error("Reset fail.");
+ }
+
+
+ wait(1);
+ cam1.baud();
+ int j=1;
+ int g=1;
+ while (1) {
+
+ char fname[64];
+ // xbee.printf("hello%d\n\r",g);
+
+ if((end==true)||(j==1))
+ {
+
+ snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
+ j=0;
+ }
+ capture(&cam1, fname);
+ //if (r == 0) {
+
+
+ // }
+ //} else {
+ //DEBMSG("[%04d]:NG. (code=%d)", cnt, r);
+ // NEWLINE();
+ // error("Failure.");
+ //}
+ g++;
+ }
+}
+
+
+
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Wed Sep 09 16:45:37 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#ec1b66a3d094
--- a/mbed.bld Wed Feb 09 23:04:04 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1
--- a/mylib/Camera_LS_Y201.lib Wed Feb 09 23:04:04 2011 +0000 +++ b/mylib/Camera_LS_Y201.lib Wed Sep 09 16:45:37 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879 +https://developer.mbed.org/users/Hagrass/code/Camera_LS_Y201_CANSAT/#2e14476d7164
