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

Dependencies:   mbed statis

Revision:
5:0b3569945178
Parent:
4:ffc39af07ade
Child:
6:95195b0995dd
--- a/statis.cpp	Thu Nov 22 15:57:35 2012 +0000
+++ b/statis.cpp	Sat Nov 24 13:36:58 2012 +0000
@@ -14,6 +14,9 @@
  *                                          Septembre 1994                   *
  *****************************************************************************/
 #define DEBUG
+#include "mbed.h"
+extern Serial pc;
+
 #undef DEBUG
 
 #include <debug.h>
@@ -21,13 +24,13 @@
 #include <stdlib.h>             // cf. qsort(),fabs()
 
 // ring
-//#include "include/ring.h"     // cf. statis.h
+#include "include/ring.h"     // cf. statis.h
 
 // statis
 
-//#include "include/bitmsk.h"     // cf. statis.h
+#include "include/bitmsk.h"     // cf. statis.h
 #define _STATIS
-#include "include/statis.h"
+#include "statis.h"
 #undef  _STATIS
 
 /*****************************************************************************
@@ -36,7 +39,7 @@
 
 /*****************************************************************************
  *****************************************************************************/
-procedure Mediane_item::raz( void )
+void Mediane_item::raz( void )
 {
  valeur = FLOAT_ERREUR;
  indice = 0;
@@ -123,12 +126,12 @@
 
 /*****************************************************************************
  *****************************************************************************/
-booleen Statis_data::verifie( float &val )
+bool Statis_data::verifie( float &val )
 {
  if( ( borne_inf == borne_sup ) || ( val >= borne_inf && val <= borne_sup ) )
-   return( TRUE );
+   return( true );
  val = FLOAT_ERREUR;
- return( FALSE );
+ return( false );
 }
 
 /*****************************************************************************
@@ -144,11 +147,11 @@
 
 /*****************************************************************************
  *****************************************************************************/
-booleen Statis_data::mediane( void )
+bool Statis_data::mediane( void )
 {
  if( !mediane_methode || n_elem == 0 ) {
    med.raz();
-   return( FALSE );
+   return( false );
  }
  med = mediane_methode->mediane( cons_liste(),
                                  ( n_elem % 2 == 0 ) ? n_elem - 1 : n_elem );
@@ -157,11 +160,11 @@
 
 /*****************************************************************************
  *****************************************************************************/
-booleen Statis_data::moyenne( void )
+bool Statis_data::moyenne( void )
 {
  if( n_elem == 0 ) {
    moy = FLOAT_ERREUR;
-   return( FALSE );
+   return( false );
  }
  moy = 0;
  for( unsigned i = 0; i < n_elem; moy += ring.list[ i++ ] );
@@ -171,7 +174,7 @@
 
 /*****************************************************************************
  *****************************************************************************/
-booleen Statis_data::ecart_type( void )
+bool Statis_data::ecart_type( void )
 {
  float      somme_xi_carre = 0.0,
              somme_xi       = 0.0,
@@ -183,7 +186,7 @@
    case  0 :
    case  1 :
    case  2 : ecart = FLOAT_ERREUR;
-             return( FALSE );
+             return( false );
    default : for( i = 0,ptxi = ring.list; i < n_elem;
                   i++,ptxi++ ) {
                somme_xi       += *ptxi;
@@ -192,15 +195,15 @@
              x_bar = somme_xi / (float) n_elem;
              ecart = sqrt( fabs( somme_xi_carre / (float) n_elem -
                                  x_bar * x_bar                      ) );
-             return( TRUE );
+             return( true );
  }
 }
 
 /*****************************************************************************
  *****************************************************************************/
-procedure Statis_data::calcule( void )
+void Statis_data::calcule( void )
 {
- DPRINTF( ("Statis::calcule:stat_on=%u,calculs=%x\n",stat_on,calculs) );
+ DPRINTF( ("\r\nStatis::calcule:stat_on=%u,calculs=%x\r\n",stat_on,calculs) );
  if( stat_on ) {
    n_elem = ring.store();
    DPRINTF( ("n_elem=%u.",n_elem) );
@@ -216,7 +219,7 @@
    med.valeur = ( n_elem > 0 ) ? instant : FLOAT_ERREUR;
    med.indice = 0;
  }
- DPRINTF( ("med=%5.4g,moy=%5.4g,instant=%5.4g\n",
+ DPRINTF( ("med=%5.4g,moy=%5.4g,instant=%5.4g\r\n",
            med.valeur,moy,instant) );
  n_elem = 0;
 }
@@ -245,7 +248,7 @@
  borne_sup       = b_sup;
  n_elem          = 0;
  
- stat_on = taille > 1 ? TRUE : FALSE;
+ stat_on = taille > 1 ? true : false;
  if( stat_on ) {
 //   init_ring_d( &ring,taille );
    mediane_methode = ( ( calculs = calc ) & STAT_MED_NORM )