This commit is contained in:
2025-06-18 11:16:34 +08:00
parent d5f6744fc8
commit 94b6a42cb1

View File

@ -15,7 +15,7 @@ void init_i2c_slave() {
Wire.setSCL(I2C_SCL_PIN);
//Wire.Pins(16,17);
Wire.begin(SLAVE_ADDRESS); // 设置从机地址为 0x55
Wire.onRequest(onRequestEvent); // 注册请求回调 ***改用主机命令0x01
Wire.onRequest(onRequestEvent); // 注册请求回调 ***主机使用命令0x01不行,无应答
Wire.onReceive(onReceiveEvent); // 注册接收回调
}
@ -49,7 +49,7 @@ void onReceiveEvent(int bytes) {
turn_on_ranging();
break;
case CMD_MASTER_GET_SLAVE_DATA:
onRequestEvent(); // 主动调用一次数据发送
onRequestEvent(); // 主动调用一次数据发送.功能不正常需使用Wire.onRequest(onRequestEvent);
break;
default:
Serial.printf("Unknown command received: 0x%02X\n", cmd);
@ -89,7 +89,7 @@ void update_sensor_data() {
sensor_data.height = 0.0f;
}else {
last_receive_cnt = receive_cnt;
sensor_data.height_sta = 0x02; // 有效高度
sensor_data.height_sta = 0x03; // 有效高度,正常工作
sensor_data.height = (float)distance / 1000.0f; // mm -> m
}
}