mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 08:03:34 +08:00
ms5611 cleanup unnecessary Device CDev usage
This commit is contained in:
@@ -126,7 +126,7 @@ enum MS5611_BUS {
|
|||||||
#define MS5611_BARO_DEVICE_PATH_EXT "/dev/ms5611_ext"
|
#define MS5611_BARO_DEVICE_PATH_EXT "/dev/ms5611_ext"
|
||||||
#define MS5611_BARO_DEVICE_PATH_INT "/dev/ms5611_int"
|
#define MS5611_BARO_DEVICE_PATH_INT "/dev/ms5611_int"
|
||||||
|
|
||||||
class MS5611 : public device::CDev
|
class MS5611 : public cdev::CDev
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *path, enum MS56XX_DEVICE_TYPES device_type);
|
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *path, enum MS56XX_DEVICE_TYPES device_type);
|
||||||
@@ -143,11 +143,11 @@ public:
|
|||||||
void print_info();
|
void print_info();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Device *_interface;
|
device::Device *_interface;
|
||||||
|
|
||||||
ms5611::prom_s _prom;
|
ms5611::prom_s _prom;
|
||||||
|
|
||||||
struct work_s _work;
|
struct work_s _work {};
|
||||||
unsigned _measure_ticks;
|
unsigned _measure_ticks;
|
||||||
|
|
||||||
ringbuffer::RingBuffer *_reports;
|
ringbuffer::RingBuffer *_reports;
|
||||||
@@ -228,7 +228,7 @@ extern "C" __EXPORT int ms5611_main(int argc, char *argv[]);
|
|||||||
|
|
||||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *path,
|
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *path,
|
||||||
enum MS56XX_DEVICE_TYPES device_type) :
|
enum MS56XX_DEVICE_TYPES device_type) :
|
||||||
CDev("MS5611", path),
|
CDev(path),
|
||||||
_interface(interface),
|
_interface(interface),
|
||||||
_prom(prom_buf.s),
|
_prom(prom_buf.s),
|
||||||
_measure_ticks(0),
|
_measure_ticks(0),
|
||||||
@@ -246,16 +246,6 @@ MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *
|
|||||||
_measure_perf(perf_alloc(PC_ELAPSED, "ms5611_measure")),
|
_measure_perf(perf_alloc(PC_ELAPSED, "ms5611_measure")),
|
||||||
_comms_errors(perf_alloc(PC_COUNT, "ms5611_com_err"))
|
_comms_errors(perf_alloc(PC_COUNT, "ms5611_com_err"))
|
||||||
{
|
{
|
||||||
// work_cancel in stop_cycle called from the dtor will explode if we don't do this...
|
|
||||||
memset(&_work, 0, sizeof(_work));
|
|
||||||
|
|
||||||
// set the device type from the interface
|
|
||||||
_device_id.devid_s.bus_type = _interface->get_device_bus_type();
|
|
||||||
_device_id.devid_s.bus = _interface->get_device_bus();
|
|
||||||
_device_id.devid_s.address = _interface->get_device_address();
|
|
||||||
|
|
||||||
/* set later on init */
|
|
||||||
_device_id.devid_s.devtype = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MS5611::~MS5611()
|
MS5611::~MS5611()
|
||||||
@@ -289,7 +279,7 @@ MS5611::init()
|
|||||||
ret = CDev::init();
|
ret = CDev::init();
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
DEVICE_DEBUG("CDev init failed");
|
PX4_DEBUG("CDev init failed");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +287,7 @@ MS5611::init()
|
|||||||
_reports = new ringbuffer::RingBuffer(2, sizeof(sensor_baro_s));
|
_reports = new ringbuffer::RingBuffer(2, sizeof(sensor_baro_s));
|
||||||
|
|
||||||
if (_reports == nullptr) {
|
if (_reports == nullptr) {
|
||||||
DEVICE_DEBUG("can't get memory for reports");
|
PX4_DEBUG("can't get memory for reports");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -370,16 +360,16 @@ MS5611::init()
|
|||||||
|
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case MS5611_DEVICE:
|
case MS5611_DEVICE:
|
||||||
_device_id.devid_s.devtype = DRV_BARO_DEVTYPE_MS5611;
|
_interface->set_device_type(DRV_BARO_DEVTYPE_MS5611);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MS5607_DEVICE:
|
case MS5607_DEVICE:
|
||||||
_device_id.devid_s.devtype = DRV_BARO_DEVTYPE_MS5607;
|
_interface->set_device_type(DRV_BARO_DEVTYPE_MS5607);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ensure correct devid */
|
/* ensure correct devid */
|
||||||
brp.device_id = _device_id.devid;
|
brp.device_id = _interface->get_device_id();
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|
||||||
@@ -805,10 +795,10 @@ MS5611::collect()
|
|||||||
report.pressure = P / 100.0f; /* convert to millibar */
|
report.pressure = P / 100.0f; /* convert to millibar */
|
||||||
|
|
||||||
/* return device ID */
|
/* return device ID */
|
||||||
report.device_id = _device_id.devid;
|
report.device_id = _interface->get_device_id();
|
||||||
|
|
||||||
/* publish it */
|
/* publish it */
|
||||||
if (!(_pub_blocked) && _baro_topic != nullptr) {
|
if (_baro_topic != nullptr) {
|
||||||
/* publish it */
|
/* publish it */
|
||||||
orb_publish(ORB_ID(sensor_baro), _baro_topic, &report);
|
orb_publish(ORB_ID(sensor_baro), _baro_topic, &report);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ MS5611_SPI::init()
|
|||||||
ret = SPI::init();
|
ret = SPI::init();
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
DEVICE_DEBUG("SPI init failed");
|
PX4_DEBUG("SPI init failed");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ MS5611_SPI::init()
|
|||||||
ret = _reset();
|
ret = _reset();
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
DEVICE_DEBUG("reset failed");
|
PX4_DEBUG("reset failed");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ MS5611_SPI::init()
|
|||||||
ret = _read_prom();
|
ret = _read_prom();
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
DEVICE_DEBUG("prom readout failed");
|
PX4_DEBUG("prom readout failed");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,18 +261,18 @@ MS5611_SPI::_read_prom()
|
|||||||
all_zero = false;
|
all_zero = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//DEVICE_DEBUG("prom[%u]=0x%x", (unsigned)i, (unsigned)_prom.c[i]);
|
//PX4_DEBUG("prom[%u]=0x%x", (unsigned)i, (unsigned)_prom.c[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate CRC and return success/failure accordingly */
|
/* calculate CRC and return success/failure accordingly */
|
||||||
int ret = ms5611::crc4(&_prom.c[0]) ? OK : -EIO;
|
int ret = ms5611::crc4(&_prom.c[0]) ? OK : -EIO;
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
DEVICE_DEBUG("crc failed");
|
PX4_DEBUG("crc failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all_zero) {
|
if (all_zero) {
|
||||||
DEVICE_DEBUG("prom all zero");
|
PX4_DEBUG("prom all zero");
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user