RC_Channel: added get_pwm() function for Lua

This commit is contained in:
Andrew Tridgell
2019-12-20 19:51:46 -07:00
committed by WickedShell
parent d332773689
commit dfd7b022fd
2 changed files with 26 additions and 0 deletions
+19
View File
@@ -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;