Files
test/app/app_ultrasonic.h
2025-07-05 20:11:15 +08:00

76 lines
2.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef ULTRASONIC_H
#define ULTRASONIC_H
#ifdef __cplusplus
extern "C" {
#endif
#define ULTRASONIC_FRONT_NODE 0x1
#define ULTRASONIC_BACK_NODE 0x2
#define ULTRASONIC_ID_1 0x520 + ULTRASONIC_FRONT_NODE
#define ULTRASONIC_ID_2 0x520 + ULTRASONIC_BACK_NODE
#define ULTRASONIC_READ 0x03
#define ULTRASONIC_WRITE 0x06
#define SOFTWARE_VERSION_REG 0x0000 // 模组软件版本号(十六进制值), 数据类型: uint16_t
#define PROCESSED_DISTANCE_REG 0x0100 /*
* 处理后的距离测量值(mm), 数据类型: uint16_t
* 发送指令后启动测距,算法处理后输出
* 响应时间190-750ms(因量程而异)
*/
#define REALTIME_DISTANCE_REG 0x0101 /*
* 实时单次测距值(mm), 数据类型: uint16_t
* 发送指令后触发单次测量
* 响应时间15-140ms(因量程而异)
*/
#define TEMPERATURE_REG 0x0102 /*
* 温度传感器值, 数据类型: int16_t
* 单位0.1℃ (原始值需/10), 分辨率0.5℃
* 响应时间15-140ms(因量程而异)
*/
#define ECHO_TIME_REG 0x010A /*
* 超声波回波时间原始值(μs), 数据类型: uint16_t
* 距离换算:值/5.75 = 毫米距离
* 响应时间15-140ms(因量程而异)
*/
#define SWAP_ENDIAN_16(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
#define SWAP_ENDIAN_32(x) (((x) << 24) | (((x) & 0xFF00) << 8) | (((x) >> 8) & 0xFF00) | ((x) >> 24))
void ultrasonicAppInit(void);
#ifdef __cplusplus
}
#endif
#endif // ULTRASONIC_H