Classes et code de la partie pompe du Robot 2021
Dependencies: mbed ident_crac
main.cpp@7:b7dc6201b520, 2021-03-05 (annotated)
- Committer:
- smarecar
- Date:
- Fri Mar 05 18:46:42 2021 +0000
- Revision:
- 7:b7dc6201b520
- Parent:
- 6:b06c430a7e14
- Child:
- 8:ba95705cf7d4
prog home a tester
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
goldmas | 0:253443d82cba | 1 | #include "bloc_8_pompe.h" |
goldmas | 4:4bae30d48662 | 2 | #include "ident_crac.h" |
goldmas | 0:253443d82cba | 3 | |
goldmas | 1:815ca6061e15 | 4 | //initialisations relatives au Bus CAN |
goldmas | 4:4bae30d48662 | 5 | CAN bus_CAN(PB_8, PB_9, 1000000) ; |
goldmas | 4:4bae30d48662 | 6 | CANMessage commande_carte ; |
goldmas | 6:b06c430a7e14 | 7 | CANMessage envoie ; |
goldmas | 1:815ca6061e15 | 8 | int flag_reception_CAN = 0 ; |
goldmas | 2:61ffa6e3eee5 | 9 | void interruption_reception(void) ; |
goldmas | 4:4bae30d48662 | 10 | void gestion_Message_CAN(void) ; |
goldmas | 6:b06c430a7e14 | 11 | void Envoi_msg_CAN(char donnee); |
goldmas | 1:815ca6061e15 | 12 | |
goldmas | 4:4bae30d48662 | 13 | //Fin de jeu |
goldmas | 4:4bae30d48662 | 14 | char end_game = 0; |
goldmas | 4:4bae30d48662 | 15 | |
goldmas | 4:4bae30d48662 | 16 | bloc_8_pompe::bloc_8_pompe classe_pompe (PC_9, PA_8, PB_0, //bloc 1 |
goldmas | 0:253443d82cba | 17 | PA_9, PA_10, PB_1, //bloc 2 |
goldmas | 0:253443d82cba | 18 | PA_11, PA_15, PC_1, //bloc 3 |
goldmas | 0:253443d82cba | 19 | PB_7, PB_6, PC_0, //bloc 4 |
goldmas | 0:253443d82cba | 20 | PC_7, PC_8, PC_5, //bloc 5 |
goldmas | 0:253443d82cba | 21 | PB_10, PB_2, PC_4, //bloc 6 |
goldmas | 0:253443d82cba | 22 | PA_6, PA_5, PA_7, //bloc 7 |
goldmas | 0:253443d82cba | 23 | PA_0, PA_1, PA_4); //bloc 8 |
goldmas | 4:4bae30d48662 | 24 | |
goldmas | 4:4bae30d48662 | 25 | int main() |
goldmas | 4:4bae30d48662 | 26 | { |
goldmas | 4:4bae30d48662 | 27 | bus_CAN.attach(&interruption_reception) ; |
goldmas | 6:b06c430a7e14 | 28 | |
goldmas | 0:253443d82cba | 29 | while(1) |
goldmas | 0:253443d82cba | 30 | { |
goldmas | 6:b06c430a7e14 | 31 | //bus_CAN(envoie); |
goldmas | 6:b06c430a7e14 | 32 | if(flag_reception_CAN) |
goldmas | 6:b06c430a7e14 | 33 | { |
goldmas | 6:b06c430a7e14 | 34 | gestion_Message_CAN() ; |
goldmas | 6:b06c430a7e14 | 35 | } |
goldmas | 0:253443d82cba | 36 | |
goldmas | 6:b06c430a7e14 | 37 | if(end_game) |
goldmas | 6:b06c430a7e14 | 38 | { |
goldmas | 6:b06c430a7e14 | 39 | for (int i=0 ; i<8 ; i++) |
goldmas | 6:b06c430a7e14 | 40 | { |
goldmas | 6:b06c430a7e14 | 41 | classe_pompe.stop_pompe(i); |
goldmas | 6:b06c430a7e14 | 42 | wait_ms(10) ; |
goldmas | 6:b06c430a7e14 | 43 | } |
goldmas | 6:b06c430a7e14 | 44 | } |
smarecar | 7:b7dc6201b520 | 45 | //Envoi_msg_CAN(1); //envoie un msg pour tester la liaison can |
goldmas | 0:253443d82cba | 46 | } |
goldmas | 0:253443d82cba | 47 | |
goldmas | 4:4bae30d48662 | 48 | } |
goldmas | 4:4bae30d48662 | 49 | |
goldmas | 4:4bae30d48662 | 50 | void interruption_reception(void) |
goldmas | 4:4bae30d48662 | 51 | { |
goldmas | 4:4bae30d48662 | 52 | if (bus_CAN.read(commande_carte)) |
goldmas | 4:4bae30d48662 | 53 | flag_reception_CAN = 1 ; |
goldmas | 4:4bae30d48662 | 54 | } |
goldmas | 4:4bae30d48662 | 55 | |
goldmas | 4:4bae30d48662 | 56 | void gestion_Message_CAN(void) |
goldmas | 4:4bae30d48662 | 57 | { |
goldmas | 4:4bae30d48662 | 58 | int identifiant = commande_carte.id ; |
goldmas | 4:4bae30d48662 | 59 | char num_groupe = 1 ; |
goldmas | 6:b06c430a7e14 | 60 | char etat_groupe = 0 ; |
goldmas | 4:4bae30d48662 | 61 | |
goldmas | 4:4bae30d48662 | 62 | switch (identifiant) |
goldmas | 4:4bae30d48662 | 63 | { |
goldmas | 4:4bae30d48662 | 64 | case VENT_AT: |
goldmas | 4:4bae30d48662 | 65 | num_groupe = commande_carte.data[0]; |
goldmas | 4:4bae30d48662 | 66 | classe_pompe.aspirer(num_groupe) ; |
goldmas | 4:4bae30d48662 | 67 | break; |
goldmas | 4:4bae30d48662 | 68 | |
goldmas | 4:4bae30d48662 | 69 | case VENT_RE: |
goldmas | 4:4bae30d48662 | 70 | num_groupe = commande_carte.data[0]; |
goldmas | 4:4bae30d48662 | 71 | classe_pompe.relacher(num_groupe) ; |
goldmas | 4:4bae30d48662 | 72 | break; |
goldmas | 4:4bae30d48662 | 73 | |
goldmas | 4:4bae30d48662 | 74 | case VENT_ETAT: |
goldmas | 6:b06c430a7e14 | 75 | num_groupe = commande_carte.data[0]; |
goldmas | 6:b06c430a7e14 | 76 | etat_groupe = classe_pompe.etat_actuel(num_groupe) ; |
goldmas | 6:b06c430a7e14 | 77 | |
goldmas | 6:b06c430a7e14 | 78 | if(etat_groupe == 0x07) |
goldmas | 6:b06c430a7e14 | 79 | { |
goldmas | 6:b06c430a7e14 | 80 | classe_pompe.aspirer(num_groupe) ; |
goldmas | 6:b06c430a7e14 | 81 | etat_groupe = classe_pompe.etat_actuel(num_groupe) ; |
goldmas | 6:b06c430a7e14 | 82 | } |
goldmas | 6:b06c430a7e14 | 83 | |
goldmas | 6:b06c430a7e14 | 84 | |
goldmas | 6:b06c430a7e14 | 85 | Envoi_msg_CAN(etat_groupe); |
goldmas | 6:b06c430a7e14 | 86 | |
goldmas | 4:4bae30d48662 | 87 | break; |
goldmas | 4:4bae30d48662 | 88 | |
goldmas | 4:4bae30d48662 | 89 | case GLOBAL_GAME_END: |
goldmas | 4:4bae30d48662 | 90 | end_game = 1; |
goldmas | 6:b06c430a7e14 | 91 | break; |
goldmas | 4:4bae30d48662 | 92 | |
goldmas | 6:b06c430a7e14 | 93 | |
goldmas | 4:4bae30d48662 | 94 | /* |
goldmas | 4:4bae30d48662 | 95 | |
goldmas | 4:4bae30d48662 | 96 | case TEST_VENT_1_ON: |
goldmas | 4:4bae30d48662 | 97 | classe_pompe[AV_DROIT]->action(1); |
goldmas | 4:4bae30d48662 | 98 | classe_pompe[AV_CENTRE]->action(1); |
goldmas | 4:4bae30d48662 | 99 | classe_pompe[AV_GAUCHE]->action(1); |
goldmas | 4:4bae30d48662 | 100 | classe_pompe[AR_DROIT]->action(1); |
goldmas | 4:4bae30d48662 | 101 | classe_pompe[AR_CENTRE]->action(1); |
goldmas | 4:4bae30d48662 | 102 | classe_pompe[AR_GAUCHE]->action(1); |
goldmas | 4:4bae30d48662 | 103 | break; |
goldmas | 4:4bae30d48662 | 104 | |
goldmas | 4:4bae30d48662 | 105 | case TEST_VENT_1_OFF: |
goldmas | 4:4bae30d48662 | 106 | classe_pompe[AV_CENTRE]->action(0); |
goldmas | 4:4bae30d48662 | 107 | classe_pompe[AV_GAUCHE]->action(0); |
goldmas | 4:4bae30d48662 | 108 | classe_pompe[AR_DROIT]->action(0); |
goldmas | 4:4bae30d48662 | 109 | classe_pompe[AR_CENTRE]->action(0); |
goldmas | 4:4bae30d48662 | 110 | classe_pompe[AR_GAUCHE]->action(0); |
goldmas | 4:4bae30d48662 | 111 | classe_pompe[AV_DROIT]->action(0); |
goldmas | 4:4bae30d48662 | 112 | break;*/ |
goldmas | 4:4bae30d48662 | 113 | default: |
goldmas | 4:4bae30d48662 | 114 | break; |
goldmas | 6:b06c430a7e14 | 115 | } |
goldmas | 6:b06c430a7e14 | 116 | flag_reception_CAN = 0 ; |
goldmas | 4:4bae30d48662 | 117 | |
goldmas | 4:4bae30d48662 | 118 | } |
goldmas | 4:4bae30d48662 | 119 | |
goldmas | 6:b06c430a7e14 | 120 | void Envoi_msg_CAN(char donnee) |
goldmas | 4:4bae30d48662 | 121 | { |
goldmas | 6:b06c430a7e14 | 122 | CANMessage etat_ventouses; |
goldmas | 6:b06c430a7e14 | 123 | etat_ventouses.id = 0x220; |
goldmas | 6:b06c430a7e14 | 124 | etat_ventouses.len=1; |
goldmas | 4:4bae30d48662 | 125 | etat_ventouses.format=CANStandard; |
goldmas | 4:4bae30d48662 | 126 | etat_ventouses.type=CANData; |
goldmas | 6:b06c430a7e14 | 127 | etat_ventouses.data[0]=donnee; |
goldmas | 6:b06c430a7e14 | 128 | |
goldmas | 6:b06c430a7e14 | 129 | bus_CAN.write(etat_ventouses); |
goldmas | 0:253443d82cba | 130 | } |