Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
CleoQc committed Jun 21, 2018
1 parent aa74e28 commit 0bc2c4a
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions distancesensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bc2c4a

Please sign in to comment.