File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -250,6 +250,41 @@ uint8_t VL53L1X::getDistanceMode()
250250 return _distanceMode;
251251}
252252
253+ // Set a custom zone from the array of sensors. Minimum of 4x4, maximum of 16x16.
254+ void VL53L1X::setUserRoi (UserRoi *roi)
255+ {
256+ uint8_t centerX = (roi->topLeftX + roi->bottomRightX + 1 ) / 2 ;
257+ uint8_t centerY = (roi->topLeftY + roi->bottomRightY + 1 ) / 2 ;
258+ uint8_t width = roi->bottomRightX - roi->topLeftX ;
259+ uint8_t height = roi->topLeftY - roi->bottomRightY ;
260+
261+ if (width < 3 || height < 3 ){
262+ return ;
263+ }
264+ else {
265+ setCenter (centerX, centerY);
266+ setZoneSize (width, height);
267+ }
268+ }
269+
270+ void VL53L1X::setCenter (uint8_t centerX, uint8_t centerY){
271+ uint8_t centerValue;
272+
273+ if (centerX > 7 ){
274+ centerValue = 128 + (centerY << 3 ) + (15 - centerX);
275+ }
276+ else {
277+ centerValue = ((15 - centerY) << 3 ) + centerX;
278+ }
279+
280+ writeRegister (VL53L1_ROI_CONFIG__USER_ROI_CENTRE_SPAD , centerValue);
281+ }
282+
283+ void VL53L1X::setZoneSize (uint8_t width, uint8_t height){
284+ uint8_t dimensions = (height << 4 ) + width;
285+ writeRegister (VL53L1_ROI_CONFIG__USER_ROI_REQUESTED_GLOBAL_XY_SIZE, dimensions);
286+ }
287+
253288// The sensor returns a range status that needs to be re-mapped to one of 9 different statuses
254289// This does that.
255290uint8_t VL53L1X::getRangeStatus ()
Original file line number Diff line number Diff line change @@ -79,6 +79,14 @@ const byte defaultAddress_VL53L1X = 0x29; //The default I2C address for the VL53
7979#endif
8080// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8181
82+ // Struct to contain the parameters for custom user zones. Each value must be in the range from 0 to 15.
83+ typedef struct {
84+ uint8_t topLeftX;
85+ uint8_t topLeftY;
86+ uint8_t bottomRightX;
87+ uint8_t bottomRightY;
88+ }UserRoi;
89+
8290class VL53L1X {
8391 public:
8492
@@ -97,7 +105,11 @@ class VL53L1X {
97105 uint16_t readRegister16 (uint16_t addr); // Read two bytes from a 16-bit address
98106 boolean writeRegister (uint16_t addr, uint8_t val); // Write a byte to a spot
99107 boolean writeRegister16 (uint16_t addr, uint16_t val); // Write two bytes to a spot
100-
108+
109+ void setUserRoi (UserRoi*); // Set custom sensor zones
110+ void setCenter (uint8_t centerX, uint8_t centerY); // Set the center of a custom zone
111+ void setZoneSize (uint8_t width, uint8_t height); // Set the size of a custom zone
112+
101113 private:
102114
103115 // Variables
You can’t perform that action at this time.
0 commit comments