20160815 計器最新版

Dependencies:   SDFileSystem mbed

Fork of keiki2016verRtos by albatross

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Fusokukei.h Source File

Fusokukei.h

00001 #ifndef FUSOKUKEI_H
00002 #define FUSOKUKEI_H
00003 
00004 #include "mbed.h"
00005 
00006 
00007 #define AIR_K 0.14737
00008 #define AIR_N 1.12
00009 #define AIR_A 1.4314
00010 #define AIR_B 0.209
00011 #define AIR_SUM_NUM 20
00012 #define AIR_BUFFER 30
00013 
00014 float airSpeed = 0.0;
00015 float airSpeed_ave = 0.0;
00016 float airSpeed_max = 0.0;
00017 int air_counter = 0;
00018 float air_sum[AIR_SUM_NUM] = {0.0};
00019 
00020 class Fusokukei{
00021     protected:
00022     
00023     public:      
00024     float make_ave(float s[], int n){
00025         float p = 0;
00026         int i;
00027         for(i = 0; i < n; i++){
00028            p += s[i];    
00029         }
00030         if(n != 0)
00031         return p / n;    
00032         else
00033         return 0;
00034     }
00035     
00036     void calcAirSpeed(float x){
00037           air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)x, 1 / AIR_N);
00038           if(air_counter % AIR_SUM_NUM == 0)
00039             air_counter = 0;
00040           airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM);
00041           //airSpeed = airSpeed_ave*AIR_A+AIR_B;
00042           airSpeed=airSpeed_ave;
00043           if(airSpeed > airSpeed_max)
00044             airSpeed_max = airSpeed;  
00045           air_counter++;
00046       }
00047 };
00048 #endif