Fork with some minor changes

Dependencies:   Motordriver

Fork of Camera_LS_Y201 by Shinichiro Nakamura

Revision:
1:43358d40f879
Parent:
0:f71232252dcf
diff -r f71232252dcf -r 43358d40f879 Camera_LS_Y201.cpp
--- 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;