Module ECAM interfacé au cockpit A320 FS Polytech PAris Sud Orsay Electronique et Systèmes Embarqués

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
bouaziz
Date:
Sun Mar 13 18:56:29 2011 +0000
Child:
1:1c0e7a7c86fe
Commit message:
ECAM_A320_SERIALCOM
COckpit Polytech PAris Sud A320

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 13 18:56:29 2011 +0000
@@ -0,0 +1,150 @@
+#include "mbed.h"
+I2C i2c(p28, p27);
+Serial pc(USBTX, USBRX); // tx, rx
+// Code � respecter pour FS
+//Write this offset to trigger an ECAM Control Panel button press.
+// The value is 1 for ENG, 2 for BLEED, 3 for PRESS, 4 for ELEC, 5 for HYD,
+// 6 for FUEL, 7 for APU, 8 for COND, 9 for DOOR, 10 for WHEEL, 11 fro FCTL,
+// 12 for STS, 16 for TO CONFIG, 17 for CLR, 18 for RCL.
+// Is set to 0 when the action is done.
+
+// correspondance touche-bit sur les 8575
+//ADDR2 :  X HYD X ALL X CLRD X X  INT_UPPER INT_LOWER XX X EMER X FUEL
+//            5    23      17          20        21         22     6
+//ADDR1 :  X ELEC X Wheel X RCL X STS XXXX X XX F/CTL
+//            4      10     18    12             11
+//ADDR0 :  X Cond X ENG X APU X CLRG X TOCONFIG X Press X Door X Bleed
+//            8     1      7     17      16        3       9      2 
+const unsigned LEDt[12]={0x0dfff,0x0fffd,0x0ffdf,0x17fff,
+                         0x27fff,0x2fffd,0x0f7ff,0x07fff,
+                         0x0fff7,0x1dfff,0x1fffd,0x1fdff};
+const char mess[23][10]={"ENG","BLEED","PRESS","ELEC","HYD","FUEL","APU",
+                         "COND","DOOR","WHEEL","FCTL","STS"," "," "," ","TOCONFIG",
+                         "CLR","RCL"," ","INT_UP","INT_LOW","EMER","ALL"};
+                         
+const unsigned short lutbutt01[18]={0xefff,0xfffe,0xffef,0x7fff,
+                                    0,0,0xfbff,0xbfff,
+                                    0xfffb,0xdfff,0xfffd,0xfdff,
+                                    0,0,0,0xffbf,0xfeff,0xf7ff};
+                                    
+unsigned short addrt[3] = {0x40,0x42,0x44}; // define the I2C Address write pcf1
+unsigned short valt[3],oldt[3]={0xffff,0xffff,0xffff};                                    
+                                    
+unsigned char decod_butt(unsigned short *v){ //tableau 3 cases
+     unsigned short loc=(v[0]&0x5555)| ((v[1]<<1)&0xAAAA);
+     unsigned short iloc;
+     
+     if(loc!=(unsigned short)0xffff){
+            iloc=0;
+            while((iloc<18)&(loc!=lutbutt01[iloc])){
+                iloc++;
+            }
+            if(iloc<18){
+                return iloc+1;
+            }
+            return 255;
+     }
+     loc=v[2]&0x54C5;
+     if(loc !=0x5405){
+        switch(loc){
+            case 0x14C5: return 5;
+            case 0x44C5: return 23;
+            case 0x50C5: return 17;
+            case 0x54c1: return 22;
+            case 0x54C4: return 6;
+                    
+            default :
+                      break;
+        }
+     }
+     // reste &#65533; traiter les 2 boutons rotatifs .... v[2]&0x00c0
+     return 255;
+}
+
+//unsigned short int tt[8]={0xFFFd,0xFFF7,0xFFdF,0xFF7F,0xFdFF,0xF7FF,0xDFFF,0x7FFF};
+void read_ecam(unsigned short *v){
+      unsigned char cmd[2];
+      oldt[2]=v[2];
+      i2c.read(addrt[0]+1, (char *)cmd, 2);
+      v[0]=cmd[0]*256u+(unsigned short)cmd[1];
+      i2c.read(addrt[1]+1, (char *)cmd, 2);
+      v[1]=cmd[0]*256u+(unsigned short)cmd[1];
+      i2c.read(addrt[2]+1, (char *)cmd, 2);
+      v[2]=cmd[0]*256u+(unsigned short)cmd[1];
+}
+
+int main() {
+    unsigned constffff=0xffff;
+    unsigned short i=0,j=0xFFFF; 
+     char tmp[2];
+    unsigned short state=0,touche=0;
+     pc.printf("COUCOU1\n");
+    i2c.write(addrt[0],(char *)&j,2); 
+    i2c.write(addrt[1],(char *)&j,2); 
+    i2c.write(addrt[2],(char *)&j,2); 
+   // pc.printf("COUCOU3\n");
+    while (1) {
+           wait(0.1);
+           read_ecam(valt);
+           i=decod_butt(valt);
+            //pc.printf("%4x %4x  %4x  %u",valt[0],valt[1],valt[2],i);
+           if(i<24){
+                if(state==0){                        
+                        state=1;
+                        touche=i;
+                }
+           }else{
+                state=0;
+           }
+           
+           if(touche>0){
+                pc.printf("X %s %2u\n\r",mess[touche-1],(unsigned) touche);
+                if(touche<13){
+                    j=LEDt[touche-1]&0xffff;
+                    tmp[0]= j>>8;
+                    tmp[1]= j&0xff;
+                    j=addrt[LEDt[touche-1]>>16];
+                    i2c.write(addrt[0],(char *)&constffff,2); 
+                    i2c.write(addrt[1],(char *)&constffff,2); 
+                    i2c.write(addrt[2],(char *)&constffff,2); 
+                    i2c.write(j,tmp,2);
+                }
+                touche=0;
+           }
+           
+           /*else{
+                pc.printf("\n\r");
+           }*/
+           
+    /*
+
+        i2c.read(addrt[i]+1, (char *)cmd, 2);
+        pc.printf("%2x%2x   ",cmd[0],cmd[1]);
+        wait(0.1);
+        i=i+1;
+        if (i==3) {
+            pc.printf("\n\r");
+            i=0;
+            scanf("%x",&i);
+            i2c.write(addrt[2],(char *)&i,2);
+            wait(0.3);
+            i=0;
+        }
+        i2c.write(addrt[0],(char *)(tt+i),2);  
+        pc.printf("%u\n\r",i );
+        wait(0.6);
+        i=(i+1)%8;
+       
+        wait(0.1);
+         i2c.read(addrt[0]+1, (char *)&j, 2);
+           pc.printf("COUCOU2\n\r");
+          j=(j<<1);
+          j=j|0x5555;
+          wait_us(70);
+          i2c.write(addrt[2],(char *)&j,2);
+        */
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Mar 13 18:56:29 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912