Windshape control / Mbed OS Controle_ventilo_ethernet_v1_2_4

Fork of Controle_ventilo_ethernet_v1_2_4 by Sergio Márquez

Revision:
11:aa1cb8df15dc
Parent:
10:617194438c6b
Child:
12:b9ac1a23ac41
--- a/main.cpp	Fri Jun 09 17:30:37 2017 +0000
+++ b/main.cpp	Wed Jun 14 16:16:54 2017 +0000
@@ -2,20 +2,27 @@
 #include "EthernetInterface.h"
 #include "SocketAddress.h"
 #include "UDPSocket.h"
+#include "lwip/ip.h"
+#include "lwip/api.h"
 #include <string.h>
 
 const char* ECHO_SERVER_ADDRESS = "131.215.118.148";    // addresse du PC home "192.168.1.2" sergio "169.254.61.104" or "129.194.185.33" or "192.168.137.1" liotard "10.136.134.73"
 const int ECHO_SERVER_PORT = 1039;
+//const int BROADCAST_PORT = 58083;
 
 Timer t;
+Timer t1;
+Timer t2;
+Timer t3;
 DigitalOut PSU_DEAD(D8); // Kill PSU
 DigitalOut PSU_OFF(D9); // Power On PSU
 
 volatile long int count[18] = {0};
-int tours = 10;
+int tours = 5;
 double rpm[18] = {0.0};
 bool readRpm = 0;
 bool readAllRpm = 0;
+bool skipRead = 0;
 
 // Front fans
 //PwmOut frontFans[9]={PB_11,PE_14,PE_9,PB_3,PB_15,PB_6,PB_13,PE_5,PC_8}; // PE_11 also possible for front fan n°5
@@ -25,8 +32,8 @@
 PwmOut frontFans[9]={PC_6,PB_5,PB_8,PC_8,PE_5,PB_1,PE_9,PB_10,PE_12};
 PwmOut rearFans[9]={PB_15,PB_3,PB_9,PC_9,PE_6,PD_13,PB_11,PE_10,PE_14};
 
-PinName counterFront[9]={PC_10,PC_12,PD_7,PD_0,PE_3,PF_0,PE_4,PD_6,PB_2};
-PinName counterRear[9]={PG_2,PG_3,PF_10,PF_9,PF_1,PG_0,PD_2,PD_11,PF_4};
+PinName counterFront[9]={PA_3,PC_3,PF_5,PF_7,PE_3,PG_1,PE_4,PC_2,PB_2};
+PinName counterRear[9]={PC_0,PF_3,PF_10,PF_9,PE_0,PG_0,PF_8,PD_11,PF_4};
 
 DigitalOut greenLed(LED1);
 DigitalOut bleuLed(LED2);
@@ -48,7 +55,7 @@
 void countFunction();
 void countFunction2();
 void countFunction3();
-void countFunction4();
+/*void countFunction4();
 void countFunction5();
 void countFunction6();
 void countFunction7();
@@ -62,14 +69,12 @@
 void countFunction15();
 void countFunction16();
 void countFunction17();
-void countFunction18();
+void countFunction18();*/
 
 int main(int argc, char *argv[]) {
 
     PSU_OFF = true;
     
-    //InterruptIn teesst[2](PD_13, PD_15);
-    
     for(int i = 0; i < 9; i++){
         frontFans[i].period_ms(10);
         rearFans[i].period_ms(10);
@@ -211,128 +216,69 @@
             //sock.sendto(echo_server, out_bufferR, sizeof(out_bufferR));
             break;
             
-            case 10:{
-                InterruptIn rpmIn(counterRear[0]);
-                count[0] = 0;
-                rpmIn.rise(&countFunction);
-                t.reset();
-                t.start();
-                while(t.read_ms() < 1001);
-                t.stop();
-                rpmIn.rise(NULL);
-                double rev = (double)count[0];
-                double rpm1 = rev*30;
-                printf("%lf\n", rpm1);
-            }
-            break;
-            
-            case 11:{
-                for(int i = 0; i < fan_len; i++){
-                    InterruptIn rpmIn(counterRear[fan[i] - 1]);
-                    t.reset();
-                    count[0] = 0;
-                    rpmIn.rise(&countFunction);
-                    while(count[0] == 0);
-                    t.start();
-                    while(count[0] <= (2*tours)+1);             // changer ligne 15 pour augmenter ou diminuer le nombre d'interrupt (tour)
-                    t.stop();                                   // mettre count[0] <= 2 pour temps entre 2 pulses 
-                    rpmIn.rise(NULL);
-                    double rpm1 = (60000*tours)/t.read_ms();    // mettre 30000/t.read_ms() pour convertion entre 2 pulses
-                    printf("rpm : %lf\n", rpm1);
-                }
-            }
-            break;
-            
-            case 12:{
-                while(readAllRpm == 0) {
-                    if(readRpm == 0) {
-                        InterruptIn RI1(counterFront[0]);
-                        InterruptIn RI2(counterFront[1]);
-                        InterruptIn RI3(counterFront[2]);
-                        InterruptIn RI4(counterFront[3]);
-                        InterruptIn RI5(counterFront[4]);
-                        InterruptIn RI6(counterFront[5]);
-                        InterruptIn RI7(counterFront[6]);
-                        InterruptIn RI8(counterFront[7]);
-                        InterruptIn RI9(counterFront[8]);
-                        for(int i = 0; i < 9; i++) {
-                            count[i] = 0;
+            case 14:{
+                for(int i = 0; i < 9; i++){
+                    InterruptIn rpmIn1(counterRear[i]);
+                    InterruptIn rpmIn2(counterFront[i]);
+                    
+                    t1.reset();
+                    t2.reset();
+                    
+                    count[1] = 0;
+                    count[2] = 0;
+                    
+                    rpmIn1.rise(&countFunction2);
+                    printf("Hello\n");
+                    
+                    while(count[1] == 0){
+                        t3.reset();
+                        t3.start();
+                        if((t3.read_ms() >= 200) && (count[1] == 0)){
+                            skipRead = 1;
+                        }
+                        //printf("Hello1\n");
+                        if(skipRead == 1){
+                            printf("Hello2\n");
+                            t3.stop();
+                            break;
                         }
-                        RI1.rise(&countFunction);
-                        RI2.rise(&countFunction2);
-                        RI3.rise(&countFunction3);
-                        RI4.rise(&countFunction4);
-                        RI5.rise(&countFunction5);
-                        RI6.rise(&countFunction6);
-                        RI7.rise(&countFunction7);
-                        RI8.rise(&countFunction8);
-                        RI9.rise(&countFunction9);
-                        t.reset();
-                        t.start();
-                        while(t.read_ms() < 501);
-                        t.stop();
-                        RI1.rise(NULL);
-                        RI2.rise(NULL);
-                        RI3.rise(NULL);
-                        RI4.rise(NULL);
-                        RI5.rise(NULL);
-                        RI6.rise(NULL);
-                        RI7.rise(NULL);
-                        RI8.rise(NULL);
-                        RI9.rise(NULL);
-                        for(int i = 0; i < 9; i++) {
-                            double rev1[9] = {0.0};
-                            rev1[i] = (double)count[i];
-                            rpm[i] = rev1[i]*60;
-                            printf("rpm%d : %lf\n", i, rpm[i]);
+                    }
+                    t1.start();
+                    printf("Hello3\n");
+                    while(count[1] <= (2*tours)+1){
+                        if(skipRead == 1){
+                            printf("Hello4\n");
+                            break;
+                        }
+                    }
+                    skipRead = 0;
+                    t1.stop();
+                    rpmIn1.rise(NULL);
+                    rpmIn2.rise(&countFunction3);
+                    while(count[2] == 0){
+                        t3.reset();
+                        t3.start();
+                        if(t3.read_ms() >= 200){
+                            skipRead = 1;
                         }
-                        readRpm = 1;
-                    } else {
-                        InterruptIn RI1(counterRear[0]);
-                        InterruptIn RI2(counterRear[1]);
-                        InterruptIn RI3(counterRear[2]);
-                        InterruptIn RI4(counterRear[3]);
-                        InterruptIn RI5(counterRear[4]);
-                        InterruptIn RI6(counterRear[5]);
-                        InterruptIn RI7(counterRear[6]);
-                        InterruptIn RI8(counterRear[7]);
-                        InterruptIn RI9(counterRear[8]);
-                        for(int i = 0; i < 9; i++) {
-                            count[9+i] = 0;
+                        if(skipRead == 1){
+                            t3.stop();
+                            break;
                         }
-                        RI1.rise(&countFunction10);
-                        RI2.rise(&countFunction11);
-                        RI3.rise(&countFunction12);
-                        RI4.rise(&countFunction13);
-                        RI5.rise(&countFunction14);
-                        RI6.rise(&countFunction15);
-                        RI7.rise(&countFunction16);
-                        RI8.rise(&countFunction17);
-                        RI9.rise(&countFunction18);
-                        t.reset();
-                        t.start();
-                        while(t.read_ms() < 501);
-                        t.stop();
-                        RI1.rise(NULL);
-                        RI2.rise(NULL);
-                        RI3.rise(NULL);
-                        RI4.rise(NULL);
-                        RI5.rise(NULL);
-                        RI6.rise(NULL);
-                        RI7.rise(NULL);
-                        RI8.rise(NULL);
-                        RI9.rise(NULL);
-                        for(int i = 0; i < 9; i++) {
-                            double rev1[9] = {0.0};
-                            rev1[i] = (double)count[9+i];
-                            rpm[9+i] = rev1[i]*60;
-                            printf("rpm%d : %lf\n", 9+i, rpm[9+i]);
+                    }
+                    t2.start();
+                    while(count[2] <= (2*tours)+1){
+                        if(skipRead == 1){
+                            break;
                         }
-                        readAllRpm = 1;
-                        readRpm = 0;
                     }
+                    skipRead = 0;
+                    t2.stop();
+                    rpmIn2.rise(NULL);
+                    double rpm1 = (60000*tours)/t1.read_ms();
+                    double rpm2 = (60000*tours)/t2.read_ms();
+                    printf("rpm1 : %lf\nrpm2 : %lf\n", rpm1, rpm2);
                 }
-                readAllRpm = 0;
             }
             break;
             
@@ -396,7 +342,7 @@
     count[2]++;
 }
 
-void countFunction4(){
+/*void countFunction4(){
     count[3]++;
 }
 
@@ -454,4 +400,4 @@
 
 void countFunction18(){
     count[17]++;
-}
+}*/
\ No newline at end of file