41 #include <px4_platform_common/getopt.h>    51 void    start(
bool external_bus, 
enum Rotation rotation, 
unsigned range);
    64     if (g_dev != 
nullptr) {
    65         errx(0, 
"already started");
    70 #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_ACCEL_MAG)    71         g_dev = 
new LSM303D(PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_ACCEL_MAG, rotation);
    73         errx(0, 
"External SPI not available");
    77         g_dev = 
new LSM303D(PX4_SPI_BUS_SENSORS, PX4_SPIDEV_ACCEL_MAG, rotation);
    80     if (g_dev == 
nullptr) {
    81         PX4_ERR(
"failed instantiating LSM303D obj");
    92     if (g_dev != 
nullptr) {
    97     errx(1, 
"driver start failed");
   106     if (g_dev == 
nullptr) {
   107         errx(1, 
"driver not running\n");
   110     printf(
"state @ %p\n", g_dev);
   119     PX4_INFO(
"missing command: try 'start', 'info'");
   120     PX4_INFO(
"options:");
   121     PX4_INFO(
"    -X    (external bus)");
   122     PX4_INFO(
"    -R rotation");
   130     bool external_bus = 
false;
   136     const char *myoptarg = 
nullptr;
   139     while ((ch = px4_getopt(argc, argv, 
"XR:a:", &myoptind, &myoptarg)) != EOF) {
   146             rotation = (
enum Rotation)atoi(myoptarg);
   150             accel_range = atoi(myoptarg);
   159     if (myoptind >= argc) {
   164     const char *verb = argv[myoptind];
   170     if (!strcmp(verb, 
"start")) {
   177     if (!strcmp(verb, 
"info")) {
   181     errx(1, 
"unrecognized command, try 'start', info'");
 void start(bool external_bus, enum Rotation rotation, unsigned range)
Start the driver. 
 
Local functions in support of the shell command. 
 
void info()
Print a little info about the driver. 
 
int lsm303d_main(int argc, char *argv[])
 
void print_info()
Diagnostics - print some basic information about the driver. 
 
Rotation
Enum for board and external compass rotations. 
 
void usage()
Prints info about the driver argument usage. 
 
Driver for the ST LSM303D MEMS accelerometer / magnetometer connected via SPI.