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