Theo Le Paih / Mbed 2 deprecated Lib_Pixy2

Dependencies:   mbed

Committer:
theolp
Date:
Thu Nov 28 07:39:32 2019 +0000
Revision:
26:a56cc5d715e9
Parent:
25:2a2fcb9e4775
Child:
27:bee63ac9b70b
Avant la tentative de correction de Pixy2_getFeatures()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theolp 22:5f76404e2cbc 1 #include "pixy2.h"
theolp 22:5f76404e2cbc 2
theolp 22:5f76404e2cbc 3 /* _DEBUG_ */
theolp 22:5f76404e2cbc 4 int sommeDeControle,sommeRecue;
theolp 22:5f76404e2cbc 5
theolp 22:5f76404e2cbc 6 Serial pc(USBTX, USBRX, 9600);
theolp 22:5f76404e2cbc 7 /* */
theolp 22:5f76404e2cbc 8
theolp 22:5f76404e2cbc 9 typedef enum {IDLE, SND, CHECKSUM_ERROR, TIMEOUT, OK} T_state;
theolp 22:5f76404e2cbc 10
theolp 22:5f76404e2cbc 11 // FLAGS
theolp 22:5f76404e2cbc 12 char FLAG_BP = 0;
theolp 22:5f76404e2cbc 13
theolp 22:5f76404e2cbc 14 // Prototypes
theolp 22:5f76404e2cbc 15 void appui_BP(void);
theolp 22:5f76404e2cbc 16
theolp 22:5f76404e2cbc 17
theolp 22:5f76404e2cbc 18 int main(void)
theolp 22:5f76404e2cbc 19 {
theolp 22:5f76404e2cbc 20 PIXY2 maPixy(PC_12, PD_2); // PC_12 : UART5_TX --- PD_2 : UART5_RX
theolp 22:5f76404e2cbc 21
theolp 22:5f76404e2cbc 22 T_pixy2ErrorCode rep;
theolp 22:5f76404e2cbc 23
theolp 22:5f76404e2cbc 24 // Initialisations
theolp 22:5f76404e2cbc 25 InterruptIn BP(USER_BUTTON);
theolp 22:5f76404e2cbc 26 BP.rise(&appui_BP);
theolp 22:5f76404e2cbc 27
theolp 22:5f76404e2cbc 28 Timer temps;
theolp 22:5f76404e2cbc 29 temps.start();
theolp 22:5f76404e2cbc 30
theolp 22:5f76404e2cbc 31 T_state etat = IDLE;
theolp 22:5f76404e2cbc 32
theolp 22:5f76404e2cbc 33 while(1) {
theolp 22:5f76404e2cbc 34
theolp 22:5f76404e2cbc 35 switch (etat) {
theolp 22:5f76404e2cbc 36 case IDLE :
theolp 22:5f76404e2cbc 37 if (FLAG_BP) {
theolp 22:5f76404e2cbc 38 pc.printf("Envoi...\n\r");
theolp 22:5f76404e2cbc 39 etat = SND;
theolp 22:5f76404e2cbc 40 FLAG_BP = 0;
theolp 22:5f76404e2cbc 41 temps.reset();
theolp 22:5f76404e2cbc 42 }
theolp 22:5f76404e2cbc 43 break;
theolp 22:5f76404e2cbc 44
theolp 22:5f76404e2cbc 45 case SND :
theolp 26:a56cc5d715e9 46 rep = maPixy.pixy2_getMainFeature(1);
theolp 26:a56cc5d715e9 47
theolp 22:5f76404e2cbc 48 if (rep == PIXY2_BAD_CHECKSUM) {
theolp 22:5f76404e2cbc 49 etat = CHECKSUM_ERROR;
theolp 22:5f76404e2cbc 50 }
theolp 22:5f76404e2cbc 51 if (temps.read()>0.5f) {
theolp 22:5f76404e2cbc 52 etat = TIMEOUT;
theolp 22:5f76404e2cbc 53 }
theolp 26:a56cc5d715e9 54 if (rep >= PIXY2_VECTOR) {
theolp 22:5f76404e2cbc 55 etat = OK;
theolp 22:5f76404e2cbc 56 }
theolp 22:5f76404e2cbc 57 break;
theolp 22:5f76404e2cbc 58
theolp 22:5f76404e2cbc 59 case CHECKSUM_ERROR :
theolp 22:5f76404e2cbc 60 pc.printf("Erreur de CheckSum...\n\r");
theolp 22:5f76404e2cbc 61 pc.printf("CheckSum Recu : %d\n\r", sommeRecue);
theolp 22:5f76404e2cbc 62 pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle);
theolp 22:5f76404e2cbc 63 etat = IDLE;
theolp 22:5f76404e2cbc 64 break;
theolp 22:5f76404e2cbc 65
theolp 22:5f76404e2cbc 66 case TIMEOUT :
theolp 22:5f76404e2cbc 67 pc.printf("Erreur Timeout\n\r");
theolp 22:5f76404e2cbc 68 etat = IDLE;
theolp 22:5f76404e2cbc 69 break;
theolp 22:5f76404e2cbc 70
theolp 22:5f76404e2cbc 71 case OK :
theolp 26:a56cc5d715e9 72 pc.printf("Number of vectors : %d\n\r", maPixy.Pixy2_numVectors);
theolp 26:a56cc5d715e9 73 for(int i=0; i<maPixy.Pixy2_numVectors; ++i) {
theolp 26:a56cc5d715e9 74 pc.printf("Vector number : %d\n\r", maPixy.Pixy2_vectors[i].pixIndex);
theolp 26:a56cc5d715e9 75 pc.printf("x0 : %d - y0 : %d\n\r", maPixy.Pixy2_vectors[i].pixX0, maPixy.Pixy2_vectors[i].pixY0);
theolp 26:a56cc5d715e9 76 pc.printf("x1 : %d - y1 : %d\n\r", maPixy.Pixy2_vectors[i].pixX1, maPixy.Pixy2_vectors[i].pixY1);
theolp 26:a56cc5d715e9 77 }
theolp 22:5f76404e2cbc 78 etat = IDLE;
theolp 22:5f76404e2cbc 79 break;
theolp 22:5f76404e2cbc 80
theolp 22:5f76404e2cbc 81 }
theolp 22:5f76404e2cbc 82 }
theolp 22:5f76404e2cbc 83 }
theolp 22:5f76404e2cbc 84
theolp 22:5f76404e2cbc 85 // FONCTIONS
theolp 22:5f76404e2cbc 86 void appui_BP(void)
theolp 22:5f76404e2cbc 87 {
theolp 22:5f76404e2cbc 88 FLAG_BP = 1;
theolp 22:5f76404e2cbc 89 }