LinkSprite LS-Y201 JPEG Color Camera.

Dependents:   Camera_LS_Y201_TestProgram Camera_LS_Y201_TestProgram ServoCamV1 RFIDdoor ... more

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Wed Dec 01 23:10:56 2010 +0000
Parent:
0:f71232252dcf
Commit message:
Added progress listener function.

Changed in this revision

Camera_LS_Y201.cpp Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201.h Show annotated file Show diff for this revision Revisions of this file
--- a/Camera_LS_Y201.cpp	Thu Nov 25 15:43:42 2010 +0000
+++ b/Camera_LS_Y201.cpp	Wed Dec 01 23:10:56 2010 +0000
@@ -157,6 +157,11 @@
             && (recv[2] == 0x36)
             && (recv[3] == 0x00)
             && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
         return NoError;
     } else {
         return UnexpectedReply;
@@ -207,7 +212,7 @@
  * @param func A pointer to a call back function.
  * @return Error code.
  */
-Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileContent(void (*func)(uint8_t *buf, size_t siz)) {
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz)) {
     uint8_t send[16] = {
         0x56,
         0x00,
@@ -231,6 +236,17 @@
     uint16_t k = sizeof(body); // Packet size.
     uint16_t x = 10;    // Interval time. XX XX * 0.01m[sec]
     bool end = false;
+
+    /*
+     * Get the data size.
+     */
+    int siz_done = 0;
+    int siz_total = 0;
+    ErrorCode r = readJpegFileSize(&siz_total);
+    if (r != NoError) {
+        return r;
+    }
+
     do {
         send[8] = (m >> 8) & 0xff;
         send[9] = (m >> 0) & 0xff;
@@ -262,8 +278,12 @@
             if (!recvBytes(body, sizeof(body), 2 * 1000 * 1000)) {
                 return RecvError;
             }
+            siz_done += sizeof(body);
             if (func != NULL) {
-                func(body, sizeof(body));
+                if (siz_done > siz_total) {
+                    siz_done = siz_total;
+                }
+                func(siz_done, siz_total, body, sizeof(body));
             }
             for (int i = 1; i < sizeof(body); i++) {
                 if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9)) {
@@ -313,6 +333,11 @@
             && (recv[2] == 0x36)
             && (recv[3] == 0x00)
             && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
         return NoError;
     } else {
         return UnexpectedReply;
--- a/Camera_LS_Y201.h	Thu Nov 25 15:43:42 2010 +0000
+++ b/Camera_LS_Y201.h	Wed Dec 01 23:10:56 2010 +0000
@@ -108,7 +108,7 @@
      * @param func A pointer to a call back function.
      * @return Error code.
      */
-    ErrorCode readJpegFileContent(void (*func)(uint8_t *buf, size_t siz));
+    ErrorCode readJpegFileContent(void (*func)(int done, int total, uint8_t *buf, size_t siz));
 
     /**
      * Stop taking pictures.