From 2d1357b44cdbb8860d416b9186777ce5e9ddfa50 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 27 Aug 2019 16:23:30 +1000 Subject: [PATCH] AP_Mount: stop passing serial manager through to init() --- libraries/AP_Mount/AP_Mount.cpp | 4 ++-- libraries/AP_Mount/AP_Mount.h | 3 +-- libraries/AP_Mount/AP_Mount_Alexmos.cpp | 5 ++++- libraries/AP_Mount/AP_Mount_Alexmos.h | 2 +- libraries/AP_Mount/AP_Mount_Backend.h | 2 +- libraries/AP_Mount/AP_Mount_SToRM32.h | 2 +- libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp | 5 ++++- libraries/AP_Mount/AP_Mount_SToRM32_serial.h | 2 +- libraries/AP_Mount/AP_Mount_Servo.cpp | 2 +- libraries/AP_Mount/AP_Mount_Servo.h | 2 +- libraries/AP_Mount/AP_Mount_SoloGimbal.cpp | 2 +- libraries/AP_Mount/AP_Mount_SoloGimbal.h | 2 +- 12 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libraries/AP_Mount/AP_Mount.cpp b/libraries/AP_Mount/AP_Mount.cpp index b7e0f103e8..8214518be3 100644 --- a/libraries/AP_Mount/AP_Mount.cpp +++ b/libraries/AP_Mount/AP_Mount.cpp @@ -408,7 +408,7 @@ AP_Mount::AP_Mount(const struct Location ¤t_loc) : } // init - detect and initialise all mounts -void AP_Mount::init(const AP_SerialManager& serial_manager) +void AP_Mount::init() { // check init has not been called before if (_num_instances != 0) { @@ -466,7 +466,7 @@ void AP_Mount::init(const AP_SerialManager& serial_manager) // init new instance if (_backends[instance] != nullptr) { - _backends[instance]->init(serial_manager); + _backends[instance]->init(); if (!primary_set) { _primary = instance; primary_set = true; diff --git a/libraries/AP_Mount/AP_Mount.h b/libraries/AP_Mount/AP_Mount.h index e5b616eb1d..37d7ed713c 100644 --- a/libraries/AP_Mount/AP_Mount.h +++ b/libraries/AP_Mount/AP_Mount.h @@ -23,7 +23,6 @@ #include #include #include -#include // maximum number of mounts #define AP_MOUNT_MAX_INSTANCES 1 @@ -74,7 +73,7 @@ public: }; // init - detect and initialise all mounts - void init(const AP_SerialManager& serial_manager); + void init(); // update - give mount opportunity to update servos. should be called at 10hz or higher void update(); diff --git a/libraries/AP_Mount/AP_Mount_Alexmos.cpp b/libraries/AP_Mount/AP_Mount_Alexmos.cpp index ae581cc425..e47b3590c0 100644 --- a/libraries/AP_Mount/AP_Mount_Alexmos.cpp +++ b/libraries/AP_Mount/AP_Mount_Alexmos.cpp @@ -1,10 +1,13 @@ #include "AP_Mount_Alexmos.h" #include +#include extern const AP_HAL::HAL& hal; -void AP_Mount_Alexmos::init(const AP_SerialManager& serial_manager) +void AP_Mount_Alexmos::init() { + const AP_SerialManager& serial_manager = AP::serialmanager(); + // check for alexmos protcol if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_AlexMos, 0))) { _initialised = true; diff --git a/libraries/AP_Mount/AP_Mount_Alexmos.h b/libraries/AP_Mount/AP_Mount_Alexmos.h index 8a9d4a5e05..c6dcb94494 100644 --- a/libraries/AP_Mount/AP_Mount_Alexmos.h +++ b/libraries/AP_Mount/AP_Mount_Alexmos.h @@ -70,7 +70,7 @@ public: {} // init - performs any required initialisation for this instance - void init(const AP_SerialManager& serial_manager) override; + void init() override; // update mount position - should be called periodically void update() override; diff --git a/libraries/AP_Mount/AP_Mount_Backend.h b/libraries/AP_Mount/AP_Mount_Backend.h index 1414653491..217949e01a 100644 --- a/libraries/AP_Mount/AP_Mount_Backend.h +++ b/libraries/AP_Mount/AP_Mount_Backend.h @@ -37,7 +37,7 @@ public: virtual ~AP_Mount_Backend(void) {} // init - performs any required initialisation for this instance - virtual void init(const AP_SerialManager& serial_manager) = 0; + virtual void init() = 0; // update mount position - should be called periodically virtual void update() = 0; diff --git a/libraries/AP_Mount/AP_Mount_SToRM32.h b/libraries/AP_Mount/AP_Mount_SToRM32.h index d9ed8d3865..c0779dfb79 100644 --- a/libraries/AP_Mount/AP_Mount_SToRM32.h +++ b/libraries/AP_Mount/AP_Mount_SToRM32.h @@ -22,7 +22,7 @@ public: AP_Mount_SToRM32(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance); // init - performs any required initialisation for this instance - void init(const AP_SerialManager& serial_manager) override {} + void init() override {} // update mount position - should be called periodically void update() override; diff --git a/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp b/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp index 08c3f8b014..3d0871327b 100644 --- a/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp +++ b/libraries/AP_Mount/AP_Mount_SToRM32_serial.cpp @@ -3,6 +3,7 @@ #include #include #include +#include extern const AP_HAL::HAL& hal; @@ -12,8 +13,10 @@ AP_Mount_SToRM32_serial::AP_Mount_SToRM32_serial(AP_Mount &frontend, AP_Mount::m {} // init - performs any required initialisation for this instance -void AP_Mount_SToRM32_serial::init(const AP_SerialManager& serial_manager) +void AP_Mount_SToRM32_serial::init() { + const AP_SerialManager& serial_manager = AP::serialmanager(); + _port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_SToRM32, 0); if (_port) { _initialised = true; diff --git a/libraries/AP_Mount/AP_Mount_SToRM32_serial.h b/libraries/AP_Mount/AP_Mount_SToRM32_serial.h index 97f4dd29bc..5df9a85fd4 100644 --- a/libraries/AP_Mount/AP_Mount_SToRM32_serial.h +++ b/libraries/AP_Mount/AP_Mount_SToRM32_serial.h @@ -21,7 +21,7 @@ public: AP_Mount_SToRM32_serial(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance); // init - performs any required initialisation for this instance - void init(const AP_SerialManager& serial_manager) override; + void init() override; // update mount position - should be called periodically void update() override; diff --git a/libraries/AP_Mount/AP_Mount_Servo.cpp b/libraries/AP_Mount/AP_Mount_Servo.cpp index 6aab247ed0..34824a169d 100644 --- a/libraries/AP_Mount/AP_Mount_Servo.cpp +++ b/libraries/AP_Mount/AP_Mount_Servo.cpp @@ -4,7 +4,7 @@ extern const AP_HAL::HAL& hal; // init - performs any required initialisation for this instance -void AP_Mount_Servo::init(const AP_SerialManager& serial_manager) +void AP_Mount_Servo::init() { if (_instance == 0) { _roll_idx = SRV_Channel::k_mount_roll; diff --git a/libraries/AP_Mount/AP_Mount_Servo.h b/libraries/AP_Mount/AP_Mount_Servo.h index b7415c7718..669cbfa26a 100644 --- a/libraries/AP_Mount/AP_Mount_Servo.h +++ b/libraries/AP_Mount/AP_Mount_Servo.h @@ -24,7 +24,7 @@ public: } // init - performs any required initialisation for this instance - void init(const AP_SerialManager& serial_manager) override; + void init() override; // update mount position - should be called periodically void update() override; diff --git a/libraries/AP_Mount/AP_Mount_SoloGimbal.cpp b/libraries/AP_Mount/AP_Mount_SoloGimbal.cpp index ae1ee0bf64..54a2b4b5fe 100644 --- a/libraries/AP_Mount/AP_Mount_SoloGimbal.cpp +++ b/libraries/AP_Mount/AP_Mount_SoloGimbal.cpp @@ -17,7 +17,7 @@ AP_Mount_SoloGimbal::AP_Mount_SoloGimbal(AP_Mount &frontend, AP_Mount::mount_sta {} // init - performs any required initialisation for this instance -void AP_Mount_SoloGimbal::init(const AP_SerialManager& serial_manager) +void AP_Mount_SoloGimbal::init() { _initialised = true; set_mode((enum MAV_MOUNT_MODE)_state._default_mode.get()); diff --git a/libraries/AP_Mount/AP_Mount_SoloGimbal.h b/libraries/AP_Mount/AP_Mount_SoloGimbal.h index 47c91f5ba3..e41a997c52 100644 --- a/libraries/AP_Mount/AP_Mount_SoloGimbal.h +++ b/libraries/AP_Mount/AP_Mount_SoloGimbal.h @@ -24,7 +24,7 @@ public: AP_Mount_SoloGimbal(AP_Mount &frontend, AP_Mount::mount_state &state, uint8_t instance); // init - performs any required initialisation for this instance - void init(const AP_SerialManager& serial_manager) override; + void init() override; // update mount position - should be called periodically void update() override;