From d6b38f400920d90750b4bc7ae798673b037742e5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Nov 2024 13:55:14 +1100 Subject: [PATCH] SRV_Channel: added get_output_pwm_chan() for scripting allows for servo drivers to be written in lua --- libraries/SRV_Channel/SRV_Channel.h | 3 +++ libraries/SRV_Channel/SRV_Channels.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/libraries/SRV_Channel/SRV_Channel.h b/libraries/SRV_Channel/SRV_Channel.h index e4778b2773..acb6021b89 100644 --- a/libraries/SRV_Channel/SRV_Channel.h +++ b/libraries/SRV_Channel/SRV_Channel.h @@ -373,6 +373,9 @@ public: // set output value for a specific function channel as a pwm value static void set_output_pwm_chan(uint8_t chan, uint16_t value); + // get output value for a specific channel as a pwm value + static bool get_output_pwm_chan(uint8_t chan, uint16_t &value); + // set output value for a specific function channel as a pwm value for specified override time in ms static void set_output_pwm_chan_timeout(uint8_t chan, uint16_t value, uint16_t timeout_ms); diff --git a/libraries/SRV_Channel/SRV_Channels.cpp b/libraries/SRV_Channel/SRV_Channels.cpp index c1fda6226c..292aa2bcac 100644 --- a/libraries/SRV_Channel/SRV_Channels.cpp +++ b/libraries/SRV_Channel/SRV_Channels.cpp @@ -434,6 +434,16 @@ void SRV_Channels::set_output_pwm_chan(uint8_t chan, uint16_t value) } } +// get output value for a specific channel as a pwm value +bool SRV_Channels::get_output_pwm_chan(uint8_t chan, uint16_t &value) +{ + if (chan >= NUM_SERVO_CHANNELS) { + return false; + } + value = channels[chan].get_output_pwm(); + return true; +} + #if AP_SCRIPTING_ENABLED && AP_SCHEDULER_ENABLED // set output value for a specific function channel as a pwm value with loop based timeout // timeout_ms of zero will clear override of the channel