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@22:5f76404e2cbc, 2019-11-21 (annotated)
- Committer:
- theolp
- Date:
- Thu Nov 21 08:31:58 2019 +0000
- Revision:
- 22:5f76404e2cbc
- Child:
- 23:d6bbc4ec1f22
added documentation of pointer to pointer usage
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 | 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_pixy2Version* testVersion; |
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 | 22:5f76404e2cbc | 47 | rep = maPixy.pixy2_getVersion(&testVersion); |
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 | 22:5f76404e2cbc | 73 | |
theolp | 22:5f76404e2cbc | 74 | pc.printf("Hardware Version : %x\n\r", globale->pixHWVersion, testVersion->pixHWVersion); |
theolp | 22:5f76404e2cbc | 75 | pc.printf("Firmware Major Version : %x\n\r", globale->pixFWVersionMaj, testVersion->pixFWVersionMaj); |
theolp | 22:5f76404e2cbc | 76 | pc.printf("Firmware Minor Version : %x\n\r", globale->pixFWVersionMin, testVersion->pixFWVersionMin); |
theolp | 22:5f76404e2cbc | 77 | pc.printf("Firmware Build : %x\n\r", globale->pixFWBuild, testVersion->pixFWBuild); |
theolp | 22:5f76404e2cbc | 78 | pc.printf("Firmware Human : %s\n\r", globale->pixHFString, testVersion->pixHFString); |
theolp | 22:5f76404e2cbc | 79 | etat = IDLE; |
theolp | 22:5f76404e2cbc | 80 | break; |
theolp | 22:5f76404e2cbc | 81 | |
theolp | 22:5f76404e2cbc | 82 | } |
theolp | 22:5f76404e2cbc | 83 | } |
theolp | 22:5f76404e2cbc | 84 | } |
theolp | 22:5f76404e2cbc | 85 | |
theolp | 22:5f76404e2cbc | 86 | // FONCTIONS |
theolp | 22:5f76404e2cbc | 87 | void appui_BP(void) |
theolp | 22:5f76404e2cbc | 88 | { |
theolp | 22:5f76404e2cbc | 89 | FLAG_BP = 1; |
theolp | 22:5f76404e2cbc | 90 | } |