Malexis 90640 sensor

Dependencies:   mbed

Revision:
2:44869d695501
Parent:
1:3f763d28c1be
Child:
3:d2e64ef64905
--- a/main.cpp	Thu Apr 19 18:23:43 2018 +0000
+++ b/main.cpp	Thu Apr 19 19:16:44 2018 +0000
@@ -5,7 +5,8 @@
 #define FRAMES_NUM 15
 #define TA_SHIFT 8
 
-Timer timer;
+#define FIRMWARE "eye_r_eye-mlx90640_32x24-v_1_0"
+
 Serial pc(USBTX, USBRX);                                                        // tx, rx, Virtual serial port over USB
 void PrintEEPROM(uint16_t *p);
 void PrintRawData(uint16_t *p);
@@ -14,8 +15,11 @@
 
 DigitalOut led_green(LED2);
 
+char buffer[3076]={'S'};
+
 int main()
 {
+    uint8_t printme=0;
     MLX90640_I2CFreqSet(1000);
     pc.baud(230400);
     paramsMLX90640 mlx90640;
@@ -23,51 +27,99 @@
     uint16_t *pEE;
     uint16_t *pFrame;
     static uint16_t eeMLX90640[832];
-    float mlx90640Vdd;
-    float mlx90640Ta;
     static uint16_t mlx90640Frame[834];
     static float mlx90640To[768];
     float emissivity = 1;
-    int status = 0;
-    int frameCnt = 0;
     float eTa;                      //Ta for emissivity compensation
 
     pEE = eeMLX90640;
     pFrame = mlx90640Frame;
-    status = MLX90640_SetRefreshRate(slaveAddress,1);
+    MLX90640_SetRefreshRate(slaveAddress,2);
     //status = MLX90640_SetResolution(slaveAddress[i],0x03);
     //status = MLX90640_SetInterleavedMode(slaveAddress[i]);
-    status = MLX90640_SetChessMode(slaveAddress);
+    MLX90640_SetChessMode(slaveAddress);
     //printf("Reading EEPROM for MLX90640 device %d...\r\n",i+1);
     MLX90640_I2CFreqSet(400);
-    status = MLX90640_DumpEE(slaveAddress, pEE);
+    MLX90640_DumpEE(slaveAddress, pEE);
     MLX90640_I2CFreqSet(1000);
     //printf("Extracting parameters for MLX90640 device %d...\r\n",i+1);
-    status = MLX90640_ExtractParameters(pEE, &mlx90640 );
+    MLX90640_ExtractParameters(pEE, &mlx90640 );
 
     while (1) 
     {
+        if (pc.readable())
+        {
+            char c = pc.getc();
+            if (printme)
+            {
+                switch (c)
+                {
+                    case 'p':
+                        printme=1;
+                        break;
+                    
+                    case 'q':
+                        printme=0;
+                        break;
+                }
+                continue;
+            }
+            
+            switch (c)
+            {
+                case '1':
+                    MLX90640_SetRefreshRate(slaveAddress,1);
+                    break;
+                    
+                case '2':
+                    MLX90640_SetRefreshRate(slaveAddress,2);
+                    break;
+                    
+                case '4':
+                    MLX90640_SetRefreshRate(slaveAddress,4);
+                    break;
+                   
+                case '?':
+                    pc.printf(FIRMWARE "\n");
+                    break;                    
+                    
+                case 'p':
+                    printme=1;
+                    break;
+                    
+                case 'q':
+                    printme=0;
+                    break;
+            } // switch
+        }
+
         led_green = 1;    // turn on LED until initialization is complete
-        status = MLX90640_GetFrameData(slaveAddress, pFrame);
+        MLX90640_GetFrameData(slaveAddress, pFrame);
         led_green = 0;    // turn on LED until initialization is complete
         eTa = MLX90640_GetTa(pFrame, &mlx90640) - TA_SHIFT;
         MLX90640_CalculateTo(pFrame, &mlx90640, emissivity, eTa, mlx90640To);
-        PrintToU(mlx90640To);
+        if (printme)
+        {            
+            PrintToU(mlx90640To);
+        }
     }
 
 }
 
 void PrintToU(float *p)
 {
-    uint16_t d;
-    pc.printf("S",d);
-    for(int i=0; i<768; i++) 
+    uint16_t idx=1,i;
+    uint16_t d;    
+    for(i=0; i<768; i++) 
     {
         d = 10 * *p++;
-        pc.printf("%04x",d);
+        sprintf(buffer+idx,"%04x",d);
+        idx+=4;
     }
-    pc.printf("E\n");
-
+    buffer[idx++] = 'E';
+    buffer[idx++] = '\n';
+    buffer[idx++] = 0;
+    pc.printf(buffer);
 }
 
 void PrintToF(float *p)