array size

Fork of JPEGCamera by Hiroshi Yamaguchi

Files at this revision

API Documentation at this revision

Comitter:
rockstar
Date:
Sat Aug 22 10:12:47 2015 +0000
Parent:
1:27417b6a951d
Commit message:
Done some changes in array size

Changed in this revision

JPEGCamera.cpp Show annotated file Show diff for this revision Revisions of this file
JPEGCamera.h Show annotated file Show diff for this revision Revisions of this file
diff -r 27417b6a951d -r 609037d25e10 JPEGCamera.cpp
--- a/JPEGCamera.cpp	Thu Nov 17 13:59:40 2011 +0000
+++ b/JPEGCamera.cpp	Sat Aug 22 10:12:47 2015 +0000
@@ -34,12 +34,34 @@
 }
 
 bool JPEGCamera::isProcessing() {
+   // printf("Im here/n2");
     return state == PROCESSING;
 }
 
+bool JPEGCamera::processPicture_ref() {
+    if (state == PROCESSING) {
+        if (address < imageSize) {
+            char data[1024];
+            int size = readData(data, min(sizeof(data), imageSize - address), address);
+            int ret = fwrite(data, size, 1, fp);
+            if (ret > 0)
+                address += size;
+            if (ret == 0 || address >= imageSize) {
+                stopPictures();
+                fclose(fp);
+                wait(0.1); // ????
+                state = ret > 0 ? READY : ERROR;
+            }
+        }
+    }
+    return state == PROCESSING || state == READY;
+}
+
+
 bool JPEGCamera::takePicture(char *filename) {
+    //printf("Im here1O/n");
     if (state == READY) {
-        fp = fopen(filename, "wb");
+        fp = fopen(filename, "wb");      
         if (fp != 0) {
             if (takePicture()) {
                 imageSize = getImageSize();
@@ -55,6 +77,7 @@
             state = ERROR;
         }
     }
+   // printf("Im here1C/n");
     return state != ERROR;
 }
 
@@ -104,6 +127,10 @@
     return ret == 4 && buf[0] == 0x76;
 }
 
+int JPEGCamera::getSizeOfimage(void){
+    return imageSize;
+}
+
 int JPEGCamera::getImageSize() {
     char buf[9] = {0x56, 0x00, 0x34, 0x01, 0x00};
     int ret = sendReceive(buf, sizeof buf, 9);
@@ -135,7 +162,7 @@
 
     int i = 0;
     while (i < size && timer.read_ms() < timeout) {
-        if (readable())
+            if (readable())
             buf[i++] = getc();
     }
 
diff -r 27417b6a951d -r 609037d25e10 JPEGCamera.h
--- a/JPEGCamera.h	Thu Nov 17 13:59:40 2011 +0000
+++ b/JPEGCamera.h	Sat Aug 22 10:12:47 2015 +0000
@@ -67,7 +67,7 @@
      * @returns true if no error in processing, false otherwise
      */
     bool processPicture();
-
+    bool processPicture_ref();
     /**
      * Perform reset oepration (it takes 4 seconds)
      *
@@ -106,10 +106,13 @@
      * @returns the size of the data read
      */
     int readData(char *dataBuf, int size, int address);
-
+    
+    //return the current value of imageSize
+    int getSizeOfimage(void);
 //private:
     Timer timer;
-    FILE *fp;
+    FILE *fp, *ir;
+    int def;
     int imageSize;
     int address;
     enum State {UNKNOWN, READY, PROCESSING, ERROR = -1} state;