Changeset 49e0132d6bb68b9d14ad8878d14a5f2ed17a1a93
- Timestamp:
- 06/14/07 04:16:11 (6 years ago)
- Children:
- bd4c9bdfca9e847cf6c0bc77ce98f90785eff251
- Parents:
- a09a4eea431c232fa82b3b1a9a728c8b07345d4f
- git-author:
- L. Donnie Smith <donnie.smith@…> (06/14/07 04:16:11)
- git-committer:
- dsmith <dsmith@…> (06/14/07 04:16:11)
- Files:
-
- 9 added
- 21 modified
-
ChangeLog (modified) (1 diff)
-
Makefile.in (modified) (4 diffs)
-
common/include/app.mak (modified) (1 diff)
-
common/include/lib.mak.in (modified) (1 diff)
-
common/include/plugin.mak (modified) (1 diff)
-
configure.ac (modified) (3 diffs)
-
defs.mak.in (modified) (1 diff)
-
doc/Makefile.in (modified) (1 diff)
-
lswm/Makefile.in (modified) (1 diff)
-
lswm/lswm.c (modified) (6 diffs)
-
man/Makefile.in (modified) (1 diff)
-
python/Makefile.in (added)
-
python/Wiimote.c (added)
-
python/cwiidmodule.c (added)
-
python/setup.py (added)
-
wminput/Makefile.in (modified) (1 diff)
-
wminput/c_plugin.c (added)
-
wminput/c_plugin.h (added)
-
wminput/conf.c (modified) (7 diffs)
-
wminput/conf.h (modified) (2 diffs)
-
wminput/main.c (modified) (16 diffs)
-
wminput/plugins/acc/acc.c (modified) (8 diffs)
-
wminput/plugins/acc/acc.py (added)
-
wminput/plugins/ir_ptr/ir_ptr.c (modified) (5 diffs)
-
wminput/plugins/nunchuk_acc/nunchuk_acc.c (modified) (9 diffs)
-
wminput/py_plugin.c (added)
-
wminput/py_plugin.h (added)
-
wminput/uinput.c (modified) (1 diff)
-
wminput/util.c (modified) (2 diffs)
-
wminput/wmplugin.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
ra09a4ee r49e0132 1 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 2 python 3 * removed Wiimote_FromC function 4 * added bdaddr argument to Wiimote.init 5 * overloaded Wiimote.init to accept CObject (existing wiimote), 6 and logic to avoid closing it on dealloc 7 8 wminput 9 * refactored to isolate plugin logic 10 * now imports python plugins without changing directories 11 12 2007-06-01 Nick <nickishappy@gmail.com> 13 lswm 14 * reworked command-line options (added standard options, long options) 15 16 wminput 17 * reworked command-line options (added standard options, long options) 18 19 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 20 python 21 * added Wiimote_FromC 22 * exported Wiimote_FromC and ConvertMesgArray as CObjects 23 * added get_acc_cal 24 25 wminput 26 * added pyplugin.c, pyplugin.h 27 * changed wmplugin_exec prototype (&mesg->mesg) 28 * changed param format (pass pointers) 29 * added python plugin support (experimental) 30 31 2007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 32 configure.ac 33 * added python/Makefile and PYTHON_VERSION variable 34 35 build system 36 * added ROOTDIR (massaged DESTDIR) 37 38 python 39 * added directory 40 41 2007-05-27 Arthur Peters <amp@singingwizard.org> 42 python 43 * removed set_mesg_callback from methods table 44 1 45 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 2 46 libcwiid -
Makefile.in
r805477a r49e0132 6 6 BIN_DIRS = wmgui wminput lswm 7 7 DOC_DIRS = man doc 8 BIND_DIRS = python 9 10 SUB_DIRS = $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) $(BIND_DIRS) wmdemo 8 11 9 12 all install clean distclean uninstall: TARGET += $(MAKECMDGOALS) 10 13 11 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) 14 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) $(BIND_DIRS) 12 15 13 16 install uninstall distclean: $(DOC_DIRS) … … 17 20 ifneq ($(MAKECMDGOALS),clean) 18 21 ifneq ($(MAKECMDGOALS),distclean) 19 $(BIN_DIRS) : $(LIB_DIRS)22 $(BIN_DIRS) $(BIND_DIRS): $(LIB_DIRS) 20 23 endif 21 24 endif … … 25 28 endif 26 29 27 $( LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) wmdemo:30 $(SUB_DIRS): 28 31 $(MAKE) $(TARGET) -C $@ 29 32 … … 44 47 rm -rf $(CWIID_CONFIG_DIR) 45 48 46 .PHONY: all install clean distclean uninstall uninstall_config $(LIB_DIRS) \ 47 $(BIN_DIRS) $(DOC_DIRS) wmdemo 49 .PHONY: all install clean distclean uninstall uninstall_config $(SUB_DIRS) 48 50 49 51 .NOTPARALLEL: -
common/include/app.mak
r75581e0 r49e0132 6 6 INST_DIR ?= /usr/local/bin 7 7 8 DEST_INST_DIR = $( DESTDIR)/$(INST_DIR)8 DEST_INST_DIR = $(ROOTDIR)$(INST_DIR) 9 9 10 10 all: $(APP_NAME) -
common/include/lib.mak.in
r75581e0 r49e0132 8 8 SO_NAME = $(LINK_NAME).$(MAJOR_VER) 9 9 SHARED_LIB = $(SO_NAME).$(MINOR_VER) 10 DEST_INC_INST_DIR = $( DESTDIR)/$(INC_INST_DIR)11 DEST_LIB_INST_DIR = $( DESTDIR)/$(LIB_INST_DIR)10 DEST_INC_INST_DIR = $(ROOTDIR)$(INC_INST_DIR) 11 DEST_LIB_INST_DIR = $(ROOTDIR)$(LIB_INST_DIR) 12 12 13 13 OBJECTS = $(SOURCES:.c=.o) -
common/include/plugin.mak
r75581e0 r49e0132 8 8 CFLAGS += -fpic 9 9 10 #TODO:unify the way DESTDIR is handled11 #Currently, defs.mak adds DESTDIR to the plugin INST_DIR,10 #TODO:unify the way ROOTDIR is handled 11 #Currently, defs.mak adds ROOTDIR to the plugin INST_DIR, 12 12 #so we don't do it here 13 #DEST_INST_DIR = $( DESTDIR)/$(INST_DIR)13 #DEST_INST_DIR = $(ROOTDIR)/$(INST_DIR) 14 14 DEST_INST_DIR = $(INST_DIR) 15 15 -
configure.ac
r805477a r49e0132 1 1 # ChangeLog: 2 # 2007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 3 # * added python/Makefile 4 # * added PYTHON_VERSION variable 5 # 2 6 # 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 3 7 # * updated for libcwiid rename … … 32 36 AC_MSG_ERROR([bison not found]) 33 37 fi 38 39 PYTHON_VERSION=[`python -c 'import sys; print sys.version[:3]'`] 40 AC_SUBST(PYTHON_VERSION) 34 41 35 42 AC_CHECK_LIB([pthread], [pthread_create],, … … 105 112 [wminput/plugins/nunchuk_acc/Makefile] 106 113 [lswm/Makefile] 114 [python/Makefile] 107 115 ) 108 116 -
defs.mak.in
r2547e8f r49e0132 24 24 COMMON = @abs_top_builddir@/common 25 25 26 CWIID_CONFIG_DIR = $(DESTDIR)/@CWIID_CONFIG_DIR@ 27 CWIID_PLUGINS_DIR = $(DESTDIR)/@CWIID_PLUGINS_DIR@ 26 ifdef DESTDIR 27 ROOTDIR = $(DESTDIR:%/=%) 28 endif 29 30 CWIID_CONFIG_DIR = $(ROOTDIR)@CWIID_CONFIG_DIR@ 31 CWIID_PLUGINS_DIR = $(ROOTDIR)@CWIID_PLUGINS_DIR@ 28 32 29 33 DEBUGFLAGS = -g -
doc/Makefile.in
rd21ea37 r49e0132 5 5 docfiles = Xmodmap wminput.list 6 6 7 DEST_DOC_DIR = $( DESTDIR)/$(docdir)7 DEST_DOC_DIR = $(ROOTDIR)$(docdir) 8 8 9 9 all: -
lswm/Makefile.in
r805477a r49e0132 7 7 SOURCES = lswm.c 8 8 9 CFLAGS += -I@top_builddir@/libcwiid 9 CFLAGS += -I@top_builddir@/libcwiid -DCWIID_VERSION=\"${PACKAGE_VERSION}\" 10 10 LDFLAGS += -L@top_builddir@/libcwiid 11 11 LDLIBS += -lcwiid -
lswm/lswm.c
r805477a r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 Nick <nickishappy@gmail.com> 19 * * reworked command-line options (added standard options, long options) 20 * 18 21 * 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * updated for libcwiid rename … … 32 35 #include <bluetooth/bluetooth.h> 33 36 #include <cwiid.h> 37 #include <getopt.h> 34 38 35 #define OPTSTRING "ahlq" 36 37 #define USAGE \ 38 "%s [OPTIONS]\n" \ 39 " -a list all bluetooth devices (not just wiimotes)\n" \ 40 " -h print this help message\n" \ 41 " -l long format (device details)\n" \ 42 " -q quiet mode\n" 39 void print_usage(void) 40 { 41 printf("lswm lists availiable wiimotes\n"); 42 printf("Usage: %s [OPTIONS]...\n\n", "lswm"); 43 printf("Options:\n"); 44 printf("\t-h, --help\t\tPrints this output.\n"); 45 printf("\t-v, --version\t\toutput version information and exit.\n"); 46 printf("\t-l, --long\t\tlong format (device details).\n"); 47 printf("\t-q, --quiet\t\tquiet mode (less verbose).\n"); 48 printf("\t-a, --all\t\tlist all bluetooth devices (not just wiimotes).\n"); 49 } 43 50 44 51 int main(int argc, char *argv[]) … … 54 61 55 62 /* Parse options */ 56 while ((c = getopt(argc, argv, OPTSTRING)) != -1) { 63 while (1) { 64 int option_index = 0; 65 66 static struct option long_options[] = { 67 {"help", 0, 0, 'h'}, 68 {"all", 0, 0, 'a'}, 69 {"long", 0, 0, 'l'}, 70 {"version", 0, 0, 'v'}, 71 {"quiet", 0, 0, 'q'}, 72 {0, 0, 0, 0} 73 }; 74 75 c = getopt_long(argc, argv, "halvq", long_options, &option_index); 76 77 if (c == -1) { 78 break; 79 } 80 57 81 switch (c) { 58 82 case 'h': 59 print f(USAGE, argv[0]);83 print_usage(); 60 84 return 0; 61 85 break; … … 66 90 long_format = 1; 67 91 break; 92 case 'v': 93 printf("CWiid Version %s\n", CWIID_VERSION); 94 return 0; 95 break; 68 96 case 'q': 69 97 quiet = 1; … … 71 99 case '?': 72 100 default: 73 fprintf(stderr, "Try '%s - h' for more information\n", argv[0]);101 fprintf(stderr, "Try '%s --help' for more information\n", argv[0]); 74 102 return -1; 75 103 break; 76 104 } 77 105 } 78 79 /* TODO: check for other stuff on the command-line? */80 106 81 107 /* Handle quiet mode */ … … 112 138 return 0; 113 139 } 114 -
man/Makefile.in
rd21ea37 r49e0132 3 3 include @top_builddir@/defs.mak 4 4 5 DEST_MAN_DIR = $( DESTDIR)/$(mandir)5 DEST_MAN_DIR = $(ROOTDIR)$(mandir) 6 6 7 7 all: -
wminput/Makefile.in
r805477a r49e0132 5 5 APP_NAME = wminput 6 6 7 SOURCES = main.c conf.c uinput.c action_enum.c parser.c lexer.c util.c 7 SOURCES = main.c conf.c c_plugin.c py_plugin.c uinput.c action_enum.c parser.c \ 8 lexer.c util.c 8 9 9 10 WMINPUT_CONFIG_DIR = $(CWIID_CONFIG_DIR)/wminput 10 CFLAGS += -I@top_builddir@/libcwiid \11 CFLAGS += -I@top_builddir@/libcwiid -I/usr/include/python@PYTHON_VERSION@ \ 11 12 -DWMINPUT_CONFIG_DIR=\"$(WMINPUT_CONFIG_DIR)\" \ 12 -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" 13 LDLIBS += -lcwiid -ldl 13 -DCWIID_PLUGINS_DIR=\"$(CWIID_PLUGINS_DIR)\" \ 14 -DCWIID_VERSION=\"${PACKAGE_VERSION}\" 15 LDLIBS += -lcwiid -ldl -lpython@PYTHON_VERSION@ 14 16 LDFLAGS += -L@top_builddir@/libcwiid -rdynamic 15 17 INST_DIR = @bindir@ -
wminput/conf.c
raeed7f7 r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * refactored to isolate plugin logic 20 * 21 * 2007-06-03 L. Donnie Smith <cwiid@abstrakraft.org> 22 * * fixed plugin->data malloc bug 23 * 24 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 25 * * added python plugin support 26 * * changed param interface (pass pointers) 27 * 18 28 * 2007-04-15 <work.eric@gmail.com> 19 29 * * fixed classic controller configuration bug … … 33 43 #include <string.h> 34 44 35 #include <sys/types.h>36 #include <sys/stat.h>37 #include <dlfcn.h>38 #include <unistd.h>39 40 45 #include "conf.h" 41 46 #include "util.h" 42 47 #include "y.tab.h" 48 #include "c_plugin.h" 49 #include "py_plugin.h" 43 50 44 51 extern FILE *yyin; … … 85 92 if (conf->plugins[i].name) { 86 93 free(conf->plugins[i].name); 87 dlclose(conf->plugins[i].handle); 88 } 89 else { 90 break; 94 switch (conf->plugins[i].type) { 95 case PLUGIN_C: 96 c_plugin_close(&conf->plugins[i]); 97 break; 98 case PLUGIN_PYTHON: 99 py_plugin_close(&conf->plugins[i]); 100 break; 101 } 91 102 } 92 103 } … … 326 337 } 327 338 328 switch (plugin-> info->param_info[i].type) {329 case WMPLUGIN_PARAM_INT:330 plugin->info->param_info[i].value.Int = value;331 break;332 case WMPLUGIN_PARAM_FLOAT:333 plugin->info->param_info[i].value.Float = (float) value;334 break;335 default:336 wminput_err("unknown parameter type: %s.%s", name, param);337 return -1;339 switch (plugin->type) { 340 case PLUGIN_C: 341 if (c_plugin_param_int(plugin, i, value)) { 342 return -1; 343 } 344 break; 345 case PLUGIN_PYTHON: 346 if (py_plugin_param_int(plugin, i, value)) { 347 return -1; 348 } 338 349 break; 339 350 } … … 365 376 } 366 377 367 switch (plugin->info->param_info[i].type) { 368 case WMPLUGIN_PARAM_INT: 369 wminput_err("possible loss of precision: %s.%s (cast float to int)", 370 name, param); 371 plugin->info->param_info[i].value.Int = value; 372 break; 373 case WMPLUGIN_PARAM_FLOAT: 374 plugin->info->param_info[i].value.Float = value; 375 break; 376 default: 377 wminput_err("unknown parameter type: %s.%s", name, param); 378 return -1; 378 switch (plugin->type) { 379 case PLUGIN_C: 380 if (c_plugin_param_float(plugin, i, value)) { 381 return -1; 382 } 383 break; 384 case PLUGIN_PYTHON: 385 if (py_plugin_param_float(plugin, i, value)) { 386 return -1; 387 } 379 388 break; 380 389 } … … 556 565 } 557 566 558 #define PLUGIN_PATHNAME_LEN 128559 567 struct plugin *get_plugin(struct conf *conf, const char *name) 560 568 { 561 569 int i; 562 char p athname[PLUGIN_PATHNAME_LEN];570 char plugin_found = 0; 563 571 struct plugin *plugin; 564 struct stat buf;565 wmplugin_info_t *info;566 572 567 573 for (i=0; i < CONF_MAX_PLUGINS; i++) { … … 578 584 return NULL; 579 585 } 580 else { 581 plugin = &conf->plugins[i]; 582 plugin->name = (char *)name; 583 584 for (i=0; conf->plugin_search_dirs[i]; i++) { 585 snprintf(pathname, PLUGIN_PATHNAME_LEN, "%s/%s.so", 586 conf->plugin_search_dirs[i], name); 587 if (!stat(pathname, &buf)) { 588 if (!(plugin->handle = dlopen(pathname, RTLD_NOW))) { 589 wminput_err(dlerror()); 590 } 591 break; 592 } 593 } 594 595 if (!plugin->handle) { 596 wminput_err("plugin not found: %s", name); 597 free(plugin->name); 598 plugin->name = NULL; 599 return NULL; 600 } 601 else if ((info = dlsym(plugin->handle, "wmplugin_info")) == 602 NULL) { 603 wminput_err("Unable to load plugin info function: %s", dlerror()); 604 free(plugin->name); 605 plugin->name = NULL; 606 dlclose(plugin->handle); 607 return NULL; 608 } 609 else if ((plugin->info = (*info)()) == NULL) { 610 wminput_err("Invalid plugin info from %s", plugin->name); 611 free(plugin->name); 612 plugin->name = NULL; 613 dlclose(plugin->handle); 614 return NULL; 615 } 616 else if ((plugin->init = dlsym(plugin->handle, "wmplugin_init")) == 617 NULL) { 618 wminput_err("Unable to load plugin init function: %s", dlerror()); 619 free(plugin->name); 620 plugin->name = NULL; 621 dlclose(plugin->handle); 622 return NULL; 623 } 624 else if ((plugin->exec = dlsym(plugin->handle, "wmplugin_exec")) == 625 NULL) { 626 wminput_err("Unable to load plugin exec function: %s", dlerror()); 627 free(plugin->name); 628 plugin->name = NULL; 629 dlclose(plugin->handle); 630 return NULL; 631 } 586 587 plugin = &conf->plugins[i]; 588 plugin->name = (char *)name; 589 590 for (i=0; conf->plugin_search_dirs[i]; i++) { 591 if (!c_plugin_open(plugin, conf->plugin_search_dirs[i])) { 592 plugin_found = 1; 593 break; 594 } 595 if (!py_plugin_open(plugin, conf->plugin_search_dirs[i])) { 596 plugin_found = 1; 597 break; 598 } 599 } 600 601 if (!plugin_found) { 602 wminput_err("plugin not found: %s", name); 603 free(plugin->name); 604 plugin->name = NULL; 605 return NULL; 632 606 } 633 607 634 608 return plugin; 635 609 } 636 -
wminput/conf.h
r805477a r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * refactored to isolate plugin logic 20 * 21 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 22 * * added python plugin support 23 * 18 24 * 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 19 25 * * updated for libcwiid rename … … 133 139 }; 134 140 141 enum plugin_type { 142 PLUGIN_C, 143 PLUGIN_PYTHON 144 }; 145 135 146 struct plugin { 136 147 char *name; 148 enum plugin_type type; 149 uint8_t rpt_mode_flags; 137 150 struct wmplugin_info *info; 138 void *handle; 139 wmplugin_init_t *init; 140 wmplugin_exec_t *exec; 141 uint8_t rpt_mode_flags; 151 struct wmplugin_data *data; 142 152 uint16_t prev_buttons; 143 153 struct btn_map bmap[WMPLUGIN_MAX_BUTTON_COUNT]; 144 154 struct axis_map amap[WMPLUGIN_MAX_AXIS_COUNT]; 155 void *p; 145 156 }; 146 157 -
wminput/main.c
ra09a4ee r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * refactored to isolate plugin logic 20 * 21 * 2007-06-01 Nick <nickishappy@gmail.com> 22 * * reworked command-line options (added standard options, long options) 23 * 24 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 25 * * added python plugin support 26 * * pass mesg instead of &mesg to wmplugin_exec 27 * 18 28 * 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 19 29 * * changed cwiid_{connect,disconnect,command} to … … 40 50 #include <stdio.h> 41 51 #include <stdlib.h> 52 #include <getopt.h> 42 53 43 54 #include <pthread.h> … … 51 62 #include "util.h" 52 63 #include "wmplugin.h" 64 #include "c_plugin.h" 65 #include "py_plugin.h" 53 66 54 67 struct conf conf; 55 56 /* GetOpt */57 #define OPTSTRING "hwc:"58 extern char *optarg;59 extern int optind, opterr, optopt;60 68 61 69 /* Prototypes */ … … 73 81 #define DEFAULT_CONFIG_FILE "default" 74 82 75 #define USAGE "usage:%s [-h] [-w] [-c config] [bdaddr]\n"76 77 83 #define HOME_DIR_LEN 128 84 85 void print_usage(void) 86 { 87 printf("wminput is a program that allows you to use a wiimote as a standard input device\n"); 88 printf("Usage: %s [OPTIONS]...\n\n", "wminput"); 89 printf("Options:\n"); 90 printf("\t-h, --help\t\tPrints this output.\n"); 91 printf("\t-v, --version\t\toutput version information and exit.\n"); 92 printf("\t-c, --config [file]\tChoose config file to use.\n"); 93 printf("\t-w, --wait\t\tWait indefinitely for wiimote to connect.\n"); 94 } 95 78 96 int main(int argc, char *argv[]) 79 97 { … … 95 113 96 114 /* Parse Options */ 97 while ((c = getopt(argc, argv, OPTSTRING)) != -1) { 115 while (1) { 116 int option_index = 0; 117 118 static struct option long_options[] = { 119 {"help", 0, 0, 'h'}, 120 {"wait", 0, 0, 'w'}, 121 {"config", 1, 0, 'c'}, 122 {"version", 0, 0, 'v'}, 123 {0, 0, 0, 0} 124 }; 125 126 c = getopt_long (argc, argv, "hwc:v", long_options, &option_index); 127 128 if (c == -1) { 129 break; 130 } 131 98 132 switch (c) { 99 133 case 'h': 100 print f(USAGE, argv[0]);134 print_usage(); 101 135 return 0; 102 136 break; … … 107 141 config_filename = optarg; 108 142 break; 143 case 'v': 144 printf("CWiid Version %s\n", CWIID_VERSION); 145 return 0; 146 break; 109 147 case '?': 148 printf("Try `wminput --help` for more information\n"); 149 return 1; 150 break; 110 151 default: 111 152 return -1; … … 114 155 } 115 156 157 if (c_init()) { 158 return -1; 159 } 160 if (py_init()) { 161 return -1; 162 } 163 116 164 /* Load Config */ 165 /* Setup search directory arrays */ 117 166 if ((tmp = getenv("HOME")) == NULL) { 118 167 wminput_err("unable to find home directory"); … … 136 185 } 137 186 138 /* BDADDR */ 187 /* Determine BDADDR */ 188 /* priority: command-line option, environment variable, BDADDR_ANY */ 139 189 if (optind < argc) { 140 190 if (str2ba(argv[optind], &bdaddr)) { … … 145 195 if (optind < argc) { 146 196 wminput_err("invalid command-line"); 147 print f(USAGE, argv[0]);197 print_usage(); 148 198 conf_unload(&conf); 149 199 return -1; … … 160 210 } 161 211 162 /* Wiimote connect */ 212 /* TODO: fix wait_forever logic - currently assumes bdaddr is unspecified */ 213 /* Wiimote Connect */ 163 214 printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); 164 215 if (wait_forever) { … … 180 231 } 181 232 233 if (c_wiimote(wiimote)) { 234 conf_unload(&conf); 235 return -1; 236 } 237 if (py_wiimote(wiimote)) { 238 conf_unload(&conf); 239 return -1; 240 } 241 182 242 /* init plugins */ 183 243 for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) { 184 if ((*conf.plugins[i].init)(i, wiimote)) { 185 wminput_err("error on %s init", conf.plugins[i].name); 186 conf_unload(&conf); 187 cwiid_close(wiimote); 188 return -1; 244 switch (conf.plugins[i].type) { 245 case PLUGIN_C: 246 if (c_plugin_init(&conf.plugins[i], i)) { 247 wminput_err("error on %s init", conf.plugins[i].name); 248 conf_unload(&conf); 249 cwiid_close(wiimote); 250 return -1; 251 } 252 break; 253 case PLUGIN_PYTHON: 254 if (py_plugin_init(&conf.plugins[i], i)) { 255 wminput_err("error %s init", conf.plugins[i].name); 256 conf_unload(&conf); 257 cwiid_close(wiimote); 258 return -1; 259 } 260 break; 189 261 } 190 262 } … … 240 312 } 241 313 314 py_deinit(); 315 242 316 return ret; 243 317 } 244 318 245 int wmplugin_set_report_mode(int id, uint8_t flags) 319 int wminput_set_report_mode() 320 { 321 unsigned char rpt_mode_flags; 322 int i; 323 324 rpt_mode_flags = conf.rpt_mode_flags; 325 326 for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) { 327 rpt_mode_flags |= conf.plugins[i].rpt_mode_flags; 328 } 329 330 if (cwiid_set_rpt_mode(wiimote, rpt_mode_flags)) { 331 wminput_err("error setting report mode"); 332 return -1; 333 } 334 335 return 0; 336 } 337 338 int wmplugin_set_rpt_mode(int id, uint8_t flags) 246 339 { 247 340 conf.plugins[id].rpt_mode_flags = flags; … … 249 342 if (!init) { 250 343 wminput_set_report_mode(); 251 }252 253 return 0;254 }255 256 int wminput_set_report_mode()257 {258 unsigned char rpt_mode_flags;259 int i;260 261 rpt_mode_flags = conf.rpt_mode_flags;262 263 for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) {264 rpt_mode_flags |= conf.plugins[i].rpt_mode_flags;265 }266 267 if (cwiid_set_rpt_mode(wiimote, rpt_mode_flags)) {268 wminput_err("error setting report mode");269 return -1;270 344 } 271 345 … … 520 594 union cwiid_mesg mesg[]) 521 595 { 522 union cwiid_mesg *plugin_mesg[CWIID_MAX_MESG_COUNT];596 static union cwiid_mesg plugin_mesg[CWIID_MAX_MESG_COUNT]; 523 597 int plugin_mesg_count = 0; 524 598 int i; 525 599 uint8_t flag; 526 struct wmplugin_data *data;527 600 uint16_t pressed, released; 528 601 __s32 axis_value; … … 552 625 } 553 626 if (plugin->rpt_mode_flags & flag) { 554 plugin_mesg[plugin_mesg_count++] = &mesg[i]; 627 /* TODO: copy correct (smaller) message size */ 628 memcpy(&plugin_mesg[plugin_mesg_count++], &mesg[i], sizeof mesg[i]); 555 629 } 556 630 } 557 631 558 632 if (plugin_mesg_count > 0) { 559 if (!(data = (*plugin->exec)(plugin_mesg_count, plugin_mesg))) { 560 return; 633 switch (plugin->type) { 634 case PLUGIN_C: 635 if (c_plugin_exec(plugin, plugin_mesg_count, plugin_mesg)) { 636 return; 637 } 638 break; 639 case PLUGIN_PYTHON: 640 if (py_plugin_exec(plugin, plugin_mesg_count, plugin_mesg)) { 641 return; 642 } 643 break; 561 644 } 562 645 563 646 /* Plugin Button/Key Events */ 564 pressed = data->buttons & ~plugin->prev_buttons;565 released = ~ data->buttons & plugin->prev_buttons;647 pressed = plugin->data->buttons & ~plugin->prev_buttons; 648 released = ~plugin->data->buttons & plugin->prev_buttons; 566 649 for (i=0; i < plugin->info->button_count; i++) { 567 650 if (plugin->bmap[i].active) { … … 574 657 } 575 658 } 576 plugin->prev_buttons = data->buttons;659 plugin->prev_buttons = plugin->data->buttons; 577 660 578 661 /* Plugin Axis Events */ 579 662 for (i=0; i < plugin->info->axis_count; i++) { 580 if (plugin->amap[i].active && data->axes && data->axes[i].valid) { 581 axis_value = data->axes[i].value; 663 if (plugin->amap[i].active && plugin->data->axes && 664 plugin->data->axes[i].valid) { 665 axis_value = plugin->data->axes[i].value; 582 666 if (plugin->amap[i].flags & CONF_INVERT) { 583 667 axis_value = plugin->info->axis_info[i].max + -
wminput/plugins/acc/acc.c
r8fa1f11 r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * updated for wmplugin_exec prototype change (&mesg->mesg) 20 * * updated for param interface change (pass pointers) 21 * 18 22 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * use cwiid_get_acc_cal to get acc calibration values … … 58 62 wmplugin_exec_t wmplugin_exec; 59 63 static void process_acc(struct cwiid_acc_mesg *mesg); 64 65 static float Roll_Scale = 1.0; 66 static float Pitch_Scale = 1.0; 67 static float X_Scale = 1.0; 68 static float Y_Scale = 1.0; 60 69 61 70 struct wmplugin_info *wmplugin_info() { … … 90 99 info.param_info[0].name = "Roll_Scale"; 91 100 info.param_info[0].type = WMPLUGIN_PARAM_FLOAT; 92 info.param_info[0]. value.Float = 1.0;101 info.param_info[0].ptr = &Roll_Scale; 93 102 info.param_info[1].name = "Pitch_Scale"; 94 103 info.param_info[1].type = WMPLUGIN_PARAM_FLOAT; 95 info.param_info[1]. value.Float = 1.0;104 info.param_info[1].ptr = &Pitch_Scale; 96 105 info.param_info[2].name = "X_Scale"; 97 106 info.param_info[2].type = WMPLUGIN_PARAM_FLOAT; 98 info.param_info[2]. value.Float = 1.0;107 info.param_info[2].ptr = &X_Scale; 99 108 info.param_info[3].name = "Y_Scale"; 100 109 info.param_info[3].type = WMPLUGIN_PARAM_FLOAT; 101 info.param_info[3]. value.Float = 1.0;110 info.param_info[3].ptr = &Y_Scale; 102 111 info_init = 1; 103 112 } … … 112 121 data.axes[0].valid = 1; 113 122 data.axes[1].valid = 1; 114 if (wmplugin_set_r eport_mode(id, CWIID_RPT_ACC)) {123 if (wmplugin_set_rpt_mode(id, CWIID_RPT_ACC)) { 115 124 return -1; 116 125 } … … 124 133 } 125 134 126 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg *mesg[])135 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) 127 136 { 128 137 int i; … … 130 139 131 140 for (i=0; i < mesg_count; i++) { 132 switch (mesg[i] ->type) {141 switch (mesg[i].type) { 133 142 case CWIID_MESG_ACC: 134 process_acc(&mesg[i] ->acc_mesg);143 process_acc(&mesg[i].acc_mesg); 135 144 ret = &data; 136 145 break; … … 170 179 pitch = atan(a_y/a_z*cos(roll)); 171 180 172 data.axes[0].value = roll * 1000 * info.param_info[0].value.Float;173 data.axes[1].value = pitch * 1000 * info.param_info[1].value.Float;181 data.axes[0].value = roll * 1000 * Roll_Scale; 182 data.axes[1].value = pitch * 1000 * Pitch_Scale; 174 183 175 184 if ((a > 0.85) && (a < 1.15)) { 176 185 if ((fabs(roll)*(180/PI) > 10) && (fabs(pitch)*(180/PI) < 80)) { 177 186 data.axes[2].valid = 1; 178 data.axes[2].value = roll * 5 * info.param_info[2].value.Float;187 data.axes[2].value = roll * 5 * X_Scale; 179 188 } 180 189 else { … … 183 192 if (fabs(pitch)*(180/PI) > 10) { 184 193 data.axes[3].valid = 1; 185 data.axes[3].value = pitch * 10 * info.param_info[3].value.Float;194 data.axes[3].value = pitch * 10 * Y_Scale; 186 195 } 187 196 else { -
wminput/plugins/ir_ptr/ir_ptr.c
ra09a4ee r49e0132 1 /* Copyright (C) 2007 L. Donnie Smith < wiimote@abstrakraft.org>1 /* Copyright (C) 2007 L. Donnie Smith <cwiidabstrakraft.org> 2 2 * 3 3 * This program is free software; you can redistribute it and/or modify … … 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * updated for wmplugin_exec prototype change (&mesg->mesg) 20 * 18 21 * 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * changed cwiid_{connect,disconnect,command} to … … 92 95 data.buttons = 0; 93 96 94 if (wmplugin_set_r eport_mode(id, CWIID_RPT_IR)) {97 if (wmplugin_set_rpt_mode(id, CWIID_RPT_IR)) { 95 98 return -1; 96 99 } … … 99 102 } 100 103 101 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg *mesg[])104 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) 102 105 { 103 106 int i; … … 108 111 ir_mesg = NULL; 109 112 for (i=0; i < mesg_count; i++) { 110 if (mesg[i] ->type == CWIID_MESG_IR) {111 ir_mesg = &mesg[i] ->ir_mesg;113 if (mesg[i].type == CWIID_MESG_IR) { 114 ir_mesg = &mesg[i].ir_mesg; 112 115 } 113 116 } -
wminput/plugins/nunchuk_acc/nunchuk_acc.c
r8fa1f11 r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * updated for wmplugin_exec prototype change (&mesg->mesg) 20 * * updated for param interface change (pass pointers) 21 * 18 22 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * use cwiid_get_acc_cal to get acc calibration values … … 56 60 wmplugin_init_t wmplugin_init; 57 61 wmplugin_exec_t wmplugin_exec; 58 59 62 static void process_nunchuk(struct cwiid_nunchuk_mesg *mesg); 63 64 static float Roll_Scale = 1.0; 65 static float Pitch_Scale = 1.0; 66 static float X_Scale = 1.0; 67 static float Y_Scale = 1.0; 60 68 61 69 struct wmplugin_info *wmplugin_info() { … … 90 98 info.param_info[0].name = "Roll_Scale"; 91 99 info.param_info[0].type = WMPLUGIN_PARAM_FLOAT; 92 info.param_info[0]. value.Float = 1.0;100 info.param_info[0].ptr = &Roll_Scale; 93 101 info.param_info[1].name = "Pitch_Scale"; 94 102 info.param_info[1].type = WMPLUGIN_PARAM_FLOAT; 95 info.param_info[1]. value.Float = 1.0;103 info.param_info[1].ptr = &Pitch_Scale; 96 104 info.param_info[2].name = "X_Scale"; 97 105 info.param_info[2].type = WMPLUGIN_PARAM_FLOAT; 98 info.param_info[2]. value.Float = 1.0;106 info.param_info[2].ptr = &X_Scale; 99 107 info.param_info[3].name = "Y_Scale"; 100 108 info.param_info[3].type = WMPLUGIN_PARAM_FLOAT; 101 info.param_info[3]. value.Float = 1.0;109 info.param_info[3].ptr = &Y_Scale; 102 110 info_init = 1; 103 111 } … … 112 120 data.axes[0].valid = 1; 113 121 data.axes[1].valid = 1; 114 if (wmplugin_set_report_mode(id, 115 CWIID_RPT_STATUS | CWIID_RPT_NUNCHUK)) { 122 if (wmplugin_set_rpt_mode(id, CWIID_RPT_STATUS | CWIID_RPT_NUNCHUK)) { 116 123 return -1; 117 124 } … … 120 127 } 121 128 122 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg *mesg[])129 struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) 123 130 { 124 131 int i; … … 127 134 128 135 for (i=0; i < mesg_count; i++) { 129 switch (mesg[i] ->type) {136 switch (mesg[i].type) { 130 137 case CWIID_MESG_STATUS: 131 if ((mesg[i] ->status_mesg.ext_type == CWIID_EXT_NUNCHUK) &&138 if ((mesg[i].status_mesg.ext_type == CWIID_EXT_NUNCHUK) && 132 139 (ext_type != CWIID_EXT_NUNCHUK)) { 133 140 if (cwiid_get_acc_cal(wiimote, CWIID_EXT_NUNCHUK, &acc_cal)) { … … 135 142 } 136 143 } 137 ext_type = mesg[i] ->status_mesg.ext_type;144 ext_type = mesg[i].status_mesg.ext_type; 138 145 break; 139 146 case CWIID_MESG_NUNCHUK: 140 process_nunchuk(&mesg[i] ->nunchuk_mesg);147 process_nunchuk(&mesg[i].nunchuk_mesg); 141 148 ret = &data; 142 149 break; … … 176 183 pitch = atan(a_y/a_z*cos(roll)); 177 184 178 data.axes[0].value = roll * 1000 * info.param_info[0].value.Float;179 data.axes[1].value = pitch * 1000 * info.param_info[1].value.Float;185 data.axes[0].value = roll * 1000 * Roll_Scale; 186 data.axes[1].value = pitch * 1000 * Pitch_Scale; 180 187 181 188 if ((a > 0.85) && (a < 1.15)) { 182 189 if ((fabs(roll)*(180/PI) > 10) && (fabs(pitch)*(180/PI) < 80)) { 183 190 data.axes[2].valid = 1; 184 data.axes[2].value = roll * 5 * info.param_info[2].value.Float;191 data.axes[2].value = roll * 5 * X_Scale; 185 192 } 186 193 else { … … 189 196 if (fabs(pitch)*(180/PI) > 10) { 190 197 data.axes[3].valid = 1; 191 data.axes[3].value = pitch * 10 * info.param_info[3].value.Float;198 data.axes[3].value = pitch * 10 * Y_Scale; 192 199 } 193 200 else { -
wminput/uinput.c
ra09a4ee r49e0132 291 291 } while (-1); 292 292 } 293 -
wminput/util.c
re39b37a r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * refactored to isolate plugin logic 20 * 18 21 * 2007-03-04 L. Donnie Smith <cwiid@abstrakraft.org> 19 22 * * Initial ChangeLog … … 34 37 va_end(ap); 35 38 } 36 37 void wmplugin_err(int id, char *str, ...)38 {39 va_list ap;40 41 va_start(ap, str);42 vfprintf(stderr, str, ap);43 fprintf(stderr, "\n");44 va_end(ap);45 }46 -
wminput/wmplugin.h
r805477a r49e0132 16 16 * 17 17 * ChangeLog: 18 * 2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org> 19 * * changed wmplugin_exec prototype (pass mesg instead of &mesg) 20 * * changed param interface (pass pointers) 21 * 18 22 * 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * updated for libcwiid rename … … 59 63 }; 60 64 61 union wmplugin_param_value {62 int Int;63 float Float;64 };65 66 65 struct wmplugin_param_info { 67 66 char *name; 68 67 enum wmplugin_param_type type; 69 union wmplugin_param_value value;68 void *ptr; 70 69 }; 71 70 … … 91 90 typedef struct wmplugin_info *wmplugin_info_t(void); 92 91 typedef int wmplugin_init_t(int, cwiid_wiimote_t *); 93 typedef struct wmplugin_data *wmplugin_exec_t(int, union cwiid_mesg *[]);92 typedef struct wmplugin_data *wmplugin_exec_t(int, union cwiid_mesg []); 94 93 95 int wmplugin_set_r eport_mode(int id, uint8_t flags);94 int wmplugin_set_rpt_mode(int id, uint8_t rpt_mode); 96 95 void wmplugin_err(int id, char *str, ...); 97 96 98 97 #endif 99
