RC_Channel: simplify channel check in get_pwm()

This commit is contained in:
Andrew Tridgell 2019-12-19 17:36:44 +11:00 committed by WickedShell
parent b69afff6a7
commit 750718bdd3
2 changed files with 3 additions and 3 deletions

View File

@ -208,10 +208,10 @@ void RC_Channels::read_mode_switch()
*/
bool RC_Channels::get_pwm(uint8_t c, uint16_t &pwm) const
{
if (c < 1 || c > NUM_RC_CHANNELS) {
RC_Channel *chan = rc_channel(c-1);
if (chan == nullptr) {
return false;
}
RC_Channel *chan = rc_channel(c-1);
int16_t pwm_signed = chan->get_radio_in();
if (pwm_signed < 0) {
return false;

View File

@ -29,7 +29,7 @@ public:
RC_Channel_Example obj_channels[NUM_RC_CHANNELS];
RC_Channel_Example *channel(const uint8_t chan) override {
if (chan > NUM_RC_CHANNELS) {
if (chan >= NUM_RC_CHANNELS) {
return nullptr;
}
return &obj_channels[chan];