mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 06:53:34 +08:00
ERROR macro: get rid of the many 'oddly, ERROR is not defined for c++', use PX4_ERROR
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
*/
|
||||
|
||||
#include "LidarLiteI2C.h"
|
||||
#include <px4_defines.h>
|
||||
#include <semaphore.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
@@ -48,12 +49,6 @@
|
||||
#include <stdio.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
/* oddly, ERROR is not defined for c++ */
|
||||
#ifdef ERROR
|
||||
# undef ERROR
|
||||
#endif
|
||||
static const int ERROR = -1;
|
||||
|
||||
LidarLiteI2C::LidarLiteI2C(int bus, const char *path, int address) :
|
||||
I2C("LL40LS", path, bus, address, 100000),
|
||||
_work{},
|
||||
@@ -110,7 +105,7 @@ LidarLiteI2C::~LidarLiteI2C()
|
||||
|
||||
int LidarLiteI2C::init()
|
||||
{
|
||||
int ret = ERROR;
|
||||
int ret = PX4_ERROR;
|
||||
|
||||
/* do I2C init (and probe) first */
|
||||
if (I2C::init() != OK) {
|
||||
|
||||
@@ -45,14 +45,10 @@
|
||||
#include "LidarLitePWM.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <px4_defines.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_pwm_input.h>
|
||||
|
||||
/* oddly, ERROR is not defined for c++ */
|
||||
#ifdef __cplusplus
|
||||
static const int ERROR = -1;
|
||||
#endif
|
||||
|
||||
LidarLitePWM::LidarLitePWM(const char *path) :
|
||||
CDev("LidarLitePWM", path),
|
||||
_work{},
|
||||
@@ -95,15 +91,15 @@ int LidarLitePWM::init()
|
||||
/* do regular cdev init */
|
||||
int ret = CDev::init();
|
||||
|
||||
if (ret != OK) {
|
||||
return ERROR;
|
||||
if (ret != PX4_OK) {
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
/* allocate basic report buffers */
|
||||
_reports = new ringbuffer::RingBuffer(2, sizeof(struct distance_sensor_s));
|
||||
|
||||
if (_reports == nullptr) {
|
||||
return ERROR;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
_class_instance = register_class_devname(RANGE_FINDER_BASE_DEVICE_PATH);
|
||||
@@ -119,7 +115,7 @@ int LidarLitePWM::init()
|
||||
DEVICE_DEBUG("failed to create distance_sensor object. Did you start uOrb?");
|
||||
}
|
||||
|
||||
return OK;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void LidarLitePWM::print_info()
|
||||
@@ -172,11 +168,11 @@ int LidarLitePWM::measure()
|
||||
{
|
||||
perf_begin(_sample_perf);
|
||||
|
||||
if (OK != collect()) {
|
||||
if (PX4_OK != collect()) {
|
||||
DEVICE_DEBUG("collection error");
|
||||
perf_count(_read_errors);
|
||||
perf_end(_sample_perf);
|
||||
return ERROR;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
_range.timestamp = hrt_absolute_time();
|
||||
@@ -206,7 +202,7 @@ int LidarLitePWM::measure()
|
||||
|
||||
poll_notify(POLLIN);
|
||||
perf_end(_sample_perf);
|
||||
return OK;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
ssize_t LidarLitePWM::read(struct file *filp, char *buffer, size_t buflen)
|
||||
@@ -266,12 +262,12 @@ int LidarLitePWM::collect()
|
||||
int fd = ::open(PWMIN0_DEVICE_PATH, O_RDONLY);
|
||||
|
||||
if (fd == -1) {
|
||||
return ERROR;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
if (::read(fd, &_pwm, sizeof(_pwm)) == sizeof(_pwm)) {
|
||||
::close(fd);
|
||||
return OK;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
::close(fd);
|
||||
@@ -284,7 +280,7 @@ int LidarLitePWM::reset_sensor()
|
||||
int fd = ::open(PWMIN0_DEVICE_PATH, O_RDONLY);
|
||||
|
||||
if (fd == -1) {
|
||||
return ERROR;
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
int ret = ::ioctl(fd, SENSORIOCRESET, 0);
|
||||
|
||||
@@ -70,12 +70,6 @@ extern "C" __EXPORT int ll40ls_main(int argc, char *argv[]);
|
||||
namespace ll40ls
|
||||
{
|
||||
|
||||
/* oddly, ERROR is not defined for c++ */
|
||||
#ifdef ERROR
|
||||
# undef ERROR
|
||||
#endif
|
||||
const int ERROR = -1;
|
||||
|
||||
LidarLiteI2C *g_dev_int;
|
||||
LidarLiteI2C *g_dev_ext;
|
||||
LidarLitePWM *g_dev_pwm;
|
||||
@@ -132,7 +126,7 @@ void start(const bool use_i2c, const int bus)
|
||||
|
||||
g_dev_ext = new LidarLiteI2C(PX4_I2C_BUS_EXPANSION, LL40LS_DEVICE_PATH_EXT);
|
||||
|
||||
if (g_dev_ext != nullptr && OK != g_dev_ext->init()) {
|
||||
if (g_dev_ext != nullptr && PX4_OK != g_dev_ext->init()) {
|
||||
delete g_dev_ext;
|
||||
g_dev_ext = nullptr;
|
||||
|
||||
@@ -152,7 +146,7 @@ void start(const bool use_i2c, const int bus)
|
||||
|
||||
g_dev_int = new LidarLiteI2C(PX4_I2C_BUS_ONBOARD, LL40LS_DEVICE_PATH_INT);
|
||||
|
||||
if (g_dev_int != nullptr && OK != g_dev_int->init()) {
|
||||
if (g_dev_int != nullptr && PX4_OK != g_dev_int->init()) {
|
||||
/* tear down the failing onboard instance */
|
||||
delete g_dev_int;
|
||||
g_dev_int = nullptr;
|
||||
@@ -203,7 +197,7 @@ void start(const bool use_i2c, const int bus)
|
||||
} else {
|
||||
g_dev_pwm = new LidarLitePWM(LL40LS_DEVICE_PATH_PWM);
|
||||
|
||||
if (g_dev_pwm != nullptr && OK != g_dev_pwm->init()) {
|
||||
if (g_dev_pwm != nullptr && PX4_OK != g_dev_pwm->init()) {
|
||||
delete g_dev_pwm;
|
||||
g_dev_pwm = nullptr;
|
||||
warnx("failed to init PWM");
|
||||
@@ -321,7 +315,7 @@ test(const bool use_i2c, const int bus)
|
||||
warnx("time: %lld", report.timestamp);
|
||||
|
||||
/* start the sensor polling at 2Hz */
|
||||
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
|
||||
if (PX4_OK != ioctl(fd, SENSORIOCSPOLLRATE, 2)) {
|
||||
errx(1, "failed to set 2Hz poll rate");
|
||||
}
|
||||
|
||||
@@ -353,7 +347,7 @@ test(const bool use_i2c, const int bus)
|
||||
}
|
||||
|
||||
/* reset the sensor polling to default rate */
|
||||
if (OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
|
||||
if (PX4_OK != ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT)) {
|
||||
errx(1, "failed to set default poll rate");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user