mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-05 03:41:37 +08:00
LSM303D: Add option for 16g range
This commit is contained in:
@@ -1416,6 +1416,13 @@ LSM303D::stop()
|
|||||||
{
|
{
|
||||||
hrt_cancel(&_accel_call);
|
hrt_cancel(&_accel_call);
|
||||||
hrt_cancel(&_mag_call);
|
hrt_cancel(&_mag_call);
|
||||||
|
|
||||||
|
/* reset internal states */
|
||||||
|
memset(_last_accel, 0, sizeof(_last_accel));
|
||||||
|
|
||||||
|
/* discard unread data in the buffers */
|
||||||
|
_accel_reports->flush();
|
||||||
|
_mag_reports->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1856,7 +1863,7 @@ namespace lsm303d
|
|||||||
|
|
||||||
LSM303D *g_dev;
|
LSM303D *g_dev;
|
||||||
|
|
||||||
void start(bool external_bus, enum Rotation rotation);
|
void start(bool external_bus, enum Rotation rotation, unsigned range);
|
||||||
void test();
|
void test();
|
||||||
void reset();
|
void reset();
|
||||||
void info();
|
void info();
|
||||||
@@ -1871,11 +1878,12 @@ void test_error();
|
|||||||
* up and running or failed to detect the sensor.
|
* up and running or failed to detect the sensor.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
start(bool external_bus, enum Rotation rotation)
|
start(bool external_bus, enum Rotation rotation, unsigned range)
|
||||||
{
|
{
|
||||||
int fd, fd_mag;
|
int fd, fd_mag;
|
||||||
if (g_dev != nullptr)
|
if (g_dev != nullptr) {
|
||||||
errx(0, "already started");
|
errx(0, "already started");
|
||||||
|
}
|
||||||
|
|
||||||
/* create the driver */
|
/* create the driver */
|
||||||
if (external_bus) {
|
if (external_bus) {
|
||||||
@@ -1899,11 +1907,17 @@ start(bool external_bus, enum Rotation rotation)
|
|||||||
/* set the poll rate to default, starts automatic data collection */
|
/* set the poll rate to default, starts automatic data collection */
|
||||||
fd = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
|
fd = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
|
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, ACCELIOCSRANGE, range) < 0) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
|
fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
|
||||||
|
|
||||||
@@ -1995,7 +2009,10 @@ test()
|
|||||||
warnx("mag z: \t%d\traw", (int)m_report.z_raw);
|
warnx("mag z: \t%d\traw", (int)m_report.z_raw);
|
||||||
warnx("mag range: %8.4f ga", (double)m_report.range_ga);
|
warnx("mag range: %8.4f ga", (double)m_report.range_ga);
|
||||||
|
|
||||||
/* XXX add poll-rate tests here too */
|
/* reset to default polling */
|
||||||
|
if (ioctl(fd_accel, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
||||||
|
err(1, "reset to default polling");
|
||||||
|
}
|
||||||
|
|
||||||
close(fd_accel);
|
close(fd_accel);
|
||||||
close(fd_mag);
|
close(fd_mag);
|
||||||
@@ -2099,9 +2116,10 @@ lsm303d_main(int argc, char *argv[])
|
|||||||
bool external_bus = false;
|
bool external_bus = false;
|
||||||
int ch;
|
int ch;
|
||||||
enum Rotation rotation = ROTATION_NONE;
|
enum Rotation rotation = ROTATION_NONE;
|
||||||
|
int accel_range = 8;
|
||||||
|
|
||||||
/* jump over start/off/etc and look at options first */
|
/* jump over start/off/etc and look at options first */
|
||||||
while ((ch = getopt(argc, argv, "XR:")) != EOF) {
|
while ((ch = getopt(argc, argv, "XR:a:")) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'X':
|
case 'X':
|
||||||
external_bus = true;
|
external_bus = true;
|
||||||
@@ -2109,6 +2127,9 @@ lsm303d_main(int argc, char *argv[])
|
|||||||
case 'R':
|
case 'R':
|
||||||
rotation = (enum Rotation)atoi(optarg);
|
rotation = (enum Rotation)atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'a':
|
||||||
|
accel_range = atoi(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
lsm303d::usage();
|
lsm303d::usage();
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -2122,7 +2143,7 @@ lsm303d_main(int argc, char *argv[])
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
if (!strcmp(verb, "start"))
|
if (!strcmp(verb, "start"))
|
||||||
lsm303d::start(external_bus, rotation);
|
lsm303d::start(external_bus, rotation, accel_range);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test the driver/device.
|
* Test the driver/device.
|
||||||
|
|||||||
Reference in New Issue
Block a user