Changeset 7e5f213decff36c62421b1b3d02d02b3037c79a2
- Timestamp:
- 08/15/07 03:28:42 (5 years ago)
- git-author:
- L. Donnie Smith <donnie.smith@gatech.edu> / 2007-08-15T03:28:42Z+0000
- Parents:
- f74d95ef1b141f63caaf55d5f29bd5df1ff9cdb0
- Children:
- 3c99e2c9568a84f9e8bb60549c145d3f03d73716
- git-committer:
- dsmith <dsmith@918edb2d-ff29-0410-9de2-eb38e7f22bc7> / 2007-08-15T03:28:42Z+0000
- Files:
-
- 6 modified
-
ChangeLog (modified) (1 diff)
-
wminput/c_plugin.c (modified) (2 diffs)
-
wminput/c_plugin.h (modified) (2 diffs)
-
wminput/main.c (modified) (8 diffs)
-
wminput/py_plugin.c (modified) (3 diffs)
-
wminput/py_plugin.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
rd087284 r7e5f213 1 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 2 wminput 3 * added {c,py}_wiimote_deinit functions 4 * added daemon, quiet, and reconnect options 5 1 6 2007-07-29 L. Donnie Smith <cwiid@abstrakraft.org> 2 7 wminput -
wminput/c_plugin.c
r49e0132 r7e5f213 16 16 * 17 17 * ChangeLog: 18 * 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added c_wiimote_deinit 20 * 18 21 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * Initial ChangeLog … … 50 53 51 54 return 0; 55 } 56 57 void c_wiimote_deinit() 58 { 59 return; 52 60 } 53 61 -
wminput/c_plugin.h
r49e0132 r7e5f213 16 16 * 17 17 * ChangeLog: 18 * 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added c_wiimote_deinit 20 * 18 21 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * Initial ChangeLog … … 25 28 int c_init(void); 26 29 int c_wiimote(cwiid_wiimote_t *wiimote); 30 void c_wiimote_deinit(void); 27 31 void c_deinit(void); 28 32 int c_plugin_open(struct plugin *plugin, char *dir); -
wminput/main.c
rf74d95e r7e5f213 16 16 * 17 17 * ChangeLog: 18 * 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added daemon, quiet, and reconnect options 20 * 18 21 * 2007-07-29 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * fixed wait forever logic … … 109 112 printf("\t-v, --version\t\toutput version information and exit.\n"); 110 113 printf("\t-c, --config [file]\tChoose config file to use.\n"); 114 printf("\t-d, --daemon\t\tImplies -q, -r, and -w.\n"); 115 printf("\t-q, --quiet\t\tReduce output to errors\n"); 116 printf("\t-r, --reconnect [wait]\t\tAutomatically try reconnect after wiimote disconnect.\n"); 111 117 printf("\t-w, --wait\t\tWait indefinitely for wiimote to connect.\n"); 112 118 } … … 114 120 int main(int argc, char *argv[]) 115 121 { 116 char wait_forever = 0 ;122 char wait_forever = 0, quiet = 0, reconnect = 0, reconnect_wait = 0; 117 123 char *config_search_dirs[3], *plugin_search_dirs[3]; 118 124 char *config_filename = DEFAULT_CONFIG_FILE; … … 122 128 int c, i; 123 129 char *str_addr; 124 bdaddr_t bdaddr ;130 bdaddr_t bdaddr, current_bdaddr; 125 131 sigset_t sigset; 126 132 int signum, ret=0; … … 136 142 static struct option long_options[] = { 137 143 {"help", 0, 0, 'h'}, 144 {"version", 0, 0, 'v'}, 145 {"config", 1, 0, 'c'}, 146 {"daemon", 0, 0, 'd'}, 147 {"quiet", 0, 0, 'q'}, 148 {"reconnect", 2, 0, 'r'}, 138 149 {"wait", 0, 0, 'w'}, 139 {"config", 1, 0, 'c'},140 {"version", 0, 0, 'v'},141 150 {0, 0, 0, 0} 142 151 }; 143 152 144 c = getopt_long (argc, argv, "h wc:v", long_options, &option_index);153 c = getopt_long (argc, argv, "hvc:dqr::w", long_options, &option_index); 145 154 146 155 if (c == -1) { … … 153 162 return 0; 154 163 break; 155 case 'w':156 wait_forever = 1;157 break;158 case 'c':159 config_filename = optarg;160 break;161 164 case 'v': 162 165 printf("CWiid Version %s\n", PACKAGE_VERSION); 163 166 return 0; 167 break; 168 case 'c': 169 config_filename = optarg; 170 break; 171 case 'd': 172 wait_forever = 1; 173 quiet = 1; 174 reconnect = 1; 175 break; 176 case 'q': 177 quiet = 1; 178 break; 179 case 'r': 180 reconnect = 1; 181 if (optarg) { 182 reconnect_wait = strtol(optarg, &tmp, 10); 183 if (*tmp != '\0') { 184 wminput_err("bad reconnect wait time"); 185 return -1; 186 } 187 } 188 break; 189 case 'w': 190 wait_forever = 1; 164 191 break; 165 192 case '?': … … 231 258 } 232 259 233 /* Wiimote Connect */234 printf("Put Wiimote in discoverable mode now (press 1+2)...\n");235 if (wait_forever) {236 if (!bacmp(&bdaddr, BDADDR_ANY)) {237 if (cwiid_find_wiimote(&bdaddr, -1)) {238 wminput_err("error finding wiimote");239 conf_unload(&conf);240 return -1;241 }242 }243 /* TODO: avoid continuously calling cwiid_open */244 /* TODO: kill error messages on failed cwiid_open calls */245 while (!(wiimote = cwiid_open(&bdaddr, CWIID_FLAG_MESG_IFC)));246 }247 else {248 if ((wiimote = cwiid_open(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) {249 wminput_err("unable to connect");250 conf_unload(&conf);251 return -1;252 }253 }254 if (cwiid_set_mesg_callback(wiimote, &cwiid_callback)) {255 wminput_err("error setting callback");256 conf_unload(&conf);257 return -1;258 }259 260 if (c_wiimote(wiimote)) {261 conf_unload(&conf);262 return -1;263 }264 #ifdef HAVE_PYTHON265 if (py_wiimote(wiimote)) {266 conf_unload(&conf);267 return -1;268 }269 #endif270 271 /* init plugins */272 for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) {273 switch (conf.plugins[i].type) {274 case PLUGIN_C:275 if (c_plugin_init(&conf.plugins[i], i)) {276 wminput_err("error on %s init", conf.plugins[i].name);277 conf_unload(&conf);278 cwiid_close(wiimote);279 return -1;280 }281 break;282 #ifdef HAVE_PYTHON283 case PLUGIN_PYTHON:284 if (py_plugin_init(&conf.plugins[i], i)) {285 wminput_err("error %s init", conf.plugins[i].name);286 conf_unload(&conf);287 cwiid_close(wiimote);288 return -1;289 }290 break;291 #endif292 }293 }294 295 if (wminput_set_report_mode()) {296 conf_unload(&conf);297 cwiid_close(wiimote);298 return -1;299 }300 301 uinput_listen_data.wiimote = wiimote;302 uinput_listen_data.conf = &conf;303 if (pthread_create(&uinput_listen_thread, NULL,304 (void *(*)(void *))uinput_listen,305 &uinput_listen_data)) {306 wminput_err("error starting uinput listen thread");307 conf_unload(&conf);308 cwiid_close(wiimote);309 return -1;310 }311 312 313 printf("Ready.\n");314 315 init = 0;316 317 /* wait */318 260 sigemptyset(&sigset); 319 261 sigaddset(&sigset, SIGTERM); 320 262 sigaddset(&sigset, SIGINT); 321 263 sigaddset(&sigset, SIGUSR1); 322 sigprocmask(SIG_BLOCK, &sigset, NULL); 323 sigwait(&sigset, &signum); 324 325 printf("Exiting.\n"); 326 327 if (pthread_cancel(uinput_listen_thread)) { 328 wminput_err("Error canceling uinput listen thread"); 329 ret = -1; 330 } 331 else if (pthread_join(uinput_listen_thread, NULL)) { 332 wminput_err("Error joining uinput listen thread"); 333 ret = -1; 334 } 335 336 /* disconnect */ 337 if (cwiid_close(wiimote)) { 338 wminput_err("Error on wiimote disconnect"); 339 ret = -1; 340 } 264 265 do { 266 bacpy(¤t_bdaddr, &bdaddr); 267 268 /* Wiimote Connect */ 269 if (!quiet) { 270 printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); 271 } 272 if (wait_forever) { 273 if (!bacmp(¤t_bdaddr, BDADDR_ANY)) { 274 if (cwiid_find_wiimote(¤t_bdaddr, -1)) { 275 wminput_err("error finding wiimote"); 276 conf_unload(&conf); 277 return -1; 278 } 279 } 280 /* TODO: avoid continuously calling cwiid_open */ 281 /* TODO: kill error messages on failed cwiid_open calls */ 282 while (!(wiimote = cwiid_open(¤t_bdaddr, CWIID_FLAG_MESG_IFC))); 283 } 284 else { 285 if ((wiimote = cwiid_open(¤t_bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 286 wminput_err("unable to connect"); 287 conf_unload(&conf); 288 return -1; 289 } 290 } 291 if (cwiid_set_mesg_callback(wiimote, &cwiid_callback)) { 292 wminput_err("error setting callback"); 293 conf_unload(&conf); 294 return -1; 295 } 296 297 if (c_wiimote(wiimote)) { 298 conf_unload(&conf); 299 return -1; 300 } 301 #ifdef HAVE_PYTHON 302 if (py_wiimote(wiimote)) { 303 conf_unload(&conf); 304 return -1; 305 } 306 #endif 307 308 /* init plugins */ 309 for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) { 310 switch (conf.plugins[i].type) { 311 case PLUGIN_C: 312 if (c_plugin_init(&conf.plugins[i], i)) { 313 wminput_err("error on %s init", conf.plugins[i].name); 314 conf_unload(&conf); 315 cwiid_close(wiimote); 316 return -1; 317 } 318 break; 319 #ifdef HAVE_PYTHON 320 case PLUGIN_PYTHON: 321 if (py_plugin_init(&conf.plugins[i], i)) { 322 wminput_err("error %s init", conf.plugins[i].name); 323 conf_unload(&conf); 324 cwiid_close(wiimote); 325 return -1; 326 } 327 break; 328 #endif 329 } 330 } 331 332 if (wminput_set_report_mode()) { 333 conf_unload(&conf); 334 cwiid_close(wiimote); 335 return -1; 336 } 337 338 uinput_listen_data.wiimote = wiimote; 339 uinput_listen_data.conf = &conf; 340 if (pthread_create(&uinput_listen_thread, NULL, 341 (void *(*)(void *))uinput_listen, 342 &uinput_listen_data)) { 343 wminput_err("error starting uinput listen thread"); 344 conf_unload(&conf); 345 cwiid_close(wiimote); 346 return -1; 347 } 348 349 if (!quiet) { 350 printf("Ready.\n"); 351 } 352 353 init = 0; 354 355 /* wait */ 356 sigprocmask(SIG_BLOCK, &sigset, NULL); 357 sigwait(&sigset, &signum); 358 sigprocmask(SIG_UNBLOCK, &sigset, NULL); 359 360 if ((signum == SIGTERM) || (signum == SIGINT)) { 361 reconnect = 0; 362 } 363 364 if (pthread_cancel(uinput_listen_thread)) { 365 wminput_err("Error canceling uinput listen thread"); 366 ret = -1; 367 } 368 else if (pthread_join(uinput_listen_thread, NULL)) { 369 wminput_err("Error joining uinput listen thread"); 370 ret = -1; 371 } 372 373 c_wiimote_deinit(); 374 #ifdef HAVE_PYTHON 375 py_wiimote_deinit(); 376 #endif 377 378 /* disconnect */ 379 if (cwiid_close(wiimote)) { 380 wminput_err("Error on wiimote disconnect"); 381 ret = -1; 382 } 383 384 if (reconnect && reconnect_wait) { 385 sleep(reconnect_wait); 386 } 387 } while (reconnect); 341 388 342 389 if (conf_unload(&conf)) { … … 344 391 } 345 392 393 c_deinit(); 346 394 #ifdef HAVE_PYTHON 347 395 py_deinit(); 348 396 #endif 397 398 if (!quiet) { 399 printf("Exiting.\n"); 400 } 349 401 350 402 return ret; -
wminput/py_plugin.c
refbd885 r7e5f213 16 16 * 17 17 * ChangeLog: 18 * 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added py_wiimote_deinit 20 * 18 21 * 2007-06-28 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * supress error for nonexistent python plugins … … 90 93 int i; 91 94 92 Py_Initialize ();95 Py_InitializeEx(0); 93 96 94 97 if (!(PyCWiidModule = PyImport_ImportModule("cwiid"))) { … … 191 194 } 192 195 196 void py_wiimote_deinit() 197 { 198 Py_DECREF(PyWiimote); 199 } 200 193 201 void py_deinit(void) 194 202 { 195 Py_DECREF(PyWiimote);196 203 Py_DECREF(PyCWiidModule); 197 204 Py_DECREF(PyPath); -
wminput/py_plugin.h
r49e0132 r7e5f213 16 16 * 17 17 * ChangeLog: 18 * 2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * added py_wiimote_deinit 20 * 18 21 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * refactored to isolate plugin logic … … 28 31 int py_init(void); 29 32 int py_wiimote(cwiid_wiimote_t *wiimote); 33 void py_wiimote_deinit(void); 30 34 void py_deinit(void); 31 35 int py_plugin_open(struct plugin *plugin, char *dir);
