diff --git a/distancesensor.ts b/distancesensor.ts index 8d34217..7ca15f5 100644 --- a/distancesensor.ts +++ b/distancesensor.ts @@ -734,43 +734,6 @@ namespace distanceSensor { return true } - // Start continuous ranging measurements. If period_ms (optional) is 0 or not - // given, continuous back-to-back mode is used (the sensor takes measurements as - // often as possible) otherwise, continuous timed mode is used, with the given - // inter-measurement period in milliseconds determining how often the sensor - // takes a measurement. - // based on VL53L0X_StartMeasurement() - function DS_start_continuous(period_ms: number) { // period_ms = 0 - I2C_WriteReg8(DS_ADDRESS, 0x80, 0x01) - I2C_WriteReg8(DS_ADDRESS, 0xFF, 0x01) - I2C_WriteReg8(DS_ADDRESS, 0x00, 0x00) - I2C_WriteReg8(DS_ADDRESS, 0x91, DS_stop_variable) - I2C_WriteReg8(DS_ADDRESS, 0x00, 0x01) - I2C_WriteReg8(DS_ADDRESS, 0xFF, 0x00) - I2C_WriteReg8(DS_ADDRESS, 0x80, 0x00) - - if (period_ms != 0) { - // continuous timed mode - - // VL53L0X_SetInterMeasurementPeriodMilliSeconds() begin - - let osc_calibrate_val = I2C_ReadReg16(DS_ADDRESS, DS_Constants.OSC_CALIBRATE_VAL) - - if (osc_calibrate_val != 0) { - period_ms *= osc_calibrate_val - } - - I2C_WriteReg32(DS_ADDRESS, DS_Constants.SYSTEM_INTERMEASUREMENT_PERIOD, period_ms) - - // VL53L0X_SetInterMeasurementPeriodMilliSeconds() end - - I2C_WriteReg8(DS_ADDRESS, DS_Constants.SYSRANGE_START, 0x04) // VL53L0X_REG_SYSRANGE_MODE_TIMED - } else { - // continuous back-to-back mode - I2C_WriteReg8(DS_ADDRESS, DS_Constants.SYSRANGE_START, 0x02) // VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK - } - } - // Did a timeout occur in one of the read functions since the last call to // timeout_occurred()? function timeoutOccurred(): boolean { @@ -792,6 +755,9 @@ namespace distanceSensor { export function vcselPeriodPreRange() { return DS_VcselPeriodPreRange } + export function vcselPeriodFinalRange() { + return DS_VcselPeriodFinalRange + } export function init() { // try resetting from ADDRESS_TARGET @@ -819,6 +785,44 @@ namespace distanceSensor { DS_set_timeout(500) // 0.5 seconds } + // Start continuous ranging measurements. If period_ms (optional) is 0 or not + // given, continuous back-to-back mode is used (the sensor takes measurements as + // often as possible) otherwise, continuous timed mode is used, with the given + // inter-measurement period in milliseconds determining how often the sensor + // takes a measurement. + // based on VL53L0X_StartMeasurement() + export function startContinuous(period_ms: number) { // period_ms = 0 + I2C_WriteReg8(DS_ADDRESS, 0x80, 0x01) + I2C_WriteReg8(DS_ADDRESS, 0xFF, 0x01) + I2C_WriteReg8(DS_ADDRESS, 0x00, 0x00) + I2C_WriteReg8(DS_ADDRESS, 0x91, DS_stop_variable) + I2C_WriteReg8(DS_ADDRESS, 0x00, 0x01) + I2C_WriteReg8(DS_ADDRESS, 0xFF, 0x00) + I2C_WriteReg8(DS_ADDRESS, 0x80, 0x00) + + if (period_ms != 0) { + // continuous timed mode + + // VL53L0X_SetInterMeasurementPeriodMilliSeconds() begin + + let osc_calibrate_val = I2C_ReadReg16(DS_ADDRESS, DS_Constants.OSC_CALIBRATE_VAL) + + if (osc_calibrate_val != 0) { + period_ms *= osc_calibrate_val + } + + I2C_WriteReg32(DS_ADDRESS, DS_Constants.SYSTEM_INTERMEASUREMENT_PERIOD, period_ms) + + // VL53L0X_SetInterMeasurementPeriodMilliSeconds() end + + I2C_WriteReg8(DS_ADDRESS, DS_Constants.SYSRANGE_START, 0x04) // VL53L0X_REG_SYSRANGE_MODE_TIMED + } else { + // continuous back-to-back mode + I2C_WriteReg8(DS_ADDRESS, DS_Constants.SYSRANGE_START, 0x02) // VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK + } + } + + // Set the return signal rate limit check value in units of MCPS (mega counts // per second). "This represents the amplitude of the signal reflected from the