Changeset d2323a579f283ed7393c20b762697766d2d01e1f

Show
Ignore:
Timestamp:
04/01/07 20:46:16 (6 years ago)
Author:
dsmith <dsmith@…>
Children:
cc418bb14a0cf2615e57971f52b2a2f07868e3a7
Parents:
d7c9be1302a434adc8e9472e1bb70ec5eded1b61
git-author:
L. Donnie Smith <donnie.smith@…> (04/01/07 20:46:16)
git-committer:
dsmith <dsmith@…> (04/01/07 20:46:16)
Message:

Added struct wiimote info and info retrieval functions

git-svn-id: http://abstrakraft.org/cwiid/svn/trunk@47 918edb2d-ff29-0410-9de2-eb38e7f22bc7

Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rd3094f8 rd2323a5  
    22        wmdemo 
    33        * renamed main.c to wmdemo.c 
     4 
     5        wiimote 
     6        * created bluetooth.c 
     7        * moved wiimote_findfirst to bluetooth.c, renamed to wiimote_find_wiimote, 
     8          added timeout argument 
     9        * defined struct wiimote_info 
     10        * wrote wiimote_get_info_array 
    411 
    5122007-03-27 L. Donnie Smith <cwiid@abstrakraft.org> 
  • wiimote/Makefile.in

    r055987a rd2323a5  
    77MAJOR_VER = 0 
    88MINOR_VER = 1 
    9 SOURCES = connect.c command.c event.c rw.c util.c queue.c 
     9SOURCES = connect.c command.c event.c rw.c bluetooth.c util.c queue.c 
    1010LDLIBS += -lbluetooth -lpthread -lrt 
    1111LIB_INST_DIR = @libdir@ 
  • wiimote/connect.c

    r00aa494 rd2323a5  
    1616 * 
    1717 *  ChangeLog: 
     18 *  04/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed wiimote_findfirst to wiimote_find_wiimote 
     20 * 
    1821 *  03/14/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * changed memcpy to bacmp 
     
    7982        /* If BDADDR_ANY is given, find available wiimote */ 
    8083        if (bacmp(&bdaddr, BDADDR_ANY) == 0) { 
    81                 if (wiimote_findfirst(&bdaddr)) { 
     84                if (wiimote_find_wiimote(&bdaddr, 2)) { 
    8285                        /* TODO: wiimote functions should print their own errors */ 
    8386                        wiimote_err(wiimote, "Unable to find wiimote"); 
  • wiimote/util.c

    r00aa494 rd2323a5  
    1616 * 
    1717 *  ChangeLog: 
     18 *  04/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * removed wiimote_findfirst (moved to bluetooth.c) 
     20 * 
     21 *  03/27/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     22 *  * moved wiimote_findfirst to bluetooth.c 
     23 * 
    1824 *  03/14/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1925 *  * audited error checking (coda and error handler sections) 
     
    3541#include <string.h> 
    3642#include <unistd.h> 
    37 #include <bluetooth/bluetooth.h> 
    38 #include <bluetooth/hci.h> 
    39 #include <bluetooth/hci_lib.h> 
    4043#include "wiimote_internal.h" 
    4144 
     
    160163} 
    161164 
    162 #define MAX_RSP 256 
    163 int wiimote_findfirst(bdaddr_t *bdaddr) 
    164 { 
    165         /* TODO: I suppose we'll have to sift through BlueZ source to properly 
    166          * check errors here... 
    167          */ 
    168         int dev_id; 
    169         int sock = -1; 
    170         inquiry_info *dev_list = NULL; 
    171         int i; 
    172         int dev_count; 
    173         int ret = -1; 
    174         char dev_name[WIIMOTE_CMP_LEN]; 
    175  
    176         /* Get the first available Bluetooth device */ 
    177         if ((dev_id = hci_get_route(NULL)) == -1) { 
    178                 wiimote_err(NULL, "No Bluetooth device found"); 
    179                 ret = -1; 
    180                 goto CODA; 
    181         } 
    182         if ((sock = hci_open_dev(dev_id)) == -1) { 
    183                 wiimote_err(NULL, "Error opening Bluetooth device"); 
    184                 ret = -1; 
    185                 goto CODA; 
    186         } 
    187  
    188         /* Get Device List */ 
    189         if ((dev_count = hci_inquiry(dev_id, 2, MAX_RSP, NULL, &dev_list, 
    190                                      IREQ_CACHE_FLUSH)) == -1) { 
    191                 wiimote_err(NULL, "Error on device inquiry"); 
    192                 ret = -1; 
    193                 goto CODA; 
    194         } 
    195  
    196         /* Check class and name for Wiimotes */ 
    197         for (i=0; i < dev_count; i++) { 
    198                 if ((dev_list[i].dev_class[0] == WIIMOTE_CLASS_0) && 
    199                   (dev_list[i].dev_class[1] == WIIMOTE_CLASS_1) && 
    200                   (dev_list[i].dev_class[2] == WIIMOTE_CLASS_2)) { 
    201                         if (hci_remote_name(sock, &dev_list[i].bdaddr, WIIMOTE_CMP_LEN, 
    202                                             dev_name, 5000)) { 
    203                                 wiimote_err(NULL, "Error reading device name"); 
    204                         } 
    205                         else if (strncmp(dev_name, WIIMOTE_NAME, WIIMOTE_CMP_LEN) == 0) { 
    206                                 *bdaddr = dev_list[i].bdaddr; 
    207                                 ret = 0; 
    208                                 break; 
    209                         } 
    210                 } 
    211         } 
    212  
    213 CODA: 
    214         if (sock != -1) { 
    215                 hci_close_dev(sock); 
    216         } 
    217         if (dev_list) { 
    218                 free(dev_list); 
    219         } 
    220         return ret; 
    221 } 
    222  
  • wiimote/wiimote.h

    ra339960 rd2323a5  
    1616 * 
    1717 *  ChangeLog: 
     18 *  04/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote_info definition and macros 
     20 *  * added wiimote_get_info_array prototype 
     21 *  * changed wiimote_findfirst to wiimote_find_wiimote 
     22 * 
    1823 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1924 *  * added wiimote_err_t definition 
     
    195200typedef void wiimote_err_t(int, const char *, ...); 
    196201 
     202/* getinfo flags */ 
     203#define BT_NO_WIIMOTE_FILTER 0x01 
     204#define BT_WM_NAME_LEN 32 
     205 
     206struct wiimote_info { 
     207        bdaddr_t bdaddr; 
     208        uint8_t class[3]; 
     209        char name[BT_WM_NAME_LEN]; 
     210}; 
     211 
    197212#ifdef __cplusplus 
    198213extern "C" { 
     
    211226                  uint16_t len, const void *data); 
    212227/* int wiimote_beep(wiimote_t *wiimote); */ 
    213 int wiimote_findfirst(bdaddr_t *bdaddr); 
     228int wiimote_get_info_array(int dev_id, unsigned int timeout, int max_wm, 
     229                           struct wiimote_info **wm, uint8_t flags); 
     230int wiimote_find_wiimote(bdaddr_t *bdaddr, int timeout); 
    214231 
    215232#ifdef __cplusplus 
  • wiimote/wiimote_internal.h

    ra339960 rd2323a5  
    1616 * 
    1717 *  ChangeLog: 
     18 *  04/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * removed WIIMOTE_CMP_LEN macro and wiimote_findfirst prototype 
     20 * 
    1821 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * added wiimote parameter to wiimote_err prototype 
     
    5457/* Wiimote specific magic numbers */ 
    5558#define WIIMOTE_NAME "Nintendo RVL-CNT-01" 
    56 #define WIIMOTE_CMP_LEN sizeof(WIIMOTE_NAME) 
    5759#define WIIMOTE_CLASS_0 0x04 
    5860#define WIIMOTE_CLASS_1 0x25 
     
    174176                   struct write_seq *seq); 
    175177void free_mesg_array(struct mesg_array *array); 
    176 int wiimote_findfirst(bdaddr_t *bdaddr); 
    177178 
    178179#endif