Package com.diozero.devices
Class GarminLidarLiteV4
- java.lang.Object
-
- com.diozero.devices.GarminLidarLiteV4
-
- All Implemented Interfaces:
DeviceInterface
,DistanceSensorInterface
,SensorInterface
,AutoCloseable
public class GarminLidarLiteV4 extends Object implements DistanceSensorInterface
Full credit: https://github.com/garmin/LIDARLite_Arduino_Library
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GarminLidarLiteV4.HardwareRevision
static class
GarminLidarLiteV4.PowerMode
static class
GarminLidarLiteV4.Preset
static class
GarminLidarLiteV4.Status
-
Field Summary
Fields Modifier and Type Field Description static int
HARDWARE_REV_A
static int
HARDWARE_REV_B
-
Constructor Summary
Constructors Constructor Description GarminLidarLiteV4()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this devicevoid
configure(GarminLidarLiteV4.Preset preset)
Selects one of several preset configurations as per the Garmin Arduino library configure function.void
disableHighAccuracyMode()
void
factoryReset()
Resets the NVM/Flash storage information back to default settings and executes a SoftDevice reset.int
getBoardTemperature()
Read the board's temperature in degrees Celsius.short[]
getCorrelationData(int numberOfReadings)
The correlation record used to calculate distance can be read from the device.int
getDetectionSensitivity()
Get the detection sensitivity.float
getDistanceCm()
int
getDistanceMeasurement()
Get the distance measurement result in centimetres.int
getFirmwareVersion()
Get the device's coprocessor firmware version number.int
getHardwareVersion()
Get the device's hardware version identifier.int
getHighAccuracyMode()
Get the high accuracy mode.String
getLibraryVersion()
Get the Garmin software library version stringint
getMaximumAcquisitionCount()
Get the maximum number of acquisitions during measurementGarminLidarLiteV4.PowerMode
getPowerMode()
Get theGarminLidarLiteV4.PowerMode
int
getSingleReading()
Take a single distance measurement reading in centimetres.int
getSoCTemperature()
Read the temperature of the nRF SoC in degrees Celsius.GarminLidarLiteV4.Status
getStatus()
Read the STATUS register byte and wrap in aGarminLidarLiteV4.Status
object.byte
getStatusByte()
Read the STATUS register byte value.byte[]
getUnitId()
Get the device's unit id (serial number).boolean
isDeviceBusy()
Read the STATUS register to determine if the device is busy or notboolean
isFlashStorageEnabled()
Storage to be used for register settings.boolean
isHighAccuracyModeEnabled()
Check if high accuracy mode is enabled.boolean
isQuickAcquistionTerminationEnabled()
Get the status of the quick acquisition termination flag.void
resetCorrelationData()
Reset the correlation data pointervoid
setDetectionSensitivity(int detectionSensitivity)
Set the detection sensitivity.void
setFlashStorage(boolean enabled)
Storage for register settings.void
setHighAccuracyMode(int accuracyMode)
Set the high accuracy mode.void
setMaximumAcquisitionCount(int acquisitionCount)
Set the maximum number of acquisitions during measurement.void
setPowerMode(GarminLidarLiteV4.PowerMode powerMode)
NOTE: You must disable HIGH_ACCURACY_MODE before you adjust the power mode.void
setQuickTerminationEnabled(boolean enabled)
Set the quick acquisition termination flag.void
setReceivedBiasCorrectionEnabled(boolean enabled)
Enable / disable the distance measurement receiver bias correction.
-
-
-
Field Detail
-
HARDWARE_REV_A
public static final int HARDWARE_REV_A
- See Also:
- Constant Field Values
-
HARDWARE_REV_B
public static final int HARDWARE_REV_B
- See Also:
- Constant Field Values
-
-
Method Detail
-
getUnitId
public byte[] getUnitId()
Get the device's unit id (serial number).- Returns:
- the device's unit id (serial number)
-
getHardwareVersion
public int getHardwareVersion()
Get the device's hardware version identifier.- Returns:
- hardware version
-
getFirmwareVersion
public int getFirmwareVersion()
Get the device's coprocessor firmware version number. 210 == v2.10- Returns:
- coprocessor firmware version
-
getLibraryVersion
public String getLibraryVersion()
Get the Garmin software library version string- Returns:
- Garmin software library version string
-
factoryReset
public void factoryReset()
Resets the NVM/Flash storage information back to default settings and executes a SoftDevice reset.
-
getBoardTemperature
public int getBoardTemperature()
Read the board's temperature in degrees Celsius.- Returns:
- the board temperature in degrees Celsius
-
getSoCTemperature
public int getSoCTemperature()
Read the temperature of the nRF SoC in degrees Celsius.- Returns:
- the board temperature in degrees Celsius
-
getStatusByte
public byte getStatusByte()
Read the STATUS register byte value.- Returns:
- status register byte value
-
getStatus
public GarminLidarLiteV4.Status getStatus()
Read the STATUS register byte and wrap in aGarminLidarLiteV4.Status
object.- Returns:
- status register value
-
isDeviceBusy
public boolean isDeviceBusy()
Read the STATUS register to determine if the device is busy or not- Returns:
- true if the device is busy taking a measurement or powering on
-
getPowerMode
public GarminLidarLiteV4.PowerMode getPowerMode()
Get theGarminLidarLiteV4.PowerMode
- Returns:
- the
GarminLidarLiteV4.PowerMode
-
setPowerMode
public void setPowerMode(GarminLidarLiteV4.PowerMode powerMode)
NOTE: You must disable HIGH_ACCURACY_MODE before you adjust the power mode.- Parameters:
powerMode
- the new power mode
-
isFlashStorageEnabled
public boolean isFlashStorageEnabled()
Storage to be used for register settings.- Returns:
- whether or not to use Flash/NVM storage for registry settings
-
setFlashStorage
public void setFlashStorage(boolean enabled)
Storage for register settings.
NOTE: Use caution when enabling flash storage. The total number of writes and erases is limited to 10,000.
- Enabled
- Use RAM storage only. When the device is reset, default values are loaded.
- Disabled
- Use FLASH/NVM storage. Any register that supports both read and write operations is stored in NVM and persists over power cycles. When the device is reset, the values stored in NVM are loaded instead of the default values.
- Parameters:
enabled
- whether or not to use Flash/NVM storage for register settings
-
getHighAccuracyMode
public int getHighAccuracyMode()
Get the high accuracy mode. While high accuracy mode is disabled, you can adjust theGarminLidarLiteV4.PowerMode
toAsynchronous
orSynchronous
if required.- 0x00
- High accuracy mode is disabled
- 0x01 to 0xFF
- High accuracy mode is enabled. The value is used as the number of distance measurements to accumulate and average before returning them to the user.
- Returns:
- the number of distance measurements to accumulate and average before returning them to the user (0 == disabled)
-
isHighAccuracyModeEnabled
public boolean isHighAccuracyModeEnabled()
Check if high accuracy mode is enabled.- Returns:
- high accuracy mode status
-
setHighAccuracyMode
public void setHighAccuracyMode(int accuracyMode)
Set the high accuracy mode. While high accuracy mode is disabled, you can adjust theGarminLidarLiteV4.PowerMode
toAsynchronous
orSynchronous
if required.- 0x00
- High accuracy mode is disabled
- 0x01 to 0xFF
- Enable high accuracy mode. The value is used as the number of distance measurements to accumulate and average before returning them to the user.
GarminLidarLiteV4.PowerMode
toAlways On
before you adjust to a non-zero value.- Parameters:
accuracyMode
- the number of distance measurements to accumulate and average before returning them to the user (0 == disabled)
-
disableHighAccuracyMode
public void disableHighAccuracyMode()
-
setReceivedBiasCorrectionEnabled
public void setReceivedBiasCorrectionEnabled(boolean enabled)
Enable / disable the distance measurement receiver bias correction.- Parameters:
enabled
- receiver bias correction status
-
getMaximumAcquisitionCount
public int getMaximumAcquisitionCount()
Get the maximum number of acquisitions during measurement- Returns:
- maximum acquisition count.
-
setMaximumAcquisitionCount
public void setMaximumAcquisitionCount(int acquisitionCount)
Set the maximum number of acquisitions during measurement.- Parameters:
acquisitionCount
- maximum acquisition count.
-
getDetectionSensitivity
public int getDetectionSensitivity()
Get the detection sensitivity.
- 0x00
- Use default valid measurement detection algorithm based on the peak value, signal strength, and noise in the correlation record.
- 0x01 to 0xFF
- Set simple threshold for valid measurement detection.
Values 0x20 to 0x60 generally perform well.
- Returns:
- detectionSensitivity detection sensitivity value (0..255)
-
setDetectionSensitivity
public void setDetectionSensitivity(int detectionSensitivity)
Set the detection sensitivity.
- 0x00
- Use default valid measurement detection algorithm based on the peak value, signal strength, and noise in the correlation record.
- 0x01 to 0xFF
- Set simple threshold for valid measurement detection.
Values 0x20 to 0x60 generally perform well.
- Parameters:
detectionSensitivity
- detection sensitivity value (0..255)
-
isQuickAcquistionTerminationEnabled
public boolean isQuickAcquistionTerminationEnabled()
Get the status of the quick acquisition termination flag. If enabled the device terminates the distance measurement early if it anticipates the signal peak in the correlation record will reach the maximum value.- Returns:
- acquisition quick termination status
-
setQuickTerminationEnabled
public void setQuickTerminationEnabled(boolean enabled)
Set the quick acquisition termination flag. If enabled the device terminates the distance measurement early if it anticipates the signal peak in the correlation record will reach the maximum value.- Parameters:
enabled
- quick acquisition termination value
-
getCorrelationData
public short[] getCorrelationData(int numberOfReadings)
The correlation record used to calculate distance can be read from the device. It has a bipolar wave shape, transitioning from a positive going portion to a roughly symmetrical negative going pulse. The point where the signal crosses zero represents the effective delay for the reference and return signals.
Process:
- Take a distance reading (there is no correlation record without at least one distance reading being taken)
- For as many points as you want to read from the record (max is 192) read the two byte signed correlation data point.
- Parameters:
numberOfReadings
- The number of readings to take up to a maximum of 192- Returns:
- the correlation data
-
resetCorrelationData
public void resetCorrelationData()
Reset the correlation data pointer
-
configure
public void configure(GarminLidarLiteV4.Preset preset)
Selects one of several preset configurations as per the Garmin Arduino library configure function.- Parameters:
preset
- preset max acquisition count and quick termination values
-
getDistanceMeasurement
public int getDistanceMeasurement()
Get the distance measurement result in centimetres.- Returns:
- distance measurement result in centimetres
-
getSingleReading
public int getSingleReading() throws RuntimeInterruptedException
Take a single distance measurement reading in centimetres.- Returns:
- distance in centimetres
- Throws:
RuntimeInterruptedException
- if interrupted while taking the reading
-
getDistanceCm
public float getDistanceCm() throws RuntimeIOException
- Specified by:
getDistanceCm
in interfaceDistanceSensorInterface
- Returns:
- distance in cm
- Throws:
RuntimeIOException
-
close
public void close() throws RuntimeIOException
Description copied from interface:DeviceInterface
Close this device- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceInterface
- Throws:
RuntimeIOException
-
-