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:
Thu Nov 05 17:20:03 2015 +0100
Parent:
27:22c6f69967d9
Child:
29:6d6b67e2e212
Commit message:
Settled AlsSetThresholds function that takes the parameters in lux.
VL6180x_AlsSetThresholds takes the parameters in raw device value.

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
x_nucleo_6180xa1.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Components/Display/Display_class.h	Wed Nov 04 17:17:35 2015 +0100
+++ b/Components/Display/Display_class.h	Thu Nov 05 17:20:03 2015 +0100
@@ -209,7 +209,7 @@
        *pDisplay_DGT[digit] = 0;
     }
 
-    void Digit_off (int digit)  // digits on
+    void Digit_off (int digit)  // digits off
     {
        *pDisplay_DGT[digit] = 1;
     }
--- a/Components/VL6180X/vl6180x_class.cpp	Wed Nov 04 17:17:35 2015 +0100
+++ b/Components/VL6180X/vl6180x_class.cpp	Thu Nov 05 17:20:03 2015 +0100
@@ -528,7 +528,7 @@
         if( status ) break;
         status = VL6180x_AlsSetAnalogueGain(dev,  0);
         if( status ) break;
-        status = VL6180x_AlsSetThresholds(dev, 0, 1800);
+        status = VL6180x_AlsSetThresholds(dev, 0, 0xFFFF);
         if( status ) break;
         /* set Als InterruptMode to new sample */
         status=VL6180x_AlsConfigInterrupt(dev, CONFIG_GPIO_INTERRUPT_DISABLED);
@@ -725,33 +725,16 @@
  
  
  
-int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, lux_t low, lux_t high) { 
+int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high) { 
     int status;
-    uint32_t AlsAnGain, IntPeriod, AlsScaler, GainFix, RawAlsHigh, RawAlsLow;
-    uint16_t RawThreshLow, RawThreshHigh;
-    const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC));
-    void *ptr;
- 
+
     LOG_FUNCTION_START("%d %d", (int )low, (int)high);
-    AlsAnGain=VL6180xDevDataGet(dev, AlsGainCode);
-    IntPeriod=VL6180xDevDataGet(dev, IntegrationPeriod);
-    AlsScaler=VL6180xDevDataGet(dev, AlsScaler);
-    GainFix=AlsGainLookUp[AlsAnGain];
-    IntPeriod++;
-    RawAlsLow=low*AlsScaler*GainFix;
-    RawAlsLow=RawAlsLow*IntPeriod;
-    RawAlsLow=RawAlsLow/LuxResxIntIme;  
-    RawAlsHigh=high*(AlsScaler*GainFix);
-    RawAlsHigh=RawAlsHigh*IntPeriod;
-    RawAlsHigh=RawAlsHigh/LuxResxIntIme;
-    ptr=&RawAlsLow;
-    RawThreshLow=*(uint16_t*)ptr;
-    status = VL6180x_WrWord(dev, SYSALS_THRESH_LOW, RawThreshLow); 
+
+    status = VL6180x_WrWord(dev, SYSALS_THRESH_LOW, low);
     if(!status ){
-        ptr=&RawAlsHigh;
-        RawThreshHigh=*(uint16_t*)ptr;
-        status = VL6180x_WrWord(dev, SYSALS_THRESH_HIGH, RawThreshHigh);
+        status = VL6180x_WrWord(dev, SYSALS_THRESH_HIGH, high);
     }
+
     LOG_FUNCTION_END(status) ;
     return status;
 }
@@ -1179,17 +1162,17 @@
     VL6180x_WrByte( dev, 0x0030, 0x00);
  
     /* Recommended : Public registers - See data sheet for more detail */
-    VL6180x_WrByte( dev, 0x0011, 0x10); /* Enables polling for New Sample ready when measurement completes */
-    VL6180x_WrByte( dev, 0x010a, 0x30); /* Set the averaging sample period (compromise between lower noise and increased execution time) */
-    VL6180x_WrByte( dev, 0x003f, 0x46); /* Sets the light and dark gain (upper nibble). Dark gain should not be changed.*/
-    VL6180x_WrByte( dev, 0x0031, 0xFF); /* sets the # of range measurements after which auto calibration of system is performed */
-    VL6180x_WrByte( dev, 0x0040, 0x63); /* Set ALS integration time to 100ms */
-    VL6180x_WrByte( dev, 0x002e, 0x01); /* perform a single temperature calibration of the ranging sensor */
+    VL6180x_WrByte( dev, SYSTEM_MODE_GPIO1, 0x10); /* Enables polling for New Sample ready when measurement completes */
+    VL6180x_WrByte( dev, READOUT_AVERAGING_SAMPLE_PERIOD, 0x30); /* Set the averaging sample period (compromise between lower noise and increased execution time) */
+    VL6180x_WrByte( dev, SYSALS_ANALOGUE_GAIN, 0x46); /* Sets the light and dark gain (upper nibble). Dark gain should not be changed.*/
+    VL6180x_WrByte( dev, SYSRANGE_VHV_REPEAT_RATE, 0xFF); /* sets the # of range measurements after which auto calibration of system is performed */
+    VL6180x_WrByte( dev, SYSALS_INTEGRATION_PERIOD, 0x63); /* Set ALS integration time to 100ms */
+    VL6180x_WrByte( dev, SYSRANGE_VHV_RECALIBRATE, 0x01); /* perform a single temperature calibration of the ranging sensor */
  
     /* Optional: Public registers - See data sheet for more detail */
-    VL6180x_WrByte( dev, 0x001b, 0x09); /* Set default ranging inter-measurement period to 100ms */
-    VL6180x_WrByte( dev, 0x003e, 0x31); /* Set default ALS inter-measurement period to 500ms */
-    VL6180x_WrByte( dev, 0x0014, 0x24); /* Configures interrupt on New sample ready */
+    VL6180x_WrByte( dev, SYSRANGE_INTERMEASUREMENT_PERIOD, 0x09); /* Set default ranging inter-measurement period to 100ms */
+    VL6180x_WrByte( dev, SYSALS_INTERMEASUREMENT_PERIOD, 0x31); /* Set default ALS inter-measurement period to 500ms */
+    VL6180x_WrByte( dev, SYSTEM_INTERRUPT_CONFIG_GPIO, 0x24); /* Configures interrupt on New sample ready */
  
  
     status=VL6180x_RangeSetMaxConvergenceTime(dev, 50); /*  Calculate ece value on initialization (use max conv) */
@@ -1242,16 +1225,16 @@
     VL6180x_WrByte( dev, 0x01ac, 0x3e);
     VL6180x_WrByte( dev, 0x01a7, 0x1f);
     VL6180x_WrByte( dev, 0x0030, 0x00);
-    VL6180x_WrByte( dev, 0x0011, 0x10);
-    VL6180x_WrByte( dev, 0x010a, 0x30);
-    VL6180x_WrByte( dev, 0x003f, 0x46);
-    VL6180x_WrByte( dev, 0x0031, 0xFF);
-    VL6180x_WrByte( dev, 0x0040, 0x63);
-    VL6180x_WrByte( dev, 0x002e, 0x01);
-    VL6180x_WrByte( dev, 0x002c, 0xff);
-    VL6180x_WrByte( dev, 0x001b, 0x09);
-    VL6180x_WrByte( dev, 0x003e, 0x31);
-    VL6180x_WrByte( dev, 0x0014, 0x24);
+    VL6180x_WrByte( dev, SYSTEM_MODE_GPIO1, 0x10);
+    VL6180x_WrByte( dev, READOUT_AVERAGING_SAMPLE_PERIOD, 0x30);
+    VL6180x_WrByte( dev, SYSALS_ANALOGUE_GAIN, 0x46);
+    VL6180x_WrByte( dev, SYSRANGE_VHV_REPEAT_RATE, 0xFF);
+    VL6180x_WrByte( dev, SYSALS_INTEGRATION_PERIOD, 0x63);
+    VL6180x_WrByte( dev, SYSRANGE_VHV_RECALIBRATE, 0x01);
+    VL6180x_WrByte( dev, SYSRANGE_MAX_AMBIENT_LEVEL_MULT, 0xff);
+    VL6180x_WrByte( dev, SYSRANGE_INTERMEASUREMENT_PERIOD, 0x09);
+    VL6180x_WrByte( dev, SYSALS_INTERMEASUREMENT_PERIOD, 0x31);
+    VL6180x_WrByte( dev, SYSTEM_INTERRUPT_CONFIG_GPIO, 0x24);
 #if VL6180x_EXTENDED_RANGE
     VL6180x_RangeSetMaxConvergenceTime(dev, 63);
 #else
@@ -2680,8 +2663,39 @@
    }       
    return 0;
 } 
- 
- 
+
+/******************************************************************************/
+
+int VL6180X::AlsSetThresholds(uint16_t lux_threshold_low, uint16_t lux_threshold_high)
+{
+   uint32_t AlsAnGain, IntPeriod, AlsScaler, GainFix, RawAlsHigh, RawAlsLow;
+   uint16_t RawThreshLow, RawThreshHigh;
+   const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC));
+   void *p_low;
+   void *p_high;
+ 
+   AlsAnGain=VL6180xDevDataGet(Device, AlsGainCode);
+   IntPeriod=VL6180xDevDataGet(Device, IntegrationPeriod);
+   AlsScaler=VL6180xDevDataGet(Device, AlsScaler);
+   GainFix=AlsGainLookUp[AlsAnGain];
+   IntPeriod++;
+   RawAlsLow=lux_threshold_low*AlsScaler*GainFix;
+   RawAlsLow=RawAlsLow*IntPeriod;
+   RawAlsLow=RawAlsLow/LuxResxIntIme;  
+   RawAlsHigh=lux_threshold_high*(AlsScaler*GainFix);
+   RawAlsHigh=RawAlsHigh*IntPeriod;
+   RawAlsHigh=RawAlsHigh/LuxResxIntIme;
+   p_low=&RawAlsLow;
+   RawThreshLow=*(uint16_t*)p_low;
+   p_high=&RawAlsHigh;
+   RawThreshHigh=*(uint16_t*)p_high;
+   //return VL6180x_AlsSetThresholds(Device, RawThreshLow, RawThreshHigh);
+   VL6180x_AlsSetThresholds(Device, RawThreshLow, RawThreshHigh);
+   VL6180x_RdWord(Device, SYSALS_THRESH_HIGH, &RawThreshLow);
+   VL6180x_RdWord(Device, SYSALS_THRESH_LOW, &RawThreshHigh);
+}
+
+
 int VL6180X::ReadID()
 {
    int status;
--- a/Components/VL6180X/vl6180x_class.h	Wed Nov 04 17:17:35 2015 +0100
+++ b/Components/VL6180X/vl6180x_class.h	Thu Nov 05 17:20:03 2015 +0100
@@ -123,7 +123,7 @@
    /** Destructor
     */
     //virtual ~VL6180X(){} 
-    /* FIXME warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
+    /* warning: VL6180X class inherits from GenericSensor, RangeSensor and LightSensor, that haven`t a destructor.
        The warning should request to introduce a virtual destructor to make sure to delete the object */
 		
     /* turns on the sensor */		 
@@ -277,13 +277,10 @@
        return VL6180x_AlsSetAnalogueGain(Device, gain);
     }
 		
-    int AlsSetThresholds(lux_t low, lux_t high)
-    {
-       return VL6180x_AlsSetThresholds(Device, low, high);
-    }
+    int AlsSetThresholds(uint16_t lux_threshold_low, uint16_t lux_threshold_high);
 
     int AlsGetInterruptStatus(uint8_t *pIntStatus)
-		{
+    {
        return VL6180x_AlsGetInterruptStatus(Device, pIntStatus);
     }
 
@@ -473,7 +470,7 @@
     int VL6180x_AlsSetIntegrationPeriod(VL6180xDev_t dev, uint16_t period_ms);
     int VL6180x_AlsSetInterMeasurementPeriod(VL6180xDev_t dev,  uint16_t intermeasurement_period_ms);
     int VL6180x_AlsSetAnalogueGain(VL6180xDev_t dev, uint8_t gain);
-    int VL6180x_AlsSetThresholds(VL6180xDev_t dev, lux_t low, lux_t high);
+    int VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint16_t low, uint16_t high);
     int VL6180x_AlsGetInterruptStatus(VL6180xDev_t dev, uint8_t *pIntStatus);
     int VL6180x_StaticInit(VL6180xDev_t dev);
     int VL6180x_RangeWaitDeviceReady(VL6180xDev_t dev, int MaxLoop );
--- a/x_nucleo_6180xa1.cpp	Wed Nov 04 17:17:35 2015 +0100
+++ b/x_nucleo_6180xa1.cpp	Thu Nov 05 17:20:03 2015 +0100
@@ -48,7 +48,7 @@
    if(_instance==NULL)
       _instance=new X_NUCLEO_6180XA1(ext_i2c);
    else
-      printf("Failed to init X_NUCLEO_6180XA1 board!\n");
+      VL6180x_ErrLog("Failed to create X_NUCLEO_6180XA1 instance\n\r");
    return _instance;
 }