From 575e7be540cb7b4b5e100734181b278a326e3746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 21 Aug 2017 10:48:28 +0200 Subject: [PATCH] fix linux_pwm_out: return correct value for PCA9685::init() --- src/drivers/linux_pwm_out/PCA9685.h | 2 +- src/drivers/linux_pwm_out/linux_pwm_out.cpp | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/drivers/linux_pwm_out/PCA9685.h b/src/drivers/linux_pwm_out/PCA9685.h index d54c263605..71a58275e9 100644 --- a/src/drivers/linux_pwm_out/PCA9685.h +++ b/src/drivers/linux_pwm_out/PCA9685.h @@ -82,7 +82,7 @@ public: */ PCA9685(int bus, int address); - int init() override { return _fd >= 0; } + int init() override { return _fd >= 0 ? 0 : -1; } int send_output_pwm(const uint16_t *pwm, int num_outputs) override; diff --git a/src/drivers/linux_pwm_out/linux_pwm_out.cpp b/src/drivers/linux_pwm_out/linux_pwm_out.cpp index bb1244025a..245c5fc0f2 100644 --- a/src/drivers/linux_pwm_out/linux_pwm_out.cpp +++ b/src/drivers/linux_pwm_out/linux_pwm_out.cpp @@ -217,13 +217,7 @@ void task_main(int argc, char *argv[]) pwm_out = new NavioSysfsPWMOut(_device, _max_num_outputs); } - /** - * if the _protocol is "pca9685" and the driver is executed correctly, - * the return value of "pwm_out->init()" will be higher than 0. - */ - bool check_pwm_device = (strcmp(_protocol, "pca9685") == 0) ? (0 > pwm_out->init()) : (pwm_out->init() != 0); - - if (check_pwm_device) { + if (pwm_out->init() != 0) { PX4_ERR("PWM output init failed"); delete pwm_out; return;