1
0
mirror of https://github.com/whowechina/chu_pico.git synced 2025-01-31 12:03:43 +01:00

gp2y0e distance calculation correction

This commit is contained in:
whowe 2023-10-09 23:02:08 +08:00
parent b83d9a3b68
commit a9473966bd
3 changed files with 5 additions and 6 deletions

Binary file not shown.

View File

@ -111,8 +111,7 @@ void air_update()
if (tof_model[i] == 1) {
distances[i] = readRangeContinuousMillimeters() * 10;
} else if (tof_model[i] == 2) {
/* compensation based on observation, don't know why*/
distances[i] = gp2y0e_dist16(I2C_PORT) * 16 / 10;
distances[i] = gp2y0e_dist16_mm(I2C_PORT) * 10;
}
}
}

View File

@ -31,24 +31,24 @@ static inline bool gp2y0e_is_present(i2c_inst_t *port)
time_us_64() + 1000) == 1;
}
static inline uint8_t gp2y0e_dist(i2c_inst_t *port)
static inline uint8_t gp2y0e_dist_mm(i2c_inst_t *port)
{
uint8_t cmd[] = {0x5e};
i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000);
uint8_t data;
i2c_read_blocking_until(port, GP2Y0E_DEF_ADDR, &data, 1, false, time_us_64() + 1000);
return data;
return data * 10 / 4;
}
static inline uint16_t gp2y0e_dist16(i2c_inst_t *port)
static inline uint16_t gp2y0e_dist16_mm(i2c_inst_t *port)
{
uint8_t cmd[] = {0x5e};
i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000);
uint8_t data[2];
i2c_read_blocking_until(port, GP2Y0E_DEF_ADDR, data, 2, false, time_us_64() + 1000);
return (data[0] << 4) | data[1];
return ((data[0] << 4) | data[1]) * 10 / 64;
}
#endif