src/drivers/lsm303d/lsm303d.cpp
/**
 * Start the driver.
 *
 * This function call only returns once the driver is
 * up and running or failed to detect the sensor.
 */
Start the driver.
This function call only returns once the driver is
up and running or failed to detect the sensor.
Start the driver . This function call only returns once the driver is up and running or failed to detect the sensor .
void
start(bool external_bus, enum Rotation rotation)
{
	int fd, fd_mag;
	if (g_dev != nullptr)
		errx(0, "already started");
        if (external_bus) {
        	#ifdef PX4_SPI_BUS_EXT
		g_dev = new LSM303D(PX4_SPI_BUS_EXT, LSM303D_DEVICE_PATH_ACCEL, (spi_dev_e)PX4_SPIDEV_EXT_ACCEL_MAG, rotation);
		#else
		errx(0, "External SPI not available");
		#endif
	} else {
		g_dev = new LSM303D(PX4_SPI_BUS_SENSORS, LSM303D_DEVICE_PATH_ACCEL, (spi_dev_e)PX4_SPIDEV_ACCEL_MAG, rotation);
	}
	if (g_dev == nullptr) {
		warnx("failed instantiating LSM303D obj");
		goto fail;
	}
	if (OK != g_dev->init())
		goto fail;
	fd = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
	if (fd < 0)
		goto fail;
	if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
		goto fail;
	fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
	if (0 <= fd_mag) {
		if (ioctl(fd_mag, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
			goto fail;
		}
	}
        close(fd);
        close(fd_mag);
	exit(0);
fail:
	if (g_dev != nullptr) {
		delete g_dev;
		g_dev = nullptr;
	}
	errx(1, "driver start failed");
}
void start ( bool external_bus , enum Rotation rotation ) { int fd , fd_mag ; if ( g_dev != nullptr ) errx ( 0 , " " ) ; if ( external_bus ) { #ifdef PX4_SPI_BUS_EXT g_dev = new LSM303D ( PX4_SPI_BUS_EXT , LSM303D_DEVICE_PATH_ACCEL , ( spi_dev_e ) PX4_SPIDEV_EXT_ACCEL_MAG , rotation ) ; #else errx ( 0 , " " ) ; #endif } else { g_dev = new LSM303D ( PX4_SPI_BUS_SENSORS , LSM303D_DEVICE_PATH_ACCEL , ( spi_dev_e ) PX4_SPIDEV_ACCEL_MAG , rotation ) ; } if ( g_dev == nullptr ) { warnx ( " " ) ; goto fail ; } if ( OK != g_dev -> init ( ) ) goto fail ; fd = open ( LSM303D_DEVICE_PATH_ACCEL , O_RDONLY ) ; if ( fd < 0 ) goto fail ; if ( ioctl ( fd , SENSORIOCSPOLLRATE , SENSOR_POLLRATE_DEFAULT ) < 0 ) goto fail ; fd_mag = open ( LSM303D_DEVICE_PATH_MAG , O_RDONLY ) ; if ( 0 <= fd_mag ) { if ( ioctl ( fd_mag , SENSORIOCSPOLLRATE , SENSOR_POLLRATE_DEFAULT ) < 0 ) { goto fail ; } } close ( fd ) ; close ( fd_mag ) ; exit ( 0 ) ; fail : if ( g_dev != nullptr ) { delete g_dev ; g_dev = nullptr ; } errx ( 1 , " " ) ; }
Start the driver.
Start the driver .
/* create the driver */ /* set the poll rate to default, starts automatic data collection */ /* don't fail if open cannot be opened */