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@27:bee63ac9b70b, 2020-01-21 (annotated)
- Committer:
- theolp
- Date:
- Tue Jan 21 12:59:37 2020 +0000
- Revision:
- 27:bee63ac9b70b
- Parent:
- 26:a56cc5d715e9
Last
Who changed what in which revision?
User | Revision | Line number | New 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 | 27:bee63ac9b70b | 5 | char *ptr; |
theolp | 27:bee63ac9b70b | 6 | |
theolp | 27:bee63ac9b70b | 7 | void automate_debug(T_Pixy2State &etat); |
theolp | 22:5f76404e2cbc | 8 | |
theolp | 22:5f76404e2cbc | 9 | Serial pc(USBTX, USBRX, 9600); |
theolp | 22:5f76404e2cbc | 10 | /* */ |
theolp | 22:5f76404e2cbc | 11 | |
theolp | 27:bee63ac9b70b | 12 | typedef enum {IDLE, SND, SND_2, CHECKSUM_ERROR, TIMEOUT, OK, OK_2} T_state; |
theolp | 22:5f76404e2cbc | 13 | |
theolp | 22:5f76404e2cbc | 14 | // FLAGS |
theolp | 27:bee63ac9b70b | 15 | bool FLAG_BP = false; |
theolp | 27:bee63ac9b70b | 16 | int nb_appui = 0; |
theolp | 22:5f76404e2cbc | 17 | |
theolp | 22:5f76404e2cbc | 18 | // Prototypes |
theolp | 22:5f76404e2cbc | 19 | void appui_BP(void); |
theolp | 22:5f76404e2cbc | 20 | |
theolp | 22:5f76404e2cbc | 21 | |
theolp | 22:5f76404e2cbc | 22 | int main(void) |
theolp | 22:5f76404e2cbc | 23 | { |
theolp | 22:5f76404e2cbc | 24 | PIXY2 maPixy(PC_12, PD_2); // PC_12 : UART5_TX --- PD_2 : UART5_RX |
theolp | 22:5f76404e2cbc | 25 | |
theolp | 27:bee63ac9b70b | 26 | T_pixy2Version* version; |
theolp | 27:bee63ac9b70b | 27 | T_pixy2Resolution* resolution; |
theolp | 22:5f76404e2cbc | 28 | T_pixy2ErrorCode rep; |
theolp | 22:5f76404e2cbc | 29 | |
theolp | 22:5f76404e2cbc | 30 | // Initialisations |
theolp | 22:5f76404e2cbc | 31 | InterruptIn BP(USER_BUTTON); |
theolp | 22:5f76404e2cbc | 32 | BP.rise(&appui_BP); |
theolp | 22:5f76404e2cbc | 33 | |
theolp | 22:5f76404e2cbc | 34 | Timer temps; |
theolp | 22:5f76404e2cbc | 35 | temps.start(); |
theolp | 22:5f76404e2cbc | 36 | |
theolp | 22:5f76404e2cbc | 37 | T_state etat = IDLE; |
theolp | 22:5f76404e2cbc | 38 | |
theolp | 22:5f76404e2cbc | 39 | while(1) { |
theolp | 22:5f76404e2cbc | 40 | |
theolp | 22:5f76404e2cbc | 41 | switch (etat) { |
theolp | 22:5f76404e2cbc | 42 | case IDLE : |
theolp | 27:bee63ac9b70b | 43 | if (FLAG_BP && nb_appui == 0) { |
theolp | 22:5f76404e2cbc | 44 | pc.printf("Envoi...\n\r"); |
theolp | 22:5f76404e2cbc | 45 | etat = SND; |
theolp | 27:bee63ac9b70b | 46 | FLAG_BP = false; |
theolp | 22:5f76404e2cbc | 47 | temps.reset(); |
theolp | 27:bee63ac9b70b | 48 | nb_appui += 1; |
theolp | 27:bee63ac9b70b | 49 | } |
theolp | 27:bee63ac9b70b | 50 | if (FLAG_BP && nb_appui == 1) { |
theolp | 27:bee63ac9b70b | 51 | pc.printf("Envoi...\n\r"); |
theolp | 27:bee63ac9b70b | 52 | etat = SND_2; |
theolp | 27:bee63ac9b70b | 53 | FLAG_BP = false; |
theolp | 27:bee63ac9b70b | 54 | temps.reset(); |
theolp | 27:bee63ac9b70b | 55 | nb_appui = 0; |
theolp | 22:5f76404e2cbc | 56 | } |
theolp | 22:5f76404e2cbc | 57 | break; |
theolp | 22:5f76404e2cbc | 58 | |
theolp | 22:5f76404e2cbc | 59 | case SND : |
theolp | 27:bee63ac9b70b | 60 | rep = maPixy.pixy2_getVersion(&version); |
theolp | 26:a56cc5d715e9 | 61 | |
theolp | 22:5f76404e2cbc | 62 | if (rep == PIXY2_BAD_CHECKSUM) { |
theolp | 22:5f76404e2cbc | 63 | etat = CHECKSUM_ERROR; |
theolp | 22:5f76404e2cbc | 64 | } |
theolp | 22:5f76404e2cbc | 65 | if (temps.read()>0.5f) { |
theolp | 22:5f76404e2cbc | 66 | etat = TIMEOUT; |
theolp | 22:5f76404e2cbc | 67 | } |
theolp | 27:bee63ac9b70b | 68 | if (rep == PIXY2_OK) { |
theolp | 22:5f76404e2cbc | 69 | etat = OK; |
theolp | 22:5f76404e2cbc | 70 | } |
theolp | 22:5f76404e2cbc | 71 | break; |
theolp | 27:bee63ac9b70b | 72 | |
theolp | 27:bee63ac9b70b | 73 | case SND_2 : |
theolp | 27:bee63ac9b70b | 74 | rep = maPixy.pixy2_getResolution(&resolution); |
theolp | 27:bee63ac9b70b | 75 | |
theolp | 27:bee63ac9b70b | 76 | if (rep == PIXY2_BAD_CHECKSUM) { |
theolp | 27:bee63ac9b70b | 77 | etat = CHECKSUM_ERROR; |
theolp | 27:bee63ac9b70b | 78 | } |
theolp | 27:bee63ac9b70b | 79 | if (temps.read()>0.5f) { |
theolp | 27:bee63ac9b70b | 80 | etat = TIMEOUT; |
theolp | 27:bee63ac9b70b | 81 | } |
theolp | 27:bee63ac9b70b | 82 | if (rep == PIXY2_OK) { |
theolp | 27:bee63ac9b70b | 83 | etat = OK_2; |
theolp | 27:bee63ac9b70b | 84 | } |
theolp | 27:bee63ac9b70b | 85 | break; |
theolp | 22:5f76404e2cbc | 86 | |
theolp | 22:5f76404e2cbc | 87 | case CHECKSUM_ERROR : |
theolp | 22:5f76404e2cbc | 88 | pc.printf("Erreur de CheckSum...\n\r"); |
theolp | 22:5f76404e2cbc | 89 | pc.printf("CheckSum Recu : %d\n\r", sommeRecue); |
theolp | 22:5f76404e2cbc | 90 | pc.printf("CheckSum Calcule : %d\n\r", sommeDeControle); |
theolp | 22:5f76404e2cbc | 91 | etat = IDLE; |
theolp | 22:5f76404e2cbc | 92 | break; |
theolp | 22:5f76404e2cbc | 93 | |
theolp | 22:5f76404e2cbc | 94 | case TIMEOUT : |
theolp | 27:bee63ac9b70b | 95 | pc.printf("Erreur Timeout...\n\rRep : %d\n\r", rep); |
theolp | 27:bee63ac9b70b | 96 | for(int i=0; i<2; ++i) |
theolp | 27:bee63ac9b70b | 97 | pc.printf("%d\n\r", *(ptr + i)); |
theolp | 22:5f76404e2cbc | 98 | etat = IDLE; |
theolp | 22:5f76404e2cbc | 99 | break; |
theolp | 22:5f76404e2cbc | 100 | |
theolp | 22:5f76404e2cbc | 101 | case OK : |
theolp | 27:bee63ac9b70b | 102 | pc.printf("Version de la camera : %s\n\r", version->pixHFString); |
theolp | 27:bee63ac9b70b | 103 | etat = IDLE; |
theolp | 27:bee63ac9b70b | 104 | break; |
theolp | 27:bee63ac9b70b | 105 | |
theolp | 27:bee63ac9b70b | 106 | case OK_2 : |
theolp | 27:bee63ac9b70b | 107 | pc.printf("Resolution de la camera : %d - %d\n\r", resolution->pixFrameWidth, resolution->pixFrameHeight); |
theolp | 22:5f76404e2cbc | 108 | etat = IDLE; |
theolp | 22:5f76404e2cbc | 109 | break; |
theolp | 22:5f76404e2cbc | 110 | |
theolp | 22:5f76404e2cbc | 111 | } |
theolp | 27:bee63ac9b70b | 112 | |
theolp | 27:bee63ac9b70b | 113 | //automate_debug(maPixy.etat); |
theolp | 22:5f76404e2cbc | 114 | } |
theolp | 22:5f76404e2cbc | 115 | } |
theolp | 22:5f76404e2cbc | 116 | |
theolp | 22:5f76404e2cbc | 117 | // FONCTIONS |
theolp | 22:5f76404e2cbc | 118 | void appui_BP(void) |
theolp | 22:5f76404e2cbc | 119 | { |
theolp | 27:bee63ac9b70b | 120 | FLAG_BP = true; |
theolp | 27:bee63ac9b70b | 121 | } |
theolp | 27:bee63ac9b70b | 122 | |
theolp | 27:bee63ac9b70b | 123 | void automate_debug(T_Pixy2State &etat) { |
theolp | 27:bee63ac9b70b | 124 | |
theolp | 27:bee63ac9b70b | 125 | static int etat_debug_passe = -1; |
theolp | 27:bee63ac9b70b | 126 | |
theolp | 27:bee63ac9b70b | 127 | if(etat != etat_debug_passe) { |
theolp | 27:bee63ac9b70b | 128 | switch(etat) { |
theolp | 27:bee63ac9b70b | 129 | case idle : |
theolp | 27:bee63ac9b70b | 130 | pc.printf("IDLE\n\r"); |
theolp | 27:bee63ac9b70b | 131 | break; |
theolp | 27:bee63ac9b70b | 132 | case messageSent : |
theolp | 27:bee63ac9b70b | 133 | pc.printf("DATA_SENT\n\r"); |
theolp | 27:bee63ac9b70b | 134 | break; |
theolp | 27:bee63ac9b70b | 135 | case receivingHeader : |
theolp | 27:bee63ac9b70b | 136 | pc.printf("RECEIVING_HEADER\n\r"); |
theolp | 27:bee63ac9b70b | 137 | break; |
theolp | 27:bee63ac9b70b | 138 | case receivingData : |
theolp | 27:bee63ac9b70b | 139 | pc.printf("RECEIVING_DATA\n\r"); |
theolp | 27:bee63ac9b70b | 140 | break; |
theolp | 27:bee63ac9b70b | 141 | case dataReceived : |
theolp | 27:bee63ac9b70b | 142 | pc.printf("DATA_RECEIVED\n\r"); |
theolp | 27:bee63ac9b70b | 143 | break; |
theolp | 27:bee63ac9b70b | 144 | } |
theolp | 27:bee63ac9b70b | 145 | } |
theolp | 27:bee63ac9b70b | 146 | |
theolp | 27:bee63ac9b70b | 147 | etat_debug_passe = etat; |
theolp | 22:5f76404e2cbc | 148 | } |