40 #include <px4_platform_common/getopt.h> 74 #ifdef PX4_I2C_BUS_EXPANSION1 77 #ifdef PX4_I2C_BUS_EXPANSION2 80 #ifdef PX4_I2C_BUS_ONBOARD 87 #define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0])) 95 if (bus.
dev !=
nullptr) {
96 PX4_ERR(
"bus option already started");
101 if (interface->init() !=
OK) {
103 PX4_WARN(
"no device on bus %u (type: %u)", (
unsigned)bus.busnum, (
unsigned)bus.busid);
107 bus.dev =
new HMC5883(interface, bus.devpath, rotation);
109 if (bus.dev !=
nullptr &&
OK != bus.dev->init()) {
123 PX4_ERR(
"Failed to setup poll rate");
141 bool started =
false;
167 bool stopped =
false;
194 PX4_ERR(
"bus %u not started", (
unsigned)busid);
243 if (bus ==
nullptr) {
247 const char *path = bus->
devpath;
252 PX4_ERR(
"%s open failed (try 'hmc5883 start' if the driver is not running", path);
259 PX4_ERR(
"failed to enable sensor calibration mode");
275 if (bus ==
nullptr) {
279 const char *path = bus->
devpath;
289 PX4_ERR(
"set temperature compensation failed");
305 if (bus ==
nullptr) {
309 if (bus !=
nullptr) {
310 PX4_INFO(
"running on bus: %u (%s)\n", (
unsigned)bus->
busid, bus->
devpath);
320 warnx(
"missing command: try 'start', 'info', 'calibrate'");
322 warnx(
" -R rotation");
323 warnx(
" -C calibrate on start");
324 warnx(
" -X only external bus");
325 #if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC) 326 warnx(
" -I only internal bus");
338 const char *myoptarg =
nullptr;
343 bool temp_compensation =
false;
349 while ((ch = px4_getopt(argc, argv,
"XISR:CT", &myoptind, &myoptarg)) != EOF) {
352 rotation = (
enum Rotation)atoi(myoptarg);
354 #if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC) 374 temp_compensation =
true;
382 if (myoptind >= argc) {
386 const char *verb = argv[myoptind];
391 if (!strcmp(verb,
"start")) {
395 PX4_ERR(
"calibration failed");
399 if (temp_compensation) {
411 if (!strcmp(verb,
"stop")) {
418 if (!strcmp(verb,
"tempoff")) {
422 if (!strcmp(verb,
"tempon")) {
429 if (!strcmp(verb,
"info") || !strcmp(verb,
"status")) {
436 if (!strcmp(verb,
"calibrate")) {
438 PX4_INFO(
"calibration successful");
442 PX4_ERR(
"calibration failed");
void print_info()
Diagnostics - print some basic information about the driver.
static int info(enum HMC5883_BUS busid)
Print a little info about the driver.
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
static int start(enum HMC5883_BUS busid, enum Rotation rotation)
Start the driver.
__EXPORT int hmc5883_main(int argc, char *argv[])
static bool start_bus(struct hmc5883_bus_option &bus, enum Rotation rotation)
start driver for a specific bus option
device::Device *(* HMC5883_constructor)(int)
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
HMC5883_constructor interface_constructor
static int temp_enable(enum HMC5883_BUS busid, bool enable)
enable/disable temperature compensation
device::Device * HMC5883_I2C_interface(int bus)
#define MAGIOCCALIBRATE
perform self-calibration, update scale factors to canonical units
device::Device * HMC5883_SPI_interface(int bus)
Rotation
Enum for board and external compass rotations.
Shared defines for the hmc5883 driver.
static struct hmc5883_bus_option * find_bus(enum HMC5883_BUS busid)
find a bus structure for a busid
struct hmc5883::hmc5883_bus_option bus_options[]
#define MAGIOCSTEMPCOMP
enable/disable temperature compensation
Fundamental base class for all physical drivers (I2C, SPI).
static int calibrate(enum HMC5883_BUS busid)
Automatic scale calibration.
void stop()
Stop the automatic measurement state machine.
Local functions in support of the shell command.