Theo Le Paih / Mbed 2 deprecated Lib_Pixy2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
theolp
Date:
Tue Jan 21 12:59:37 2020 +0000
Parent:
26:a56cc5d715e9
Commit message:
Last

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
pixy2.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Nov 28 07:39:32 2019 +0000
+++ b/main.cpp	Tue Jan 21 12:59:37 2020 +0000
@@ -2,14 +2,18 @@
 
 /*      _DEBUG_     */
 int sommeDeControle,sommeRecue;
+char *ptr;
+
+void automate_debug(T_Pixy2State &etat);
 
 Serial pc(USBTX, USBRX, 9600);
 /*                  */
 
-typedef enum {IDLE, SND, CHECKSUM_ERROR, TIMEOUT, OK} T_state;
+typedef enum {IDLE, SND, SND_2, CHECKSUM_ERROR, TIMEOUT, OK, OK_2} T_state;
 
 // FLAGS
-char FLAG_BP = 0;
+bool FLAG_BP = false;
+int nb_appui = 0;
 
 // Prototypes
 void appui_BP(void);
@@ -19,6 +23,8 @@
 {
     PIXY2               maPixy(PC_12, PD_2);     // PC_12 : UART5_TX --- PD_2 : UART5_RX
     
+    T_pixy2Version* version;
+    T_pixy2Resolution* resolution;
     T_pixy2ErrorCode    rep;
     
     // Initialisations
@@ -34,16 +40,24 @@
 
         switch (etat) {
             case IDLE :
-                if (FLAG_BP) {
+                if (FLAG_BP && nb_appui == 0) {
                     pc.printf("Envoi...\n\r");
                     etat = SND;
-                    FLAG_BP = 0;
+                    FLAG_BP = false;
                     temps.reset();
+                    nb_appui += 1;
+                }
+                if (FLAG_BP && nb_appui == 1) {
+                    pc.printf("Envoi...\n\r");
+                    etat = SND_2;
+                    FLAG_BP = false;
+                    temps.reset();
+                    nb_appui = 0;
                 }
                 break;
 
             case SND :
-                rep = maPixy.pixy2_getMainFeature(1);
+                rep = maPixy.pixy2_getVersion(&version);
                 
                 if (rep == PIXY2_BAD_CHECKSUM) {
                     etat = CHECKSUM_ERROR;   
@@ -51,10 +65,24 @@
                 if (temps.read()>0.5f) {
                     etat = TIMEOUT;
                 }
-                if (rep >= PIXY2_VECTOR) {
+                if (rep == PIXY2_OK) {
                     etat = OK;
                 }
                 break;
+                
+            case SND_2 :
+                rep = maPixy.pixy2_getResolution(&resolution);
+                
+                if (rep == PIXY2_BAD_CHECKSUM) {
+                    etat = CHECKSUM_ERROR;   
+                }
+                if (temps.read()>0.5f) {
+                    etat = TIMEOUT;
+                }
+                if (rep == PIXY2_OK) {
+                    etat = OK_2;
+                }
+                break;
             
             case CHECKSUM_ERROR :
                 pc.printf("Erreur de CheckSum...\n\r");
@@ -64,26 +92,57 @@
                 break;
             
             case TIMEOUT :
-                pc.printf("Erreur Timeout\n\r");
+                pc.printf("Erreur Timeout...\n\rRep : %d\n\r", rep);
+                for(int i=0; i<2; ++i)
+                    pc.printf("%d\n\r", *(ptr + i));
                 etat = IDLE;
                 break;
 
             case OK :
-                pc.printf("Number of vectors  : %d\n\r", maPixy.Pixy2_numVectors);
-                for(int i=0; i<maPixy.Pixy2_numVectors; ++i) {
-                    pc.printf("Vector number : %d\n\r", maPixy.Pixy2_vectors[i].pixIndex);
-                    pc.printf("x0 : %d - y0 : %d\n\r", maPixy.Pixy2_vectors[i].pixX0, maPixy.Pixy2_vectors[i].pixY0);
-                    pc.printf("x1 : %d - y1 : %d\n\r", maPixy.Pixy2_vectors[i].pixX1, maPixy.Pixy2_vectors[i].pixY1);
-                }
+                pc.printf("Version de la camera : %s\n\r", version->pixHFString);
+                etat = IDLE;
+                break;
+                
+            case OK_2 :
+                pc.printf("Resolution de la camera : %d - %d\n\r", resolution->pixFrameWidth, resolution->pixFrameHeight);
                 etat = IDLE;
                 break;
 
         }
+        
+        //automate_debug(maPixy.etat);
     }
 }
 
 // FONCTIONS
 void appui_BP(void)
 {
-    FLAG_BP = 1;
+    FLAG_BP = true;
+}
+
+void automate_debug(T_Pixy2State &etat) {
+    
+    static int etat_debug_passe = -1;
+    
+    if(etat != etat_debug_passe) {
+        switch(etat) {
+            case idle :
+                pc.printf("IDLE\n\r");
+                break;
+            case messageSent :
+                pc.printf("DATA_SENT\n\r");
+                break;
+            case receivingHeader :
+                pc.printf("RECEIVING_HEADER\n\r");
+                break;
+            case receivingData :
+                pc.printf("RECEIVING_DATA\n\r");
+                break;
+            case dataReceived :
+                pc.printf("DATA_RECEIVED\n\r");
+                break;    
+        }
+    }
+    
+    etat_debug_passe = etat;   
 }
\ No newline at end of file
--- a/pixy2.cpp	Thu Nov 28 07:39:32 2019 +0000
+++ b/pixy2.cpp	Tue Jan 21 12:59:37 2020 +0000
@@ -1,6 +1,7 @@
 #include "pixy2.h"
 
 extern  int sommeDeControle,sommeRecue;
+extern char *ptr;
 
 PIXY2::PIXY2(PinName tx, PinName rx, int debit)
 {   
@@ -634,7 +635,8 @@
     T_pixy2RcvHeader    *msg = (T_pixy2RcvHeader*) &Pixy2_buffer[hPointer];
     T_pixy2ErrorCode    cr = PIXY2_OK;
     T_pixy2LineFeature* lineFeature;
-    int                 fPointer;
+    int                 fPointer;                                                   // Pointeur sur une feature entière
+    int                 fdPointer;                                                  // Pointeur sur un élément à l'intérieur d'une feature
 
     if (frameContainChecksum) {                                                     // Si la trame contient un checksum
         if (pixy2_validateChecksum (&Pixy2_buffer[hPointer]) != 0) {                // On lance la validation du checksum
@@ -645,25 +647,29 @@
         fPointer = dPointer;                                                        // On pointe sur la premiere feature
         do {
             lineFeature = (T_pixy2LineFeature*) &Pixy2_buffer[fPointer];            // On mappe le pointeur de structure sur le buffer de réception des features.
+            ptr = (char*) &Pixy2_buffer[fPointer];
             if (lineFeature->fType == PIXY2_VECTOR) {                               // On regarde si le type est vecteur
                 Pixy2_numVectors = lineFeature->fLength / sizeof(T_pixy2Vector);    // Si oui, on compte combien il y a de vecteurs
-                Pixy2_vectors = (T_pixy2Vector*) &Pixy2_buffer[fPointer + 2];       // On mappe le résultat
-                fPointer += lineFeature->fLength;                                   // On déplace le pointeur de données et on recommence
+                fdPointer = fPointer + 2;                                           // On pointe sur le premier élément de la feature
+                Pixy2_vectors = (T_pixy2Vector*) &Pixy2_buffer[fdPointer];          // On mappe le résultat
+                fPointer += lineFeature->fLength + 2;                               // On déplace le pointeur de données et on recommence
                 cr |= PIXY2_VECTOR;
             }
             if (lineFeature->fType == PIXY2_INTERSECTION) {                         // On regarde si le type est intersection
                 Pixy2_numIntersections = lineFeature->fLength / sizeof(T_pixy2Intersection);
                                                                                     // Si oui, on compte combien il y a d'intersections
-                Pixy2_intersections = (T_pixy2Intersection*) &Pixy2_buffer[fPointer];
+                fdPointer = fPointer + 2;                                           // On pointe sur le premier élément de la feature                                                                    
+                Pixy2_intersections = (T_pixy2Intersection*) &Pixy2_buffer[fdPointer];
                                                                                     // On mappe le résultat sur l'entête de l'intersection
-                fPointer += lineFeature->fLength;                                   // On déplace le pointeur de données et on recommence
+                fPointer += lineFeature->fLength + 2;                               // On déplace le pointeur de données et on recommence
                 cr |= PIXY2_INTERSECTION;
             }
             if (lineFeature->fType == PIXY2_BARCODE) {                              // On regarde si le type est codebarre
                 Pixy2_numBarcodes = lineFeature->fLength / sizeof(T_pixy2BarCode);
                                                                                     // Si oui, on compte combien il y a de codebarre
-                Pixy2_barcodes = (T_pixy2BarCode*) &Pixy2_buffer[fPointer];         // On mappe le résultat
-                fPointer += lineFeature->fLength;                                   // On déplace le pointeur de données et on recommence
+                fdPointer = fPointer + 2;                                           // On pointe sur le premier élément de la feature
+                Pixy2_barcodes = (T_pixy2BarCode*) &Pixy2_buffer[fdPointer];        // On mappe le résultat
+                fPointer += lineFeature->fLength + 2;                               // On déplace le pointeur de données et on recommence
                 cr |= PIXY2_BARCODE;
             }
         } while(fPointer < ((dataSize - 1) + dPointer));                            // Tant qu'il y a des données à traiter