diff --git a/src/drivers/camera_capture/camera_capture.cpp b/src/drivers/camera_capture/camera_capture.cpp index 8aed49cbef28f63bcc6611a662347a31d28ee8e4..e69e8c9104543e2a72d5412b958781041bce46a7 100644 --- a/src/drivers/camera_capture/camera_capture.cpp +++ b/src/drivers/camera_capture/camera_capture.cpp @@ -232,24 +232,55 @@ CameraCapture::cycle() void CameraCapture::set_capture_control(bool enabled) { + int fd = -1; + fd = ::open(PX4FMU_DEVICE_PATH, O_RDWR); + + if (fd < 0) { + PX4_ERR("open fail"); + return; + } + + input_capture_config_t conf; + conf.channel = 5; // FMU chan 6 + conf.filter = 0; + conf.edge = _camera_capture_edge ? Rising : Falling; + conf.callback = NULL; + conf.context = NULL; + if (enabled) { - // register callbacks - if (!_camera_capture_edge) { - up_input_capture_set(5, Falling, 0, &CameraCapture::capture_trampoline, this); - } else { - up_input_capture_set(5, Rising, 0, &CameraCapture::capture_trampoline, this); + conf.callback = &CameraCapture::capture_trampoline; + conf.context = this; + + unsigned int capture_count = 0; + if (::ioctl(fd, INPUT_CAP_GET_COUNT, (unsigned long)&capture_count) != 0) { + PX4_INFO("Not in a capture mode"); + unsigned long mode = PWM_SERVO_MODE_5PWM1CAP; + + if (::ioctl(fd, PWM_SERVO_SET_MODE, mode) == 0) { + PX4_INFO("Mode changed to 5PWM1CAP"); + + } else { + PX4_ERR("Mode NOT changed to 4PWM2CAP"); + goto err_out; + } } + } - _capture_enabled = true; + if (::ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) { + _capture_enabled = enabled; } else { - up_input_capture_set(5, Disabled, 0, NULL, NULL); + PX4_ERR("Unable to set capture callback for chan %u\n", conf.channel); _capture_enabled = false; + goto err_out; } reset_statistics(false); +err_out: + ::close(fd); + return; } void diff --git a/src/drivers/camera_capture/camera_capture.hpp b/src/drivers/camera_capture/camera_capture.hpp index 99798dba5f9f5541f2cf7c749ebc1c05f020e808..d4a66da30e71e04a6582a1451f5e11a4f98b0bef 100644 --- a/src/drivers/camera_capture/camera_capture.hpp +++ b/src/drivers/camera_capture/camera_capture.hpp @@ -55,6 +55,8 @@ #include <px4_workqueue.h> #include <drivers/drv_hrt.h> +#include <drivers/drv_gpio.h> +#include <drivers/drv_pwm_output.h> #include <drivers/drv_input_capture.h> #include <drivers/device/ringbuffer.h>