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