Skip to content

Commit 9467b14

Browse files
committed
更新 matrixLidarDistance.ts
1 parent 64a64b6 commit 9467b14

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

matrixLidarDistance.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace matrixLidarDistance {
9595
sendBuffer[7] = matrix
9696
pins.i2cWriteBuffer(_addr, sendBuffer)
9797
basic.pause(10)//10 ms
98-
let buf = recvPacket(CMD_CONFIG_AVOID)
98+
let buf = recvPacket(_addr, CMD_CONFIG_AVOID)
9999
if (buf[0] == ERR_CODE_NONE || buf[0] == STATUS_SUCCESS) {
100100
let len = buf[2] << 8 | buf[3]
101101
}
@@ -118,7 +118,7 @@ namespace matrixLidarDistance {
118118
sendBuffer[3] = CMD_AVOID_OBSTACLE
119119
pins.i2cWriteBuffer(_addr, sendBuffer)
120120
basic.pause(10)//10 ms
121-
let buf = recvPacket(CMD_AVOID_OBSTACLE)
121+
let buf = recvPacket(_addr, CMD_AVOID_OBSTACLE)
122122
if (buf[0] == ERR_CODE_NONE || buf[0] == STATUS_SUCCESS) {
123123
outDir = buf[4]
124124
outEmergencyFlag = buf[5]
@@ -153,7 +153,7 @@ namespace matrixLidarDistance {
153153
sendBuffer[5] = _wall & 0xff
154154
pins.i2cWriteBuffer(_addr,sendBuffer)
155155
basic.pause(10)//10 ms
156-
let buf = recvPacket(CMD_CONFIG_AVOID)
156+
let buf = recvPacket(_addr, CMD_CONFIG_AVOID)
157157
if (buf[0] == ERR_CODE_NONE || buf[0] == STATUS_SUCCESS){
158158
let len = buf[2] << 8 | buf[3]
159159
}
@@ -262,37 +262,37 @@ namespace matrixLidarDistance {
262262
sendBuffer[5] = y
263263
pins.i2cWriteBuffer(address, sendBuffer)
264264
basic.pause(10)//10 ms
265-
let buf = recvPacket(CMD_FIXED_POINT)
265+
let buf = recvPacket(address, CMD_FIXED_POINT)
266266
if (buf[0] == ERR_CODE_NONE || buf[0] == STATUS_SUCCESS) {
267267
ret = buf[4] | buf[5] << 8
268268
}
269269
return ret
270270
}
271271

272-
function recvPacket(cmd: number): Buffer{
272+
function recvPacket(addr: number,cmd: number): Buffer{
273273
let sendBuffer = pins.createBuffer(20);
274274
let time = control.millis()
275275
while (control.millis() - time < DEBUG_TIMEOUT_MS)
276276
{
277-
let status = pins.i2cReadNumber(_addr, NumberFormat.Int8LE)
277+
let status = pins.i2cReadNumber(addr, NumberFormat.Int8LE)
278278
if (status != 0xff){
279279
if (status == STATUS_SUCCESS || status == STATUS_FAILED){
280280
sendBuffer[0] = status
281-
let command = pins.i2cReadNumber(_addr, NumberFormat.Int8LE)
281+
let command = pins.i2cReadNumber(addr, NumberFormat.Int8LE)
282282
sendBuffer[1] = command
283283
//serial.writeValue("cmd", command)
284284
if (command != cmd){
285285
return sendBuffer
286286
}
287-
let lenBuf = pins.i2cReadBuffer(_addr,2)
287+
let lenBuf = pins.i2cReadBuffer(addr,2)
288288
let len = lenBuf[1] << 8 | lenBuf[0]
289289
//serial.writeValue("len", len)
290290
sendBuffer[2] = lenBuf[0]
291291
sendBuffer[3] = lenBuf[1]
292292
if(len == 0){
293293
return sendBuffer
294294
}
295-
let dataBuf = pins.i2cReadBuffer(_addr, len)
295+
let dataBuf = pins.i2cReadBuffer(addr, len)
296296
for(let i = 0;i < len;i++){
297297
sendBuffer[4+i] = dataBuf[i]
298298
}

0 commit comments

Comments
 (0)