Theo Le Paih / Mbed 2 deprecated Lib_Pixy2

Dependencies:   mbed

Revision:
22:5f76404e2cbc
Child:
23:d6bbc4ec1f22
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 21 08:31:58 2019 +0000
@@ -0,0 +1,90 @@
+#include "pixy2.h"
+
+/*      _DEBUG_     */
+int sommeDeControle,sommeRecue;
+
+Serial pc(USBTX, USBRX, 9600);
+/*                  */
+
+typedef enum {IDLE, SND, CHECKSUM_ERROR, TIMEOUT, OK} T_state;
+
+// FLAGS
+char FLAG_BP = 0;
+
+// Prototypes
+void appui_BP(void);
+
+
+int main(void)
+{
+    PIXY2               maPixy(PC_12, PD_2);     // PC_12 : UART5_TX --- PD_2 : UART5_RX
+    
+    T_pixy2Version*     testVersion;
+    T_pixy2ErrorCode    rep;
+    
+    // Initialisations
+    InterruptIn BP(USER_BUTTON);
+    BP.rise(&appui_BP);
+    
+    Timer temps;
+    temps.start();
+    
+    T_state etat = IDLE;
+    
+    while(1) {
+
+        switch (etat) {
+            case IDLE :
+                if (FLAG_BP) {
+                    pc.printf("Envoi...\n\r");
+                    etat = SND;
+                    FLAG_BP = 0;
+                    temps.reset();
+                }
+                break;
+
+            case SND :
+                rep = maPixy.pixy2_getVersion(&testVersion);
+                //pc.printf("%d\n\r",rep);                      // Affichage des erreurs renvoyées
+                if (rep == PIXY2_BAD_CHECKSUM) {
+                    etat = CHECKSUM_ERROR;   
+                }
+                if (temps.read()>0.5f) {
+                    etat = TIMEOUT;
+                }
+                if (rep == PIXY2_OK) {
+                    etat = OK;
+                }
+                break;
+            
+            case CHECKSUM_ERROR :
+                pc.printf("Erreur de CheckSum...\n\r");
+                pc.printf("CheckSum Recu    : %d\n\r", sommeRecue);
+                pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle); 
+                etat = IDLE;
+                break;
+            
+            case TIMEOUT :
+                pc.printf("Erreur Timeout\n\r");
+                etat = IDLE;
+                break;
+
+            case OK :
+            
+                pc.printf("Hardware Version : %x\n\r", globale->pixHWVersion, testVersion->pixHWVersion);
+                pc.printf("Firmware Major Version  : %x\n\r", globale->pixFWVersionMaj, testVersion->pixFWVersionMaj);
+                pc.printf("Firmware Minor Version : %x\n\r", globale->pixFWVersionMin, testVersion->pixFWVersionMin);
+                pc.printf("Firmware Build : %x\n\r", globale->pixFWBuild, testVersion->pixFWBuild);
+                pc.printf("Firmware Human : %s\n\r", globale->pixHFString, testVersion->pixHFString);
+                etat = IDLE;
+                break;
+
+        }
+    }
+}
+
+// FONCTIONS
+void appui_BP(void)
+{
+    FLAG_BP = 1;
+}
\ No newline at end of file