@depz/sensor-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +69 -0
  2. package/dist/dataset.d.ts +93 -0
  3. package/dist/dataset.d.ts.map +1 -0
  4. package/dist/dataset.js +253 -0
  5. package/dist/dataset.js.map +1 -0
  6. package/dist/device/device.d.ts +185 -0
  7. package/dist/device/device.d.ts.map +1 -0
  8. package/dist/device/device.js +421 -0
  9. package/dist/device/device.js.map +1 -0
  10. package/dist/device/link.d.ts +62 -0
  11. package/dist/device/link.d.ts.map +1 -0
  12. package/dist/device/link.js +130 -0
  13. package/dist/device/link.js.map +1 -0
  14. package/dist/discovery.d.ts +109 -0
  15. package/dist/discovery.d.ts.map +1 -0
  16. package/dist/discovery.js +281 -0
  17. package/dist/discovery.js.map +1 -0
  18. package/dist/errors.d.ts +39 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +69 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index.d.ts +42 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +31 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/protocol/bno086.d.ts +36 -0
  27. package/dist/protocol/bno086.d.ts.map +1 -0
  28. package/dist/protocol/bno086.js +38 -0
  29. package/dist/protocol/bno086.js.map +1 -0
  30. package/dist/protocol/common.d.ts +103 -0
  31. package/dist/protocol/common.d.ts.map +1 -0
  32. package/dist/protocol/common.js +121 -0
  33. package/dist/protocol/common.js.map +1 -0
  34. package/dist/protocol/crc.d.ts +17 -0
  35. package/dist/protocol/crc.d.ts.map +1 -0
  36. package/dist/protocol/crc.js +55 -0
  37. package/dist/protocol/crc.js.map +1 -0
  38. package/dist/protocol/framing.d.ts +65 -0
  39. package/dist/protocol/framing.d.ts.map +1 -0
  40. package/dist/protocol/framing.js +152 -0
  41. package/dist/protocol/framing.js.map +1 -0
  42. package/dist/protocol/fwdepz.d.ts +21 -0
  43. package/dist/protocol/fwdepz.d.ts.map +1 -0
  44. package/dist/protocol/fwdepz.js +46 -0
  45. package/dist/protocol/fwdepz.js.map +1 -0
  46. package/dist/protocol/identity.d.ts +14 -0
  47. package/dist/protocol/identity.d.ts.map +1 -0
  48. package/dist/protocol/identity.js +28 -0
  49. package/dist/protocol/identity.js.map +1 -0
  50. package/dist/protocol/sr04.d.ts +38 -0
  51. package/dist/protocol/sr04.d.ts.map +1 -0
  52. package/dist/protocol/sr04.js +58 -0
  53. package/dist/protocol/sr04.js.map +1 -0
  54. package/dist/protocol/usb-ids.d.ts +60 -0
  55. package/dist/protocol/usb-ids.d.ts.map +1 -0
  56. package/dist/protocol/usb-ids.js +79 -0
  57. package/dist/protocol/usb-ids.js.map +1 -0
  58. package/dist/protocol/vl53l8.d.ts +59 -0
  59. package/dist/protocol/vl53l8.d.ts.map +1 -0
  60. package/dist/protocol/vl53l8.js +116 -0
  61. package/dist/protocol/vl53l8.js.map +1 -0
  62. package/dist/sensors/bno086/bno086.d.ts +197 -0
  63. package/dist/sensors/bno086/bno086.d.ts.map +1 -0
  64. package/dist/sensors/bno086/bno086.js +543 -0
  65. package/dist/sensors/bno086/bno086.js.map +1 -0
  66. package/dist/sensors/bno086/reports.d.ts +289 -0
  67. package/dist/sensors/bno086/reports.d.ts.map +1 -0
  68. package/dist/sensors/bno086/reports.js +397 -0
  69. package/dist/sensors/bno086/reports.js.map +1 -0
  70. package/dist/sensors/bno086/sh2.d.ts +307 -0
  71. package/dist/sensors/bno086/sh2.d.ts.map +1 -0
  72. package/dist/sensors/bno086/sh2.js +480 -0
  73. package/dist/sensors/bno086/sh2.js.map +1 -0
  74. package/dist/sensors/bno086/shtp.d.ts +98 -0
  75. package/dist/sensors/bno086/shtp.d.ts.map +1 -0
  76. package/dist/sensors/bno086/shtp.js +205 -0
  77. package/dist/sensors/bno086/shtp.js.map +1 -0
  78. package/dist/sensors/sr04.d.ts +65 -0
  79. package/dist/sensors/sr04.d.ts.map +1 -0
  80. package/dist/sensors/sr04.js +121 -0
  81. package/dist/sensors/sr04.js.map +1 -0
  82. package/dist/sensors/vl53l8/assets/ch.d.ts +16 -0
  83. package/dist/sensors/vl53l8/assets/ch.d.ts.map +1 -0
  84. package/dist/sensors/vl53l8/assets/ch.js +22 -0
  85. package/dist/sensors/vl53l8/assets/ch.js.map +1 -0
  86. package/dist/sensors/vl53l8/assets/cx.d.ts +16 -0
  87. package/dist/sensors/vl53l8/assets/cx.d.ts.map +1 -0
  88. package/dist/sensors/vl53l8/assets/cx.js +22 -0
  89. package/dist/sensors/vl53l8/assets/cx.js.map +1 -0
  90. package/dist/sensors/vl53l8/assets/decode.d.ts +7 -0
  91. package/dist/sensors/vl53l8/assets/decode.d.ts.map +1 -0
  92. package/dist/sensors/vl53l8/assets/decode.js +35 -0
  93. package/dist/sensors/vl53l8/assets/decode.js.map +1 -0
  94. package/dist/sensors/vl53l8/assets/index.d.ts +19 -0
  95. package/dist/sensors/vl53l8/assets/index.d.ts.map +1 -0
  96. package/dist/sensors/vl53l8/assets/index.js +11 -0
  97. package/dist/sensors/vl53l8/assets/index.js.map +1 -0
  98. package/dist/sensors/vl53l8/cnh.d.ts +113 -0
  99. package/dist/sensors/vl53l8/cnh.d.ts.map +1 -0
  100. package/dist/sensors/vl53l8/cnh.js +299 -0
  101. package/dist/sensors/vl53l8/cnh.js.map +1 -0
  102. package/dist/sensors/vl53l8/uld.d.ts +346 -0
  103. package/dist/sensors/vl53l8/uld.d.ts.map +1 -0
  104. package/dist/sensors/vl53l8/uld.js +1388 -0
  105. package/dist/sensors/vl53l8/uld.js.map +1 -0
  106. package/dist/sensors/vl53l8/vl53l8.d.ts +182 -0
  107. package/dist/sensors/vl53l8/vl53l8.d.ts.map +1 -0
  108. package/dist/sensors/vl53l8/vl53l8.js +411 -0
  109. package/dist/sensors/vl53l8/vl53l8.js.map +1 -0
  110. package/dist/transport/loopback.d.ts +18 -0
  111. package/dist/transport/loopback.d.ts.map +1 -0
  112. package/dist/transport/loopback.js +53 -0
  113. package/dist/transport/loopback.js.map +1 -0
  114. package/dist/transport/node.d.ts +51 -0
  115. package/dist/transport/node.d.ts.map +1 -0
  116. package/dist/transport/node.js +123 -0
  117. package/dist/transport/node.js.map +1 -0
  118. package/dist/transport/replay.d.ts +68 -0
  119. package/dist/transport/replay.d.ts.map +1 -0
  120. package/dist/transport/replay.js +196 -0
  121. package/dist/transport/replay.js.map +1 -0
  122. package/dist/transport/types.d.ts +23 -0
  123. package/dist/transport/types.d.ts.map +1 -0
  124. package/dist/transport/types.js +7 -0
  125. package/dist/transport/types.js.map +1 -0
  126. package/dist/transport/webserial.d.ts +69 -0
  127. package/dist/transport/webserial.d.ts.map +1 -0
  128. package/dist/transport/webserial.js +196 -0
  129. package/dist/transport/webserial.js.map +1 -0
  130. package/package.json +77 -0
@@ -0,0 +1,299 @@
1
+ /**
2
+ * VL53L8CH CNH (Compact Network Histogram) — TypeScript port of the parts of
3
+ * vl53lmz_plugin_cnh.c / vl53lmz_plugin_motion_indicator.c (VL53LMZ ULD
4
+ * 2.0.16) needed to configure CNH, compute the on-device buffer size, and
5
+ * decode a captured CNH data block into per-aggregate histograms.
6
+ *
7
+ * 1:1 mirror of the Python reference `depz_sensor_sdk.vl53l8.cnh`.
8
+ *
9
+ * CNH is the reason to run the VL53L8CH firmware instead of plain VL53L8CX:
10
+ * the sensor returns a per-aggregate distance histogram (the "compact network
11
+ * histogram") on top of the normal ranging frame. The MCU streaming buffer is
12
+ * too small to push a full CNH frame, so the host captures it in poll-mode
13
+ * (chunked READ_REG) — see VL53L8CX.startRanging(cnhDataSize).
14
+ *
15
+ * Register/struct layouts are a 1:1 port of the C plugin; do not "simplify"
16
+ * the offset arithmetic. The CNH configuration here fixes the cnh_cfg flags
17
+ * to DISABLE_PING_PONG | DISABLE_VARIANCE (+ ambient / xtalk / zero-invalid /
18
+ * ref-residual), matching Example_12_cnh_data.c — the decode below assumes
19
+ * those.
20
+ */
21
+ // ---- fundamental histogram characteristics (plugin_cnh.h) ----
22
+ export const CNH_PULSE_WIDTH_BIN = 10;
23
+ export const CNH_BIN_WIDTH_MM = 37.5348;
24
+ // ---- DCI indexes ----
25
+ /** VL53LMZ_MI_CFG_DEV_IDX (cnh_send_config target). */
26
+ export const MI_CFG_DEV_IDX = 0xbfac;
27
+ /** VL53LMZ_CNH_DATA_IDX (output block index). */
28
+ export const CNH_DATA_IDX = 0xc048;
29
+ // ---- limits (plugin_cnh.h) ----
30
+ export const CNH_MAX_DATA_WORDS = 1540;
31
+ export const CNH_MAX_DATA_BYTES = CNH_MAX_DATA_WORDS * 4; // 6160
32
+ // ---- cnh_cfg flags (plugin_motion_indicator.h) ----
33
+ export const MI_SFE_DISABLE_PING_PONG = 0x01;
34
+ export const MI_SFE_DISABLE_VARIANCE = 0x02;
35
+ export const MI_SFE_ENABLE_AMBIENT_LEVEL = 0x04;
36
+ export const MI_SFE_ENABLE_XTALK_REMOVAL = 0x08;
37
+ export const MI_SFE_ZERO_NON_VALID_BINS = 0x10;
38
+ export const MI_SFE_STORE_REF_RESIDUAL = 0x20;
39
+ export const MI_MAP_ID_LENGTH = 64; // VL53LMZ_RESOLUTION_8X8
40
+ export const MI_INDICATOR_LENGTH = 32;
41
+ // ---- persistent-data header layout (plugin_cnh.c) ----
42
+ const CNH_PER_HEADER_WORDS = 5; // CNH_PER_HEADER_BYTES / 4
43
+ const CNH_PER_BUFFER_HEADER_WORDS = 2; // CNH_PER_BUFFER_HEADER_BYTES / 4
44
+ const CNH_PER_HEADER_BUFFER_INFO_IDX = 1;
45
+ const CNH_PER_HEADER_FLAGS_IDX = 3;
46
+ const BUFFER_INFO_WORDS_MASK = 0xffff;
47
+ const BUFFER_INFO_FLAGS_SHIFT = 24;
48
+ const MI_STATE_PING = 0;
49
+ export class CnhConfigError extends Error {
50
+ constructor(message) {
51
+ super(message);
52
+ this.name = "CnhConfigError";
53
+ }
54
+ }
55
+ /**
56
+ * Mirror of VL53LMZ_Motion_Configuration plus the helpers that fill it.
57
+ * Build with initConfig()/createAggMap(), check size with requiredMemory(),
58
+ * then pack() the 156-byte struct for cnh_send_config.
59
+ */
60
+ export class CnhConfig {
61
+ refBinOffset = 0;
62
+ detectionThreshold = 0;
63
+ extraNoiseSigma = 0;
64
+ nullDenClipValue = 0;
65
+ memUpdateMode = 0;
66
+ memUpdateChoice = 0;
67
+ sumSpan = 0;
68
+ featureLength = 0;
69
+ nbOfAggregates = 0;
70
+ nbOfTemporalAccumulations = 1;
71
+ minNbForGlobalDetection = 0;
72
+ globalIndicatorFormat1 = 0;
73
+ globalIndicatorFormat2 = 0;
74
+ cnhCfg = 0;
75
+ cnhFlexShift = 0;
76
+ spare3 = 0;
77
+ mapId = new Array(MI_MAP_ID_LENGTH).fill(-1);
78
+ indicatorFormat1 = new Array(MI_INDICATOR_LENGTH).fill(0);
79
+ indicatorFormat2 = new Array(MI_INDICATOR_LENGTH).fill(0);
80
+ // ---- vl53lmz_cnh_init_config ----
81
+ /**
82
+ * startBin: first device-histogram bin; numBins: CNH bins;
83
+ * subSample: bins of the device histogram summed per CNH bin.
84
+ */
85
+ initConfig(startBin, numBins, subSample) {
86
+ this.refBinOffset = startBin * 2048;
87
+ this.detectionThreshold = 0;
88
+ this.extraNoiseSigma = 0;
89
+ this.nullDenClipValue = 0;
90
+ this.memUpdateMode = 0;
91
+ this.memUpdateChoice = 0;
92
+ this.featureLength = numBins & 0xff;
93
+ this.sumSpan = subSample & 0xff;
94
+ this.nbOfTemporalAccumulations = 1;
95
+ this.minNbForGlobalDetection = 0;
96
+ this.globalIndicatorFormat1 = 0;
97
+ this.globalIndicatorFormat2 = 0;
98
+ this.cnhCfg =
99
+ MI_SFE_DISABLE_PING_PONG |
100
+ MI_SFE_DISABLE_VARIANCE |
101
+ MI_SFE_ENABLE_AMBIENT_LEVEL |
102
+ MI_SFE_ENABLE_XTALK_REMOVAL |
103
+ MI_SFE_ZERO_NON_VALID_BINS |
104
+ MI_SFE_STORE_REF_RESIDUAL;
105
+ this.cnhFlexShift = 1;
106
+ this.spare3 = 0;
107
+ }
108
+ // ---- vl53lmz_cnh_create_agg_map ----
109
+ /**
110
+ * Map device zones to CNH aggregates. resolution: 16 (4x4) or 64 (8x8)
111
+ * — must match the value passed to setResolution().
112
+ */
113
+ createAggMap(resolution, startX, startY, mergeX, mergeY, cols, rows) {
114
+ this.mapId = new Array(MI_MAP_ID_LENGTH).fill(-1);
115
+ const zoneRes = resolution === 16 ? 4 : 8;
116
+ if (startX + cols * mergeX > zoneRes || startY + rows * mergeY > zoneRes) {
117
+ throw new CnhConfigError("agg map exceeds zone grid");
118
+ }
119
+ this.nbOfAggregates = cols * rows;
120
+ for (let row = startY; row < startY + rows * mergeY; row++) {
121
+ for (let col = startX; col < startX + cols * mergeX; col++) {
122
+ const i = row * zoneRes + col;
123
+ const aggId = Math.floor((row - startY) / mergeY) * cols + Math.floor((col - startX) / mergeX);
124
+ if (aggId >= 0 && aggId < MI_MAP_ID_LENGTH) {
125
+ this.mapId[i] = aggId;
126
+ }
127
+ else {
128
+ throw new CnhConfigError("agg id out of range");
129
+ }
130
+ }
131
+ }
132
+ }
133
+ // ---- vl53lmz_cnh_calc_required_memory ----
134
+ /**
135
+ * On-device CNH buffer size in bytes for this config. Throws if the
136
+ * config is blank or the size exceeds CNH_MAX_DATA_BYTES.
137
+ */
138
+ requiredMemory() {
139
+ if (this.nbOfAggregates === 0) {
140
+ throw new CnhConfigError("agg map not created");
141
+ }
142
+ const size = calcRequiredMemory(this.cnhCfg, this.nbOfAggregates, this.featureLength);
143
+ if (size > CNH_MAX_DATA_BYTES) {
144
+ throw new CnhConfigError(`CNH needs ${size} B > max ${CNH_MAX_DATA_BYTES} B — reduce aggregates or bins`);
145
+ }
146
+ return size;
147
+ }
148
+ // ---- vl53lmz_cnh_calc_min_max_distance ----
149
+ /** [min, max] target distance, in mm, fully captured by the histogram. */
150
+ minMaxDistanceMm() {
151
+ const constant = (CNH_PULSE_WIDTH_BIN / 2.0) * CNH_BIN_WIDTH_MM;
152
+ const start = this.refBinOffset / 2048.0;
153
+ const firstCenter = (start + this.sumSpan / 2.0) * CNH_BIN_WIDTH_MM;
154
+ const lastCenter = (start + (this.featureLength - 1) * this.sumSpan + this.sumSpan / 2.0) * CNH_BIN_WIDTH_MM;
155
+ return [Math.trunc(firstCenter + constant), Math.trunc(lastCenter - constant)];
156
+ }
157
+ /** Distance (mm) at the centre of CNH histogram bin `binIdx`. */
158
+ binCenterMm(binIdx) {
159
+ const start = this.refBinOffset / 2048.0;
160
+ return (start + binIdx * this.sumSpan + this.sumSpan / 2.0) * CNH_BIN_WIDTH_MM;
161
+ }
162
+ // ---- pack the 156-byte VL53LMZ_Motion_Configuration struct ----
163
+ pack() {
164
+ const out = new Uint8Array(156);
165
+ const dv = new DataView(out.buffer);
166
+ dv.setUint32(0, this.refBinOffset >>> 0, true); // '<i' with & 0xFFFFFFFF
167
+ dv.setUint32(4, this.detectionThreshold >>> 0, true);
168
+ dv.setUint32(8, this.extraNoiseSigma >>> 0, true);
169
+ dv.setUint32(12, this.nullDenClipValue >>> 0, true);
170
+ const bytes = [
171
+ this.memUpdateMode,
172
+ this.memUpdateChoice,
173
+ this.sumSpan,
174
+ this.featureLength,
175
+ this.nbOfAggregates,
176
+ this.nbOfTemporalAccumulations,
177
+ this.minNbForGlobalDetection,
178
+ this.globalIndicatorFormat1,
179
+ this.globalIndicatorFormat2,
180
+ this.cnhCfg,
181
+ this.cnhFlexShift,
182
+ this.spare3,
183
+ ];
184
+ for (let i = 0; i < 12; i++)
185
+ out[16 + i] = bytes[i] & 0xff;
186
+ for (let i = 0; i < MI_MAP_ID_LENGTH; i++)
187
+ dv.setInt8(28 + i, this.mapId[i]);
188
+ for (let i = 0; i < MI_INDICATOR_LENGTH; i++)
189
+ out[92 + i] = this.indicatorFormat1[i] & 0xff;
190
+ for (let i = 0; i < MI_INDICATOR_LENGTH; i++)
191
+ out[124 + i] = this.indicatorFormat2[i] & 0xff;
192
+ return out;
193
+ }
194
+ }
195
+ /** _cnh_get_pingpong_size_in_word, returned in 32-bit words. */
196
+ function pingpongSizeInWords(optionFlags, nbAgg, featLength) {
197
+ const aggXFeat = nbAgg * featLength;
198
+ let size = CNH_PER_BUFFER_HEADER_WORDS * 4;
199
+ size += aggXFeat * 4; // FEAT_INT (32b each)
200
+ size += Math.floor((3 + aggXFeat) / 4) * 4; // FEAT_FRAC (8b each, padded)
201
+ size += nbAgg * 4; // AMBIENT_INT
202
+ size += Math.floor((3 + nbAgg) / 4) * 4; // AMBIENT_FRAC
203
+ if ((optionFlags & MI_SFE_DISABLE_VARIANCE) === 0) {
204
+ size += aggXFeat * 4; // VARIANCE_INT
205
+ size += Math.floor((3 + aggXFeat) / 4) * 4; // VARIANCE_FRAC
206
+ }
207
+ return Math.floor(size / 4);
208
+ }
209
+ /** _cnh_calculate_required_memory, in bytes. */
210
+ function calcRequiredMemory(optionFlags, nbAgg, featLength) {
211
+ let size = pingpongSizeInWords(optionFlags, nbAgg, featLength) * 4;
212
+ if ((optionFlags & MI_SFE_DISABLE_PING_PONG) === 0) {
213
+ size *= 2;
214
+ }
215
+ size += CNH_PER_HEADER_WORDS * 4;
216
+ return size;
217
+ }
218
+ /**
219
+ * The two cnh_cfg flags that affect the memory calc (ping-pong + variance
220
+ * disabled); used only as `maxBins`' default `optionFlags`. Note initConfig()
221
+ * programs a larger flag superset onto the device — see its body.
222
+ */
223
+ const DEFAULT_CNH_CFG = MI_SFE_DISABLE_PING_PONG | MI_SFE_DISABLE_VARIANCE;
224
+ /**
225
+ * Largest CNH bins-per-aggregate count whose on-device buffer still fits
226
+ * CNH_MAX_DATA_BYTES for the given aggregate count.
227
+ */
228
+ export function maxBins(nbAggregates, optionFlags = DEFAULT_CNH_CFG) {
229
+ let feat = 0;
230
+ while (calcRequiredMemory(optionFlags, nbAggregates, feat + 1) <= CNH_MAX_DATA_BYTES) {
231
+ feat += 1;
232
+ }
233
+ return feat;
234
+ }
235
+ /**
236
+ * Decode a captured CNH data block (`raw` bytes, byte-swapped exactly like
237
+ * the standard ranging blocks) into per-aggregate histograms.
238
+ *
239
+ * Faithful port of vl53lmz_cnh_get_block_addresses /
240
+ * _cnh_get_mem_block_addresses for the fixed cnh_cfg (ping-pong + variance
241
+ * disabled).
242
+ */
243
+ export function decode(cfg, raw) {
244
+ const nbAgg = cfg.nbOfAggregates;
245
+ const feat = cfg.featureLength;
246
+ const dv = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
247
+ const nwords = Math.floor(raw.length / 4);
248
+ const words = [];
249
+ for (let i = 0; i < nwords; i++)
250
+ words.push(dv.getInt32(i * 4, true)); // signed int32 view
251
+ const refResidual = (words[2] >>> 0) / 2048.0; // vl53lmz_cnh_get_ref_residual
252
+ const aggregates = [];
253
+ for (let aggId = 0; aggId < nbAgg; aggId++) {
254
+ aggregates.push(decodeAggregate(words, dv, nbAgg, feat, aggId));
255
+ }
256
+ return { refResidual, aggregates };
257
+ }
258
+ function decodeAggregate(words, dv, nbAgg, feat, aggId) {
259
+ const aggXFeat = nbAgg * feat;
260
+ const aggOff = aggId * feat;
261
+ const state = words[0];
262
+ const info = words[CNH_PER_HEADER_BUFFER_INFO_IDX] >>> 0;
263
+ const ppSize = info & BUFFER_INFO_WORDS_MASK;
264
+ void ((info >>> BUFFER_INFO_FLAGS_SHIFT) & 0xff); // buffer_flags (unused, as in the reference)
265
+ // Select ping or pong buffer exactly as the C code does. With ping-pong
266
+ // disabled the device reports a single buffer and this resolves to ping.
267
+ let localPp = 1;
268
+ if ((words[CNH_PER_HEADER_FLAGS_IDX] & 0x10) === 0x10) {
269
+ localPp = 1;
270
+ }
271
+ if (state === MI_STATE_PING) {
272
+ localPp = 1 - localPp;
273
+ }
274
+ let base = CNH_PER_HEADER_WORDS;
275
+ if (localPp === 1) {
276
+ base += ppSize;
277
+ }
278
+ // buffer header is 2 words (state, nb_accumulated); data starts after it.
279
+ let blk = (base + CNH_PER_BUFFER_HEADER_WORDS) * 4; // byte offset of p[2]
280
+ // FEAT_INT: int32 per (agg, feat)
281
+ const featInt = [];
282
+ for (let k = 0; k < feat; k++)
283
+ featInt.push(dv.getInt32(blk + aggOff * 4 + 4 * k, true));
284
+ blk += aggXFeat * 4;
285
+ // FEAT_FRAC: int8 scaler per (agg, feat)
286
+ const featScaler = [];
287
+ for (let k = 0; k < feat; k++)
288
+ featScaler.push(dv.getInt8(blk + aggOff + k));
289
+ blk += Math.floor((3 + aggXFeat) / 4) * 4;
290
+ // AMBIENT_INT: int32 per aggregate (this is the value example12 prints)
291
+ const ambInt = dv.getInt32(blk + aggId * 4, true);
292
+ blk += nbAgg * 4;
293
+ // AMBIENT_FRAC: int8 scaler per aggregate
294
+ const ambScaler = dv.getInt8(blk + aggId);
295
+ const hist = featInt.map((v, k) => v / Math.pow(2.0, featScaler[k]));
296
+ const ambient = ambInt / Math.pow(2.0, ambScaler);
297
+ return { hist, histRaw: featInt, histScaler: featScaler, ambient };
298
+ }
299
+ //# sourceMappingURL=cnh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cnh.js","sourceRoot":"","sources":["../../../src/sensors/vl53l8/cnh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AACtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAExC,wBAAwB;AACxB,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AACrC,iDAAiD;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC,kCAAkC;AAClC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,GAAG,CAAC,CAAC,CAAC,OAAO;AAEjE,sDAAsD;AACtD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM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C,CAAC;IACjB,0CAA0C;IAC1C,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAClD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACrE,CAAC"}
@@ -0,0 +1,346 @@
1
+ /**
2
+ * VL53L8CX ULD driver — TypeScript port of the parts of vl53l8cx_api.c
3
+ * (ULD 2.1.0, tools/doc/VL53L8CX_Linux_driver_2.1.0) needed for init (sensor
4
+ * firmware download), 8x8 continuous ranging and result parsing.
5
+ *
6
+ * 1:1 async mirror of the Python reference `depz_sensor_sdk.vl53l8.uld`
7
+ * (itself a proven port of the C driver). The sensor is reached through a
8
+ * `platform` object the caller provides — every method that touches it is
9
+ * async.
10
+ *
11
+ * Register sequences are a 1:1 port of the C code; do not "simplify" them.
12
+ * Configuration: NB_TARGET_PER_ZONE = 1, all output blocks enabled (matches
13
+ * the default platform.h of the C driver).
14
+ */
15
+ import type { Vl53l8Assets, Vl53l8Variant } from "./assets/index.js";
16
+ /** ULD platform: chunking/bridging is the caller's concern. */
17
+ export interface Vl53l8Platform {
18
+ rdMulti(addr: number, size: number): Promise<Uint8Array>;
19
+ wrMulti(addr: number, data: Uint8Array): Promise<void>;
20
+ sleepMs(ms: number): Promise<void>;
21
+ }
22
+ export declare const FW_CHECKSUM: Record<Vl53l8Variant, number>;
23
+ export declare const RESOLUTION_4X4 = 16;
24
+ export declare const RESOLUTION_8X8 = 64;
25
+ export declare const RANGING_MODE_CONTINUOUS = 1;
26
+ export declare const RANGING_MODE_AUTONOMOUS = 3;
27
+ export declare const TARGET_ORDER_CLOSEST = 1;
28
+ export declare const TARGET_ORDER_STRONGEST = 2;
29
+ export declare const STATUS_OK = 0;
30
+ export declare const STATUS_TIMEOUT_ERROR = 1;
31
+ export declare const STATUS_CORRUPTED_FRAME = 2;
32
+ export declare const STATUS_LASER_SAFETY = 3;
33
+ export declare const STATUS_FW_CHECKSUM_FAIL = 5;
34
+ export declare const MCU_ERROR = 66;
35
+ export declare const STATUS_INVALID_PARAM = 127;
36
+ export declare const STATUS_ERROR = 255;
37
+ export declare const START_BH = 13;
38
+ export declare const METADATA_BH = 1421082816;
39
+ export declare const COMMONDATA_BH = 1421869120;
40
+ export declare const AMBIENT_RATE_BH = 1422917892;
41
+ export declare const SPAD_COUNT_BH = 1439695876;
42
+ export declare const NB_TARGET_DETECTED_BH = 3682862081;
43
+ export declare const SIGNAL_RATE_BH = 3687056388;
44
+ export declare const RANGE_SIGMA_MM_BH = 3737388034;
45
+ export declare const DISTANCE_BH = 3745776642;
46
+ export declare const REFLECTANCE_BH = 3762553857;
47
+ export declare const TARGET_STATUS_BH = 3766748161;
48
+ export declare const MOTION_DETECT_BH = 3629648064;
49
+ /** VL53LMZ CNH data output block (VL53L8CH). */
50
+ export declare const CNH_DATA_IDX = 49224;
51
+ export declare const METADATA_IDX = 21684;
52
+ export declare const SPAD_COUNT_IDX = 21968;
53
+ export declare const AMBIENT_RATE_IDX = 21712;
54
+ export declare const NB_TARGET_DETECTED_IDX = 56196;
55
+ export declare const SIGNAL_RATE_IDX = 56260;
56
+ export declare const RANGE_SIGMA_MM_IDX = 57028;
57
+ export declare const DISTANCE_IDX = 57156;
58
+ export declare const REFLECTANCE_EST_PC_IDX = 57412;
59
+ export declare const TARGET_STATUS_IDX = 57476;
60
+ export declare const MOTION_DETEC_IDX = 55384;
61
+ export declare const NVM_DATA_SIZE = 492;
62
+ export declare const OFFSET_BUFFER_SIZE = 488;
63
+ export declare const XTALK_BUFFER_SIZE = 776;
64
+ export declare const DCI_ZONE_CONFIG = 21584;
65
+ export declare const DCI_FREQ_HZ = 21592;
66
+ export declare const DCI_INT_TIME = 21596;
67
+ export declare const DCI_RANGING_MODE = 44336;
68
+ export declare const DCI_DSS_CONFIG = 44344;
69
+ export declare const DCI_TARGET_ORDER = 44644;
70
+ export declare const DCI_SHARPENER = 44760;
71
+ export declare const DCI_SINGLE_RANGE = 55652;
72
+ export declare const DCI_OUTPUT_CONFIG = 55656;
73
+ export declare const DCI_OUTPUT_ENABLES = 55664;
74
+ export declare const DCI_OUTPUT_LIST = 55680;
75
+ export declare const DCI_PIPE_CONTROL = 56192;
76
+ export declare const UI_CMD_STATUS = 11264;
77
+ export declare const UI_CMD_START = 11268;
78
+ export declare const UI_CMD_END = 12287;
79
+ export declare const CONFIGURATION_SIZE = 972;
80
+ export declare const DCI_VHV_CONFIG = 44384;
81
+ export declare const DCI_CAL_CFG = 21616;
82
+ export declare const DCI_XTALK_CFG = 44436;
83
+ export declare const DCI_MOTION_DETECTOR_CFG = 49068;
84
+ export declare const DCI_DET_THRESH_CONFIG = 21640;
85
+ export declare const DCI_DET_THRESH_GLOBAL_CONFIG = 46816;
86
+ export declare const DCI_DET_THRESH_START = 46824;
87
+ export declare const DCI_DET_THRESH_VALID_STATUS = 47600;
88
+ export declare const NB_THRESHOLDS = 64;
89
+ export declare const LAST_THRESHOLD = 128;
90
+ export declare const POWER_MODE_SLEEP = 0;
91
+ export declare const POWER_MODE_WAKEUP = 1;
92
+ export declare const POWER_MODE_DEEP_SLEEP = 2;
93
+ export declare const DIST_MM = 1;
94
+ export declare const SIGNAL_PER_SPAD_KCPS = 2;
95
+ export declare const RANGE_SIGMA_MM = 4;
96
+ export declare const AMBIENT_PER_SPAD_KCPS = 8;
97
+ export declare const NB_TARGET_DETECTED = 9;
98
+ export declare const TAR_STATUS = 12;
99
+ export declare const NB_SPADS_ENABLED = 13;
100
+ export declare const MOTION_INDICATOR = 19;
101
+ export declare const THRESH_IN_WINDOW = 0;
102
+ export declare const THRESH_OUT_OF_WINDOW = 1;
103
+ export declare const THRESH_LESS_THAN_EQUAL_MIN = 2;
104
+ export declare const THRESH_GREATER_THAN_MAX = 3;
105
+ export declare const THRESH_EQUAL_MIN = 4;
106
+ export declare const THRESH_NOT_EQUAL_MIN = 5;
107
+ export declare const THRESH_OP_NONE = 0;
108
+ export declare const THRESH_OP_OR = 0;
109
+ export declare const THRESH_OP_AND = 2;
110
+ export declare const GET_XTALK_CMD: Uint8Array<ArrayBufferLike>;
111
+ export declare const CALIBRATE_XTALK: Uint8Array<ArrayBufferLike>;
112
+ export declare const NB_TARGET_PER_ZONE = 1;
113
+ export declare class Vl53l8cxError extends Error {
114
+ readonly code: number;
115
+ readonly where: string;
116
+ constructor(code: number, where?: string);
117
+ }
118
+ /** VL53L8CX_SwapBuffer: byte-reverse every 32-bit word (tail untouched). */
119
+ export declare function swapBuffer(data: Uint8Array): Uint8Array;
120
+ /** union Block_header: type[3:0], size[15:4], idx[31:16]. */
121
+ export declare function bhFields(bh: number): [type: number, size: number, idx: number];
122
+ export declare function bhSetSize(bh: number, size: number): number;
123
+ /**
124
+ * is_alive register sequence, standalone so the device facade can probe
125
+ * without constructing a full driver (which needs the blob assets).
126
+ * Returns [deviceId, revisionId]; alive when (0xF0, 0x0C).
127
+ */
128
+ export declare function readDeviceRevisionId(p: Vl53l8Platform): Promise<[number, number]>;
129
+ /** One detection-threshold entry (real units; mirror of the Python dict). */
130
+ export interface DetectionThreshold {
131
+ lowThresh: number;
132
+ highThresh: number;
133
+ measurement: number;
134
+ type: number;
135
+ zoneNum: number;
136
+ operation: number;
137
+ }
138
+ /** Motion-indicator results block (mirror of the Python `motion_indicator` dict). */
139
+ export interface MotionResult {
140
+ globalIndicator1: number;
141
+ globalIndicator2: number;
142
+ status: number;
143
+ nbOfDetectedAggregates: number;
144
+ nbOfAggregates: number;
145
+ motion: number[];
146
+ }
147
+ /** One parsed raw results frame (plain arrays, mirroring the Python dict). */
148
+ export interface Vl53l8Results {
149
+ distanceMm: number[];
150
+ targetStatus: number[];
151
+ nbTargetDetected: number[];
152
+ signalPerSpad: number[];
153
+ ambientPerSpad: number[];
154
+ nbSpadsEnabled: number[];
155
+ rangeSigmaMm: number[];
156
+ reflectance: number[];
157
+ siliconTempDegc: number;
158
+ cnhRaw: Uint8Array | null;
159
+ /** Motion-indicator output when the motion detector is configured. */
160
+ motion: MotionResult | null;
161
+ }
162
+ /**
163
+ * Mirror of VL53L8CX_Motion_Configuration (156 bytes, plugin source).
164
+ * `pack()` reproduces the C struct byte layout (`<i3I12B64b32B32B`).
165
+ */
166
+ export declare class MotionConfig {
167
+ refBinOffset: number;
168
+ detectionThreshold: number;
169
+ extraNoiseSigma: number;
170
+ nullDenClipValue: number;
171
+ memUpdateMode: number;
172
+ memUpdateChoice: number;
173
+ sumSpan: number;
174
+ featureLength: number;
175
+ nbOfAggregates: number;
176
+ nbOfTemporalAccumulations: number;
177
+ minNbForGlobalDetection: number;
178
+ globalIndicatorFormat1: number;
179
+ globalIndicatorFormat2: number;
180
+ spare1: number;
181
+ spare2: number;
182
+ spare3: number;
183
+ mapId: number[];
184
+ indicatorFormat1: number[];
185
+ indicatorFormat2: number[];
186
+ pack(): Uint8Array;
187
+ }
188
+ /** Set MotionConfig.map_id for the given resolution (pure — no I/O). */
189
+ export declare function motionConfigSetResolution(cfg: MotionConfig, resolution: number): void;
190
+ /**
191
+ * The default motion-indicator configuration used by `motionIndicatorInit`
192
+ * for a resolution (pure — same bytes the sensor is programmed with).
193
+ */
194
+ export declare function defaultMotionConfig(resolution: number): MotionConfig;
195
+ /** Xtalk margin (kcps/spad) → raw DCI value (round(kcps * 2048)). */
196
+ export declare function xtalkMarginToRaw(marginKcps: number): number;
197
+ /**
198
+ * Pack 64 detection thresholds into the DCI_DET_THRESH_START payload plus the
199
+ * 8-byte valid-status block (pure — mirror of set_detection_thresholds). Each
200
+ * threshold's low/high are scaled by its measurement selector.
201
+ */
202
+ export declare function packDetectionThresholds(thresholds: Partial<DetectionThreshold>[]): {
203
+ start: Uint8Array;
204
+ valid: Uint8Array;
205
+ };
206
+ export declare class VL53L8CX {
207
+ readonly p: Vl53l8Platform;
208
+ readonly variant: Vl53l8Variant;
209
+ readonly fwChecksum: number;
210
+ readonly firmware: Uint8Array;
211
+ readonly defaultCfg: Uint8Array;
212
+ readonly defaultXtalk: Uint8Array;
213
+ readonly getNvmCmd: Uint8Array;
214
+ offsetData: Uint8Array;
215
+ xtalkData: Uint8Array;
216
+ streamcount: number;
217
+ dataReadSize: number;
218
+ /** { fw, host } when the FW disagrees with the api.c formula. */
219
+ frameSizeMismatch: {
220
+ fw: number;
221
+ host: number;
222
+ } | null;
223
+ /** [idx, type, size] of the blocks in the last parsed frame. */
224
+ lastBlocks: Array<[number, number, number]>;
225
+ /** Whether the motion-indicator output block is configured. */
226
+ motionPresent: boolean;
227
+ private readonly outputEnableW3;
228
+ private readonly frameTail;
229
+ private readonly footerIdOff;
230
+ constructor(platform: Vl53l8Platform, assets: Vl53l8Assets, variant?: Vl53l8Variant);
231
+ private rdByte;
232
+ private wrByte;
233
+ /**
234
+ * _vl53l8cx_poll_for_answer(): poll `size` bytes at `address` until
235
+ * buf[pos] & mask == expected. 10 ms period, 2 s timeout.
236
+ */
237
+ private pollForAnswer;
238
+ private pollForMcuBoot;
239
+ dciReadData(index: number, dataSize: number): Promise<Uint8Array>;
240
+ dciWriteData(index: number, data: Uint8Array): Promise<void>;
241
+ dciReplaceData(index: number, dataSize: number, newData: Uint8Array, newDataPos: number): Promise<void>;
242
+ private sendOffsetData;
243
+ private sendXtalkData;
244
+ /** Returns [deviceId, revisionId]; alive when (0xF0, 0x0C). */
245
+ isAlive(): Promise<[number, number]>;
246
+ /**
247
+ * vl53l8cx_init(): boot the sensor MCU, download the 84 KB sensor
248
+ * firmware, upload NVM offset / xtalk / default configuration.
249
+ * `progress(text)` is an optional UI callback.
250
+ */
251
+ init(progress?: (text: string) => void): Promise<void>;
252
+ getResolution(): Promise<number>;
253
+ setResolution(resolution: number): Promise<void>;
254
+ getRangingFrequencyHz(): Promise<number>;
255
+ setRangingFrequencyHz(hz: number): Promise<void>;
256
+ setRangingMode(mode: number): Promise<void>;
257
+ getRangingMode(): Promise<number>;
258
+ getIntegrationTimeMs(): Promise<number>;
259
+ /** Integration time 2..1000 ms. No effect in continuous ranging mode. */
260
+ setIntegrationTimeMs(timeMs: number): Promise<void>;
261
+ getSharpenerPercent(): Promise<number>;
262
+ /** Sharpener 0..99 % (0 = disabled). */
263
+ setSharpenerPercent(pct: number): Promise<void>;
264
+ getTargetOrder(): Promise<number>;
265
+ setTargetOrder(order: number): Promise<void>;
266
+ /**
267
+ * Start ranging. When `cnhDataSize` is given (bytes, from
268
+ * CnhConfig.requiredMemory), a VL53L8CH CNH data block is appended to the
269
+ * output list so each frame also carries the compact-network-histogram
270
+ * buffer. The CNH frame is far larger than the MCU stream cap, so the
271
+ * caller must read it in poll-mode (checkDataReady + getRangingData),
272
+ * not via the MCU INT stream.
273
+ */
274
+ startRanging(cnhDataSize?: number | null): Promise<void>;
275
+ stopRanging(): Promise<void>;
276
+ checkDataReady(): Promise<boolean>;
277
+ /** Poll-mode read: fetch one results frame from reg 0x00 and parse it. */
278
+ getRangingData(): Promise<Vl53l8Results>;
279
+ /**
280
+ * Parse one raw results frame (dataReadSize bytes read from reg 0x00).
281
+ * Used both by poll-mode getRangingData() and by the host when the MCU
282
+ * pushes frames over the INT-driven stream. Returns per-zone arrays
283
+ * distanceMm, targetStatus, nbTargetDetected, signalPerSpad (kcps/SPAD),
284
+ * ambientPerSpad (kcps/SPAD), nbSpadsEnabled, rangeSigmaMm, reflectance
285
+ * (%), plus the per-frame scalar siliconTempDegc.
286
+ */
287
+ parseFrame(raw: Uint8Array): Vl53l8Results;
288
+ /**
289
+ * Extract the MOTION_INDICATOR results block (index 0xD858) if it was walked
290
+ * in the last frame: global_indicator_1/2 (u32), status/nb_of_detected/
291
+ * nb_of_aggregates/spare (u8), motion[32] (u32 per aggregate).
292
+ */
293
+ private parseMotion;
294
+ getPowerMode(): Promise<number>;
295
+ /**
296
+ * WAKEUP (1), SLEEP (0) or DEEP_SLEEP (2). Not allowed while ranging. Wake
297
+ * from DEEP_SLEEP re-runs init() (the FW blob is lost).
298
+ */
299
+ setPowerMode(powerMode: number): Promise<void>;
300
+ /** Xtalk margin in kcps/spad. */
301
+ getXtalkMargin(): Promise<number>;
302
+ setXtalkMargin(marginKcps: number): Promise<void>;
303
+ /**
304
+ * Read the live 776-byte xtalk calibration blob back from the sensor FW (as
305
+ * produced by calibrateXtalk). Restores the current resolution afterwards.
306
+ */
307
+ getCaldataXtalk(): Promise<Uint8Array>;
308
+ /**
309
+ * Restore a previously saved 776-byte xtalk calibration blob. The blob is
310
+ * re-uploaded to the FW by the next setResolution()/startRanging().
311
+ */
312
+ setCaldataXtalk(xtalkData: Uint8Array): Promise<void>;
313
+ getDetectionThresholdsEnable(): Promise<number>;
314
+ setDetectionThresholdsEnable(enabled: boolean): Promise<void>;
315
+ /** Return the 64 detection thresholds; low/high rescaled to real units. */
316
+ getDetectionThresholds(): Promise<DetectionThreshold[]>;
317
+ /**
318
+ * Program the 64 detection thresholds (missing entries default to zeros).
319
+ */
320
+ setDetectionThresholds(thresholds: Partial<DetectionThreshold>[]): Promise<void>;
321
+ setDetectionThresholdsAutoStop(autoStop: boolean): Promise<void>;
322
+ /**
323
+ * Initialize a motion-indicator configuration (default distance window) and
324
+ * write it to the sensor. Enables the motion output block so subsequent
325
+ * frames carry motion data.
326
+ */
327
+ motionIndicatorInit(resolution: number): Promise<MotionConfig>;
328
+ motionIndicatorSetResolution(cfg: MotionConfig, resolution: number): Promise<void>;
329
+ motionIndicatorSetDistanceMotion(cfg: MotionConfig, distanceMinMm: number, distanceMaxMm: number): Promise<void>;
330
+ /**
331
+ * Program the sensor output list/config/enables for `resolution` (a copy of
332
+ * the block startRanging() uses inline, kept separate so startRanging stays
333
+ * byte-identical for the replay gate); used by calibrateXtalk.
334
+ */
335
+ private programOutputConfig;
336
+ /**
337
+ * vl53l8cx_calibrate_xtalk: run on-device crosstalk calibration.
338
+ *
339
+ * NOTE: ported from ST ULD source but NOT verified against live hardware in
340
+ * this SDK — the get/set caldata-xtalk buffer path IS the tested save/restore
341
+ * route. Saves & restores resolution/frequency/int-time/sharpener/target-
342
+ * order/xtalk-margin/ranging-mode around the run.
343
+ */
344
+ calibrateXtalk(reflectancePercent: number, nbSamples: number, distanceMm: number): Promise<void>;
345
+ }
346
+ //# sourceMappingURL=uld.d.ts.map