-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvl53_manager.cpp
More file actions
55 lines (42 loc) · 1.23 KB
/
vl53_manager.cpp
File metadata and controls
55 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "vl53_manager.h"
static VL53Sensor sensors[MAX_VL53_SENSORS];
static int sensorCount = 0;
static void selectChannel(uint8_t channel) {
Wire.beginTransmission(TCA9548A_ADDR);
Wire.write(1 << channel);
Wire.endTransmission();
delay(2);
}
void vl53Init() {
Wire.begin();
Wire.setClock(400000);
sensorCount = 0;
}
bool vl53AddSensor(uint8_t channel) {
if (sensorCount >= MAX_VL53_SENSORS) return false;
selectChannel(channel);
if (!sensors[sensorCount].tof.begin()) {
Serial.printf("VL53 not found on channel %d\n", channel);
return false;
}
sensors[sensorCount].tof.setResolution(64);
sensors[sensorCount].tof.startRanging();
sensors[sensorCount].channel = channel;
sensors[sensorCount].active = true;
sensorCount++;
Serial.printf("VL53 initialized on channel %d\n", channel);
return true;
}
bool vl53Read(uint8_t idx) {
if (idx >= sensorCount || !sensors[idx].active) return false;
selectChannel(sensors[idx].channel);
if (!sensors[idx].tof.isDataReady()) return false;
return sensors[idx].tof.getRangingData(&sensors[idx].results);
}
int vl53GetCount() {
return sensorCount;
}
VL53Sensor* vl53GetSensor(uint8_t idx) {
if (idx >= sensorCount) return nullptr;
return &sensors[idx];
}