prog de test carte eclairage kiffy

Dependencies:   mbed

Committer:
superphil06
Date:
Mon Oct 08 14:36:17 2018 +0000
Revision:
0:967f1b496596
version de base carte eclairage mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
superphil06 0:967f1b496596 1 #include "mbed.h"
superphil06 0:967f1b496596 2
superphil06 0:967f1b496596 3
superphil06 0:967f1b496596 4 #define PERIODE 10
superphil06 0:967f1b496596 5
superphil06 0:967f1b496596 6 DigitalOut myled(LED3);
superphil06 0:967f1b496596 7 DigitalOut AvD(PB_0);
superphil06 0:967f1b496596 8 DigitalOut AvClD(PB_1);
superphil06 0:967f1b496596 9 DigitalOut AvG(PF_0);
superphil06 0:967f1b496596 10 DigitalOut AvClG(PF_1);
superphil06 0:967f1b496596 11 DigitalOut myled3(LED3);
superphil06 0:967f1b496596 12 DigitalOut Buz (PA_8);
superphil06 0:967f1b496596 13 Serial pc(USBTX, USBRX); // tx, rx
superphil06 0:967f1b496596 14
superphil06 0:967f1b496596 15 DigitalIn InClD (PA_1);
superphil06 0:967f1b496596 16 DigitalIn InClG (PA_3);
superphil06 0:967f1b496596 17 DigitalIn InRoute (PA_5);
superphil06 0:967f1b496596 18 DigitalIn InCrois (PA_7);
superphil06 0:967f1b496596 19 DigitalIn InBuz (PA_6);
superphil06 0:967f1b496596 20 int iClD,iClDOld,iClG,iClGOld,iRoute=1,iRouteOld=1,iCrois,iCroisOld,iBuz,iBuzOld;
superphil06 0:967f1b496596 21 int TimCl=0;
superphil06 0:967f1b496596 22 bool bStcld=false,bStclg=false,bSroute=false,bScrois=false,bBuz=false,bTim1=false;// state of output
superphil06 0:967f1b496596 23 int iState=0,iTim1=0;//
superphil06 0:967f1b496596 24
superphil06 0:967f1b496596 25
superphil06 0:967f1b496596 26 enum State { ROUTE,CROIS,CLIGN,OFF,OFF1,OFF2,OFF3 };
superphil06 0:967f1b496596 27 State Light = OFF3;// startup value as ROUTE beam
superphil06 0:967f1b496596 28
superphil06 0:967f1b496596 29
superphil06 0:967f1b496596 30 int giCommodo;
superphil06 0:967f1b496596 31
superphil06 0:967f1b496596 32
superphil06 0:967f1b496596 33 Ticker tick100ms;
superphil06 0:967f1b496596 34
superphil06 0:967f1b496596 35 void lect_commodo (void)
superphil06 0:967f1b496596 36 {giCommodo=giCommodo |(((!InClD)&0X1)+ ((!InClG)&0X1)<<1+((!InRoute)&0X1)<<2+((!InCrois)&0X1)<<3+((!InBuz)&0X1)<<4);
superphil06 0:967f1b496596 37 giCommodo=giCommodo &(((!InClD)&0X1)+ ((!InClG)&0X1)<<1+((!InRoute)&0X1)<<2+((!InCrois)&0X1)<<3+((!InBuz)&0X1)<<4);
superphil06 0:967f1b496596 38
superphil06 0:967f1b496596 39 }
superphil06 0:967f1b496596 40
superphil06 0:967f1b496596 41
superphil06 0:967f1b496596 42 void Gest_Event (void) // gestionnaire d evenement global
superphil06 0:967f1b496596 43 {iClD=InClD.read();iClG=InClG.read();iRoute=InRoute.read();iCrois=InCrois.read();iBuz=InBuz.read();// read input
superphil06 0:967f1b496596 44
superphil06 0:967f1b496596 45
superphil06 0:967f1b496596 46
superphil06 0:967f1b496596 47
superphil06 0:967f1b496596 48 if ((iRoute==0) && (iRouteOld==1)) // passage en mode Route
superphil06 0:967f1b496596 49 { bSroute=true;// switch to high beam
superphil06 0:967f1b496596 50 }
superphil06 0:967f1b496596 51 if ((iRoute==1) && (iRouteOld==0)) // sortie mode Route
superphil06 0:967f1b496596 52 { bSroute=false;// switch to high beam
superphil06 0:967f1b496596 53 }
superphil06 0:967f1b496596 54
superphil06 0:967f1b496596 55 if ((iCrois==0) && (iCroisOld==1)) // passage en mode croisement
superphil06 0:967f1b496596 56 { bScrois=true;// switch to high beam
superphil06 0:967f1b496596 57 }
superphil06 0:967f1b496596 58 if ((iCrois==1) && (iCroisOld==0)) // sortie en mode croisement
superphil06 0:967f1b496596 59 { bScrois=false;// switch to high beam
superphil06 0:967f1b496596 60 }
superphil06 0:967f1b496596 61
superphil06 0:967f1b496596 62 /* if ((iClD==0) && (iClDOld==1)) // cligno D actif
superphil06 0:967f1b496596 63 { bStcld=true;// switch to high beam
superphil06 0:967f1b496596 64 }
superphil06 0:967f1b496596 65 if ((iClD==1) && (iClDOld==0)) // clign D inactift
superphil06 0:967f1b496596 66 { bStcld=false;// switch to high beam
superphil06 0:967f1b496596 67 }
superphil06 0:967f1b496596 68
superphil06 0:967f1b496596 69 if ((iClG==0) && (iClGOld==1)) // cligno g actif
superphil06 0:967f1b496596 70 { bStclg=true;// switch to high beam
superphil06 0:967f1b496596 71 }
superphil06 0:967f1b496596 72 if ((iClG==1) && (iClGOld==0)) // clign g inactift
superphil06 0:967f1b496596 73 { bStclg=false;// switch to high beam
superphil06 0:967f1b496596 74 }
superphil06 0:967f1b496596 75 */
superphil06 0:967f1b496596 76 if ((iBuz==0) && (iBuzOld==1)) // buzzer actif
superphil06 0:967f1b496596 77 { bBuz=true;// switch to high beam
superphil06 0:967f1b496596 78 }
superphil06 0:967f1b496596 79 /* if ((iBuz==1) && (iBuzOld==0)) // buzzer inactift
superphil06 0:967f1b496596 80 { bBuz=false;// switch to high beam
superphil06 0:967f1b496596 81 }*/
superphil06 0:967f1b496596 82
superphil06 0:967f1b496596 83 if (iTim1>0){iTim1-- ; bTim1=true;}
superphil06 0:967f1b496596 84 else bTim1=false;
superphil06 0:967f1b496596 85
superphil06 0:967f1b496596 86
superphil06 0:967f1b496596 87 // update old event value for next time
superphil06 0:967f1b496596 88 iBuzOld=iBuz;
superphil06 0:967f1b496596 89 iClGOld=iClG;
superphil06 0:967f1b496596 90 iClDOld=iClD;
superphil06 0:967f1b496596 91 iCroisOld=iCrois;
superphil06 0:967f1b496596 92 iRouteOld=iRoute;
superphil06 0:967f1b496596 93 }
superphil06 0:967f1b496596 94
superphil06 0:967f1b496596 95 void init_gene(void)
superphil06 0:967f1b496596 96 {Buz=0;
superphil06 0:967f1b496596 97 AvD=0;// front beam OFF
superphil06 0:967f1b496596 98 AvClD=0;
superphil06 0:967f1b496596 99 AvG=0;// front beam OFF
superphil06 0:967f1b496596 100 AvClG=0;
superphil06 0:967f1b496596 101
superphil06 0:967f1b496596 102 }
superphil06 0:967f1b496596 103
superphil06 0:967f1b496596 104
superphil06 0:967f1b496596 105
superphil06 0:967f1b496596 106 void Tick100ms_(void)
superphil06 0:967f1b496596 107 {
superphil06 0:967f1b496596 108
superphil06 0:967f1b496596 109 // iClD=InClD.read();iClG=InClG.read();iRoute=InRoute.read();iCrois=InCrois.read();iBuz=InBuz.read();
superphil06 0:967f1b496596 110 Gest_Event();// call event manager
superphil06 0:967f1b496596 111
superphil06 0:967f1b496596 112
superphil06 0:967f1b496596 113
superphil06 0:967f1b496596 114
superphil06 0:967f1b496596 115
superphil06 0:967f1b496596 116 switch (iState)
superphil06 0:967f1b496596 117 {
superphil06 0:967f1b496596 118 case OFF3:
superphil06 0:967f1b496596 119 AvD=0;AvG=0;// front beam off
superphil06 0:967f1b496596 120 if (bSroute==true )
superphil06 0:967f1b496596 121 { iState=ROUTE;
superphil06 0:967f1b496596 122 }
superphil06 0:967f1b496596 123
superphil06 0:967f1b496596 124
superphil06 0:967f1b496596 125
superphil06 0:967f1b496596 126 /* else{if (bRoute==true) &&(bTim1==true))
superphil06 0:967f1b496596 127 { iState=CLIGN; iTim1=30*PERIODE;}*/
superphil06 0:967f1b496596 128 break;
superphil06 0:967f1b496596 129
superphil06 0:967f1b496596 130 case ROUTE:
superphil06 0:967f1b496596 131 AvD=1;AvG=1;// front beam on
superphil06 0:967f1b496596 132 if (bSroute==false)
superphil06 0:967f1b496596 133 { iTim1=(int) 30*PERIODE;
superphil06 0:967f1b496596 134 iState=OFF1; }
superphil06 0:967f1b496596 135 break;
superphil06 0:967f1b496596 136
superphil06 0:967f1b496596 137 case OFF1:
superphil06 0:967f1b496596 138 AvD=0;AvG=0;// front beam off
superphil06 0:967f1b496596 139 if ((bSroute==true) &&(bTim1==true))
superphil06 0:967f1b496596 140 { iState=CROIS; }
superphil06 0:967f1b496596 141 if ((bSroute==true) &&(bTim1==false))
superphil06 0:967f1b496596 142 {iState=ROUTE;}
superphil06 0:967f1b496596 143
superphil06 0:967f1b496596 144 case CROIS:
superphil06 0:967f1b496596 145 AvD=1;AvG=1;// front beam on
superphil06 0:967f1b496596 146 if (bSroute==false)
superphil06 0:967f1b496596 147 { iState=OFF2;
superphil06 0:967f1b496596 148 iTim1=30*PERIODE;}
superphil06 0:967f1b496596 149
superphil06 0:967f1b496596 150 break;
superphil06 0:967f1b496596 151
superphil06 0:967f1b496596 152 case OFF2:
superphil06 0:967f1b496596 153 AvD=0;AvG=0;// front beam off
superphil06 0:967f1b496596 154 if ((bSroute==true) &&(bTim1==false))
superphil06 0:967f1b496596 155 { iState=ROUTE; }
superphil06 0:967f1b496596 156 if ((bSroute==true) &&(bTim1==true))
superphil06 0:967f1b496596 157 {iState=CLIGN;}
superphil06 0:967f1b496596 158 break;
superphil06 0:967f1b496596 159
superphil06 0:967f1b496596 160 case CLIGN:
superphil06 0:967f1b496596 161 AvD=1;AvG=1;// front beam on
superphil06 0:967f1b496596 162 if (bSroute==false)
superphil06 0:967f1b496596 163 { iState=OFF3;
superphil06 0:967f1b496596 164 iTim1=30*PERIODE; }
superphil06 0:967f1b496596 165
superphil06 0:967f1b496596 166 break;
superphil06 0:967f1b496596 167
superphil06 0:967f1b496596 168
superphil06 0:967f1b496596 169 }
superphil06 0:967f1b496596 170
superphil06 0:967f1b496596 171 if (iBuz==0)// commande klaxon
superphil06 0:967f1b496596 172 Buz=1;
superphil06 0:967f1b496596 173 else Buz=0;
superphil06 0:967f1b496596 174
superphil06 0:967f1b496596 175
superphil06 0:967f1b496596 176
superphil06 0:967f1b496596 177 // allumage clignotant
superphil06 0:967f1b496596 178 if (TimCl==4)// 0.5s elapsed
superphil06 0:967f1b496596 179 {TimCl=0;
superphil06 0:967f1b496596 180 // clignotant droit
superphil06 0:967f1b496596 181 if (iClD==0) // clid d actif
superphil06 0:967f1b496596 182 if (bStcld==false) //cld off
superphil06 0:967f1b496596 183 {bStcld=true; AvClD=1;}
superphil06 0:967f1b496596 184 else
superphil06 0:967f1b496596 185 {bStcld=false; AvClD=0;}
superphil06 0:967f1b496596 186 else
superphil06 0:967f1b496596 187 { bStcld=false; AvClD=0;}//
superphil06 0:967f1b496596 188 // clignotant gauche
superphil06 0:967f1b496596 189 if (iClG==0) // clig d actif
superphil06 0:967f1b496596 190 if (bStclg==false) //cld off
superphil06 0:967f1b496596 191 {bStclg=true; AvClG=1;}
superphil06 0:967f1b496596 192 else
superphil06 0:967f1b496596 193 {bStclg=false; AvClG=0;}
superphil06 0:967f1b496596 194 else
superphil06 0:967f1b496596 195 { bStclg=false; AvClG=0;}//
superphil06 0:967f1b496596 196
superphil06 0:967f1b496596 197
superphil06 0:967f1b496596 198
superphil06 0:967f1b496596 199
superphil06 0:967f1b496596 200 }
superphil06 0:967f1b496596 201 else TimCl++;
superphil06 0:967f1b496596 202
superphil06 0:967f1b496596 203
superphil06 0:967f1b496596 204
superphil06 0:967f1b496596 205
superphil06 0:967f1b496596 206
superphil06 0:967f1b496596 207 }
superphil06 0:967f1b496596 208
superphil06 0:967f1b496596 209
superphil06 0:967f1b496596 210 int main() {
superphil06 0:967f1b496596 211
superphil06 0:967f1b496596 212
superphil06 0:967f1b496596 213 char cChoix;
superphil06 0:967f1b496596 214 tick100ms.attach(&Tick100ms_,(1/(float)PERIODE)); // main ticker 100ms
superphil06 0:967f1b496596 215 init_gene();
superphil06 0:967f1b496596 216
superphil06 0:967f1b496596 217
superphil06 0:967f1b496596 218 while(cChoix!='q' and cChoix!='Q')
superphil06 0:967f1b496596 219 {pc.printf(" veuillez saisir un choix parmi la liste proposee: \n");
superphil06 0:967f1b496596 220 pc.printf("a: on/off avD \n");
superphil06 0:967f1b496596 221 pc.printf("b: on/off avG \n");
superphil06 0:967f1b496596 222 pc.printf("c: on/off ClavD \n");
superphil06 0:967f1b496596 223 pc.printf("d: on/off ClAvG \n");
superphil06 0:967f1b496596 224 pc.printf("e: on/off Buz \n");
superphil06 0:967f1b496596 225 pc.printf("f: lecture commodo \n");
superphil06 0:967f1b496596 226 pc.printf(" q:quitter \n");
superphil06 0:967f1b496596 227
superphil06 0:967f1b496596 228 /************* multithreading : main thread need to sleep in order to allow web response */
superphil06 0:967f1b496596 229 while (pc.readable()==0) // determine if char availabler
superphil06 0:967f1b496596 230 {//Thread::wait(10);
superphil06 0:967f1b496596 231 wait_ms(10);
superphil06 0:967f1b496596 232
superphil06 0:967f1b496596 233 } // wait 10 until char available on serial input
superphil06 0:967f1b496596 234
superphil06 0:967f1b496596 235 /************* end of main thread sleep ****************/
superphil06 0:967f1b496596 236
superphil06 0:967f1b496596 237 pc.scanf(" %c",&cChoix);
superphil06 0:967f1b496596 238 switch (cChoix){
superphil06 0:967f1b496596 239 case 'a':
superphil06 0:967f1b496596 240 AvD=!AvD;
superphil06 0:967f1b496596 241 break;
superphil06 0:967f1b496596 242 case 'b':
superphil06 0:967f1b496596 243 AvG=!AvG;
superphil06 0:967f1b496596 244 break;
superphil06 0:967f1b496596 245 case 'c':
superphil06 0:967f1b496596 246 AvClD=!AvClD;
superphil06 0:967f1b496596 247 break;
superphil06 0:967f1b496596 248 case 'd':
superphil06 0:967f1b496596 249 AvClG=!AvClG;
superphil06 0:967f1b496596 250 break;
superphil06 0:967f1b496596 251
superphil06 0:967f1b496596 252 case 'e':
superphil06 0:967f1b496596 253 Buz=!Buz;
superphil06 0:967f1b496596 254 break;
superphil06 0:967f1b496596 255 case 'f':
superphil06 0:967f1b496596 256 lect_commodo ();
superphil06 0:967f1b496596 257 // pc.printf(" commodo=%2X \n",giCommodo);
superphil06 0:967f1b496596 258 pc.printf ("clD:%d lcG:%d Rou:%d Crois%d Buz:%d \n",InClD.read(),InClG.read(),InRoute.read(),InCrois.read(),InBuz.read());
superphil06 0:967f1b496596 259 break;
superphil06 0:967f1b496596 260
superphil06 0:967f1b496596 261 case 'q':
superphil06 0:967f1b496596 262 break;
superphil06 0:967f1b496596 263 }
superphil06 0:967f1b496596 264 } // end while
superphil06 0:967f1b496596 265
superphil06 0:967f1b496596 266
superphil06 0:967f1b496596 267
superphil06 0:967f1b496596 268 }
superphil06 0:967f1b496596 269
superphil06 0:967f1b496596 270