41 #include <px4_platform_common/getopt.h> 54 PX4_INFO(
"running on bus: %u (%s)", (
unsigned)bus.
bus_id, bus.
devpath);
56 int fd = open(path, O_RDONLY);
59 PX4_WARN(
"%s open failed (try 'lis3mdl start' if the driver is not running", path);
64 PX4_WARN(
"failed to enable sensor calibration mode");
75 PX4_INFO(
"running on bus: %u (%s)", (
unsigned)bus.
bus_id, bus.
devpath);
85 int fd = open(path, O_RDONLY);
93 errx(1,
"Failed to setup poll rate");
97 PX4_INFO(
"Poll rate set to max (80hz)");
108 if (bus.
dev !=
nullptr) {
109 errx(1,
"bus option already started");
113 device::Device *
interface = bus.interface_constructor(bus.busnum);
115 if (interface->init() !=
OK) {
117 warnx(
"no device on bus %u", (
unsigned)bus.bus_id);
121 bus.dev =
new LIS3MDL(interface, bus.devpath, rotation);
123 if (bus.dev !=
nullptr &&
124 bus.dev->init() !=
OK) {
136 if (bus.
dev == NULL) {
148 if (bus.
dev != NULL) {
166 const char *path = bus.
devpath;
168 PX4_INFO(
"running on bus: %u (%s)", (
unsigned)bus.
bus_id, bus.
devpath);
170 int fd = open(path, O_RDONLY);
173 PX4_WARN(
"%s open failed (try 'lis3mdl start')", path);
178 sz =
read(fd, &report,
sizeof(report));
180 if (sz !=
sizeof(report)) {
181 PX4_WARN(
"immediate read failed");
185 print_message(report);
189 PX4_WARN(
"failed to get if mag is onboard or external");
195 PX4_WARN(
"failed to set 2Hz poll rate");
202 for (
unsigned i = 0; i < 5; i++) {
207 ret = poll(&fds, 1, 2000);
210 PX4_WARN(
"timed out waiting for sensor data");
215 sz =
read(fd, &report,
sizeof(report));
217 if (sz !=
sizeof(report)) {
218 PX4_WARN(
"periodic read failed");
222 print_message(report);
232 const char *path = bus.
devpath;
234 PX4_INFO(
"running on bus: %u (%s)", (
unsigned)bus.
bus_id, bus.
devpath);
236 int fd = open(path, O_RDONLY);
239 PX4_WARN(
"open failed ");
244 PX4_WARN(
"driver reset failed");
249 PX4_WARN(
"driver poll restart failed");
259 PX4_WARN(
"missing command: try 'start', 'info', 'test', 'reset', 'info', 'calibrate'");
260 PX4_WARN(
"options:");
261 PX4_WARN(
" -R rotation");
262 PX4_WARN(
" -C calibrate on start");
263 PX4_WARN(
" -X only external bus");
264 PX4_WARN(
" -S only spi bus");
265 #if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_LIS) 266 PX4_WARN(
" -I only internal bus");
275 const char *myoptarg =
nullptr;
281 while ((ch = px4_getopt(argc, argv,
"XISR:CT", &myoptind, &myoptarg)) != EOF) {
284 rotation = (
enum Rotation)atoi(myoptarg);
286 #if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_LIS) 311 if (myoptind >= argc) {
316 const char *verb = argv[myoptind];
318 bool dev_found =
false;
319 bool cmd_found =
false;
321 if (!strcmp(verb,
"start")) {
339 PX4_WARN(
"calibration failed");
343 PX4_INFO(
"calibration successful");
368 PX4_ERR(
"bus %u not started", (
unsigned)bus_id);
379 if (!strcmp(verb,
"stop")) {
385 if (!strcmp(verb,
"test")) {
391 if (!strcmp(verb,
"reset")) {
397 if (!strcmp(verb,
"info") ||
398 !strcmp(verb,
"status")) {
404 if (!strcmp(verb,
"calibrate")) {
408 PX4_INFO(
"calibration successful");
411 PX4_WARN(
"calibration failed");
419 PX4_WARN(
"no device found, please start driver first");
422 }
else if (!cmd_found) {
423 PX4_WARN(
"unrecognized command, try 'start', 'test', 'reset', 'calibrate' 'or 'info'");
void print_info()
Diagnostics - print some basic information about the driver.
#define MAGIOCGEXTERNAL
determine if mag is external or onboard
int init(struct lis3mdl_bus_option &bus)
Initializes the driver – sets defaults and starts a cycle.
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
struct lis3mdl::lis3mdl_bus_option bus_options[]
int reset(struct lis3mdl_bus_option &bus)
Resets the driver.
void stop()
Stop the automatic measurement state machine.
static void read(bootloader_app_shared_t *pshared)
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
#define MAGIOCCALIBRATE
perform self-calibration, update scale factors to canonical units
Rotation
Enum for board and external compass rotations.
__EXPORT int lis3mdl_main(int argc, char *argv[])
Driver 'main' command.
static bool start_bus(bmp280_bus_option &bus)
int info(struct lis3mdl_bus_option &bus)
Prints info about the driver.
#define SENSORIOCRESET
Reset the sensor to its default configuration.
Fundamental base class for all physical drivers (I2C, SPI).
void usage()
Prints info about the driver argument usage.
int calibrate(struct lis3mdl_bus_option &bus)
Calibrate and self test.
int stop(struct lis3mdl_bus_option &bus)
Stop the driver.
static int calibrate(enum HMC5883_BUS busid)
Automatic scale calibration.
int test(struct lis3mdl_bus_option &bus)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
int start(struct lis3mdl_bus_option &bus, Rotation rotation)
Starts the driver.
int start_bus(struct lis3mdl_bus_option &bus, Rotation rotation)
Starts the driver for a specific bus option.