Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "pixy2.h" 00002 00003 /* _DEBUG_ */ 00004 int sommeDeControle,sommeRecue; 00005 char *ptr; 00006 00007 void automate_debug(T_Pixy2State &etat); 00008 00009 Serial pc(USBTX, USBRX, 9600); 00010 /* */ 00011 00012 typedef enum {IDLE, SND, SND_2, CHECKSUM_ERROR, TIMEOUT, OK, OK_2} T_state; 00013 00014 // FLAGS 00015 bool FLAG_BP = false; 00016 int nb_appui = 0; 00017 00018 // Prototypes 00019 void appui_BP(void); 00020 00021 00022 int main(void) 00023 { 00024 PIXY2 maPixy(PC_12, PD_2); // PC_12 : UART5_TX --- PD_2 : UART5_RX 00025 00026 T_pixy2Version* version; 00027 T_pixy2Resolution* resolution; 00028 T_pixy2ErrorCode rep; 00029 00030 // Initialisations 00031 InterruptIn BP(USER_BUTTON); 00032 BP.rise(&appui_BP); 00033 00034 Timer temps; 00035 temps.start(); 00036 00037 T_state etat = IDLE; 00038 00039 while(1) { 00040 00041 switch (etat) { 00042 case IDLE : 00043 if (FLAG_BP && nb_appui == 0) { 00044 pc.printf("Envoi...\n\r"); 00045 etat = SND; 00046 FLAG_BP = false; 00047 temps.reset(); 00048 nb_appui += 1; 00049 } 00050 if (FLAG_BP && nb_appui == 1) { 00051 pc.printf("Envoi...\n\r"); 00052 etat = SND_2; 00053 FLAG_BP = false; 00054 temps.reset(); 00055 nb_appui = 0; 00056 } 00057 break; 00058 00059 case SND : 00060 rep = maPixy.pixy2_getVersion(&version); 00061 00062 if (rep == PIXY2_BAD_CHECKSUM) { 00063 etat = CHECKSUM_ERROR; 00064 } 00065 if (temps.read()>0.5f) { 00066 etat = TIMEOUT; 00067 } 00068 if (rep == PIXY2_OK) { 00069 etat = OK; 00070 } 00071 break; 00072 00073 case SND_2 : 00074 rep = maPixy.pixy2_getResolution(&resolution); 00075 00076 if (rep == PIXY2_BAD_CHECKSUM) { 00077 etat = CHECKSUM_ERROR; 00078 } 00079 if (temps.read()>0.5f) { 00080 etat = TIMEOUT; 00081 } 00082 if (rep == PIXY2_OK) { 00083 etat = OK_2; 00084 } 00085 break; 00086 00087 case CHECKSUM_ERROR : 00088 pc.printf("Erreur de CheckSum...\n\r"); 00089 pc.printf("CheckSum Recu : %d\n\r", sommeRecue); 00090 pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle); 00091 etat = IDLE; 00092 break; 00093 00094 case TIMEOUT : 00095 pc.printf("Erreur Timeout...\n\rRep : %d\n\r", rep); 00096 for(int i=0; i<2; ++i) 00097 pc.printf("%d\n\r", *(ptr + i)); 00098 etat = IDLE; 00099 break; 00100 00101 case OK : 00102 pc.printf("Version de la camera : %s\n\r", version->pixHFString); 00103 etat = IDLE; 00104 break; 00105 00106 case OK_2 : 00107 pc.printf("Resolution de la camera : %d - %d\n\r", resolution->pixFrameWidth, resolution->pixFrameHeight); 00108 etat = IDLE; 00109 break; 00110 00111 } 00112 00113 //automate_debug(maPixy.etat); 00114 } 00115 } 00116 00117 // FONCTIONS 00118 void appui_BP(void) 00119 { 00120 FLAG_BP = true; 00121 } 00122 00123 void automate_debug(T_Pixy2State &etat) { 00124 00125 static int etat_debug_passe = -1; 00126 00127 if(etat != etat_debug_passe) { 00128 switch(etat) { 00129 case idle : 00130 pc.printf("IDLE\n\r"); 00131 break; 00132 case messageSent : 00133 pc.printf("DATA_SENT\n\r"); 00134 break; 00135 case receivingHeader : 00136 pc.printf("RECEIVING_HEADER\n\r"); 00137 break; 00138 case receivingData : 00139 pc.printf("RECEIVING_DATA\n\r"); 00140 break; 00141 case dataReceived : 00142 pc.printf("DATA_RECEIVED\n\r"); 00143 break; 00144 } 00145 } 00146 00147 etat_debug_passe = etat; 00148 }
Generated on Tue Jul 12 2022 20:05:39 by
1.7.2