Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.05 KB | None | 0 0
  1. /* Copyright (C) 2007 L. Donnie Smith <cwiid@abstrakraft.org>
  2.  *
  3.  *  This program is free software; you can redistribute it and/or modify
  4.  *  it under the terms of the GNU General Public License as published by
  5.  *  the Free Software Foundation; either version 2 of the License, or
  6.  *  (at your option) any later version.
  7.  *
  8.  *  This program is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  *  GNU General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU General Public License
  14.  *  along with this program; if not, write to the Free Software
  15.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  16.  *
  17.  *  ChangeLog:
  18.  *  2007-08-14 L. Donnie Smith <cwiid@abstrakraft.org>
  19.  *  * make cwiid_err_default public
  20.  *
  21.  *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org>
  22.  *  * changed cwiid_connect, cwiid_disconnect to cwiid_open, cwiid_close
  23.  *  * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble,
  24.  *    cwiid_set_rpt_mode
  25.  *
  26.  *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org>
  27.  *  * added timestamp to message functions
  28.  *  * added cwiid_get_acc_cal
  29.  *
  30.  *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org>
  31.  *  * rewrite for API overhaul
  32.  *
  33.  *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org>
  34.  *  * renamed wiimote to libcwiid, renamed structures accordingly
  35.  *
  36.  *  2007-04-07 L. Donnie Smith <cwiid@abstrakraft.org>
  37.  *  * changed cwiid_info.class to btclass
  38.  *
  39.  *  2007-04-04 L. Donnie Smith <cwiid@abstrakraft.org>
  40.  *  * added cwiid_mesg_error message type
  41.  *
  42.  *  2007-04-01 L. Donnie Smith <cwiid@abstrakraft.org>
  43.  *  * cwiid_connect now takes a pointer to bdaddr_t
  44.  *  * added cwiid_info definition and macros
  45.  *  * added cwiid_get_info_array prototype
  46.  *  * changed cwiid_findfirst to cwiid_find_wiimote
  47.  *
  48.  *  2007-03-05 L. Donnie Smith <cwiid@abstrakraft.org>
  49.  *  * added cwiid_err_t definition
  50.  *  * added cwiid_set_err prototype
  51.  *
  52.  *  2007-03-01 L. Donnie Smith <cwiid@abstrakraft.org>
  53.  *  * Initial ChangeLog
  54.  *  * type audit (stdint, const, char booleans)
  55.  */
  56.  
  57. #ifndef CWIID_H
  58. #define CWIID_H
  59.  
  60. #include <stdarg.h>
  61. #include <stdint.h>
  62. #include <time.h>
  63. #include <bluetooth/bluetooth.h>    /* bdaddr_t */
  64.  
  65. /* Flags */
  66. #define CWIID_FLAG_MESG_IFC     0x01
  67. #define CWIID_FLAG_CONTINUOUS   0x02
  68. #define CWIID_FLAG_REPEAT_BTN   0x04
  69. #define CWIID_FLAG_NONBLOCK     0x08
  70. #define CWIID_FLAG_MOTIONPLUS   0x10
  71.  
  72. /* Report Mode Flags */
  73. #define CWIID_RPT_STATUS        0x01
  74. #define CWIID_RPT_BTN           0x02
  75. #define CWIID_RPT_ACC           0x04
  76. #define CWIID_RPT_IR            0x08
  77. #define CWIID_RPT_NUNCHUK       0x10
  78. #define CWIID_RPT_CLASSIC       0x20
  79. #define CWIID_RPT_BALANCE       0x40
  80. #define CWIID_RPT_MOTIONPLUS    0x80
  81. #define CWIID_RPT_EXT       (CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC | \
  82.                              CWIID_RPT_BALANCE | CWIID_RPT_MOTIONPLUS)
  83.  
  84. /* LED flags */
  85. #define CWIID_LED1_ON   0x01
  86. #define CWIID_LED2_ON   0x02
  87. #define CWIID_LED3_ON   0x04
  88. #define CWIID_LED4_ON   0x08
  89.  
  90. /* Button flags */
  91. #define CWIID_BTN_2     0x0001
  92. #define CWIID_BTN_1     0x0002
  93. #define CWIID_BTN_B     0x0004
  94. #define CWIID_BTN_A     0x0008
  95. #define CWIID_BTN_MINUS 0x0010
  96. #define CWIID_BTN_HOME  0x0080
  97. #define CWIID_BTN_LEFT  0x0100
  98. #define CWIID_BTN_RIGHT 0x0200
  99. #define CWIID_BTN_DOWN  0x0400
  100. #define CWIID_BTN_UP    0x0800
  101. #define CWIID_BTN_PLUS  0x1000
  102.  
  103. #define CWIID_NUNCHUK_BTN_Z 0x01
  104. #define CWIID_NUNCHUK_BTN_C 0x02
  105.  
  106. #define CWIID_CLASSIC_BTN_UP    0x0001
  107. #define CWIID_CLASSIC_BTN_LEFT  0x0002
  108. #define CWIID_CLASSIC_BTN_ZR    0x0004
  109. #define CWIID_CLASSIC_BTN_X     0x0008
  110. #define CWIID_CLASSIC_BTN_A     0x0010
  111. #define CWIID_CLASSIC_BTN_Y     0x0020
  112. #define CWIID_CLASSIC_BTN_B     0x0040
  113. #define CWIID_CLASSIC_BTN_ZL    0x0080
  114. #define CWIID_CLASSIC_BTN_R     0x0200
  115. #define CWIID_CLASSIC_BTN_PLUS  0x0400
  116. #define CWIID_CLASSIC_BTN_HOME  0x0800
  117. #define CWIID_CLASSIC_BTN_MINUS 0x1000
  118. #define CWIID_CLASSIC_BTN_L     0x2000
  119. #define CWIID_CLASSIC_BTN_DOWN  0x4000
  120. #define CWIID_CLASSIC_BTN_RIGHT 0x8000
  121.  
  122. /* Send Report flags */
  123. #define CWIID_SEND_RPT_NO_RUMBLE    0x01
  124.  
  125. /* Data Read/Write flags */
  126. #define CWIID_RW_EEPROM 0x00
  127. #define CWIID_RW_REG    0x04
  128. #define CWIID_RW_DECODE 0x00
  129.  
  130. /* Maximum Data Read Length */
  131. #define CWIID_MAX_READ_LEN  0xFFFF
  132.  
  133. /* Array Index Defs */
  134. #define CWIID_X     0
  135. #define CWIID_Y     1
  136. #define CWIID_Z     2
  137. #define CWIID_PHI   0
  138. #define CWIID_THETA 1
  139. #define CWIID_PSI   2
  140.  
  141. /* Acc Defs */
  142. #define CWIID_ACC_MAX   0xFF
  143.  
  144. /* IR Defs */
  145. #define CWIID_IR_SRC_COUNT  4
  146. #define CWIID_IR_X_MAX      1024
  147. #define CWIID_IR_Y_MAX      768
  148.  
  149. /* Battery */
  150. #define CWIID_BATTERY_MAX   0xD0
  151.  
  152. /* Classic Controller Maxes */
  153. #define CWIID_CLASSIC_L_STICK_MAX   0x3F
  154. #define CWIID_CLASSIC_R_STICK_MAX   0x1F
  155. #define CWIID_CLASSIC_LR_MAX    0x1F
  156.  
  157. /* Environment Variables */
  158. #define WIIMOTE_BDADDR  "WIIMOTE_BDADDR"
  159.  
  160. /* Callback Maximum Message Count */
  161. #define CWIID_MAX_MESG_COUNT    5
  162.  
  163. /* Enumerations */
  164. enum cwiid_command {
  165.     CWIID_CMD_STATUS,
  166.     CWIID_CMD_LED,
  167.     CWIID_CMD_RUMBLE,
  168.     CWIID_CMD_RPT_MODE
  169. };
  170.  
  171. enum cwiid_mesg_type {
  172.     CWIID_MESG_STATUS,
  173.     CWIID_MESG_BTN,
  174.     CWIID_MESG_ACC,
  175.     CWIID_MESG_IR,
  176.     CWIID_MESG_NUNCHUK,
  177.     CWIID_MESG_CLASSIC,
  178.     CWIID_MESG_BALANCE,
  179.     CWIID_MESG_MOTIONPLUS,
  180.     CWIID_MESG_ERROR,
  181.     CWIID_MESG_UNKNOWN
  182. };
  183.  
  184. enum cwiid_ext_type {
  185.     CWIID_EXT_NONE,
  186.     CWIID_EXT_NUNCHUK,
  187.     CWIID_EXT_CLASSIC,
  188.     CWIID_EXT_BALANCE,
  189.     CWIID_EXT_MOTIONPLUS,
  190.     CWIID_EXT_UNKNOWN
  191. };
  192.  
  193. enum cwiid_error {
  194.     CWIID_ERROR_NONE,
  195.     CWIID_ERROR_DISCONNECT,
  196.     CWIID_ERROR_COMM
  197. };
  198.  
  199. struct acc_cal {
  200.     uint8_t zero[3];
  201.     uint8_t one[3];
  202. };
  203.  
  204. struct balance_cal {
  205.     uint16_t right_top[3];
  206.     uint16_t right_bottom[3];
  207.     uint16_t left_top[3];
  208.     uint16_t left_bottom[3];
  209. };
  210.  
  211. /* Message Structs */
  212. struct cwiid_status_mesg {
  213.     enum cwiid_mesg_type type;
  214.     uint8_t battery;
  215.     enum cwiid_ext_type ext_type;
  216. }; 
  217.  
  218. struct cwiid_btn_mesg {
  219.     enum cwiid_mesg_type type;
  220.     uint16_t buttons;
  221. };
  222.  
  223. struct cwiid_acc_mesg {
  224.     enum cwiid_mesg_type type;
  225.     uint8_t acc[3];
  226. };
  227.  
  228. struct cwiid_ir_src {
  229.     char valid;
  230.     uint16_t pos[2];
  231.     int8_t size;
  232. };
  233.  
  234. struct cwiid_ir_mesg {
  235.     enum cwiid_mesg_type type;
  236.     struct cwiid_ir_src src[CWIID_IR_SRC_COUNT];
  237. };
  238.  
  239. struct cwiid_nunchuk_mesg {
  240.     enum cwiid_mesg_type type;
  241.     uint8_t stick[2];
  242.     uint8_t acc[3];
  243.     uint8_t buttons;
  244. };
  245.  
  246. struct cwiid_classic_mesg {
  247.     enum cwiid_mesg_type type;
  248.     uint8_t l_stick[2];
  249.     uint8_t r_stick[2];
  250.     uint8_t l;
  251.     uint8_t r;
  252.     uint16_t buttons;
  253. };
  254.  
  255. struct cwiid_balance_mesg {
  256.     enum cwiid_mesg_type type;
  257.     uint16_t right_top;
  258.     uint16_t right_bottom;
  259.     uint16_t left_top;
  260.     uint16_t left_bottom;
  261. };
  262.  
  263. struct cwiid_motionplus_mesg {
  264.     enum cwiid_mesg_type type;
  265.     uint16_t angle_rate[3];
  266. };
  267.  
  268. struct cwiid_error_mesg {
  269.     enum cwiid_mesg_type type;
  270.     enum cwiid_error error;
  271. };
  272.  
  273. union cwiid_mesg {
  274.     enum cwiid_mesg_type type;
  275.     struct cwiid_status_mesg status_mesg;
  276.     struct cwiid_btn_mesg btn_mesg;
  277.     struct cwiid_acc_mesg acc_mesg;
  278.     struct cwiid_ir_mesg ir_mesg;
  279.     struct cwiid_nunchuk_mesg nunchuk_mesg;
  280.     struct cwiid_classic_mesg classic_mesg;
  281.     struct cwiid_balance_mesg balance_mesg;
  282.     struct cwiid_motionplus_mesg motionplus_mesg;
  283.     struct cwiid_error_mesg error_mesg;
  284. };
  285.  
  286. /* State Structs */
  287. struct nunchuk_state {
  288.     uint8_t stick[2];
  289.     uint8_t acc[3];
  290.     uint8_t buttons;
  291. };
  292.  
  293. struct classic_state {
  294.     uint8_t l_stick[2];
  295.     uint8_t r_stick[2];
  296.     uint8_t l;
  297.     uint8_t r;
  298.     uint16_t buttons;
  299. };
  300.  
  301. struct balance_state {
  302.     uint16_t right_top;
  303.     uint16_t right_bottom;
  304.     uint16_t left_top;
  305.     uint16_t left_bottom;
  306. };
  307.  
  308. struct motionplus_state {
  309.     uint16_t angle_rate[3];
  310. };
  311.  
  312. union ext_state {
  313.     struct nunchuk_state nunchuk;
  314.     struct classic_state classic;
  315.     struct balance_state balance;
  316.     struct motionplus_state motionplus;
  317. };
  318.  
  319. struct cwiid_state {
  320.     uint8_t rpt_mode;
  321.     uint8_t led;
  322.     uint8_t rumble;
  323.     uint8_t battery;
  324.     uint16_t buttons;
  325.     uint8_t acc[3];
  326.     struct cwiid_ir_src ir_src[CWIID_IR_SRC_COUNT];
  327.     enum cwiid_ext_type ext_type;
  328.     union ext_state ext;
  329.     enum cwiid_error error;
  330. };
  331.  
  332. /* Typedefs */
  333. typedef struct wiimote cwiid_wiimote_t;
  334.  
  335. typedef void cwiid_mesg_callback_t(cwiid_wiimote_t *, int,
  336.                                    union cwiid_mesg [], struct timespec *);
  337. typedef void cwiid_err_t(cwiid_wiimote_t *, const char *, va_list ap);
  338.  
  339. /* get_bdinfo */
  340. #define BT_NO_WIIMOTE_FILTER 0x01
  341. #define BT_NAME_LEN 32
  342.  
  343. struct cwiid_bdinfo {
  344.     bdaddr_t bdaddr;
  345.     uint8_t btclass[3];
  346.     char name[BT_NAME_LEN];
  347. };
  348.  
  349. #ifdef __cplusplus
  350. extern "C" {
  351. #endif
  352.  
  353. /* Error reporting (library wide) */
  354. int cwiid_set_err(cwiid_err_t *err);
  355. void cwiid_err_default(struct wiimote *wiimote, const char *str, va_list ap);
  356.  
  357. /* Connection */
  358. #define cwiid_connect cwiid_open
  359. #define cwiid_disconnect cwiid_close
  360. cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags);
  361. cwiid_wiimote_t *cwiid_open_timeout(bdaddr_t *bdaddr, int flags, int timeout);
  362. int cwiid_close(cwiid_wiimote_t *wiimote);
  363.  
  364. int cwiid_get_id(cwiid_wiimote_t *wiimote);
  365. int cwiid_set_data(cwiid_wiimote_t *wiimote, const void *data);
  366. const void *cwiid_get_data(cwiid_wiimote_t *wiimote);
  367. int cwiid_enable(cwiid_wiimote_t *wiimote, int flags);
  368. int cwiid_disable(cwiid_wiimote_t *wiimote, int flags);
  369.  
  370. /* Interfaces */
  371. int cwiid_set_mesg_callback(cwiid_wiimote_t *wiimote,
  372.                        cwiid_mesg_callback_t *callback);
  373. int cwiid_get_mesg(cwiid_wiimote_t *wiimote, int *mesg_count,
  374.                    union cwiid_mesg *mesg[], struct timespec *timestamp);
  375. int cwiid_get_state(cwiid_wiimote_t *wiimote, struct cwiid_state *state);
  376. int cwiid_get_acc_cal(struct wiimote *wiimote, enum cwiid_ext_type ext_type,
  377.                       struct acc_cal *acc_cal);
  378. int cwiid_get_balance_cal(struct wiimote *wiimote,
  379.                           struct balance_cal *balance_cal);
  380.  
  381. /* Operations */
  382. int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command,
  383.                   int flags);
  384. int cwiid_send_rpt(cwiid_wiimote_t *wiimote, uint8_t flags, uint8_t report,
  385.                    size_t len, const void *data);
  386. int cwiid_request_status(cwiid_wiimote_t *wiimote);
  387. int cwiid_set_led(cwiid_wiimote_t *wiimote, uint8_t led);
  388. int cwiid_set_rumble(cwiid_wiimote_t *wiimote, uint8_t rumble);
  389. int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode);
  390. int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
  391.                uint16_t len, void *data);
  392. int cwiid_write(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
  393.                 uint16_t len, const void *data);
  394. /* int cwiid_beep(cwiid_wiimote_t *wiimote); */
  395.  
  396. /* HCI functions */
  397. int cwiid_get_bdinfo_array(int dev_id, unsigned int timeout, int max_bdinfo,
  398.                            struct cwiid_bdinfo **bdinfo, uint8_t flags);
  399. int cwiid_find_wiimote(bdaddr_t *bdaddr, int timeout);
  400.  
  401. #ifdef __cplusplus
  402. }
  403. #endif
  404.  
  405. #endif
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. gcc wmdemo.c
  414. /tmp/ccIAbJvR.o: In function `err':
  415. wmdemo.c:(.text+0x13): undefined reference to `cwiid_get_id'
  416. /tmp/ccIAbJvR.o: In function `main':
  417. wmdemo.c:(.text+0x84): undefined reference to `cwiid_set_err'
  418. wmdemo.c:(.text+0xa2): undefined reference to `str2ba'
  419. wmdemo.c:(.text+0xf4): undefined reference to `cwiid_open'
  420. wmdemo.c:(.text+0x145): undefined reference to `cwiid_set_mesg_callback'
  421. wmdemo.c:(.text+0x2cf): undefined reference to `cwiid_set_rumble'
  422. wmdemo.c:(.text+0x411): undefined reference to `cwiid_enable'
  423. wmdemo.c:(.text+0x460): undefined reference to `cwiid_disable'
  424. wmdemo.c:(.text+0x4b8): undefined reference to `cwiid_request_status'
  425. wmdemo.c:(.text+0x501): undefined reference to `cwiid_get_state'
  426. wmdemo.c:(.text+0x5c6): undefined reference to `cwiid_close'
  427. /tmp/ccIAbJvR.o: In function `set_led_state':
  428. wmdemo.c:(.text+0x61f): undefined reference to `cwiid_set_led'
  429. /tmp/ccIAbJvR.o: In function `set_rpt_mode':
  430. wmdemo.c:(.text+0x66c): undefined reference to `cwiid_set_rpt_mode'
  431. /tmp/ccIAbJvR.o: In function `cwiid_callback':
  432. wmdemo.c:(.text+0xe49): undefined reference to `cwiid_close'
  433. collect2: ld returned 1 exit status
  434. dave@laptop:~/Desktop/cwiid-0.6.00/wmdemo$ gcc wmdemo.c
  435. /tmp/ccqYhvIn.o: In function `err':
  436. wmdemo.c:(.text+0x13): undefined reference to `cwiid_get_id'
  437. /tmp/ccqYhvIn.o: In function `main':
  438. wmdemo.c:(.text+0x84): undefined reference to `cwiid_set_err'
  439. wmdemo.c:(.text+0xa2): undefined reference to `str2ba'
  440. wmdemo.c:(.text+0xf4): undefined reference to `cwiid_open'
  441. wmdemo.c:(.text+0x145): undefined reference to `cwiid_set_mesg_callback'
  442. wmdemo.c:(.text+0x2cf): undefined reference to `cwiid_set_rumble'
  443. wmdemo.c:(.text+0x411): undefined reference to `cwiid_enable'
  444. wmdemo.c:(.text+0x460): undefined reference to `cwiid_disable'
  445. wmdemo.c:(.text+0x4b8): undefined reference to `cwiid_request_status'
  446. wmdemo.c:(.text+0x501): undefined reference to `cwiid_get_state'
  447. wmdemo.c:(.text+0x5c6): undefined reference to `cwiid_close'
  448. /tmp/ccqYhvIn.o: In function `set_led_state':
  449. wmdemo.c:(.text+0x61f): undefined reference to `cwiid_set_led'
  450. /tmp/ccqYhvIn.o: In function `set_rpt_mode':
  451. wmdemo.c:(.text+0x66c): undefined reference to `cwiid_set_rpt_mode'
  452. /tmp/ccqYhvIn.o: In function `cwiid_callback':
  453. wmdemo.c:(.text+0xe49): undefined reference to `cw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement