Librairie adaptée au laboratoire 2

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
gallonm
Date:
Wed Oct 28 13:07:59 2015 +0000
Parent:
19:39ea6bab0e5b
Child:
21:5fb360508b6e
Commit message:
Removed PollDelay and introduced simply wait_ms function.; Updated file platform.h.; Fixed all FIXME.; Fixed error printing.; Updated x_nucleo_6180xa1.cpp file.

Changed in this revision

Components/Display/Display_class.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_class.cpp Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_class.h Show annotated file Show diff for this revision Revisions of this file
Components/VL6180X/vl6180x_platform.h Show annotated file Show diff for this revision Revisions of this file
x_nucleo_6180xa1.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Components/Display/Display_class.h	Wed Oct 28 09:28:52 2015 +0000
+++ b/Components/Display/Display_class.h	Wed Oct 28 13:07:59 2015 +0000
@@ -163,194 +163,189 @@
 #ifndef FAST_DISPLAY
  
     Display(DevI2C &i2c, STMPE1600DigiOut &D1,	STMPE1600DigiOut &D2, STMPE1600DigiOut &D3, STMPE1600DigiOut &D4,
-						STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D,
-						STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G)
-						: Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4),
-							Display_A(D_A), Display_B(D_B), Display_C(D_C), Display_D(D_D), 
- 							Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c)
-		{
-			pDisplay_DGT[0] = &Display_D1;
-			pDisplay_DGT[1] = &Display_D2;
-			pDisplay_DGT[2] = &Display_D3;
-			pDisplay_DGT[3] = &Display_D4;	
-			pDisplay_SEG[0] = &Display_A;
-			pDisplay_SEG[1] = &Display_B;
-			pDisplay_SEG[2] = &Display_C;
-			pDisplay_SEG[3] = &Display_D;
-			pDisplay_SEG[4] = &Display_E;
-			pDisplay_SEG[5] = &Display_F;
-			pDisplay_SEG[6] = &Display_G;		
+	        STMPE1600DigiOut &D_A, STMPE1600DigiOut &D_B, STMPE1600DigiOut &D_C, STMPE1600DigiOut &D_D,
+	        STMPE1600DigiOut &D_E, STMPE1600DigiOut &D_F, STMPE1600DigiOut &D_G)
+	        : Display_D1(D1), Display_D2(D2), Display_D3(D3), Display_D4(D4),
+	        Display_A(D_A), Display_B(D_B), Display_C(D_C), Display_D(D_D), 
+ 	        Display_E(D_E), Display_F(D_F), Display_G(D_G), dev_i2c(i2c)
+    {
+       pDisplay_DGT[0] = &Display_D1;
+       pDisplay_DGT[1] = &Display_D2;
+       pDisplay_DGT[2] = &Display_D3;
+       pDisplay_DGT[3] = &Display_D4;	
+       pDisplay_SEG[0] = &Display_A;
+       pDisplay_SEG[1] = &Display_B;
+       pDisplay_SEG[2] = &Display_C;
+       pDisplay_SEG[3] = &Display_D;
+       pDisplay_SEG[4] = &Display_E;
+       pDisplay_SEG[5] = &Display_F;
+       pDisplay_SEG[6] = &Display_G;		
 
-			for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; }
-			for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1;	}		
-		}
+       for (int i=0; i<4; i++) { *pDisplay_DGT[i]=1; }
+       for (int i=0; i<7; i++) { *pDisplay_SEG[i]=1;	}		
+    }
 #else		
     Display(DevI2C &i2c) :  dev_i2c(i2c) {}
 #endif		
-    virtual ~Display() 
-    {
-        //nella classe board ci sara' un puntatore ad un oggetto di tipo Display che verra' creato con una new
-		    //qui devo fare il delete[] del new 			
-    } 
 
 #ifndef FAST_DISPLAY			
- 		void Digits_off (void)  // all 4 digits off
-		{
-			Display_D1=1;
-			Display_D2=1; 
-			Display_D3=1; 
-			Display_D4=1;  			
-		}
+    void Digits_off (void)  // all 4 digits off
+    {
+       Display_D1=1;
+       Display_D2=1; 
+       Display_D3=1; 
+       Display_D4=1;  			
+    }
 
- 		void Digits_on (void)  // all 4 digits on
-		{
-			Display_D1=0;
-			Display_D2=0; 
-			Display_D3=0; 
-			Display_D4=0;  			
-		}
+    void Digits_on (void)  // all 4 digits on
+    {
+       Display_D1=0;
+       Display_D2=0; 
+       Display_D3=0; 
+       Display_D4=0;  			
+    }
 
- 		void Digit_on (int digit)  // digits on
-		{
-			*pDisplay_DGT[digit] = 0;
-		}
+    void Digit_on (int digit)  // digits on
+    {
+       *pDisplay_DGT[digit] = 0;
+    }
 
- 		void Digit_off (int digit)  // digits on
-		{
-			*pDisplay_DGT[digit] = 1;
-		}
+    void Digit_off (int digit)  // digits on
+    {
+       *pDisplay_DGT[digit] = 1;
+    }
 		
-		void Segments_off ()   // all 7 segments off			
-		{
-			Display_A=1;
-			Display_B=1;
-			Display_C=1;
-			Display_D=1;
-			Display_E=1;
-			Display_F=1;			
-			Display_G=1;						
-		}		
+    void Segments_off ()   // all 7 segments off			
+    {
+       Display_A=1;
+       Display_B=1;
+       Display_C=1;
+       Display_D=1;
+       Display_E=1;
+       Display_F=1;			
+       Display_G=1;						
+    }		
 		
-		void Segment_off (int seg)   // segment off			
-		{
-			*pDisplay_SEG[seg] = 1;
-		}
+    void Segment_off (int seg)   // segment off			
+    {
+       *pDisplay_SEG[seg] = 1;
+    }
 		
-		void Segment_on (int seg)   // segment on			
-		{
-			*pDisplay_SEG[seg] = 0;
-		}
+    void Segment_on (int seg)   // segment on			
+    {
+       *pDisplay_SEG[seg] = 0;
+    }
 		
 		
-		void DisplayString (char str[4])
-		{
-    int i;
-    const char *pc;
+    void DisplayString (char str[4])
+    {
+       int i;
+       const char *pc;
  
-			for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++){
-        _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i);
-        if( *(pc+1)== '.'){
+       for( i=0, pc=str; i<4 && *pc!=0 ; i++, pc++){
+          _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], i);
+          if( *(pc+1)== '.'){
             pc++;
-        }
-				 wait_ms(DISPLAY_DELAY);
-				 Digits_off();
-			}			
-		}
+          }
+          wait_ms(DISPLAY_DELAY);
+          Digits_off();
+       }			
+    }
 				
  
-   void _V2_Set7Segment( int Leds, int digit ){
-		  //Digits_off();
-			Segments_off();					  // 7 seg off */
-		 int mask=1;
-		  for (int i=0; i<7; i++) { 
-				if (Leds & mask) Segment_on(i);
-				mask = mask<<1;
-			}		 
-		  Digit_on(digit);
-		}
+    void _V2_Set7Segment( int Leds, int digit ){
+       //Digits_off();
+       Segments_off();	// 7 seg off */
+       int mask=1;
+       for (int i=0; i<7; i++) { 
+          if (Leds & mask) Segment_on(i);
+          mask = mask<<1;
+       }		 
+       Digit_on(digit);
+    }
 
 
 #else
 
-		void DisplayDigit (char *val, char dgt)	
-		{
-		uint8_t data[2];
-		uint16_t *pdata = (uint16_t*)data;				
-      dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7					
-		  *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-			dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
+    void DisplayDigit (char *val, char dgt)	
+    {
+       uint8_t data[2];
+       uint16_t *pdata = (uint16_t*)data;				
+       dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); //  GPSR_0_7					
+       *pdata = *pdata | (uint16_t)0x0780; // all digits off
+       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2); //  GPSR_0_7		 
 			
-      _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);						
-		}
+       _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*val], dgt);						
+    }
 		
-		void DisplayString (char str[4], char strlen)
-		{
-    int i, dgt;
-    const char *pc;
-		uint8_t data[2];
-		uint16_t *pdata = (uint16_t*)data;	
+    void DisplayString (char str[4], char strlen)
+    {
+       int i, dgt;
+       const char *pc;
+       uint8_t data[2];
+       uint16_t *pdata = (uint16_t*)data;	
 			
- //     dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7					
-//		  *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-//			dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
+//     dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7					
+//     *pdata = *pdata | (uint16_t)0x0780;				// all digits off
+//     dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
 			
-			for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++){
-        _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
-        if( *(pc+1)== '.'){
-            pc++;
-        }
-				wait_ms(DISPLAY_DELAY);
-				dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7
-		    *pdata = *pdata | (uint16_t)0x0780;				// all digits off
-			  dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7	
-			}			
-		}
+       for(i=0, dgt=4-strlen, pc=str; i<strlen && *pc!=0; i++, pc++, dgt++){
+       _V2_Set7Segment( ascii_to_display_lut[(uint8_t)*pc], dgt);
+       if( *(pc+1)== '.'){
+          pc++;
+       }
+       wait_ms(DISPLAY_DELAY);
+       dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7
+       *pdata = *pdata | (uint16_t)0x0780;				// all digits off
+       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7	
+       }			
+    }
 				
  
-   void _V2_Set7Segment( int Leds, int digit ){
-		  //Digits_off();
+    void _V2_Set7Segment( int Leds, int digit ){
+       //Digits_off();
 		 
-		  uint16_t dgt;
-		  dgt = 1<<digit;
-		  dgt = ((uint16_t)dgt)<<7;
-		  dgt = ~dgt;	
-			uint8_t data[2];
-			uint16_t *pdata = (uint16_t*)data;			 
+       uint16_t dgt;
+       dgt = 1<<digit;
+       dgt = ((uint16_t)dgt)<<7;
+       dgt = ~dgt;	
+       uint8_t data[2];
+       uint16_t *pdata = (uint16_t*)data;			 
 
 		 
-			/* set the exppinname state to lvl */
-			dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7  		 
-		  *pdata = *pdata  | (uint16_t)0x007F;      // 7 segments off
-			dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
+       /* set the exppinname state to lvl */
+       dev_i2c.i2c_read(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7  		 
+       *pdata = *pdata  | (uint16_t)0x007F;      // 7 segments off
+       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 
 		 
-		 int mask=1;
-		  for (int i=0; i<7; i++) { 
-				if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;  
-				mask = mask<<1;
-			}		 
-			*pdata = *pdata & dgt;
-			dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 			
-		}
+       int mask=1;
+       for (int i=0; i<7; i++) { 
+          if (Leds & mask) *pdata = *pdata & ~(uint16_t)mask;  
+          mask = mask<<1;
+       }		 
+       *pdata = *pdata & dgt;
+       dev_i2c.i2c_write(data, (uint8_t)STMPE1600_DEF_DEVICE_ADDRESS, (uint8_t)GPSR_0_7, 2);		//  GPSR_0_7		 			
+    }
 #endif		
 		
 		
  private:		
 		
 #ifndef FAST_DISPLAY
-		STMPE1600DigiOut &Display_D1;
-		STMPE1600DigiOut &Display_D2;
-		STMPE1600DigiOut &Display_D3;
-		STMPE1600DigiOut &Display_D4;
-		STMPE1600DigiOut *pDisplay_DGT[4];		// the 4 display digits
+    STMPE1600DigiOut &Display_D1;
+    STMPE1600DigiOut &Display_D2;
+    STMPE1600DigiOut &Display_D3;
+    STMPE1600DigiOut &Display_D4;
+    STMPE1600DigiOut *pDisplay_DGT[4];		// the 4 display digits
 		
- 		STMPE1600DigiOut &Display_A;
- 		STMPE1600DigiOut &Display_B;
- 		STMPE1600DigiOut &Display_C;
- 		STMPE1600DigiOut &Display_D;
- 		STMPE1600DigiOut &Display_E; 
-		STMPE1600DigiOut &Display_F;
- 		STMPE1600DigiOut &Display_G; 
-		STMPE1600DigiOut *pDisplay_SEG[7];		// the 7 digit segmments
+    STMPE1600DigiOut &Display_A;
+    STMPE1600DigiOut &Display_B;
+    STMPE1600DigiOut &Display_C;
+    STMPE1600DigiOut &Display_D;
+    STMPE1600DigiOut &Display_E; 
+    STMPE1600DigiOut &Display_F;
+    STMPE1600DigiOut &Display_G; 
+    STMPE1600DigiOut *pDisplay_SEG[7];		// the 7 digit segmments
 #endif
     DevI2C           &dev_i2c; 		
 };
--- a/Components/VL6180X/vl6180x_class.cpp	Wed Oct 28 09:28:52 2015 +0000
+++ b/Components/VL6180X/vl6180x_class.cpp	Wed Oct 28 13:07:59 2015 +0000
@@ -65,7 +65,7 @@
  */
 #define VL6180X_LOG_ENABLE  0
 #endif
- 
+
 #ifdef MY_LOG 
 Serial pc(USBTX, USBRX);
 #endif 
@@ -2678,15 +2678,15 @@
 }
  
  
-int VL6180X::InitSensor(uint8_t NewAddr) //FIXME printf da sostituire con VL6180x_ErrLog e poi specificare il contenuto di questa funzione
+int VL6180X::InitSensor(uint8_t NewAddr)
 {
    int status;
  
    VL6180x_Off();
    VL6180x_On();
-     /*status=VL6180x_WaitDeviceBooted(Device);
-     if(status)
-          printf("WaitDeviceBooted fail\n\r");*/
+   status=VL6180x_WaitDeviceBooted(Device);
+   if(status)
+      printf("WaitDeviceBooted fail\n\r");
    status=IsPresent();
    if(!status)
    {
@@ -2719,8 +2719,6 @@
       }
       Device->Ready=1;
    }
-   VL6180x_RangeSetMaxConvergenceTime(Device,10); //FIXME temporaneo, capire se devo fissare questi valori di default oppure impostarli solo quando faccio la hand gesture
-   VL6180x_RangeSetInterMeasPeriod(Device,10); //FIXME
    return status; 
 }
  
@@ -3155,7 +3153,7 @@
    if(status)
    {
       VL6180x_ErrLog("Failed to write SYSALS_INTERMEASUREMENT_PERIOD!\n\r");
-   return status;
+      return status;
    }
    return AlsStartContinuousMode();
 }
--- a/Components/VL6180X/vl6180x_class.h	Wed Oct 28 09:28:52 2015 +0000
+++ b/Components/VL6180X/vl6180x_class.h	Wed Oct 28 13:07:59 2015 +0000
@@ -534,7 +534,7 @@
 			
        status=ReadID();
        if(status)
-          printf("Failed to read ID device! Device not present!\n\r"); //FIXME da sistemare la funzione di stampa errore ErrLog da platform.h
+          printf("Failed to read ID device. Device not present!\n\r");
        return status;
     }	
     int StopRangeMeasurement(OperatingMode operating_mode);
--- a/Components/VL6180X/vl6180x_platform.h	Wed Oct 28 09:28:52 2015 +0000
+++ b/Components/VL6180X/vl6180x_platform.h	Wed Oct 28 13:07:59 2015 +0000
@@ -33,7 +33,7 @@
 #define VL6180x_RANGE_STATUS_ERRSTRING  1
 #define VL6180X_SAFE_POLLING_ENTER 	0
 #define VL6180X_LOG_ENABLE              0
-#define MY_LOG 1
+#define MY_LOG                          1
 
 #define VL6180x_DEV_DATA_ATTR
 #define ROMABLE_DATA
@@ -70,14 +70,14 @@
 
 #else /* VL6180X_LOG_ENABLE no logging */
   //void OnErrLog(void);
-  #define LOG_FUNCTION_START(...) //(void)0
-  #define LOG_FUNCTION_END(...) //(void)0
-  #define LOG_FUNCTION_END_FMT(...) //(void)0
+  #define LOG_FUNCTION_START(...) (void)0
+  #define LOG_FUNCTION_END(...) (void)0
+  #define LOG_FUNCTION_END_FMT(...) (void)0
   #define VL6180x_ErrLog(... ) //OnErrLog() //(void)0
 #endif
 
   
-#ifdef MY_LOG  
+#ifdef MY_LOG  /* define printf as pc.printf in order to change the baudrate */
   extern Serial pc;
   #define printf(...) pc.printf(__VA_ARGS__)
 #endif
@@ -88,11 +88,11 @@
 #endif
 		
 struct MyVL6180Dev_t {
-		struct VL6180xDevData_t Data;
-		uint8_t I2cAddr;
-		//uint8_t DevID;
+    struct VL6180xDevData_t Data;
+    uint8_t I2cAddr;
+    //uint8_t DevID;
     
-	//misc flags for application 	
+    //misc flags for application 	
     unsigned Present:1;
     unsigned Ready:1;
 };
--- a/x_nucleo_6180xa1.cpp	Wed Oct 28 09:28:52 2015 +0000
+++ b/x_nucleo_6180xa1.cpp	Wed Oct 28 13:07:59 2015 +0000
@@ -48,12 +48,12 @@
    if(_instance==NULL)
       _instance=new X_NUCLEO_6180XA1(ext_i2c);
    else
-      VL6180x_ErrLog("Failed to init X_NUCLEO_6180XA1 board!\n");
+      printf("Failed to init X_NUCLEO_6180XA1 board!\n");
    return _instance;
 }
 
 
-int X_NUCLEO_6180XA1::InitBoard() //FIXME sistemare le stampe degli errori
+int X_NUCLEO_6180XA1::InitBoard()
 {	
    int status, n_dev=0;
 	
@@ -68,7 +68,6 @@
       delete gpio0_top;
       sensor_top=NULL;
       gpio0_top=NULL;
-      //VL6180x_ErrLog("Failed to init sensor_top\n\r");
       printf("Failed to init sensor_top\n\r");
    }
    else
@@ -82,7 +81,6 @@
       delete gpio0_bottom;
       sensor_bottom=NULL;
       gpio0_bottom=NULL;
-      //VL6180x_ErrLog("Failed to init sensor_bottom\n\r");
       printf("Failed to init sensor_bottom\n\r");
    }
    else
@@ -96,7 +94,6 @@
       delete gpio0_left;
       sensor_left=NULL;
       gpio0_left=NULL;
-      //VL6180x_ErrLog("Failed to init sensor_left\n\r");
       printf("Failed to init sensor_left\n\r");
    }
    else
@@ -109,8 +106,7 @@
       delete sensor_right;
       delete gpio0_right;
       sensor_right=NULL;
-       gpio0_right=NULL;
-      //VL6180x_ErrLog("Failed to init sensor_right\n\r");
+      gpio0_right=NULL;
       printf("Failed to init sensor_right\n\r");
    }
    else