Files
BC3S-firmware/app/by_measure.c

37 lines
677 B
C
Raw Normal View History

2024-05-19 16:03:21 +08:00
#include "by_measure.h"
#include "by_debug.h"
#include "vl53l0x_wmd_api.h"
void by_measure_init(void)
{
VL53L0X_Init();
}
void by_measure_run(void)
{
float x = VL53L0X_GetValue();
float distance = x;
static float distance_last = 0;
if (x < 270) {
distance = x - 80.0f;
} else if (x < 330) {
distance = 2.0755f * x - 368.85f;
}
// 错误值
if (distance <= 20 || distance > 330) {
distance = distance_last;
}
// if (distance <= 20) {
// distance = distance_last;
// } else if (distance > 330) {
// distance = 330;
// }
distance_last = distance;
LOGI("distance:%f", distance);
}