Theo Le Paih / Mbed 2 deprecated Lib_Pixy2

Dependencies:   mbed

Committer:
theolp
Date:
Thu Nov 21 09:31:05 2019 +0000
Revision:
25:2a2fcb9e4775
Parent:
23:d6bbc4ec1f22
Child:
26:a56cc5d715e9
Test checksum errors fixed. Version and resolution working.

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 25:2a2fcb9e4775 22 T_pixy2Resolution* testResolution;
theolp 22:5f76404e2cbc 23 T_pixy2ErrorCode rep;
theolp 22:5f76404e2cbc 24
theolp 22:5f76404e2cbc 25 // Initialisations
theolp 22:5f76404e2cbc 26 InterruptIn BP(USER_BUTTON);
theolp 22:5f76404e2cbc 27 BP.rise(&appui_BP);
theolp 22:5f76404e2cbc 28
theolp 22:5f76404e2cbc 29 Timer temps;
theolp 22:5f76404e2cbc 30 temps.start();
theolp 22:5f76404e2cbc 31
theolp 22:5f76404e2cbc 32 T_state etat = IDLE;
theolp 22:5f76404e2cbc 33
theolp 22:5f76404e2cbc 34 while(1) {
theolp 22:5f76404e2cbc 35
theolp 22:5f76404e2cbc 36 switch (etat) {
theolp 22:5f76404e2cbc 37 case IDLE :
theolp 22:5f76404e2cbc 38 if (FLAG_BP) {
theolp 22:5f76404e2cbc 39 pc.printf("Envoi...\n\r");
theolp 22:5f76404e2cbc 40 etat = SND;
theolp 22:5f76404e2cbc 41 FLAG_BP = 0;
theolp 22:5f76404e2cbc 42 temps.reset();
theolp 22:5f76404e2cbc 43 }
theolp 22:5f76404e2cbc 44 break;
theolp 22:5f76404e2cbc 45
theolp 22:5f76404e2cbc 46 case SND :
theolp 25:2a2fcb9e4775 47 rep = maPixy.pixy2_getResolution(&testResolution);
theolp 22:5f76404e2cbc 48 //pc.printf("%d\n\r",rep); // Affichage des erreurs renvoyées
theolp 22:5f76404e2cbc 49 if (rep == PIXY2_BAD_CHECKSUM) {
theolp 22:5f76404e2cbc 50 etat = CHECKSUM_ERROR;
theolp 22:5f76404e2cbc 51 }
theolp 22:5f76404e2cbc 52 if (temps.read()>0.5f) {
theolp 22:5f76404e2cbc 53 etat = TIMEOUT;
theolp 22:5f76404e2cbc 54 }
theolp 22:5f76404e2cbc 55 if (rep == PIXY2_OK) {
theolp 22:5f76404e2cbc 56 etat = OK;
theolp 22:5f76404e2cbc 57 }
theolp 22:5f76404e2cbc 58 break;
theolp 22:5f76404e2cbc 59
theolp 22:5f76404e2cbc 60 case CHECKSUM_ERROR :
theolp 22:5f76404e2cbc 61 pc.printf("Erreur de CheckSum...\n\r");
theolp 22:5f76404e2cbc 62 pc.printf("CheckSum Recu : %d\n\r", sommeRecue);
theolp 22:5f76404e2cbc 63 pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle);
theolp 22:5f76404e2cbc 64 etat = IDLE;
theolp 22:5f76404e2cbc 65 break;
theolp 22:5f76404e2cbc 66
theolp 22:5f76404e2cbc 67 case TIMEOUT :
theolp 22:5f76404e2cbc 68 pc.printf("Erreur Timeout\n\r");
theolp 22:5f76404e2cbc 69 etat = IDLE;
theolp 22:5f76404e2cbc 70 break;
theolp 22:5f76404e2cbc 71
theolp 22:5f76404e2cbc 72 case OK :
theolp 25:2a2fcb9e4775 73 pc.printf("Pixy frame width : %d\n\r", testResolution->pixFrameWidth);
theolp 25:2a2fcb9e4775 74 pc.printf("Pixy frame height : %d\n\r", testResolution->pixFrameHeight);
theolp 22:5f76404e2cbc 75 etat = IDLE;
theolp 22:5f76404e2cbc 76 break;
theolp 22:5f76404e2cbc 77
theolp 22:5f76404e2cbc 78 }
theolp 22:5f76404e2cbc 79 }
theolp 22:5f76404e2cbc 80 }
theolp 22:5f76404e2cbc 81
theolp 22:5f76404e2cbc 82 // FONCTIONS
theolp 22:5f76404e2cbc 83 void appui_BP(void)
theolp 22:5f76404e2cbc 84 {
theolp 22:5f76404e2cbc 85 FLAG_BP = 1;
theolp 22:5f76404e2cbc 86 }