squelette de demarrage projet ERS3 IUT NICE GEII

Dependencies:   mbed bloc_io mbed-rtos html EthernetInterface

Revision:
2:153d417b318b
Parent:
1:545a3d6b5933
Child:
3:a659bef8f6a5
--- a/main.cpp	Tue Oct 15 07:14:47 2019 +0000
+++ b/main.cpp	Tue Oct 22 09:18:45 2019 +0000
@@ -10,7 +10,7 @@
 #define DELTA_T 0.1F // speed measurement counting period
 DigitalOut valid(p21);//rajout
 void Init(int);//rajout
-void lecture(void);
+void lecture(void);//permet lecture intern du pld
 Bloc_IO MyPLD(p25,p26,p5,p6,p7,p8,p9,p10,p23,p24);// instantiate object needed to communicate with PLD
 // analog input connected to mbed
 // valid pmw mbed pin
@@ -49,8 +49,8 @@
 DigitalOut led4(LED4); // blink when can message is received
 
 
-
-
+AnalogIn poignee (p17);
+FILE*pfile=NULL;
 
 //************ local function prototypes *******************
 
@@ -117,11 +117,23 @@
 //*************************** main function *****************************************
 int main()
 {
-    int data_in;
-    char cChoix=0;
+    float min ;
+    float max;
+    //int x;
+    //int data_in;
+    char cChoix;
     valid.write(0);
     MyPLD.write(0);
     valid.write(1);
+    float gaz;
+    FILE* pfile = fopen ("/local/ragas.txt","r");
+    if(pfile!=NULL) {
+        fscanf(pfile,"min=%f max=%f", &min,&max);
+        pc.printf("\n min=%f max=%f", min,max);
+    } else {
+        pc.printf("erreur");
+    }
+    fclose(pfile); // close file
 
 
 
@@ -146,11 +158,14 @@
 //Thread CanThread(CAN_REC_THREAD);// create and launch can receiver  thread
 //********************* end can bus section *****************************************************
 
-    
+
     while(cChoix!='q' and cChoix!='Q' /*and cChoix='c'*/) {
+
         pc.printf(" veuillez saisir un choix parmi la liste proposee: \r\n");
         pc.printf(" a:saisie consigne pwm \r\n");
         pc.printf(" c:lecture interne \r\n");
+        pc.printf(" b:calibration \r\n");
+        pc.printf(" g:ccontrole \r\n");
         pc.printf(" q:quitter \r\n");
 
         /************* multithreading : main thread need to sleep in order to allow web response */
@@ -162,81 +177,59 @@
         pc.scanf(" %c",&cChoix);
         switch (cChoix) {
             case 'a':
-                
+
                 printf("donne moi une valeur de pwmref entre 0 et 255:");
                 scanf("%d",&valref);
-                if(valref<=255)
-                {
-                MyPLD.write(valref);
-                }
-                else
-                {
+                if(valref<=255) {
+                    MyPLD.write(valref);
+                } else {
                     valref=0;
                     MyPLD.write(valref);
                     printf("valeur entre 0 et 255");
-                    }
+                }
                 break;
             case 'c' :
                 lecture();
-                if((MyPLD.read()  and 4)== 4){
-                    pc.printf("Frein inactif\n\r");
-                    }
-                else{
-                    printf("Frein actif\n\r");
-                }
-                if((MyPLD.read()  and 8==8)){
-                    pc.printf("FLTA actif\n\r");
-                }
-                else{
-                    printf("FLTA inactif\n\r");
-                }
-                if((MyPLD.read()  and 16)==16){
-                    pc.printf("overcurrent inactif\n\r");
-                }
-                else{
-                    printf("avercurrent actif\n\r");
-                }
-                if((MyPLD.read()  and 32)==32){
-                    pc.printf("direction avant\n\r");
-                }
-                else{
-                    printf("direction arriere\n\r");
-                }
-                if((MyPLD.read()  and 64)==64){
-                    pc.printf("hallC a 1\n\r");
-                }
-                else{
-                    printf("hallC a 0\n\r");
-                }
-                if((MyPLD.read()  and 128)==128){
-                    pc.printf("hallB a 1\n\r");
-                }
-                else{
-                    printf("hallB a 0\n\r");
-                }
-                if((MyPLD.read()  and 256)==256){
-                    pc.printf("hallA a 1\n\r");
-                }
-                else{
-                    printf("hallA a 0\n\r");
-                }
-                
+                break;
+            case 'b':
+
+
+                printf("mettre au  min et appuyer sur une touche quand termine\n\r");
+                getchar();
+                min=poignee.read();
+                printf("min=%f\n\r",min);
+                printf("vmettre au max  max et appuyer sur une touche quand termine\n\r");
+                getchar();
+                max=poignee.read();
+                printf("max%f\n\r",max);
+                FILE* pfile = fopen ("/local/ragas.txt","w");
+                if(pfile!=NULL)
+                    fprintf(pfile,"min=%f max=%f", min,max);
+                fclose(pfile); // close file
                 break;
-            case 'q':
-            valid.write(0);
-    MyPLD.write(0);
-    
+            case 'g':
+            
+                gaz=poignee.read();
+                MyPLD.write(((255/(max-min))*gaz)-(255-(min*(255)/(max-min))));
+                getchar();
                 break;
-            /*      case 'q':
-      
-frein.read();
-DigitalIn flta.read();
-DigitalIn overcurrent.read();
-DigitalIn direction.read();
- HALLA.read();
- HALLB.read();
- HALLC.read();
-                break;*/
+
+
+            case 'q':
+                valid.write(0);
+                MyPLD.write(0);
+
+                break;
+                /*      case 'q':
+
+                frein.read();
+                DigitalIn flta.read();
+                DigitalIn overcurrent.read();
+                DigitalIn direction.read();
+                HALLA.read();
+                HALLB.read();
+                HALLC.read();
+                    break;*/
         }
     } // end while
 
@@ -248,92 +241,40 @@
 } // end main
 
 
-void lecture (void){
-    if((MyPLD.read()  and 4)== 4){
-                    pc.printf("Frein inactif\n\r");
-                    }
-                else{
-                    printf("Frein actif\n\r");
-                }
-                if((MyPLD.read()  and 8==8)){
-                    pc.printf("FLTA actif\n\r");
-                }
-                else{
-                    printf("FLTA inactif\n\r");
-                }
-                if((MyPLD.read()  and 16)==16){
-                    pc.printf("overcurrent inactif\n\r");
-                }
-                else{
-                    printf("avercurrent actif\n\r");
-                }
-                if((MyPLD.read()  and 32)==32){
-                    pc.printf("direction avant\n\r");
-                }
-                else{
-                    printf("direction arriere\n\r");
-                }
-                if((MyPLD.read()  and 64)==64){
-                    pc.printf("hallC a 1\n\r");
-                }
-                else{
-                    printf("hallC a 0\n\r");
-                }
-                if((MyPLD.read()  and 128)==128){
-                    pc.printf("hallB a 1\n\r");
-                }
-                else{
-                    printf("hallB a 0\n\r");
-                }
-                if((MyPLD.read()  and 256)==256){
-                    pc.printf("hallA a 1\n\r");
-                }
-                else{
-                    printf("hallA a 0\n\r");
-                }
+void lecture (void)
+{
+    int tout = MyPLD.read();
+    int Hall= tout & 7;
+    int FLTA = tout & 16;
+    int direction = tout & 8;
+    int overcurrent = tout &64;
+    int frein = tout &32;  
+    
+    pc.printf("Secteur=%d \t FLTA=%d \t Direction=%d \t Frein=%d \t Overcurrent = %d\n\r",Hall,FLTA,direction,frein,overcurrent);
+    
+    if(direction==8) {                                             //direction 1=av  0=ar   
+        pc.printf("direction avant\n\r");
+    } else {
+        printf("direction arriere\n\r");
+    }
+    
+    if(overcurrent==64) {                                           //overcurrent actif=0
+        pc.printf("surcharge de courant inactif\n\r");
+    } else {
+        printf("surcharge de courant actif\n\r");
+    }
+    
+    if(FLTA == 16) {                                               //FLTA actif=1
+        pc.printf("FLTA actif\n\r");
+    } else {
+        printf("FLTA inactif\n\r");
+    }
+    
+    if(frein == 32) {                                              //brake actif=0
+        pc.printf("Frein inactif\n\r");
+    } else {
+        pc.printf("Frein actif\n\r");
+    }
 }
-/*void Init(int r)
-{
-    valid.write(r);
-    //MyPLD.write(valref);
-
-}*/
 
 
- /*void modulo (int a)
-    {
-        char x;
-        if(a==0)
-        {
-        x=0;
-          MyPLD.write(x);    a
-         
-           }
-           if(a==64)
-           {
-           x=64;
-         MyPLD.write(x);    
-         
-           }
-            if(a==96)
-           {
-           x=96;
-         MyPLD.write(x);    
-         
-           }
-            if(a==112)
-           {
-           x=112;
-          MyPLD.write(x);    
-         
-           } if(a==80)
-           {
-           x=80;
-          MyPLD.write(x);    
-         
-           } if(a==48)
-           {
-           x=48;
-          MyPLD.write(x);    
-         
-           }}*/
\ No newline at end of file