Changeset 125

Show
Ignore:
Timestamp:
06/13/07 21:16:11 (2 years ago)
Author:
dsmith
Message:

merged branches/dev into trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r116 r125  
     12007-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 
     122007-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 
     192007-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 
     312007-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 
     412007-05-27 Arthur Peters <amp@singingwizard.org> 
     42        python 
     43        * removed set_mesg_callback from methods table 
     44 
    1452007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
    246        libcwiid 
  • trunk/Makefile.in

    r83 r125  
    66BIN_DIRS = wmgui wminput lswm 
    77DOC_DIRS = man doc 
     8BIND_DIRS = python 
     9 
     10SUB_DIRS = $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) $(BIND_DIRS) wmdemo 
    811 
    912all install clean distclean uninstall: TARGET += $(MAKECMDGOALS) 
    1013 
    11 all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) 
     14all install clean distclean uninstall: $(BIN_DIRS) $(LIB_DIRS) $(BIND_DIRS) 
    1215 
    1316install uninstall distclean: $(DOC_DIRS) 
     
    1720ifneq ($(MAKECMDGOALS),clean) 
    1821ifneq ($(MAKECMDGOALS),distclean) 
    19 $(BIN_DIRS): $(LIB_DIRS) 
     22$(BIN_DIRS) $(BIND_DIRS): $(LIB_DIRS) 
    2023endif 
    2124endif 
     
    2528endif 
    2629 
    27 $(LIB_DIRS) $(BIN_DIRS) $(DOC_DIRS) wmdemo
     30$(SUB_DIRS)
    2831        $(MAKE) $(TARGET) -C $@ 
    2932 
     
    4447        rm -rf $(CWIID_CONFIG_DIR) 
    4548 
    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) 
    4850 
    4951.NOTPARALLEL: 
  • trunk/common/include/app.mak

    r52 r125  
    66INST_DIR ?= /usr/local/bin 
    77 
    8 DEST_INST_DIR = $(DESTDIR)/$(INST_DIR) 
     8DEST_INST_DIR = $(ROOTDIR)$(INST_DIR) 
    99 
    1010all: $(APP_NAME) 
  • trunk/common/include/lib.mak.in

    r52 r125  
    88SO_NAME    = $(LINK_NAME).$(MAJOR_VER) 
    99SHARED_LIB = $(SO_NAME).$(MINOR_VER) 
    10 DEST_INC_INST_DIR = $(DESTDIR)/$(INC_INST_DIR) 
    11 DEST_LIB_INST_DIR = $(DESTDIR)/$(LIB_INST_DIR) 
     10DEST_INC_INST_DIR = $(ROOTDIR)$(INC_INST_DIR) 
     11DEST_LIB_INST_DIR = $(ROOTDIR)$(LIB_INST_DIR) 
    1212 
    1313OBJECTS = $(SOURCES:.c=.o) 
  • trunk/common/include/plugin.mak

    r52 r125  
    88CFLAGS += -fpic 
    99 
    10 #TODO:unify the way DESTDIR is handled 
    11 #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, 
    1212#so we don't do it here 
    13 #DEST_INST_DIR = $(DESTDIR)/$(INST_DIR) 
     13#DEST_INST_DIR = $(ROOTDIR)/$(INST_DIR) 
    1414DEST_INST_DIR = $(INST_DIR) 
    1515 
  • trunk/configure.ac

    r83 r125  
    11# ChangeLog: 
     2# 2007-05-30 L. Donnie Smith <cwiid@abstrakraft.org> 
     3# * added python/Makefile 
     4# * added PYTHON_VERSION variable 
     5# 
    26# 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    37# * updated for libcwiid rename 
     
    3236        AC_MSG_ERROR([bison not found]) 
    3337fi 
     38 
     39PYTHON_VERSION=[`python -c 'import sys; print sys.version[:3]'`] 
     40AC_SUBST(PYTHON_VERSION) 
    3441 
    3542AC_CHECK_LIB([pthread], [pthread_create],, 
     
    105112        [wminput/plugins/nunchuk_acc/Makefile] 
    106113        [lswm/Makefile] 
     114        [python/Makefile] 
    107115        ) 
    108116 
  • trunk/defs.mak.in

    r72 r125  
    2424COMMON = @abs_top_builddir@/common 
    2525 
    26 CWIID_CONFIG_DIR = $(DESTDIR)/@CWIID_CONFIG_DIR@ 
    27 CWIID_PLUGINS_DIR = $(DESTDIR)/@CWIID_PLUGINS_DIR@ 
     26ifdef DESTDIR 
     27        ROOTDIR = $(DESTDIR:%/=%) 
     28endif 
     29 
     30CWIID_CONFIG_DIR = $(ROOTDIR)@CWIID_CONFIG_DIR@ 
     31CWIID_PLUGINS_DIR = $(ROOTDIR)@CWIID_PLUGINS_DIR@ 
    2832 
    2933DEBUGFLAGS = -g 
  • trunk/doc/Makefile.in

    r56 r125  
    55docfiles = Xmodmap wminput.list 
    66 
    7 DEST_DOC_DIR = $(DESTDIR)/$(docdir) 
     7DEST_DOC_DIR = $(ROOTDIR)$(docdir) 
    88 
    99all: 
  • trunk/lswm/Makefile.in

    r83 r125  
    77SOURCES = lswm.c 
    88 
    9 CFLAGS += -I@top_builddir@/libcwiid 
     9CFLAGS += -I@top_builddir@/libcwiid -DCWIID_VERSION=\"${PACKAGE_VERSION}\" 
    1010LDFLAGS += -L@top_builddir@/libcwiid 
    1111LDLIBS += -lcwiid 
  • trunk/lswm/lswm.c

    r83 r125  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-06-01 Nick <nickishappy@gmail.com> 
     19 *  * reworked command-line options (added standard options, long options) 
     20 * 
    1821 *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * updated for libcwiid rename 
     
    3235#include <bluetooth/bluetooth.h> 
    3336#include <cwiid.h> 
     37#include <getopt.h> 
    3438 
    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" 
     39void 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
    4350 
    4451int main(int argc, char *argv[]) 
     
    5461 
    5562        /* 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 
    5781                switch (c) { 
    5882                case 'h': 
    59                         printf(USAGE, argv[0]); 
     83                        print_usage(); 
    6084                        return 0; 
    6185                        break; 
     
    6690                        long_format = 1; 
    6791                        break; 
     92                case 'v': 
     93                        printf("CWiid Version %s\n", CWIID_VERSION); 
     94                        return 0; 
     95                        break; 
    6896                case 'q': 
    6997                        quiet = 1; 
     
    7199                case '?': 
    72100                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]); 
    74102                        return -1; 
    75103                        break; 
    76104                } 
    77105        } 
    78  
    79         /* TODO: check for other stuff on the command-line? */ 
    80106 
    81107        /* Handle quiet mode */ 
     
    112138        return 0; 
    113139} 
    114  
  • trunk/man/Makefile.in

    r56 r125  
    33include @top_builddir@/defs.mak 
    44 
    5 DEST_MAN_DIR = $(DESTDIR)/$(mandir) 
     5DEST_MAN_DIR = $(ROOTDIR)$(mandir) 
    66 
    77all: 
  • trunk/wminput/Makefile.in

    r83 r125  
    55APP_NAME = wminput 
    66 
    7 SOURCES = main.c conf.c uinput.c action_enum.c parser.c lexer.c util.c 
     7SOURCES = main.c conf.c c_plugin.c py_plugin.c uinput.c action_enum.c parser.c \ 
     8        lexer.c util.c 
    89 
    910WMINPUT_CONFIG_DIR = $(CWIID_CONFIG_DIR)/wminput 
    10 CFLAGS += -I@top_builddir@/libcwiid
     11CFLAGS += -I@top_builddir@/libcwiid -I/usr/include/python@PYTHON_VERSION@
    1112        -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}\" 
     15LDLIBS += -lcwiid -ldl -lpython@PYTHON_VERSION@ 
    1416LDFLAGS += -L@top_builddir@/libcwiid -rdynamic 
    1517INST_DIR = @bindir@ 
  • trunk/wminput/conf.c

    r91 r125  
    1616 * 
    1717 *  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 * 
    1828 *  2007-04-15 <work.eric@gmail.com> 
    1929 *  * fixed classic controller configuration bug 
     
    3343#include <string.h> 
    3444 
    35 #include <sys/types.h> 
    36 #include <sys/stat.h> 
    37 #include <dlfcn.h> 
    38 #include <unistd.h> 
    39  
    4045#include "conf.h" 
    4146#include "util.h" 
    4247#include "y.tab.h" 
     48#include "c_plugin.h" 
     49#include "py_plugin.h" 
    4350 
    4451extern FILE *yyin; 
     
    8592                if (conf->plugins[i].name) { 
    8693                        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                        } 
    91102                } 
    92103        } 
     
    326337        } 
    327338 
    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                } 
    338349                break; 
    339350        } 
     
    365376        } 
    366377 
    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                } 
    379388                break; 
    380389        } 
     
    556565} 
    557566 
    558 #define PLUGIN_PATHNAME_LEN     128 
    559567struct plugin *get_plugin(struct conf *conf, const char *name) 
    560568{ 
    561569        int i; 
    562         char pathname[PLUGIN_PATHNAME_LEN]
     570        char plugin_found = 0
    563571        struct plugin *plugin; 
    564         struct stat buf; 
    565         wmplugin_info_t *info; 
    566572 
    567573        for (i=0; i < CONF_MAX_PLUGINS; i++) { 
     
    578584                return NULL; 
    579585        } 
    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; 
    632606        } 
    633607 
    634608        return plugin; 
    635609} 
    636  
  • trunk/wminput/conf.h

    r83 r125  
    1616 * 
    1717 *  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 * 
    1824 *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    1925 *  * updated for libcwiid rename 
     
    133139}; 
    134140 
     141enum plugin_type { 
     142        PLUGIN_C, 
     143        PLUGIN_PYTHON 
     144}; 
     145 
    135146struct plugin { 
    136147        char *name; 
     148        enum plugin_type type; 
     149        uint8_t rpt_mode_flags; 
    137150        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; 
    142152        uint16_t prev_buttons; 
    143153        struct btn_map bmap[WMPLUGIN_MAX_BUTTON_COUNT]; 
    144154        struct axis_map amap[WMPLUGIN_MAX_AXIS_COUNT]; 
     155        void *p; 
    145156}; 
    146157 
  • trunk/wminput/main.c

    r116 r125  
    1616 * 
    1717 *  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 * 
    1828 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
    1929 *  * changed cwiid_{connect,disconnect,command} to 
     
    4050#include <stdio.h> 
    4151#include <stdlib.h> 
     52#include <getopt.h> 
    4253 
    4354#include <pthread.h> 
     
    5162#include "util.h" 
    5263#include "wmplugin.h" 
     64#include "c_plugin.h" 
     65#include "py_plugin.h" 
    5366 
    5467struct conf conf; 
    55  
    56 /* GetOpt */ 
    57 #define OPTSTRING       "hwc:" 
    58 extern char *optarg; 
    59 extern int optind, opterr, optopt; 
    6068 
    6169/* Prototypes */ 
     
    7381#define DEFAULT_CONFIG_FILE     "default" 
    7482 
    75 #define USAGE "usage:%s [-h] [-w] [-c config] [bdaddr]\n" 
    76  
    7783#define HOME_DIR_LEN    128 
     84 
     85void 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 
    7896int main(int argc, char *argv[]) 
    7997{ 
     
    95113 
    96114        /* 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 
    98132                switch (c) { 
    99133                case 'h': 
    100                         printf(USAGE, argv[0]); 
     134                        print_usage(); 
    101135                        return 0; 
    102136                        break; 
     
    107141                        config_filename = optarg; 
    108142                        break; 
     143                case 'v': 
     144                        printf("CWiid Version %s\n", CWIID_VERSION); 
     145                        return 0; 
     146                        break; 
    109147                case '?': 
     148                        printf("Try `wminput --help` for more information\n"); 
     149                        return 1; 
     150                        break; 
    110151                default: 
    111152                        return -1; 
     
    114155        } 
    115156 
     157        if (c_init()) { 
     158                return -1; 
     159        } 
     160        if (py_init()) { 
     161                return -1; 
     162        } 
     163 
    116164        /* Load Config */ 
     165        /* Setup search directory arrays */ 
    117166        if ((tmp = getenv("HOME")) == NULL) { 
    118167                wminput_err("unable to find home directory"); 
     
    136185        } 
    137186 
    138         /* BDADDR */ 
     187        /* Determine BDADDR */ 
     188        /* priority: command-line option, environment variable, BDADDR_ANY */ 
    139189        if (optind < argc) { 
    140190                if (str2ba(argv[optind], &bdaddr)) { 
     
    145195                if (optind < argc) { 
    146196                        wminput_err("invalid command-line"); 
    147                         printf(USAGE, argv[0]); 
     197                        print_usage(); 
    148198                        conf_unload(&conf); 
    149199                        return -1; 
     
    160210        } 
    161211 
    162         /* Wiimote connect */ 
     212        /* TODO: fix wait_forever logic - currently assumes bdaddr is unspecified */ 
     213        /* Wiimote Connect */ 
    163214        printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); 
    164215        if (wait_forever) { 
     
    180231        } 
    181232 
     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 
    182242        /* init plugins */ 
    183243        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; 
    189261                } 
    190262        } 
     
    240312        } 
    241313 
     314        py_deinit(); 
     315 
    242316        return ret; 
    243317} 
    244318 
    245 int wmplugin_set_report_mode(int id, uint8_t flags) 
     319int 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 
     338int wmplugin_set_rpt_mode(int id, uint8_t flags) 
    246339{ 
    247340        conf.plugins[id].rpt_mode_flags = flags; 
     
    249342        if (!init) { 
    250343                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; 
    270344        } 
    271345 
     
    520594                    union cwiid_mesg mesg[]) 
    521595{ 
    522         union cwiid_mesg *plugin_mesg[CWIID_MAX_MESG_COUNT]; 
     596        static union cwiid_mesg plugin_mesg[CWIID_MAX_MESG_COUNT]; 
    523597        int plugin_mesg_count = 0; 
    524598        int i; 
    525599        uint8_t flag; 
    526         struct wmplugin_data *data; 
    527600        uint16_t pressed, released; 
    528601        __s32 axis_value; 
     
    552625                } 
    553626                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]); 
    555629                } 
    556630        } 
    557631 
    558632        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; 
    561644                } 
    562645 
    563646                /* 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; 
    566649                for (i=0; i < plugin->info->button_count; i++) { 
    567650                        if (plugin->bmap[i].active) { 
     
    574657                        } 
    575658                } 
    576                 plugin->prev_buttons = data->buttons; 
     659                plugin->prev_buttons = plugin->data->buttons; 
    577660 
    578661                /* Plugin Axis Events */ 
    579662                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; 
    582666                                if (plugin->amap[i].flags & CONF_INVERT) { 
    583667                                        axis_value = plugin->info->axis_info[i].max + 
  • trunk/wminput/plugins/acc/acc.c

    r113 r125  
    1616 * 
    1717 *  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 * 
    1822 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * use cwiid_get_acc_cal to get acc calibration values 
     
    5862wmplugin_exec_t wmplugin_exec; 
    5963static void process_acc(struct cwiid_acc_mesg *mesg); 
     64 
     65static float Roll_Scale = 1.0; 
     66static float Pitch_Scale = 1.0; 
     67static float X_Scale = 1.0; 
     68static float Y_Scale = 1.0; 
    6069 
    6170struct wmplugin_info *wmplugin_info() { 
     
    9099                info.param_info[0].name = "Roll_Scale"; 
    91100                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
    93102                info.param_info[1].name = "Pitch_Scale"; 
    94103                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
    96105                info.param_info[2].name = "X_Scale"; 
    97106                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
    99108                info.param_info[3].name = "Y_Scale"; 
    100109                info.param_info[3].type = WMPLUGIN_PARAM_FLOAT; 
    101                 info.param_info[3].value.Float = 1.0
     110