squelette de demarrage projet ERS3 IUT NICE GEII

Dependencies:   mbed bloc_io mbed-rtos html EthernetInterface

Revision:
3:a659bef8f6a5
Parent:
2:153d417b318b
Child:
4:08e917c15d87
--- a/main.cpp	Tue Oct 22 09:18:45 2019 +0000
+++ b/main.cpp	Tue Oct 22 14:46:28 2019 +0000
@@ -17,6 +17,17 @@
 Serial pc(USBTX, USBRX); // tx, rx
 // Top_Hall Pin
 int valref=0 ;//rajout
+float min ;
+float max;
+int tout;
+int Hall;
+int direction;
+int FLTA;
+int frein;
+int overcurrent;
+float gaz;
+
+
 //void modulo (int );
 
 /************ persistent file parameters section *****************/
@@ -51,6 +62,11 @@
 
 AnalogIn poignee (p17);
 FILE*pfile=NULL;
+Ticker guidon;
+
+
+void task1(void);
+int mode ;
 
 //************ local function prototypes *******************
 
@@ -117,8 +133,6 @@
 //*************************** main function *****************************************
 int main()
 {
-    float min ;
-    float max;
     //int x;
     //int data_in;
     char cChoix;
@@ -126,6 +140,8 @@
     MyPLD.write(0);
     valid.write(1);
     float gaz;
+    mode=0;
+
     FILE* pfile = fopen ("/local/ragas.txt","r");
     if(pfile!=NULL) {
         fscanf(pfile,"min=%f max=%f", &min,&max);
@@ -134,7 +150,7 @@
         pc.printf("erreur");
     }
     fclose(pfile); // close file
-
+    guidon.attach(&task1,0.05);
 
 
 
@@ -165,7 +181,8 @@
         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(" m:mode \r\n");
         pc.printf(" q:quitter \r\n");
 
         /************* multithreading : main thread need to sleep in order to allow web response */
@@ -184,7 +201,7 @@
                     MyPLD.write(valref);
                 } else {
                     valref=0;
-                    MyPLD.write(valref);
+                    //MyPLD.write(valref);
                     printf("valeur entre 0 et 255");
                 }
                 break;
@@ -192,8 +209,6 @@
                 lecture();
                 break;
             case 'b':
-
-
                 printf("mettre au  min et appuyer sur une touche quand termine\n\r");
                 getchar();
                 min=poignee.read();
@@ -207,18 +222,18 @@
                     fprintf(pfile,"min=%f max=%f", min,max);
                 fclose(pfile); // close file
                 break;
-            case 'g':
-            
-                gaz=poignee.read();
-                MyPLD.write(((255/(max-min))*gaz)-(255-(min*(255)/(max-min))));
-                getchar();
-                break;
 
 
+            case 'm':
+                do {
+                    printf("choisissez un mode :0 pour automatique et 1 pour manuel");
+                    scanf("%d",&mode);
+                } while(mode<0 || mode >1);
+                break ;
             case 'q':
                 valid.write(0);
                 MyPLD.write(0);
-
+                guidon.detach();
                 break;
                 /*      case 'q':
 
@@ -243,33 +258,32 @@
 
 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;  
-    
+    tout = MyPLD.read();
+    Hall= tout & 7;
+    direction = tout & 8;
+    FLTA = tout & 16;
+    frein = tout &32;
+    overcurrent = tout &64;
     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   
+
+    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 {
@@ -278,3 +292,32 @@
 }
 
 
+
+void task1(void)    //0.05seconde
+{
+    tout = MyPLD.read();
+    Hall= tout & 7;
+    direction = tout & 8;
+    FLTA = tout & 16;
+    frein = tout &32;
+    overcurrent = tout &64;
+    
+     int val=0;
+    gaz=poignee.read();
+    float valPoignee=((255/(max-min))*gaz)-(min*(255)/(max-min));
+    if(mode==0) {                         //mode auto
+        if(frein==0) {                    //frein actif
+            val=0;
+        } else  {            //frein inactif
+            if(val<valPoignee) {    //incrémentation
+                val=val+1;
+            } else {                //bonne valeur
+                val=valPoignee;
+            }
+        }
+    } else {             //mode manuel
+        val=valref;      //valeurs dans le case "a"
+    }
+    MyPLD.write(val);
+}
+