Rev 484 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 484 | Rev 485 | ||
---|---|---|---|
1 | #include "config.h" |
1 | #include "config.h" |
2 | 2 | ||
3 | 3 | ||
4 | 4 | ||
5 | char *input_evdev_name; |
5 | char *input_evdev_name; |
6 | char *input_joydev_name; |
6 | char *input_joydev_name; |
7 | 7 | ||
8 | char *bluetooth_mac; |
8 | char *bluetooth_mac; |
9 | char *mk_tty; |
9 | char *mk_tty; |
10 | 10 | ||
11 | 11 | ||
12 | char *evdev_path; |
12 | char *evdev_path; |
13 | 13 | ||
14 | int mk_socket_port=0; |
14 | int mk_socket_port=0; |
15 | int loop_delay=0; |
15 | int loop_delay=0; |
16 | 16 | ||
17 | double nick_mul=0.3f; |
17 | double nick_mul=0.3f; |
18 | double roll_mul=0.3f; |
18 | double roll_mul=0.3f; |
19 | double gier_mul=0.3f; |
19 | double gier_mul=0.3f; |
20 | double gas_mul=0.3f; |
20 | double gas_mul=0.3f; |
21 | 21 | ||
22 | 22 | ||
23 | double nick_add=0.3f; |
23 | double nick_add=0.3f; |
24 | double roll_add=0.3f; |
24 | double roll_add=0.3f; |
25 | double gier_add=0.3f; |
25 | double gier_add=0.3f; |
26 | double gas_add=0.3f; |
26 | double gas_add=0.3f; |
27 | 27 | ||
28 | int rel_axis_nick; |
28 | int rel_axis_nick; |
29 | int rel_axis_roll; |
29 | int rel_axis_roll; |
30 | int rel_axis_gier; |
30 | int rel_axis_gier; |
31 | int rel_axis_gas; |
31 | int rel_axis_gas; |
32 | 32 | ||
33 | cfg_bool_t exit_after_init = cfg_false; |
33 | cfg_bool_t exit_after_init = cfg_false; |
34 | 34 | ||
35 | 35 | ||
36 | int input_count=0; |
36 | int input_count=0; |
- | 37 | ||
- | 38 | cfg_t *cfg; |
|
37 | 39 | ||
38 | int parse_config(char* fname) |
40 | int parse_config(char* fname) |
39 | { |
41 | { |
40 | - | ||
- | 42 | ||
41 | 43 | // section for inputs |
|
42 | static cfg_opt_t input_opts[] = { |
44 | static cfg_opt_t input_opts[] = { |
43 | CFG_STR("name", 0, CFGF_NONE), |
45 | CFG_STR("name", 0, CFGF_NONE), |
44 | 46 | ||
45 | CFG_FLOAT("nick_mul", 1.0,CFGF_NONE), |
47 | CFG_FLOAT("nick_mul", 1.0,CFGF_NONE), |
46 | CFG_FLOAT("roll_mul", 1.0,CFGF_NONE), |
48 | CFG_FLOAT("roll_mul", 1.0,CFGF_NONE), |
47 | CFG_FLOAT("gier_mul", 1.0,CFGF_NONE), |
49 | CFG_FLOAT("gier_mul", 1.0,CFGF_NONE), |
48 | CFG_FLOAT("gas_mul", 1.0,CFGF_NONE), |
50 | CFG_FLOAT("gas_mul", 1.0,CFGF_NONE), |
49 | 51 | ||
50 | CFG_FLOAT("nick_add", 0,CFGF_NONE), |
52 | CFG_FLOAT("nick_add", 0,CFGF_NONE), |
51 | CFG_FLOAT("roll_add", 0,CFGF_NONE), |
53 | CFG_FLOAT("roll_add", 0,CFGF_NONE), |
52 | CFG_FLOAT("gier_add", 0,CFGF_NONE), |
54 | CFG_FLOAT("gier_add", 0,CFGF_NONE), |
53 | CFG_FLOAT("gas_add", 0,CFGF_NONE), |
55 | CFG_FLOAT("gas_add", 0,CFGF_NONE), |
54 | 56 | ||
55 | CFG_INT("rel_axis_nick", -1,CFGF_NONE), |
57 | CFG_INT("rel_axis_nick", -1,CFGF_NONE), |
56 | CFG_INT("rel_axis_roll", -1,CFGF_NONE), |
58 | CFG_INT("rel_axis_roll", -1,CFGF_NONE), |
57 | CFG_INT("rel_axis_gier", -1,CFGF_NONE), |
59 | CFG_INT("rel_axis_gier", -1,CFGF_NONE), |
58 | CFG_INT("rel_axis_gas", -1,CFGF_NONE), |
60 | CFG_INT("rel_axis_gas", -1,CFGF_NONE), |
59 | 61 | ||
60 | CFG_INT("nick_up_btn", -1,CFGF_NONE), |
62 | CFG_INT("nick_up_btn", -1,CFGF_NONE), |
61 | CFG_INT("nick_down_btn", -1,CFGF_NONE), |
63 | CFG_INT("nick_down_btn", -1,CFGF_NONE), |
62 | CFG_INT("roll_left_btn", -1,CFGF_NONE), |
64 | CFG_INT("roll_left_btn", -1,CFGF_NONE), |
63 | CFG_INT("roll_right_btn", -1,CFGF_NONE), |
65 | CFG_INT("roll_right_btn", -1,CFGF_NONE), |
64 | - | ||
65 | - | ||
66 | - | ||
67 | - | ||
68 | - | ||
69 | 66 | ||
70 | CFG_END() |
67 | CFG_END() |
71 | }; |
68 | }; |
72 | 69 | ||
73 | cfg_opt_t opts[] = { |
70 | cfg_opt_t opts[] = { |
74 | CFG_SEC("input", input_opts, CFGF_MULTI | CFGF_TITLE), |
71 | CFG_SEC("input", input_opts, CFGF_MULTI | CFGF_TITLE), |
75 | CFG_SIMPLE_STR("bluetooth_mac", &bluetooth_mac), |
72 | CFG_SIMPLE_STR("bluetooth_mac", &bluetooth_mac), |
76 | 73 | ||
77 | CFG_SIMPLE_STR("mk_tty", &mk_tty), |
74 | CFG_SIMPLE_STR("mk_tty", &mk_tty), |
78 | CFG_SIMPLE_STR("evdev_path", &evdev_path), |
75 | CFG_SIMPLE_STR("evdev_path", &evdev_path), |
79 | 76 | ||
80 | CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init), |
77 | CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init), |
81 | CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
78 | CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
82 | CFG_SIMPLE_STR("input_joydev", &input_joydev_name), |
79 | CFG_SIMPLE_STR("input_joydev", &input_joydev_name), |
83 | CFG_SIMPLE_INT("loop_delay", &loop_delay), |
80 | CFG_SIMPLE_INT("loop_delay", &loop_delay), |
84 | CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port), |
81 | CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port), |
85 | 82 | ||
86 | CFG_SIMPLE_FLOAT("nick_mul", &nick_mul), |
83 | CFG_SIMPLE_FLOAT("nick_mul", &nick_mul), |
87 | CFG_SIMPLE_FLOAT("roll_mul", &roll_mul), |
84 | CFG_SIMPLE_FLOAT("roll_mul", &roll_mul), |
88 | CFG_SIMPLE_FLOAT("gier_mul", &gier_mul), |
85 | CFG_SIMPLE_FLOAT("gier_mul", &gier_mul), |
89 | CFG_SIMPLE_FLOAT("gas_mul", &gas_mul), |
86 | CFG_SIMPLE_FLOAT("gas_mul", &gas_mul), |
90 | 87 | ||
91 | CFG_SIMPLE_FLOAT("nick_add", &nick_add), |
88 | CFG_SIMPLE_FLOAT("nick_add", &nick_add), |
92 | CFG_SIMPLE_FLOAT("roll_add", &roll_add), |
89 | CFG_SIMPLE_FLOAT("roll_add", &roll_add), |
93 | CFG_SIMPLE_FLOAT("gier_add", &gier_add), |
90 | CFG_SIMPLE_FLOAT("gier_add", &gier_add), |
94 | CFG_SIMPLE_FLOAT("gas_add", &gas_add), |
91 | CFG_SIMPLE_FLOAT("gas_add", &gas_add), |
95 | 92 | ||
96 | CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick), |
93 | CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick), |
97 | CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll), |
94 | CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll), |
98 | CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier), |
95 | CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier), |
99 | CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas), |
96 | CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas), |
100 | 97 | ||
101 | CFG_END() |
98 | CFG_END() |
102 | }; |
99 | }; |
103 | - | ||
104 | cfg_t *cfg; |
- | |
105 | 100 | ||
106 | 101 | ||
107 | printf("Parsing config file %s\n",fname); |
102 | printf("Parsing config file %s\n",fname); |
108 | 103 | ||
109 | cfg = cfg_init(opts, 0); |
104 | cfg = cfg_init(opts, 0); |
110 | 105 | ||
111 | cfg_parse(cfg,fname); |
106 | cfg_parse(cfg,fname); |
- | 107 | ||
- | 108 | } |
|
- | 109 | ||
- | 110 | void parse_config_input_sections() |
|
112 | 111 | { |
|
113 | 112 | printf("parsing inputs \n"); |
|
114 | input_count=cfg_size(cfg,"input"); |
113 | input_count=cfg_size(cfg,"input"); |
115 | 114 | ||
116 | printf("%d inputs configured\n", input_count); |
115 | printf("%d inputs configured\n", input_count); |
117 | int i; |
116 | int i; |
118 | int act_input=0; |
117 | int act_input=0; |
119 | for (i=0;i<input_count;i++) |
118 | for (i=0;i<input_count;i++) |
120 | { |
119 | { |
121 | cfg_t *input_sect=cfg_getnsec(cfg,"input",i); |
120 | cfg_t *input_sect=cfg_getnsec(cfg,"input",i); |
122 | 121 | ||
123 | 122 | ||
124 | printf("processing input: %s\n",cfg_getstr( input_sect, "name")); |
123 | printf("processing input: %s\n",cfg_getstr( input_sect, "name")); |
125 | int evdev_i=0; |
124 | int evdev_i=0; |
126 | 125 | ||
127 | for (evdev_i=0;evdev_i<evdevs_count;evdev_i++) |
126 | for (evdev_i=0;evdev_i<evdevs_count;evdev_i++) |
128 | if (!strcmp(cfg_getstr( input_sect, "name"),evdevs[evdev_i].name)) |
127 | if (!strcmp(cfg_getstr( input_sect, "name"),evdevs[evdev_i].name)) |
129 | { |
128 | { |
130 | sprintf( inputs[act_input].fname,"%s",evdevs[evdev_i].fname); |
129 | sprintf( inputs[act_input].fname,"%s",evdevs[evdev_i].fname); |
131 | 130 | ||
132 | // todo check lengt |
131 | // todo check lengt |
133 | sprintf(inputs[act_input].name,"processing input: %s\n",cfg_getstr( input_sect, "name")); |
132 | sprintf(inputs[act_input].name,"processing input: %s\n",cfg_getstr( input_sect, "name")); |
134 | 133 | ||
135 | inputs[act_input].nick_mul=cfg_getfloat(input_sect,"nick_mul"); |
134 | inputs[act_input].nick_mul=cfg_getfloat(input_sect,"nick_mul"); |
136 | inputs[act_input].roll_mul=cfg_getfloat(input_sect,"roll_mul"); |
135 | inputs[act_input].roll_mul=cfg_getfloat(input_sect,"roll_mul"); |
137 | inputs[act_input].gier_mul=cfg_getfloat(input_sect,"gier_mul"); |
136 | inputs[act_input].gier_mul=cfg_getfloat(input_sect,"gier_mul"); |
138 | inputs[act_input].gas_mul=cfg_getfloat(input_sect,"gas_mul"); |
137 | inputs[act_input].gas_mul=cfg_getfloat(input_sect,"gas_mul"); |
139 | 138 | ||
140 | inputs[act_input].nick_add=cfg_getfloat(input_sect,"nick_add"); |
139 | inputs[act_input].nick_add=cfg_getfloat(input_sect,"nick_add"); |
141 | inputs[act_input].roll_add=cfg_getfloat(input_sect,"roll_add"); |
140 | inputs[act_input].roll_add=cfg_getfloat(input_sect,"roll_add"); |
142 | inputs[act_input].gier_add=cfg_getfloat(input_sect,"gier_add"); |
141 | inputs[act_input].gier_add=cfg_getfloat(input_sect,"gier_add"); |
143 | inputs[act_input].gas_add=cfg_getfloat(input_sect,"gas_add"); |
142 | inputs[act_input].gas_add=cfg_getfloat(input_sect,"gas_add"); |
144 | 143 | ||
145 | 144 | ||
146 | inputs[act_input].nick_up_btn=cfg_getint(input_sect,"nick_up_btn"); |
145 | inputs[act_input].nick_up_btn=cfg_getint(input_sect,"nick_up_btn"); |
147 | inputs[act_input].nick_down_btn=cfg_getint(input_sect,"nick_down_btn"); |
146 | inputs[act_input].nick_down_btn=cfg_getint(input_sect,"nick_down_btn"); |
148 | 147 | ||
149 | inputs[act_input].roll_left_btn=cfg_getint(input_sect,"roll_left_btn"); |
148 | inputs[act_input].roll_left_btn=cfg_getint(input_sect,"roll_left_btn"); |
150 | inputs[act_input].roll_right_btn=cfg_getint(input_sect,"roll_right_btn"); |
149 | inputs[act_input].roll_right_btn=cfg_getint(input_sect,"roll_right_btn"); |
151 | 150 | ||
152 | 151 | ||
153 | inputs[act_input].rel_axis_nick=cfg_getint(input_sect,"rel_axis_nick"); |
152 | inputs[act_input].rel_axis_nick=cfg_getint(input_sect,"rel_axis_nick"); |
154 | inputs[act_input].rel_axis_roll=cfg_getint(input_sect,"rel_axis_roll"); |
153 | inputs[act_input].rel_axis_roll=cfg_getint(input_sect,"rel_axis_roll"); |
155 | 154 | ||
156 | inputs[act_input].rel_axis_gier=cfg_getint(input_sect,"rel_axis_gier"); |
155 | inputs[act_input].rel_axis_gier=cfg_getint(input_sect,"rel_axis_gier"); |
157 | inputs[act_input].rel_axis_gas=cfg_getint(input_sect,"rel_axis_gas"); |
156 | inputs[act_input].rel_axis_gas=cfg_getint(input_sect,"rel_axis_gas"); |
158 | 157 | ||
159 | 158 | ||
160 | 159 | ||
161 | act_input++; |
160 | act_input++; |
162 | } |
161 | } |
163 | 162 | ||
164 | 163 | ||
165 | } |
164 | } |
166 | 165 | ||
167 | input_count=act_input; |
166 | input_count=act_input; |
168 | printf("%d inputs matching\n", input_count); |
167 | printf("%d inputs matching\n", input_count); |
169 | return 0; |
168 | return 0; |
170 | } |
169 | } |
171 | 170 | ||
172 | 171 | ||
173 | 172 |