hmc5883: added -C option to calibrate on startup

Conflicts:
	src/drivers/hmc5883/hmc5883.cpp
This commit is contained in:
Andrew Tridgell 2014-07-04 12:07:23 +10:00 committed by Lorenz Meier
parent d952e81ab7
commit 5e62ae7a9e
1 changed files with 35 additions and 7 deletions

View File

@ -1516,6 +1516,11 @@ hmc5883_usage()
warnx("missing command: try 'start', 'info', 'test', 'reset', 'info', 'calibrate'"); warnx("missing command: try 'start', 'info', 'test', 'reset', 'info', 'calibrate'");
warnx("options:"); warnx("options:");
warnx(" -R rotation"); warnx(" -R rotation");
warnx(" -C calibrate on start");
warnx(" -X only external bus");
#ifdef PX4_I2C_BUS_ONBOARD
warnx(" -I only internal bus");
#endif
} }
int int
@ -1523,46 +1528,69 @@ hmc5883_main(int argc, char *argv[])
{ {
int ch; int ch;
enum Rotation rotation = ROTATION_NONE; enum Rotation rotation = ROTATION_NONE;
bool calibrate = false;
while ((ch = getopt(argc, argv, "R:")) != EOF) { while ((ch = getopt(argc, argv, "XIR:C")) != EOF) {
switch (ch) { switch (ch) {
case 'R': case 'R':
rotation = (enum Rotation)atoi(optarg); rotation = (enum Rotation)atoi(optarg);
break; break;
#ifdef PX4_I2C_BUS_ONBOARD
case 'I':
bus = PX4_I2C_BUS_ONBOARD;
break;
#endif
case 'X':
bus = PX4_I2C_BUS_EXPANSION;
break;
case 'C':
calibrate = true;
break;
default: default:
hmc5883_usage(); hmc5883_usage();
exit(0); exit(0);
} }
} }
const char *verb = argv[optind];
/* /*
* Start/load the driver. * Start/load the driver.
*/ */
if (!strcmp(argv[1], "start")) if (!strcmp(verb, "start")) {
hmc5883::start(rotation); hmc5883::start(bus, rotation);
if (calibrate) {
if (hmc5883::calibrate(bus) == 0) {
errx(0, "calibration successful");
} else {
errx(1, "calibration failed");
}
}
}
/* /*
* Test the driver/device. * Test the driver/device.
*/ */
if (!strcmp(argv[1], "test")) if (!strcmp(verb, "test"))
hmc5883::test(bus); hmc5883::test(bus);
/* /*
* Reset the driver. * Reset the driver.
*/ */
if (!strcmp(argv[1], "reset")) if (!strcmp(verb, "reset"))
hmc5883::reset(bus); hmc5883::reset(bus);
/* /*
* Print driver information. * Print driver information.
*/ */
if (!strcmp(argv[1], "info") || !strcmp(argv[1], "status")) if (!strcmp(verb, "info") || !strcmp(verb, "status"))
hmc5883::info(bus); hmc5883::info(bus);
/* /*
* Autocalibrate the scaling * Autocalibrate the scaling
*/ */
if (!strcmp(argv[1], "calibrate")) { if (!strcmp(verb, "calibrate")) {
if (hmc5883::calibrate(bus) == 0) { if (hmc5883::calibrate(bus) == 0) {
errx(0, "calibration successful"); errx(0, "calibration successful");