src/vl53l1x.cpp
void Vl53l1x::getRangingData()
{
  // VL53L1_copy_sys_and_core_results_to_range_results() begin

  uint16_t range = results.final_crosstalk_corrected_range_mm_sd0;

  // "apply correction gain"
  // gain factor of 2011 is tuning parm default (VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT)
  // Basically, this appears to scale the result by 2011/2048, or about 98%
  // (with the 1024 added for proper rounding).
  ranging_data.range_mm = ((uint32_t)range * 2011 + 0x0400) / 0x0800;

  // VL53L1_copy_sys_and_core_results_to_range_results() end

  // set range_status in ranging_data based on value of RESULT__RANGE_STATUS register
  // mostly based on ConvertStatusLite()
  switch(results.range_status)
  {
    case 17: // MULTCLIPFAIL
    case 2: // VCSELWATCHDOGTESTFAILURE
    case 1: // VCSELCONTINUITYTESTFAILURE
    case 3: // NOVHVVALUEFOUND
      // from SetSimpleData()
      ranging_data.range_status = HardwareFail;
      break;

    case 13: // USERROICLIP
     // from SetSimpleData()
      ranging_data.range_status = MinRangeFail;
      break;

    case 18: // GPHSTREAMCOUNT0READY
      ranging_data.range_status = SynchronizationInt;
      break;

    case 5: // RANGEPHASECHECK
      ranging_data.range_status =  OutOfBoundsFail;
      break;

    case 4: // MSRCNOTARGET
      ranging_data.range_status = SignalFail;
      break;

    case 6: // SIGMATHRESHOLDCHECK
      ranging_data.range_status = SigmaFail;
      break;

    case 7: // PHASECONSISTENCY
      ranging_data.range_status = WrapTargetFail;
      break;

    case 12: // RANGEIGNORETHRESHOLD
      ranging_data.range_status = XtalkSignalFail;
      break;

    case 8: // MINCLIP
      ranging_data.range_status = RangeValidMinRangeClipped;
      break;

    case 9: // RANGECOMPLETE
      // from VL53L1_copy_sys_and_core_results_to_range_results()
      if (results.stream_count == 0)
      {
        ranging_data.range_status = RangeValidNoWrapCheckFail;
      }
      else
      {
        ranging_data.range_status = RangeValid;
      }
      break;

    default:
      ranging_data.range_status = None;
  }

  // from SetSimpleData()
  ranging_data.peak_signal_count_rate_MCPS =
    countRateFixedToFloat(results.peak_signal_count_rate_crosstalk_corrected_mcps_sd0);
  ranging_data.ambient_count_rate_MCPS =
    countRateFixedToFloat(results.ambient_count_rate_mcps_sd0);
}
// get range, status, rates from results buffer
// based on VL53L1_GetRangingMeasurementData()
get range, status, rates from results buffer
based on VL53L1_GetRangingMeasurementData()
get range status rates from results buffer based on VL53L1_GetRangingMeasurementData ()
void Vl53l1x::getRangingData()
{
  uint16_t range = results.final_crosstalk_corrected_range_mm_sd0;
  ranging_data.range_mm = ((uint32_t)range * 2011 + 0x0400) / 0x0800;
  switch(results.range_status)
  {
    case 17: 
    case 2: 
    case 1: 
    case 3: 
      ranging_data.range_status = HardwareFail;
      break;
    case 13: 
      ranging_data.range_status = MinRangeFail;
      break;
    case 18: 
      ranging_data.range_status = SynchronizationInt;
      break;
    case 5: 
      ranging_data.range_status =  OutOfBoundsFail;
      break;
    case 4: 
      ranging_data.range_status = SignalFail;
      break;
    case 6: 
      ranging_data.range_status = SigmaFail;
      break;
    case 7: 
      ranging_data.range_status = WrapTargetFail;
      break;
    case 12: 
      ranging_data.range_status = XtalkSignalFail;
      break;
    case 8: 
      ranging_data.range_status = RangeValidMinRangeClipped;
      break;
    case 9: 
      if (results.stream_count == 0)
      {
        ranging_data.range_status = RangeValidNoWrapCheckFail;
      }
      else
      {
        ranging_data.range_status = RangeValid;
      }
      break;
    default:
      ranging_data.range_status = None;
  }
  ranging_data.peak_signal_count_rate_MCPS =
    countRateFixedToFloat(results.peak_signal_count_rate_crosstalk_corrected_mcps_sd0);
  ranging_data.ambient_count_rate_MCPS =
    countRateFixedToFloat(results.ambient_count_rate_mcps_sd0);
}
void Vl53l1x :: getRangingData ( ) { uint16_t range = results . final_crosstalk_corrected_range_mm_sd0 ; ranging_data . range_mm = ( ( uint32_t ) range * 2011 + 0x0400 ) / 0x0800 ; switch ( results . range_status ) { case 17 : case 2 : case 1 : case 3 : ranging_data . range_status = HardwareFail ; break ; case 13 : ranging_data . range_status = MinRangeFail ; break ; case 18 : ranging_data . range_status = SynchronizationInt ; break ; case 5 : ranging_data . range_status = OutOfBoundsFail ; break ; case 4 : ranging_data . range_status = SignalFail ; break ; case 6 : ranging_data . range_status = SigmaFail ; break ; case 7 : ranging_data . range_status = WrapTargetFail ; break ; case 12 : ranging_data . range_status = XtalkSignalFail ; break ; case 8 : ranging_data . range_status = RangeValidMinRangeClipped ; break ; case 9 : if ( results . stream_count == 0 ) { ranging_data . range_status = RangeValidNoWrapCheckFail ; } else { ranging_data . range_status = RangeValid ; } break ; default : ranging_data . range_status = None ; } ranging_data . peak_signal_count_rate_MCPS = countRateFixedToFloat ( results . peak_signal_count_rate_crosstalk_corrected_mcps_sd0 ) ; ranging_data . ambient_count_rate_MCPS = countRateFixedToFloat ( results . ambient_count_rate_mcps_sd0 ) ; }
get range, status, rates from results buffer
based on VL53L1_GetRangingMeasurementData()
get range status rates from results buffer based on VL53L1_GetRangingMeasurementData ()
// VL53L1_copy_sys_and_core_results_to_range_results() begin // "apply correction gain" // gain factor of 2011 is tuning parm default (VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT) // Basically, this appears to scale the result by 2011/2048, or about 98% // (with the 1024 added for proper rounding). // VL53L1_copy_sys_and_core_results_to_range_results() end // set range_status in ranging_data based on value of RESULT__RANGE_STATUS register // mostly based on ConvertStatusLite() // MULTCLIPFAIL // VCSELWATCHDOGTESTFAILURE // VCSELCONTINUITYTESTFAILURE // NOVHVVALUEFOUND // from SetSimpleData() // USERROICLIP // from SetSimpleData() // GPHSTREAMCOUNT0READY // RANGEPHASECHECK // MSRCNOTARGET // SIGMATHRESHOLDCHECK // PHASECONSISTENCY // RANGEIGNORETHRESHOLD // MINCLIP // RANGECOMPLETE // from VL53L1_copy_sys_and_core_results_to_range_results() // from SetSimpleData()