mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-29 19:57:12 +08:00
lps22hb: add argc check and use px4_getopt
This commit is contained in:
@@ -48,7 +48,6 @@
|
|||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <getopt.h>
|
|
||||||
|
|
||||||
static constexpr uint8_t WHO_AM_I = 0x0F;
|
static constexpr uint8_t WHO_AM_I = 0x0F;
|
||||||
static constexpr uint8_t LPS22HB_ID_WHO_AM_I = 0xB1;
|
static constexpr uint8_t LPS22HB_ID_WHO_AM_I = 0xB1;
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
|
|
||||||
#include "LPS22HB.hpp"
|
#include "LPS22HB.hpp"
|
||||||
|
|
||||||
|
#include <px4_getopt.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
extern "C" __EXPORT int lps22hb_main(int argc, char *argv[]);
|
extern "C" __EXPORT int lps22hb_main(int argc, char *argv[]);
|
||||||
@@ -234,10 +236,13 @@ usage()
|
|||||||
int
|
int
|
||||||
lps22hb_main(int argc, char *argv[])
|
lps22hb_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
enum LPS22HB_BUS busid = LPS22HB_BUS_ALL;
|
int myoptind = 1;
|
||||||
int ch;
|
int ch;
|
||||||
|
const char *myoptarg = nullptr;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "XIS:")) != EOF) {
|
enum LPS22HB_BUS busid = LPS22HB_BUS_ALL;
|
||||||
|
|
||||||
|
while ((ch = px4_getopt(argc, argv, "XIS:", &myoptind, &myoptarg)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
#if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC)
|
#if (PX4_I2C_BUS_ONBOARD || PX4_SPIDEV_HMC)
|
||||||
|
|
||||||
@@ -256,11 +261,16 @@ lps22hb_main(int argc, char *argv[])
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
lps22hb::usage();
|
lps22hb::usage();
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *verb = argv[optind];
|
if (myoptind >= argc) {
|
||||||
|
lps22hb::usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *verb = argv[myoptind];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start/load the driver.
|
* Start/load the driver.
|
||||||
|
|||||||
Reference in New Issue
Block a user