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.
Diff: main.cpp
- Revision:
- 27:bee63ac9b70b
- Parent:
- 26:a56cc5d715e9
- Child:
- 28:f1dd68d07aec
--- 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