GDP 4 / Mbed 2 deprecated KL25Z_Camera_Test

Dependencies:   FRDM-TFC mbed

Files at this revision

API Documentation at this revision

Comitter:
FatCookies
Date:
Wed Nov 02 13:20:08 2016 +0000
Parent:
1:a4883d9c75ec
Child:
4:968036e0940b
Commit message:
updated to work, send image and centre point

Changed in this revision

FRDM-TFC.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FRDM-TFC.lib	Fri Oct 14 15:55:16 2016 +0000
+++ b/FRDM-TFC.lib	Wed Nov 02 13:20:08 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/emh203/code/FRDM-TFC/#24430a0d7fd8
+http://developer.mbed.org/users/emh203/code/FRDM-TFC/#ac22426772bc
--- a/main.cpp	Fri Oct 14 15:55:16 2016 +0000
+++ b/main.cpp	Wed Nov 02 13:20:08 2016 +0000
@@ -1,70 +1,58 @@
 #include "mbed.h"
 #include "TFC.h"
-//#define CAM_THRESHOLD 3000
+#define CAM_THRESHOLD 128
  
  
 DigitalOut myled(LED1);
+Serial pc(USBTX,USBRX);
+char curr_line[128];
+
+uint8_t curr_left;
+uint8_t curr_right;
+
+uint8_t right;
+uint8_t left;
+uint8_t measured_value;
  
 int main() {
     TFC_Init();
-    
-    uint32_t i,t = 0;
-    //uint32_t width = 0;
-    char curr_line[129];
+    pc.baud(57600);
     
-    /* Ensure string is null terminated */
-    curr_line[128] = 0; 
- 
-    
-    printf("Starting camera test program\n");
-    
+    uint32_t i = 0;
     while(1) {
+        
         //If we have an image ready
-        if(TFC_LineScanImageReady>0)
-            {
-                //Reset image ready flag
-                TFC_LineScanImageReady=0;
-                printf("\r\n");
-                //printf("L:");
-                
-                //Strange thing that cycles the battery indicator
-                //Leaving in as this is a good indicator that the camera test program is running
-                if(t==4)
-                    t=0;
-                else
-                    t++;
-                TFC_SetBatteryLED_Level(t);
-                   
-                for(i = 0; i < 128; i++) {
-                    curr_line[i] = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF;
-                    printf("%02x", curr_line[i]);
+        if(TFC_LineScanImageReady>0) {                   
+           
+           left = 0;
+            right = 0;
+            for(i = 63; i > 0; i--) {
+                curr_left = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF;
+                if(curr_left < CAM_THRESHOLD) {
+                    left = i;
+                    break;
                 }
-                printf("\n");
-                
-                //Old version below, we don't threshold on the FRDM board anymore
-                //printf("0x%x\n", curr_line);
-               /*
-               //Loop through camera pixels
-               for(i=0;i<128;i++)
-               {
-                   //If the pixel value exceeds our threshold, print a 1
-                   if (TFC_LineScanImage0[i] > CAM_THRESHOLD) 
-                   {
-                       curr_line[i] = '1';
-                       width++; //Increment the width value
-                   }
-                   //Else, print a 0
-                   else
-                   {
-                      curr_line[i] = '0';  
-                   }
-               }
-               printf("%s\n",curr_line);
-                
-                printf("Width: %d\n", width);
-                width = 0;
-                */
-                   
-               }
+            }
+            
+            for(i = 64; i < 128; i++) {
+                curr_right = (int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF;
+                if(curr_right < CAM_THRESHOLD) {
+                    right = i;
+                    break;
+                }
+            }
+
+            pc.putc('H');
+            for(i = 0; i < 128; i++) {
+                pc.putc((int8_t)(TFC_LineScanImage0[i] >> 4) & 0xFF);    
+            }
+            
+            measured_value = (64 - ((left+right)/2))/64.f;
+        
+
+            //Reset image ready flag
+            TFC_LineScanImageReady=0;
+            wait(0.05);
+        }
     }
 }
\ No newline at end of file