|
|
|
@ -50,6 +50,7 @@
@@ -50,6 +50,7 @@
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <math.h> |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include <getopt.h> |
|
|
|
|
|
|
|
|
|
#include <nuttx/arch.h> |
|
|
|
|
#include <nuttx/wqueue.h> |
|
|
|
@ -775,7 +776,7 @@ namespace ms5611
@@ -775,7 +776,7 @@ namespace ms5611
|
|
|
|
|
|
|
|
|
|
MS5611 *g_dev; |
|
|
|
|
|
|
|
|
|
void start(); |
|
|
|
|
void start(bool external_bus); |
|
|
|
|
void test(); |
|
|
|
|
void reset(); |
|
|
|
|
void info(); |
|
|
|
@ -832,7 +833,7 @@ crc4(uint16_t *n_prom)
@@ -832,7 +833,7 @@ crc4(uint16_t *n_prom)
|
|
|
|
|
* Start the driver. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
start() |
|
|
|
|
start(bool external_bus) |
|
|
|
|
{ |
|
|
|
|
int fd; |
|
|
|
|
prom_u prom_buf; |
|
|
|
@ -845,7 +846,7 @@ start()
@@ -845,7 +846,7 @@ start()
|
|
|
|
|
|
|
|
|
|
/* create the driver, try SPI first, fall back to I2C if unsuccessful */ |
|
|
|
|
if (MS5611_spi_interface != nullptr) |
|
|
|
|
interface = MS5611_spi_interface(prom_buf); |
|
|
|
|
interface = MS5611_spi_interface(prom_buf, external_bus); |
|
|
|
|
if (interface == nullptr && (MS5611_i2c_interface != nullptr)) |
|
|
|
|
interface = MS5611_i2c_interface(prom_buf); |
|
|
|
|
|
|
|
|
@ -1058,41 +1059,66 @@ calibrate(unsigned altitude)
@@ -1058,41 +1059,66 @@ calibrate(unsigned altitude)
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
ms5611_usage() |
|
|
|
|
{ |
|
|
|
|
warnx("missing command: try 'start', 'info', 'test', 'test2', 'reset', 'calibrate'"); |
|
|
|
|
warnx("options:"); |
|
|
|
|
warnx(" -X (external bus)"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
ms5611_main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
bool external_bus = false; |
|
|
|
|
int ch; |
|
|
|
|
|
|
|
|
|
/* jump over start/off/etc and look at options first */ |
|
|
|
|
while ((ch = getopt(argc, argv, "X")) != EOF) { |
|
|
|
|
switch (ch) { |
|
|
|
|
case 'X': |
|
|
|
|
external_bus = true; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
ms5611_usage(); |
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char *verb = argv[optind]; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Start/load the driver. |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(argv[1], "start")) |
|
|
|
|
ms5611::start(); |
|
|
|
|
if (!strcmp(verb, "start")) |
|
|
|
|
ms5611::start(external_bus); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test the driver/device. |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(argv[1], "test")) |
|
|
|
|
if (!strcmp(verb, "test")) |
|
|
|
|
ms5611::test(); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Reset the driver. |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(argv[1], "reset")) |
|
|
|
|
if (!strcmp(verb, "reset")) |
|
|
|
|
ms5611::reset(); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print driver information. |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(argv[1], "info")) |
|
|
|
|
if (!strcmp(verb, "info")) |
|
|
|
|
ms5611::info(); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Perform MSL pressure calibration given an altitude in metres |
|
|
|
|
*/ |
|
|
|
|
if (!strcmp(argv[1], "calibrate")) { |
|
|
|
|
if (!strcmp(verb, "calibrate")) { |
|
|
|
|
if (argc < 2) |
|
|
|
|
errx(1, "missing altitude"); |
|
|
|
|
|
|
|
|
|
long altitude = strtol(argv[2], nullptr, 10); |
|
|
|
|
long altitude = strtol(argv[optind+1], nullptr, 10); |
|
|
|
|
|
|
|
|
|
ms5611::calibrate(altitude); |
|
|
|
|
} |
|
|
|
|