Samir Bouaziz
/
ECAM2IC
Module ECAM interfacé au cockpit A320 FS Polytech PAris Sud Orsay Electronique et Systèmes Embarqués
main.cpp@1:1c0e7a7c86fe, 2011-03-16 (annotated)
- Committer:
- bouaziz
- Date:
- Wed Mar 16 08:15:31 2011 +0000
- Revision:
- 1:1c0e7a7c86fe
- Parent:
- 0:c0664cca9901
prise en charge des potentiometres et des boutons
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bouaziz | 0:c0664cca9901 | 1 | #include "mbed.h" |
bouaziz | 0:c0664cca9901 | 2 | I2C i2c(p28, p27); |
bouaziz | 0:c0664cca9901 | 3 | Serial pc(USBTX, USBRX); // tx, rx |
bouaziz | 0:c0664cca9901 | 4 | // Code � respecter pour FS |
bouaziz | 0:c0664cca9901 | 5 | //Write this offset to trigger an ECAM Control Panel button press. |
bouaziz | 0:c0664cca9901 | 6 | // The value is 1 for ENG, 2 for BLEED, 3 for PRESS, 4 for ELEC, 5 for HYD, |
bouaziz | 0:c0664cca9901 | 7 | // 6 for FUEL, 7 for APU, 8 for COND, 9 for DOOR, 10 for WHEEL, 11 fro FCTL, |
bouaziz | 0:c0664cca9901 | 8 | // 12 for STS, 16 for TO CONFIG, 17 for CLR, 18 for RCL. |
bouaziz | 0:c0664cca9901 | 9 | // Is set to 0 when the action is done. |
bouaziz | 0:c0664cca9901 | 10 | |
bouaziz | 0:c0664cca9901 | 11 | // correspondance touche-bit sur les 8575 |
bouaziz | 0:c0664cca9901 | 12 | //ADDR2 : X HYD X ALL X CLRD X X INT_UPPER INT_LOWER XX X EMER X FUEL |
bouaziz | 0:c0664cca9901 | 13 | // 5 23 17 20 21 22 6 |
bouaziz | 0:c0664cca9901 | 14 | //ADDR1 : X ELEC X Wheel X RCL X STS XXXX X XX F/CTL |
bouaziz | 0:c0664cca9901 | 15 | // 4 10 18 12 11 |
bouaziz | 0:c0664cca9901 | 16 | //ADDR0 : X Cond X ENG X APU X CLRG X TOCONFIG X Press X Door X Bleed |
bouaziz | 0:c0664cca9901 | 17 | // 8 1 7 17 16 3 9 2 |
bouaziz | 0:c0664cca9901 | 18 | const unsigned LEDt[12]={0x0dfff,0x0fffd,0x0ffdf,0x17fff, |
bouaziz | 0:c0664cca9901 | 19 | 0x27fff,0x2fffd,0x0f7ff,0x07fff, |
bouaziz | 0:c0664cca9901 | 20 | 0x0fff7,0x1dfff,0x1fffd,0x1fdff}; |
bouaziz | 0:c0664cca9901 | 21 | const char mess[23][10]={"ENG","BLEED","PRESS","ELEC","HYD","FUEL","APU", |
bouaziz | 0:c0664cca9901 | 22 | "COND","DOOR","WHEEL","FCTL","STS"," "," "," ","TOCONFIG", |
bouaziz | 0:c0664cca9901 | 23 | "CLR","RCL"," ","INT_UP","INT_LOW","EMER","ALL"}; |
bouaziz | 0:c0664cca9901 | 24 | |
bouaziz | 0:c0664cca9901 | 25 | const unsigned short lutbutt01[18]={0xefff,0xfffe,0xffef,0x7fff, |
bouaziz | 0:c0664cca9901 | 26 | 0,0,0xfbff,0xbfff, |
bouaziz | 0:c0664cca9901 | 27 | 0xfffb,0xdfff,0xfffd,0xfdff, |
bouaziz | 0:c0664cca9901 | 28 | 0,0,0,0xffbf,0xfeff,0xf7ff}; |
bouaziz | 0:c0664cca9901 | 29 | |
bouaziz | 0:c0664cca9901 | 30 | unsigned short addrt[3] = {0x40,0x42,0x44}; // define the I2C Address write pcf1 |
bouaziz | 0:c0664cca9901 | 31 | unsigned short valt[3],oldt[3]={0xffff,0xffff,0xffff}; |
bouaziz | 0:c0664cca9901 | 32 | |
bouaziz | 0:c0664cca9901 | 33 | unsigned char decod_butt(unsigned short *v){ //tableau 3 cases |
bouaziz | 0:c0664cca9901 | 34 | unsigned short loc=(v[0]&0x5555)| ((v[1]<<1)&0xAAAA); |
bouaziz | 0:c0664cca9901 | 35 | unsigned short iloc; |
bouaziz | 0:c0664cca9901 | 36 | |
bouaziz | 0:c0664cca9901 | 37 | if(loc!=(unsigned short)0xffff){ |
bouaziz | 0:c0664cca9901 | 38 | iloc=0; |
bouaziz | 0:c0664cca9901 | 39 | while((iloc<18)&(loc!=lutbutt01[iloc])){ |
bouaziz | 0:c0664cca9901 | 40 | iloc++; |
bouaziz | 0:c0664cca9901 | 41 | } |
bouaziz | 0:c0664cca9901 | 42 | if(iloc<18){ |
bouaziz | 0:c0664cca9901 | 43 | return iloc+1; |
bouaziz | 0:c0664cca9901 | 44 | } |
bouaziz | 0:c0664cca9901 | 45 | return 255; |
bouaziz | 0:c0664cca9901 | 46 | } |
bouaziz | 0:c0664cca9901 | 47 | loc=v[2]&0x54C5; |
bouaziz | 0:c0664cca9901 | 48 | if(loc !=0x5405){ |
bouaziz | 0:c0664cca9901 | 49 | switch(loc){ |
bouaziz | 0:c0664cca9901 | 50 | case 0x14C5: return 5; |
bouaziz | 0:c0664cca9901 | 51 | case 0x44C5: return 23; |
bouaziz | 0:c0664cca9901 | 52 | case 0x50C5: return 17; |
bouaziz | 0:c0664cca9901 | 53 | case 0x54c1: return 22; |
bouaziz | 0:c0664cca9901 | 54 | case 0x54C4: return 6; |
bouaziz | 0:c0664cca9901 | 55 | |
bouaziz | 0:c0664cca9901 | 56 | default : |
bouaziz | 0:c0664cca9901 | 57 | break; |
bouaziz | 0:c0664cca9901 | 58 | } |
bouaziz | 0:c0664cca9901 | 59 | } |
bouaziz | 0:c0664cca9901 | 60 | // reste � traiter les 2 boutons rotatifs .... v[2]&0x00c0 |
bouaziz | 0:c0664cca9901 | 61 | return 255; |
bouaziz | 0:c0664cca9901 | 62 | } |
bouaziz | 0:c0664cca9901 | 63 | |
bouaziz | 0:c0664cca9901 | 64 | //unsigned short int tt[8]={0xFFFd,0xFFF7,0xFFdF,0xFF7F,0xFdFF,0xF7FF,0xDFFF,0x7FFF}; |
bouaziz | 0:c0664cca9901 | 65 | void read_ecam(unsigned short *v){ |
bouaziz | 0:c0664cca9901 | 66 | unsigned char cmd[2]; |
bouaziz | 0:c0664cca9901 | 67 | oldt[2]=v[2]; |
bouaziz | 0:c0664cca9901 | 68 | i2c.read(addrt[0]+1, (char *)cmd, 2); |
bouaziz | 0:c0664cca9901 | 69 | v[0]=cmd[0]*256u+(unsigned short)cmd[1]; |
bouaziz | 0:c0664cca9901 | 70 | i2c.read(addrt[1]+1, (char *)cmd, 2); |
bouaziz | 0:c0664cca9901 | 71 | v[1]=cmd[0]*256u+(unsigned short)cmd[1]; |
bouaziz | 0:c0664cca9901 | 72 | i2c.read(addrt[2]+1, (char *)cmd, 2); |
bouaziz | 0:c0664cca9901 | 73 | v[2]=cmd[0]*256u+(unsigned short)cmd[1]; |
bouaziz | 0:c0664cca9901 | 74 | } |
bouaziz | 0:c0664cca9901 | 75 | |
bouaziz | 0:c0664cca9901 | 76 | int main() { |
bouaziz | 0:c0664cca9901 | 77 | unsigned constffff=0xffff; |
bouaziz | 0:c0664cca9901 | 78 | unsigned short i=0,j=0xFFFF; |
bouaziz | 1:1c0e7a7c86fe | 79 | char tmp[2]={0x02,0xE0}; |
bouaziz | 0:c0664cca9901 | 80 | unsigned short state=0,touche=0; |
bouaziz | 1:1c0e7a7c86fe | 81 | unsigned short v2=0,v3=0; |
bouaziz | 0:c0664cca9901 | 82 | pc.printf("COUCOU1\n"); |
bouaziz | 1:1c0e7a7c86fe | 83 | // initaliser les 8575 à 1 recessif |
bouaziz | 0:c0664cca9901 | 84 | i2c.write(addrt[0],(char *)&j,2); |
bouaziz | 0:c0664cca9901 | 85 | i2c.write(addrt[1],(char *)&j,2); |
bouaziz | 0:c0664cca9901 | 86 | i2c.write(addrt[2],(char *)&j,2); |
bouaziz | 1:1c0e7a7c86fe | 87 | // initialiser les convertisseurs des potentiometres |
bouaziz | 1:1c0e7a7c86fe | 88 | i2c.write(0xA2,(char*)tmp,2); |
bouaziz | 1:1c0e7a7c86fe | 89 | wait(0.001); |
bouaziz | 1:1c0e7a7c86fe | 90 | i2c.write(0xA4,(char*)tmp,2); |
bouaziz | 1:1c0e7a7c86fe | 91 | |
bouaziz | 0:c0664cca9901 | 92 | while (1) { |
bouaziz | 1:1c0e7a7c86fe | 93 | // utilisé pour lire les potentiometres |
bouaziz | 1:1c0e7a7c86fe | 94 | tmp[0]=0x00; |
bouaziz | 1:1c0e7a7c86fe | 95 | i2c.write(0xA2,tmp,1); |
bouaziz | 1:1c0e7a7c86fe | 96 | wait(0.0001); |
bouaziz | 1:1c0e7a7c86fe | 97 | i2c.read(0xA3,tmp,2); |
bouaziz | 1:1c0e7a7c86fe | 98 | v2= tmp[0]&0x0F; |
bouaziz | 1:1c0e7a7c86fe | 99 | v2= (v2<<6)| (tmp[1]>>2)&0x3F; |
bouaziz | 1:1c0e7a7c86fe | 100 | tmp[0]=0x00; |
bouaziz | 1:1c0e7a7c86fe | 101 | i2c.write(0xA4,tmp,1); |
bouaziz | 1:1c0e7a7c86fe | 102 | i2c.read(0xA5,tmp,2); |
bouaziz | 1:1c0e7a7c86fe | 103 | v3= tmp[0]&0x0F; |
bouaziz | 1:1c0e7a7c86fe | 104 | v3= (v3<<6)| (tmp[1]>>2)&0x3F; |
bouaziz | 1:1c0e7a7c86fe | 105 | // Affichage des potentiometres |
bouaziz | 1:1c0e7a7c86fe | 106 | printf("%5u %5u\n\r",v2,v3); |
bouaziz | 0:c0664cca9901 | 107 | wait(0.1); |
bouaziz | 1:1c0e7a7c86fe | 108 | // Lecture des bouton de l'ECAM |
bouaziz | 0:c0664cca9901 | 109 | read_ecam(valt); |
bouaziz | 0:c0664cca9901 | 110 | i=decod_butt(valt); |
bouaziz | 1:1c0e7a7c86fe | 111 | //automate de gestion de l'appui des touches |
bouaziz | 0:c0664cca9901 | 112 | if(i<24){ |
bouaziz | 0:c0664cca9901 | 113 | if(state==0){ |
bouaziz | 0:c0664cca9901 | 114 | state=1; |
bouaziz | 0:c0664cca9901 | 115 | touche=i; |
bouaziz | 0:c0664cca9901 | 116 | } |
bouaziz | 0:c0664cca9901 | 117 | }else{ |
bouaziz | 0:c0664cca9901 | 118 | state=0; |
bouaziz | 0:c0664cca9901 | 119 | } |
bouaziz | 1:1c0e7a7c86fe | 120 | //renvoi du nom de la touche et de son code |
bouaziz | 1:1c0e7a7c86fe | 121 | //si touche=0 alors pas de touche appuyée |
bouaziz | 0:c0664cca9901 | 122 | if(touche>0){ |
bouaziz | 0:c0664cca9901 | 123 | pc.printf("X %s %2u\n\r",mess[touche-1],(unsigned) touche); |
bouaziz | 0:c0664cca9901 | 124 | if(touche<13){ |
bouaziz | 0:c0664cca9901 | 125 | j=LEDt[touche-1]&0xffff; |
bouaziz | 0:c0664cca9901 | 126 | tmp[0]= j>>8; |
bouaziz | 0:c0664cca9901 | 127 | tmp[1]= j&0xff; |
bouaziz | 0:c0664cca9901 | 128 | j=addrt[LEDt[touche-1]>>16]; |
bouaziz | 0:c0664cca9901 | 129 | i2c.write(addrt[0],(char *)&constffff,2); |
bouaziz | 0:c0664cca9901 | 130 | i2c.write(addrt[1],(char *)&constffff,2); |
bouaziz | 0:c0664cca9901 | 131 | i2c.write(addrt[2],(char *)&constffff,2); |
bouaziz | 0:c0664cca9901 | 132 | i2c.write(j,tmp,2); |
bouaziz | 0:c0664cca9901 | 133 | } |
bouaziz | 0:c0664cca9901 | 134 | touche=0; |
bouaziz | 0:c0664cca9901 | 135 | } |
bouaziz | 0:c0664cca9901 | 136 | } |
bouaziz | 0:c0664cca9901 | 137 | } |
bouaziz | 0:c0664cca9901 | 138 | |
bouaziz | 0:c0664cca9901 | 139 | |
bouaziz | 0:c0664cca9901 | 140 |