src/drivers/vl53l0x/vl53l0x.cpp
void
test()
{
	struct distance_sensor_s report;
	ssize_t sz;
	int ret;

	int fd = open(VL53L0X_DEVICE_PATH, O_RDONLY);

	if (fd < 0) {
		err(1, "%s open failed (try 'vl53l0x start' if the driver is not running", VL53L0X_DEVICE_PATH);
	}

	/* do a simple demand read */
	sz = read(fd, &report, sizeof(report));

	if (sz != sizeof(report)) {
		err(1, "immediate read failed");
	}

	warnx("single read");
	warnx("measurement: %0.2f mm", (double)report.current_distance);
	warnx("time:        %llu", report.timestamp);

	/* start the sensor polling at 2Hz */
	if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
		errx(1, "failed to set 2Hz poll rate");
	}

	/* read the sensor 5x and report each value */
	for (unsigned i = 0; i < 5; i++) {
		struct pollfd fds;

		/* wait for data to be ready */
		fds.fd = fd;
		fds.events = POLLIN;
		ret = poll(&fds, 1, 2000);

		if (ret != 1) {
			errx(1, "timed out waiting for sensor data");
		}

		/* now go get it */
		sz = read(fd, &report, sizeof(report));

		if (sz != sizeof(report)) {
			err(1, "periodic read failed");
		}

		warnx("periodic read %u", i);
		warnx("valid %u", (float)report.current_distance > report.min_distance
		      && (float)report.current_distance < report.max_distance ? 1 : 0);
		warnx("measurement: %0.3f", (double)report.current_distance);
		warnx("time:        %llu", report.timestamp);
	}

	/* reset the sensor polling to default rate */
	if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
		errx(1, "failed to set default poll rate");
	}

	errx(0, "PASS");
}
/**
 * Perform some basic functional tests on the driver;
 * make sure we can collect data from the sensor in polled
 * and automatic modes.
 */
Perform some basic functional tests on the driver;
make sure we can collect data from the sensor in polled
and automatic modes.
Perform some basic functional tests on the driver ; make sure we can collect data from the sensor in polled and automatic modes .
void
test()
{
	struct distance_sensor_s report;
	ssize_t sz;
	int ret;
	int fd = open(VL53L0X_DEVICE_PATH, O_RDONLY);
	if (fd < 0) {
		err(1, "%s open failed (try 'vl53l0x start' if the driver is not running", VL53L0X_DEVICE_PATH);
	}
	sz = read(fd, &report, sizeof(report));
	if (sz != sizeof(report)) {
		err(1, "immediate read failed");
	}
	warnx("single read");
	warnx("measurement: %0.2f mm", (double)report.current_distance);
	warnx("time:        %llu", report.timestamp);
	if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
		errx(1, "failed to set 2Hz poll rate");
	}
	for (unsigned i = 0; i < 5; i++) {
		struct pollfd fds;
		fds.fd = fd;
		fds.events = POLLIN;
		ret = poll(&fds, 1, 2000);
		if (ret != 1) {
			errx(1, "timed out waiting for sensor data");
		}
		sz = read(fd, &report, sizeof(report));
		if (sz != sizeof(report)) {
			err(1, "periodic read failed");
		}
		warnx("periodic read %u", i);
		warnx("valid %u", (float)report.current_distance > report.min_distance
		      && (float)report.current_distance < report.max_distance ? 1 : 0);
		warnx("measurement: %0.3f", (double)report.current_distance);
		warnx("time:        %llu", report.timestamp);
	}
	if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
		errx(1, "failed to set default poll rate");
	}
	errx(0, "PASS");
}
void test ( ) { struct distance_sensor_s report ; ssize_t sz ; int ret ; int fd = open ( VL53L0X_DEVICE_PATH , O_RDONLY ) ; if ( fd < 0 ) { err ( 1 , " " , VL53L0X_DEVICE_PATH ) ; } sz = read ( fd , & report , sizeof ( report ) ) ; if ( sz != sizeof ( report ) ) { err ( 1 , " " ) ; } warnx ( " " ) ; warnx ( " " , ( double ) report . current_distance ) ; warnx ( " " , report . timestamp ) ; if ( OK != ioctl ( fd , SENSORIOCSPOLLRATE , 2 ) ) { errx ( 1 , " " ) ; } for ( unsigned i = 0 ; i < 5 ; i ++ ) { struct pollfd fds ; fds . fd = fd ; fds . events = POLLIN ; ret = poll ( & fds , 1 , 2000 ) ; if ( ret != 1 ) { errx ( 1 , " " ) ; } sz = read ( fd , & report , sizeof ( report ) ) ; if ( sz != sizeof ( report ) ) { err ( 1 , " " ) ; } warnx ( " " , i ) ; warnx ( " " , ( float ) report . current_distance > report . min_distance && ( float ) report . current_distance < report . max_distance ? 1 : 0 ) ; warnx ( " " , ( double ) report . current_distance ) ; warnx ( " " , report . timestamp ) ; } if ( OK != ioctl ( fd , SENSORIOCSPOLLRATE , SENSOR_POLLRATE_DEFAULT ) ) { errx ( 1 , " " ) ; } errx ( 0 , " " ) ; }
Perform some basic functional tests on the driver;
 make sure we can collect data from the sensor in polled
 and automatic modes.
Perform some basic functional tests on the driver ; make sure we can collect data from the sensor in polled and automatic modes .
/* do a simple demand read */ /* start the sensor polling at 2Hz */ /* read the sensor 5x and report each value */ /* wait for data to be ready */ /* now go get it */ /* reset the sensor polling to default rate */