Browse Source

RC_Channel: added get_pwm() function for Lua

c415-sdk
Andrew Tridgell 5 years ago committed by WickedShell
parent
commit
dfd7b022fd
  1. 7
      libraries/RC_Channel/RC_Channel.h
  2. 19
      libraries/RC_Channel/RC_Channels.cpp

7
libraries/RC_Channel/RC_Channel.h

@ -347,6 +347,13 @@ public: @@ -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 {

19
libraries/RC_Channel/RC_Channels.cpp

@ -201,6 +201,25 @@ void RC_Channels::read_mode_switch() @@ -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;

Loading…
Cancel
Save