prevent div by 0

This commit is contained in:
Michael Oborne 2011-10-30 21:28:39 +08:00
parent 3f3c04f95b
commit d18bb1cc7e
1 changed files with 4 additions and 0 deletions

View File

@ -190,6 +190,10 @@ RC_Channel::pwm_to_angle()
{
int radio_trim_high = radio_trim + _dead_zone;
int radio_trim_low = radio_trim - _dead_zone;
// prevent div by 0
if ((radio_trim_low - radio_min) == 0 || (radio_max - radio_trim_high) == 0)
return 0;
if(radio_in > radio_trim_high){
return _reverse * ((long)_high * (long)(radio_in - radio_trim_high)) / (long)(radio_max - radio_trim_high);