@@ -95,7 +95,7 @@ namespace matrixLidarDistance {
95
95
sendBuffer [ 7 ] = matrix
96
96
pins . i2cWriteBuffer ( _addr , sendBuffer )
97
97
basic . pause ( 10 ) //10 ms
98
- let buf = recvPacket ( CMD_CONFIG_AVOID )
98
+ let buf = recvPacket ( _addr , CMD_CONFIG_AVOID )
99
99
if ( buf [ 0 ] == ERR_CODE_NONE || buf [ 0 ] == STATUS_SUCCESS ) {
100
100
let len = buf [ 2 ] << 8 | buf [ 3 ]
101
101
}
@@ -118,7 +118,7 @@ namespace matrixLidarDistance {
118
118
sendBuffer [ 3 ] = CMD_AVOID_OBSTACLE
119
119
pins . i2cWriteBuffer ( _addr , sendBuffer )
120
120
basic . pause ( 10 ) //10 ms
121
- let buf = recvPacket ( CMD_AVOID_OBSTACLE )
121
+ let buf = recvPacket ( _addr , CMD_AVOID_OBSTACLE )
122
122
if ( buf [ 0 ] == ERR_CODE_NONE || buf [ 0 ] == STATUS_SUCCESS ) {
123
123
outDir = buf [ 4 ]
124
124
outEmergencyFlag = buf [ 5 ]
@@ -153,7 +153,7 @@ namespace matrixLidarDistance {
153
153
sendBuffer [ 5 ] = _wall & 0xff
154
154
pins . i2cWriteBuffer ( _addr , sendBuffer )
155
155
basic . pause ( 10 ) //10 ms
156
- let buf = recvPacket ( CMD_CONFIG_AVOID )
156
+ let buf = recvPacket ( _addr , CMD_CONFIG_AVOID )
157
157
if ( buf [ 0 ] == ERR_CODE_NONE || buf [ 0 ] == STATUS_SUCCESS ) {
158
158
let len = buf [ 2 ] << 8 | buf [ 3 ]
159
159
}
@@ -262,37 +262,37 @@ namespace matrixLidarDistance {
262
262
sendBuffer [ 5 ] = y
263
263
pins . i2cWriteBuffer ( address , sendBuffer )
264
264
basic . pause ( 10 ) //10 ms
265
- let buf = recvPacket ( CMD_FIXED_POINT )
265
+ let buf = recvPacket ( address , CMD_FIXED_POINT )
266
266
if ( buf [ 0 ] == ERR_CODE_NONE || buf [ 0 ] == STATUS_SUCCESS ) {
267
267
ret = buf [ 4 ] | buf [ 5 ] << 8
268
268
}
269
269
return ret
270
270
}
271
271
272
- function recvPacket ( cmd : number ) : Buffer {
272
+ function recvPacket ( addr : number , cmd : number ) : Buffer {
273
273
let sendBuffer = pins . createBuffer ( 20 ) ;
274
274
let time = control . millis ( )
275
275
while ( control . millis ( ) - time < DEBUG_TIMEOUT_MS )
276
276
{
277
- let status = pins . i2cReadNumber ( _addr , NumberFormat . Int8LE )
277
+ let status = pins . i2cReadNumber ( addr , NumberFormat . Int8LE )
278
278
if ( status != 0xff ) {
279
279
if ( status == STATUS_SUCCESS || status == STATUS_FAILED ) {
280
280
sendBuffer [ 0 ] = status
281
- let command = pins . i2cReadNumber ( _addr , NumberFormat . Int8LE )
281
+ let command = pins . i2cReadNumber ( addr , NumberFormat . Int8LE )
282
282
sendBuffer [ 1 ] = command
283
283
//serial.writeValue("cmd", command)
284
284
if ( command != cmd ) {
285
285
return sendBuffer
286
286
}
287
- let lenBuf = pins . i2cReadBuffer ( _addr , 2 )
287
+ let lenBuf = pins . i2cReadBuffer ( addr , 2 )
288
288
let len = lenBuf [ 1 ] << 8 | lenBuf [ 0 ]
289
289
//serial.writeValue("len", len)
290
290
sendBuffer [ 2 ] = lenBuf [ 0 ]
291
291
sendBuffer [ 3 ] = lenBuf [ 1 ]
292
292
if ( len == 0 ) {
293
293
return sendBuffer
294
294
}
295
- let dataBuf = pins . i2cReadBuffer ( _addr , len )
295
+ let dataBuf = pins . i2cReadBuffer ( addr , len )
296
296
for ( let i = 0 ; i < len ; i ++ ) {
297
297
sendBuffer [ 4 + i ] = dataBuf [ i ]
298
298
}
0 commit comments