diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h index 15189b8bbe2..45fd7d7948a 100644 --- a/libraries/RC_Channel/RC_Channel.h +++ b/libraries/RC_Channel/RC_Channel.h @@ -347,6 +347,13 @@ public: return _override_timeout.get() * 1e3f; } + /* + get the RC input PWM value given a channel number. Note that + channel numbers start at 1, as this API is designed for use in + LUA + */ + bool get_pwm(uint8_t channel, uint16_t &pwm) const; + protected: enum class Option { diff --git a/libraries/RC_Channel/RC_Channels.cpp b/libraries/RC_Channel/RC_Channels.cpp index 2bbc210977d..97f9b83d38c 100644 --- a/libraries/RC_Channel/RC_Channels.cpp +++ b/libraries/RC_Channel/RC_Channels.cpp @@ -201,6 +201,25 @@ void RC_Channels::read_mode_switch() c->read_mode_switch(); } +/* + get the RC input PWM value given a channel number. Note that + channel numbers start at 1, as this API is designed for use in + LUA +*/ +bool RC_Channels::get_pwm(uint8_t c, uint16_t &pwm) const +{ + if (c < 1 || c > NUM_RC_CHANNELS) { + return false; + } + RC_Channel *chan = rc_channel(c-1); + int16_t pwm_signed = chan->get_radio_in(); + if (pwm_signed < 0) { + return false; + } + pwm = (uint16_t)pwm_signed; + return true; +} + // singleton instance RC_Channels *RC_Channels::_singleton;