altosui: Add config and pyro tabs to graph widget
[fw/altos] / src / kernel / ao_convert_pa_test.c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include <stdint.h>
20 #define AO_CONVERT_TEST
21 #define AO_TICK_TYPE uint32_t
22 typedef int32_t alt_t;
23 typedef int32_t pres_t;
24 #include "ao_host.h"
25 #include "ao_convert_pa.c"
26
27 #define STEP_P  1
28 #define STEP_A  1
29
30 static inline int i_abs(int i) { return i < 0 ? -i : i; }
31
32 int
33 main (int argc, char **argv)
34 {
35         int     i;
36         int32_t p_to_a, p_to_a_to_p;
37         int32_t a_to_p, a_to_p_to_a;
38         int max_p_error = 0, max_p_error_p = -1;
39         int max_a_error = 0, max_a_error_a = -1;
40         int p_error;
41         int a_error;
42         int ret = 0;
43
44         for (i = 0; i < 120000 + STEP_P; i += STEP_P) {
45                 if (i > 120000)
46                         i = 120000;
47                 p_to_a = ao_pa_to_altitude(i);
48                 p_to_a_to_p = ao_altitude_to_pa(p_to_a);
49                 p_error = i_abs(p_to_a_to_p - i);
50                 if (p_error > max_p_error) {
51                         max_p_error = p_error;
52                         max_p_error_p = i;
53                 }
54 //              printf ("pa %d alt %d pa %d\n",
55 //                      i, p_to_a, p_to_a_to_p);
56         }
57         for (i = -1450; i < 40000 + STEP_A; i += STEP_A) {
58                 a_to_p = ao_altitude_to_pa(i);
59                 a_to_p_to_a = ao_pa_to_altitude(a_to_p);
60                 a_error = i_abs(a_to_p_to_a - i);
61                 if (a_error > max_a_error) {
62                         max_a_error = a_error;
63                         max_a_error_a = i;
64                 }
65 //              printf ("alt %d pa %d alt %d\n",
66 //                      i, a_to_p, a_to_p_to_a);
67         }
68         if (max_p_error > 2) {
69                 printf ("max p error %d at %d\n", max_p_error,
70                         max_p_error_p);
71                 ret++;
72         }
73         if (max_a_error > 1) {
74                 printf ("max a error %d at %d\n", max_a_error,
75                         max_a_error_a);
76                 ret++;
77         }
78         return ret;
79 }