Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Check_VL6180XA1_ToF
Fork of X_NUCLEO_6180XA1 by
Diff: Components/VL6180X/vl6180x_class.cpp
- Revision:
- 24:025afc3fe30f
- Parent:
- 23:dfb5ccc7b780
- Child:
- 26:db0cdc5ecc0a
--- a/Components/VL6180X/vl6180x_class.cpp Fri Oct 30 11:35:36 2015 +0100
+++ b/Components/VL6180X/vl6180x_class.cpp Mon Nov 02 14:02:53 2015 +0100
@@ -528,7 +528,7 @@
if( status ) break;
status = VL6180x_AlsSetAnalogueGain(dev, 0);
if( status ) break;
- status = VL6180x_AlsSetThresholds(dev, 0, 0xFF);
+ status = VL6180x_AlsSetThresholds(dev, 0, 0xFFFF);
if( status ) break;
/* set Als InterruptMode to new sample */
status=VL6180x_AlsConfigInterrupt(dev, CONFIG_GPIO_INTERRUPT_DISABLED);
@@ -725,15 +725,27 @@
-int VL6180X::VL6180x_AlsSetThresholds(VL6180xDev_t dev, uint8_t low, uint8_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;
+ const uint32_t LuxResxIntIme =(uint32_t)(0.56f* DEF_INT_PEFRIOD *(1<<LUXRES_FIX_PREC));
LOG_FUNCTION_START("%d %d", (int )low, (int)high);
- /*FIXME arguments have to be uint16_t (see SYSALS_THRESH_LOW and SYSALS_THRESH_HIGH registers)
- Furthermore threshold values are not lux! You need to invert the computation made in VL6180x_AlsGetLux() */
- status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, low);
+ 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;
+ status = VL6180x_WrByte(dev, SYSALS_THRESH_LOW, (uint16_t)RawAlsLow);
if(!status ){
- status = VL6180x_WrByte(dev, SYSALS_THRESH_HIGH, high);
+ status = VL6180x_WrByte(dev, SYSALS_THRESH_HIGH, (uint16_t)RawAlsHigh);
}
LOG_FUNCTION_END(status) ;
@@ -2724,7 +2736,7 @@
}
-int VL6180X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), MeasureData_t *Data, uint16_t low, uint16_t high)
+int VL6180X::StartMeasurement(OperatingMode operating_mode, void (*fptr)(void), uint16_t low, uint16_t high)
{
int status, r_status, l_status;
@@ -2734,7 +2746,7 @@
r_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
l_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
if((!r_status)&&(!l_status))
- return RangeMeasPollSingleShot(Data);
+ return RangeMeasPollSingleShot();
else
return (r_status|l_status);
@@ -2742,7 +2754,7 @@
r_status=VL6180x_AlsConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY);
l_status=VL6180x_RangeConfigInterrupt(Device, CONFIG_GPIO_INTERRUPT_DISABLED);
if((!r_status)&&(!l_status))
- return AlsMeasPollSingleShot(Data);
+ return AlsMeasPollSingleShot();
else
return (r_status|l_status);
@@ -2984,39 +2996,43 @@
}
-int VL6180X::RangeMeasPollSingleShot(MeasureData_t *Data)
+int VL6180X::RangeMeasPollSingleShot()
{
- VL6180x_RangeData_t RangeData;
int status;
-
- status=RangePollMeasurement(&RangeData);
- if(!status)
+
+ status=VL6180x_RangeClearInterrupt(Device);
+ if(status)
{
- status=GetRangeError(Data, RangeData);
- if(!status)
- Data->range_mm=RangeData.range_mm;
- else
- Data->range_mm=0xFFFFFFFF;
+ VL6180x_ErrLog("VL6180x_RangeClearInterrupt fail");
+ return status;
}
- return status;
+ status=VL6180x_ClearErrorInterrupt(Device);
+ if(status)
+ {
+ VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
+ return status;
+ }
+ return RangeStartSingleShot();
}
-int VL6180X::AlsMeasPollSingleShot(MeasureData_t *Data)
+int VL6180X::AlsMeasPollSingleShot()
{
- VL6180x_AlsData_t AlsData;
- int status;
-
- status=AlsPollMeasurement(&AlsData);
- if(!status)
+ int status;
+
+ status=VL6180x_AlsClearInterrupt(Device);
+ if(status)
{
- status=GetAlsError(Data, AlsData);
- if(!status)
- Data->lux=AlsData.lux;
- else
- Data->lux=0xFFFFFFFF;
+ VL6180x_ErrLog("VL6180x_AlsClearInterrupt fail");
+ return status;
}
- return status;
+ status=VL6180x_ClearErrorInterrupt(Device);
+ if(status)
+ {
+ VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
+ return status;
+ }
+ return AlsStartSingleShot();
}
@@ -3258,6 +3274,7 @@
{
switch(operating_mode)
{
+ case(range_single_shot_polling):
case(range_continuous_polling):
case(range_continuous_interrupt):
case(range_continuous_polling_low_threshold):
@@ -3268,6 +3285,7 @@
case(range_continuous_interrupt_out_of_window):
return GetRangeMeas(operating_mode, Data);
+ case(als_single_shot_polling):
case(als_continuous_polling):
case(als_continuous_interrupt):
case(als_continuous_polling_low_threshold):
@@ -3319,7 +3337,7 @@
}
if(status)
return status;
- if((operating_mode==range_continuous_polling)||(operating_mode==range_continuous_interrupt))
+ if((operating_mode==range_single_shot_polling)||(operating_mode==range_continuous_polling)||(operating_mode==range_continuous_interrupt))
{
if(IntStatus.status.Range==RES_INT_STAT_GPIO_NEW_SAMPLE_READY)
status=VL6180x_RangeGetMeasurement(Device, &RangeData);
@@ -3382,7 +3400,7 @@
}
if(status)
return status;
- if((operating_mode==als_continuous_polling)||(operating_mode==als_continuous_interrupt))
+ if((operating_mode==als_single_shot_polling)||(operating_mode==als_continuous_polling)||(operating_mode==als_continuous_interrupt))
{
if(IntStatus==RES_INT_STAT_GPIO_NEW_SAMPLE_READY)
status=VL6180x_AlsGetMeasurement(Device, &AlsData);
@@ -3581,7 +3599,7 @@
VL6180x_ErrLog("VL6180x_ClearErrorInterrupt fail");
return status;
}
- status=VL6180x_AlsSetThresholds(Device, 0x0, 0xFF);
+ status=VL6180x_AlsSetThresholds(Device, 0x0, 0xFFFF);
if(status)
VL6180x_ErrLog("VL6180x_AlsSetThresholds fail");
return status;
