example code using statis library for temperature measurement with LM35 and LM335

Dependencies:   mbed statis

Revision:
4:ffc39af07ade
Parent:
3:0e06300940cd
Child:
5:0b3569945178
--- a/statis.cpp	Thu Nov 22 14:47:20 2012 +0000
+++ b/statis.cpp	Thu Nov 22 15:57:35 2012 +0000
@@ -17,17 +17,17 @@
 #undef DEBUG
 
 #include <debug.h>
-#include <sys.h>
 #include <math.h>
 #include <stdlib.h>             // cf. qsort(),fabs()
 
 // ring
-#include <ring.h>     // cf. statis.h
+//#include "include/ring.h"     // cf. statis.h
 
 // statis
-#include <bitmsk.h>     // cf. statis.h
+
+//#include "include/bitmsk.h"     // cf. statis.h
 #define _STATIS
-#include <statis.h>
+#include "include/statis.h"
 #undef  _STATIS
 
 /*****************************************************************************
@@ -57,7 +57,7 @@
  *****************************************************************************/
 static int compare( const void *a,const void *b )
 {
- register double c = ((Mediane_item *)a)->valeur - ((Mediane_item *)b)->valeur;
+ register float c = ((Mediane_item *)a)->valeur - ((Mediane_item *)b)->valeur;
 
  return( ( c == 0.0 ) ? 0 : ( ( c > 0.0 ) ? 1 : -1 ) );
 }
@@ -112,7 +112,7 @@
 
 /*****************************************************************************
  *****************************************************************************/
-Mediane_circ::Mediane_circ( double a_maxi )
+Mediane_circ::Mediane_circ( float a_maxi )
 {
  moitie = ( maxi = fabs( a_maxi ) ) / 2;
 }
@@ -123,7 +123,7 @@
 
 /*****************************************************************************
  *****************************************************************************/
-booleen Statis_data::verifie( double &val )
+booleen Statis_data::verifie( float &val )
 {
  if( ( borne_inf == borne_sup ) || ( val >= borne_inf && val <= borne_sup ) )
    return( TRUE );
@@ -165,7 +165,7 @@
  }
  moy = 0;
  for( unsigned i = 0; i < n_elem; moy += ring.list[ i++ ] );
- moy /= (double) n_elem;
+ moy /= (float) n_elem;
  return( verifie( moy ) );
 }
 
@@ -173,10 +173,10 @@
  *****************************************************************************/
 booleen Statis_data::ecart_type( void )
 {
- double      somme_xi_carre = 0.0,
+ float      somme_xi_carre = 0.0,
              somme_xi       = 0.0,
              x_bar          = 0.0;
- double *ptxi;
+ float *ptxi;
  unsigned    i;
 
  switch( n_elem ) {
@@ -189,8 +189,8 @@
                somme_xi       += *ptxi;
                somme_xi_carre += *ptxi * *ptxi;
              }
-             x_bar = somme_xi / (double) n_elem;
-             ecart = sqrt( fabs( somme_xi_carre / (double) n_elem -
+             x_bar = somme_xi / (float) n_elem;
+             ecart = sqrt( fabs( somme_xi_carre / (float) n_elem -
                                  x_bar * x_bar                      ) );
              return( TRUE );
  }
@@ -223,7 +223,7 @@
 
 /*****************************************************************************
  *****************************************************************************/
-double Statis_data::put( double val )
+float Statis_data::put( float val )
 {
  instant = val;
  if( stat_on ) ring.put( instant );
@@ -234,7 +234,7 @@
 /*****************************************************************************
  *****************************************************************************/
 Statis_data::Statis_data( BITMSK calc,unsigned taille,
-                          double b_inf /*= 0*/,double b_sup /*= 0*/ )
+                          float b_inf /*= 0*/,float b_sup /*= 0*/ )
            : ring(        taille ),
              med()
 {      
@@ -244,12 +244,15 @@
  borne_inf       = b_inf;
  borne_sup       = b_sup;
  n_elem          = 0;
- if( stat_on = ( taille > 1 ) ) {
+ 
+ stat_on = taille > 1 ? TRUE : FALSE;
+ if( stat_on ) {
 //   init_ring_d( &ring,taille );
-   if( mediane_methode = ( ( calculs = calc ) & STAT_MED_NORM )
+   mediane_methode = ( ( calculs = calc ) & STAT_MED_NORM )
                          ? new Mediane
                          : ( calc & STAT_MED_CIRC ) ? new Mediane_circ( b_sup )
-                                                    : NULL )
+                                                    : NULL;
+   if( mediane_methode )                                                 
      mediane_liste = new Mediane_item[ taille ];
    else
      mediane_liste = NULL;