From ead72214acaf8e4f78a304311fdf05b3d6e92c97 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Feb 2018 16:41:37 +1100 Subject: [PATCH] AP_OpticalFlow: support SP01 board --- libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.cpp | 8 ++++---- libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.h | 4 ++-- libraries/AP_OpticalFlow/OpticalFlow.cpp | 8 ++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.cpp b/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.cpp index e2805c15c3..ce856bb5e3 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.cpp +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.cpp @@ -80,17 +80,17 @@ extern const AP_HAL::HAL& hal; #define PIXART_SROM_CRC_RESULT 0xBEEF // constructor -AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(OpticalFlow &_frontend) : +AP_OpticalFlow_Pixart::AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend) : OpticalFlow_backend(_frontend) { - _dev = std::move(hal.spi->get_device("pixartflow")); + _dev = std::move(hal.spi->get_device(devname)); } // detect the device -AP_OpticalFlow_Pixart *AP_OpticalFlow_Pixart::detect(OpticalFlow &_frontend) +AP_OpticalFlow_Pixart *AP_OpticalFlow_Pixart::detect(const char *devname, OpticalFlow &_frontend) { - AP_OpticalFlow_Pixart *sensor = new AP_OpticalFlow_Pixart(_frontend); + AP_OpticalFlow_Pixart *sensor = new AP_OpticalFlow_Pixart(devname, _frontend); if (!sensor) { return nullptr; } diff --git a/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.h b/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.h index 5d18d55f14..abc2c99ce6 100644 --- a/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.h +++ b/libraries/AP_OpticalFlow/AP_OpticalFlow_Pixart.h @@ -7,7 +7,7 @@ class AP_OpticalFlow_Pixart : public OpticalFlow_backend { public: /// constructor - AP_OpticalFlow_Pixart(OpticalFlow &_frontend); + AP_OpticalFlow_Pixart(const char *devname, OpticalFlow &_frontend); // init - initialise the sensor void init() override {} @@ -16,7 +16,7 @@ public: void update(void) override; // detect if the sensor is available - static AP_OpticalFlow_Pixart *detect(OpticalFlow &_frontend); + static AP_OpticalFlow_Pixart *detect(const char *devname, OpticalFlow &_frontend); private: AP_HAL::OwnPtr _dev; diff --git a/libraries/AP_OpticalFlow/OpticalFlow.cpp b/libraries/AP_OpticalFlow/OpticalFlow.cpp index 71886585a6..cba6862e78 100644 --- a/libraries/AP_OpticalFlow/OpticalFlow.cpp +++ b/libraries/AP_OpticalFlow/OpticalFlow.cpp @@ -91,9 +91,13 @@ void OpticalFlow::init(void) if (!backend) { #if AP_FEATURE_BOARD_DETECT if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK || + AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PIXHAWK2 || AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_PCNC1) { // possibly have pixhart on external SPI - backend = AP_OpticalFlow_Pixart::detect(*this); + backend = AP_OpticalFlow_Pixart::detect("pixartflow", *this); + } + if (AP_BoardConfig::get_board_type() == AP_BoardConfig::PX4_BOARD_SP01) { + backend = AP_OpticalFlow_Pixart::detect("pixartPC15", *this); } if (backend == nullptr) { backend = AP_OpticalFlow_PX4Flow::detect(*this); @@ -106,7 +110,7 @@ void OpticalFlow::init(void) #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX backend = AP_OpticalFlow_PX4Flow::detect(*this); #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412 - backend = AP_OpticalFlow_Pixart::detect(*this); + backend = AP_OpticalFlow_Pixart::detect("pixartflow", *this); #endif }