Theo Le Paih / Mbed 2 deprecated Lib_Pixy2

Dependencies:   mbed

Revision:
5:28e47187bb5c
Parent:
3:6ba43af28440
Child:
6:e9e3aa6f1a55
--- a/pixy2.cpp	Mon Mar 11 15:21:33 2019 +0000
+++ b/pixy2.cpp	Mon Mar 11 17:18:25 2019 +0000
@@ -76,7 +76,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndGetResolution (void){
@@ -91,7 +91,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetCameraBrightness (Byte brightness){
@@ -106,7 +106,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetServo (Word s0, Word s1){
@@ -127,7 +127,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetLED (Byte red, Byte green, Byte blue){
@@ -144,7 +144,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetLamp (Byte upper, Byte lower){
@@ -160,7 +160,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndGetFPS (void){
@@ -174,7 +174,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc){
@@ -190,7 +190,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndGetMainFeature (Byte type, Byte feature){
@@ -206,7 +206,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetMode (Byte mode){
@@ -221,7 +221,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetNexTurn (Word angle){
@@ -240,7 +240,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetDefaultTurn (Word angle){
@@ -259,7 +259,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndSetVector (Byte vectorIndex){
@@ -274,7 +274,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndReverseVector (void){
@@ -288,7 +288,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 int PIXY2::pixy2_sndGetRGB (Word x, Word y, Byte saturate){
@@ -305,7 +305,7 @@
         _Pixy2->putc(msg.data[i]);
         i++;
     } while (i<(PIXY2_NCSHEADERSIZE+dataSize));
-    return 0;
+    return PIXY2_OK;
 }
 
 /*  La fonction est bloquante à l'envoi (pas vraiment le choix), mais elle est non bloquante en réception. On essayera de faire une fonction non bloquante en envoi avec write, mais c'est pas la priorité.
@@ -314,14 +314,14 @@
 int PIXY2::pixy2_getVersion (T_Pixy2Version *version){
 
     T_pixy2RcvHeader    *msg = (T_pixy2RcvHeader*) &Pixy2_buffer[rPointer];
-    int                 cr = 0;
+    int                 cr = PIXY2_OK;
     
     switch (etat) {
         case idle :                                                                 // Si la caméra est inactive
             PIXY2::pixy2_sndGetVersion();                                           // On envoie la trame de demande de la version
             etat = messageSent;                                                     // On passe à l'attente du message de réponse
             rPointer = wPointer;                                                    // On enregistre la position du pointeur de FIFO
-            cr = -2;                    //Busy                                      // On signale à l'utilisateur que la caméra est maintenant occupée
+            cr = PIXY2_BUSY;                                                        // On signale à l'utilisateur que la caméra est maintenant occupée
             break;
             
         case dataReceived :                                                         // Quand on a reçu l'intégralité du message
@@ -331,19 +331,19 @@
                         version = (T_Pixy2Version*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
                                                                                     // Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)                        
                         etat = idle;                                                // Et on annoce que la pixy est libre
-                    } else cr = -7;     // Type Error                               // Si le type ne correspond pas on signale une erreur
-                } else cr = -3;         // Checksum Error                           // Si le checksum est faux on retourne une erreur aussi !
+                    } else cr = PIXY2_TYPE_ERROR;                                   // Si le type ne correspond pas on signale une erreur
+                } else cr = PIXY2_BAD_CHECKSUM;                                     // Si le checksum est faux on retourne une erreur aussi !
             } else {                                                                // S'il n'y a pas de checksum (pas normal mais on ne sait jamais)
                 if (msg->pixType == PIXY2_REP_VERS) {                               // On vérifie que la trame est du type convenable                               
                     version = (T_Pixy2Version*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
                                                                                     // Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)                        
                     etat = idle;                                                    // Et on annoce que la pixy est libre
-                } else cr = -7;         // Type Error                               // Si le type ne correspond pas on signale une erreur
+                } else cr = PIXY2_TYPE_ERROR;                                       // Si le type ne correspond pas on signale une erreur
             }
             break;
 
         default :                                                                   // Dans tous les autres cas
-            cr = -2;                    // Busy                                     // On signale que la caméra est occupée.
+            cr = PIXY2_BUSY;                                                        // On signale que la caméra est occupée.
             break;
     }
     return cr;
@@ -352,14 +352,14 @@
 int PIXY2::pixy2_getResolution (T_Pixy2Resolution *resolution){
 
     T_pixy2RcvHeader    *msg = (T_pixy2RcvHeader*) &Pixy2_buffer[rPointer];
-    int                 cr = 0;
+    int                 cr = PIXY2_OK;
     
     switch (etat) {
         case idle :                                                                 // Si la caméra est inactive
             PIXY2::pixy2_sndGetResolution();                                        // On envoie la trame de demande de la résolution
             etat = messageSent;                                                     // On passe à l'attente du message de réponse
             rPointer = wPointer;                                                    // On enregistre la position du pointeur de FIFO
-            cr = -2;                    //Busy                                      // On signale à l'utilisateur que la caméra est maintenant occupée
+            cr = PIXY2_BUSY;                                                        // On signale à l'utilisateur que la caméra est maintenant occupée
             break;
             
         case dataReceived :                                                         // Quand on a reçu l'intégralité du message
@@ -369,19 +369,19 @@
                         resolution = (T_Pixy2Resolution*) &Pixy2_buffer[rPointer + PIXY2_CSHEADERSIZE];
                                                                                     // Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)                        
                         etat = idle;                                                // Et on annoce que la pixy est libre
-                    } else cr = -7;     // Type Error                               // Si le type ne correspond pas on signale une erreur
-                } else cr = -3;         // Checksum Error                           // Si le checksum est faux on retourne une erreur aussi !
+                    } else cr = PIXY2_TYPE_ERROR;                                   // Si le type ne correspond pas on signale une erreur
+                } else cr = PIXY2_BAD_CHECKSUM;                                     // Si le checksum est faux on retourne une erreur aussi !
             } else {                                                                // S'il n'y a pas de checksum (pas normal mais on ne sait jamais)
                 if (msg->pixType == PIXY2_REP_RESOL) {                              // On vérifie que la trame est du type convenable                               
                     resolution = (T_Pixy2Resolution*) &Pixy2_buffer[rPointer + PIXY2_NCSHEADERSIZE];
                                                                                     // Si le checksum et le type sont bon, on mappe le pointeur de résultat sur la FIFO (ligne précédente)                        
                     etat = idle;                                                    // Et on annoce que la pixy est libre
-                } else cr = -7;         // Type Error                               // Si le type ne correspond pas on signale une erreur
+                } else cr = PIXY2_TYPE_ERROR;                                       // Si le type ne correspond pas on signale une erreur
             }
             break;
 
         default :                                                                   // Dans tous les autres cas
-            cr = -2;                    // Busy                                     // On signale que la caméra est occupée.
+            cr = PIXY2_BUSY;                                                        // On signale à l'utilisateur que la caméra est maintenant occupée
             break;
     }
     return cr;
@@ -410,5 +410,5 @@
     for (i=0; i<*(tab+3);i++)   sum = sum + *(tab + PIXY2_CSHEADERSIZE + i);
     tmp = (T_Word*) (tab+4);
     if (tmp->mot == sum) return 0;
-    else return -1;
+    else return PIXY2_BAD_CHECKSUM;
 }