first cut at turnon scripts for EasyTimer v2
[fw/altos] / src / kernel / ao_convert_pa.c
index 410815b68bcdabac38d417a75d70910b0de91578..44b3d745f8ee7de3bf2bef660ff891f0d0969b05 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -41,7 +42,7 @@ static const alt_t altitude_table[] AO_CONST_ATTRIB = {
 alt_t
 ao_pa_to_altitude(pres_t pa)
 {
-       int16_t o;
+       uint16_t o;
        int16_t part;
        alt_t low, high;
 
@@ -49,12 +50,12 @@ ao_pa_to_altitude(pres_t pa)
                pa = 0;
        if (pa > 120000L)
                pa = 120000L;
-       o = pa >> ALT_SHIFT;
+       o = (uint16_t) (pa >> ALT_SHIFT);
        part = pa & ALT_MASK;
 
        low = (alt_t) FETCH_ALT(o) * (ALT_SCALE - part);
-       high = (alt_t) FETCH_ALT(o+1) * part + (ALT_SCALE >> 1);
-       return (low + high) >> ALT_SHIFT;
+       high = (alt_t) FETCH_ALT(o+1) * part;
+       return (low + high + (ALT_SCALE >> 1)) >> ALT_SHIFT;
 }
 
 #ifdef AO_CONVERT_TEST