Skip to content

Commit

Permalink
Updated Adafruit_VL53L0X.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Dec 14, 2021
1 parent b64546e commit a2b2ea4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
skip: "" # Use resource script entry
ignore_words_file: "Tools/spelling/ignore.txt"
check_filenames: true
# only_warn: 1
only_warn: 1
111 changes: 19 additions & 92 deletions Sming/Libraries/.patches/Adafruit_VL53L0X.patch
Original file line number Diff line number Diff line change
@@ -1,100 +1,27 @@
diff --git a/README.md b/README.md
index c7c7435..f5cc654 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,6 @@
-# Adafruit VL53L0X Library [![Build Status](https://github.com/adafruit/Adafruit_VL53L0X/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_VL53L0X/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_VL53L0X/html/index.html)
+# Adafruit VL53L0X Library
+
+[![Build Status](https://travis-ci.com/adafruit/Adafruit_VL53L0X.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_VL53L0X)

<img src="https://cdn-shop.adafruit.com/970x728/3317-03.jpg" height="300"/>

diff --git a/src/Adafruit_VL53L0X.cpp b/src/Adafruit_VL53L0X.cpp
index 5a1e650..6699d6e 100644
index 00d0af2..8fd9bd2 100644
--- a/src/Adafruit_VL53L0X.cpp
+++ b/src/Adafruit_VL53L0X.cpp
@@ -35,8 +35,8 @@
#define VERSION_REQUIRED_MINOR 0 ///< Required sensor minor version
#define VERSION_REQUIRED_BUILD 1 ///< Required sensor build
@@ -36,8 +36,8 @@
#define VERSION_REQUIRED_MINOR 0 ///< Required sensor minor version
#define VERSION_REQUIRED_BUILD 1 ///< Required sensor build

-#define STR_HELPER( x ) #x ///< a string helper
-#define STR( x ) STR_HELPER(x) ///< string helper wrapper
-#define STR_HELPER(x) #x ///< a string helper
-#define STR(x) STR_HELPER(x) ///< string helper wrapper
+//#define STR_HELPER( x ) #x ///< a string helper
+//#define STR( x ) STR_HELPER(x) ///< string helper wrapper

/**************************************************************************/
/*!
@@ -162,8 +162,33 @@ boolean Adafruit_VL53L0X::begin(uint8_t i2c_addr, boolean debug, TwoWire *i2c) {
Status = VL53L0X_SetLimitCheckEnable( pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1 );
}

- if( Status == VL53L0X_ERROR_NONE ) {
- Status = VL53L0X_SetLimitCheckValue( pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, (FixPoint1616_t)( 1.5 * 0.023 * 65536 ) );
+ if(!longRange) { // 30mm to 1.2 meter
+ if( Status == VL53L0X_ERROR_NONE ) {
+ Status = VL53L0X_SetLimitCheckValue( pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, (FixPoint1616_t)( 1.5 * 0.023 * 65536 ) );
+ }
+ }
+ else { // can detect as far as 1.5 to 2 meters on a nice white reflective surface
+ // @credits: https://github.com/satoshinm/Adafruit_VL53L0X/commit/72c71bd44091f95ef1211f9ff3928e675dda1348
+ // Long range mode - based on https://github.com/johnbryanmoore/VL53L0X_rasp_python/blob/master/python_lib/vl53l0x_python.c#L292
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = VL53L0X_SetLimitCheckValue(pMyDevice, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, (FixPoint1616_t)(0.1*65536));
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = VL53L0X_SetLimitCheckValue(pMyDevice, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, (FixPoint1616_t)(60*65536));
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(pMyDevice, 33000);
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = VL53L0X_SetVcselPulsePeriod(pMyDevice, VL53L0X_VCSEL_PERIOD_PRE_RANGE, 18);
+ }
+
+ if (Status == VL53L0X_ERROR_NONE) {
+ Status = VL53L0X_SetVcselPulsePeriod(pMyDevice, VL53L0X_VCSEL_PERIOD_FINAL_RANGE, 14);
+ }
}

if( Status == VL53L0X_ERROR_NONE ) {
@@ -268,3 +293,8 @@ void Adafruit_VL53L0X::printRangeStatus( VL53L0X_RangingMeasurementData_t* pRang
Serial.println( buf );

}
+
+void Adafruit_VL53L0X::setLongRangeMode(bool flag)
+{
+ longRange = flag;
+}
diff --git a/src/Adafruit_VL53L0X.h b/src/Adafruit_VL53L0X.h
index 6f06604..47841c7 100644
--- a/src/Adafruit_VL53L0X.h
+++ b/src/Adafruit_VL53L0X.h
@@ -38,6 +38,7 @@
class Adafruit_VL53L0X
{
public:
+ void setLongRangeMode(bool flag);
boolean begin(uint8_t i2c_addr = VL53L0X_I2C_ADDR, boolean debug = false, TwoWire *i2c = &Wire);
boolean setAddress(uint8_t newAddr);

@@ -65,6 +66,7 @@ class Adafruit_VL53L0X
VL53L0X_Version_t Version;
VL53L0X_Version_t *pVersion = &Version;
VL53L0X_DeviceInfo_t DeviceInfo;
+ bool longRange = false;
};

#endif
diff --git a/src/vl53l0x_platform_log.h b/src/vl53l0x_platform_log.h
index 26387d0..d203b3c 100644
--- a/src/vl53l0x_platform_log.h
+++ b/src/vl53l0x_platform_log.h
@@ -88,13 +88,13 @@ void trace_print_module_function(uint32_t module, uint32_t level, uint32_t funct
#define LOG_GET_TIME() (int)clock()

#define _LOG_FUNCTION_START(module, fmt, ... ) \
- trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <START> %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);
+ trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <START> %s " fmt "\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);

#define _LOG_FUNCTION_END(module, status, ... )\
trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)

#define _LOG_FUNCTION_END_FMT(module, status, fmt, ... )\
- trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status,##__VA_ARGS__)
+ trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, "%ld <END> %s %d " fmt "\n", LOG_GET_TIME(), __FUNCTION__, (int)status,##__VA_ARGS__)

// __func__ is gcc only
//#define VL53L0X_ErrLog( fmt, ...) fprintf(stderr, "VL53L0X_ErrLog %s" fmt "\n", __func__, ##__VA_ARGS__)
/*!
11 changes: 1 addition & 10 deletions samples/Distance_Vl53l0x/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,9 @@ void init()
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(true); // Enable debug output to serial

#ifndef DISABLE_WIFI
// WIFI not needed for demo. So disabling WIFI.
WifiStation.enable(false);
WifiAccessPoint.enable(false);
#endif

// Create components.
Wire.begin(SDA, SCL);

lox.setLongRangeMode(true);

if(!lox.begin()) {
if(!lox.begin(VL53L0X_I2C_ADDR, false, &Wire, Adafruit_VL53L0X::VL53L0X_SENSE_LONG_RANGE)) {
Serial.println(F("Failed to boot VL53L0X"));
while(1) {
}
Expand Down

0 comments on commit a2b2ea4

Please sign in to comment.