xwiimote 2

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

xwiimote.h
Go to the documentation of this file.
1 /*
2 * XWiimote - lib
3 * Written 2010-2013 by David Herrmann <dh.herrmann@gmail.com>
4 * Dedicated to the Public Domain
5 */
6
7 #ifndef XWII_XWIIMOTE_H
8 #define XWII_XWIIMOTE_H
9
10 #include <stdbool.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <sys/time.h>
14 #include <time.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
30 #if (__GNUC__ > 3)
31 #define XWII__DEPRECATED __attribute__((__deprecated__))
32 #else
33 #define XWII__DEPRECATED
34 #endif /* __GNUC__ */
35
310 #define XWII__NAME "Nintendo Wii Remote"
311
313 #define XWII_NAME_CORE XWII__NAME
314
315 #define XWII_NAME_ACCEL XWII__NAME " Accelerometer"
316
317 #define XWII_NAME_IR XWII__NAME " IR"
318
320 #define XWII_NAME_MOTION_PLUS XWII__NAME " Motion Plus"
321
322 #define XWII_NAME_NUNCHUK XWII__NAME " Nunchuk"
323
324 #define XWII_NAME_CLASSIC_CONTROLLER XWII__NAME " Classic Controller"
325
326 #define XWII_NAME_BALANCE_BOARD XWII__NAME " Balance Board"
327
328 #define XWII_NAME_PRO_CONTROLLER XWII__NAME " Pro Controller"
329
351 enum xwii_event_types {
360 XWII_EVENT_KEY,
361
371 XWII_EVENT_ACCEL,
372
385 XWII_EVENT_IR,
386
396 XWII_EVENT_BALANCE_BOARD,
397
407 XWII_EVENT_MOTION_PLUS,
408
418 XWII_EVENT_PRO_CONTROLLER_KEY,
419
428 XWII_EVENT_PRO_CONTROLLER_MOVE,
429
444 XWII_EVENT_WATCH,
445
452 XWII_EVENT_NUM
453 };
454
469 enum xwii_event_keys {
470 XWII_KEY_LEFT,
471 XWII_KEY_RIGHT,
472 XWII_KEY_UP,
473 XWII_KEY_DOWN,
474 XWII_KEY_A,
475 XWII_KEY_B,
476 XWII_KEY_PLUS,
477 XWII_KEY_MINUS,
478 XWII_KEY_HOME,
479 XWII_KEY_ONE,
480 XWII_KEY_TWO,
481 XWII_KEY_X,
482 XWII_KEY_Y,
483 XWII_KEY_TL,
484 XWII_KEY_TR,
485 XWII_KEY_ZL,
486 XWII_KEY_ZR,
487
495 XWII_KEY_THUMBL,
496
504 XWII_KEY_THUMBR,
505
513 XWII_KEY_NUM
514 };
515
521 struct xwii_event_key {
523 unsigned int code;
525 unsigned int state;
526 };
527
534 struct xwii_event_abs {
535 int32_t x;
536 int32_t y;
537 int32_t z;
538 };
539
545 union xwii_event_union {
547 struct xwii_event_key key;
549 struct xwii_event_abs abs[4];
551 uint8_t reserved[128];
552 };
553
563 struct xwii_event {
565 struct timeval time;
567 unsigned int type;
568
570 union xwii_event_union v;
571 };
572
581 static inline bool xwii_event_ir_is_valid(const struct xwii_event_abs *abs)
582 {
583 return abs->x != 1023 || abs->y != 1023;
584 }
585
631 struct xwii_iface;
632
640 enum xwii_iface_type {
642 XWII_IFACE_CORE = 0x000001,
644 XWII_IFACE_ACCEL = 0x000002,
646 XWII_IFACE_IR = 0x000004,
647
649 XWII_IFACE_MOTION_PLUS = 0x000100,
651 XWII_IFACE_NUNCHUK = 0x000200,
653 XWII_IFACE_CLASSIC_CONTROLLER = 0x000400,
655 XWII_IFACE_BALANCE_BOARD = 0x000800,
657 XWII_IFACE_PRO_CONTROLLER = 0x001000,
658
660 XWII_IFACE_ALL = XWII_IFACE_CORE |
661 XWII_IFACE_ACCEL |
662 XWII_IFACE_IR |
663 XWII_IFACE_MOTION_PLUS |
664 XWII_IFACE_NUNCHUK |
665 XWII_IFACE_CLASSIC_CONTROLLER |
666 XWII_IFACE_BALANCE_BOARD |
667 XWII_IFACE_PRO_CONTROLLER,
669 XWII_IFACE_WRITABLE = 0x010000,
670 };
671
677 enum xwii_led {
678 XWII_LED1 = 1,
679 XWII_LED2 = 2,
680 XWII_LED3 = 3,
681 XWII_LED4 = 4,
682 };
683
690 #define XWII_LED(num) (XWII_LED1 + (num) - 1)
691
708 int xwii_iface_new(struct xwii_iface **dev, const char *syspath);
709
715 void xwii_iface_ref(struct xwii_iface *dev);
716
726 void xwii_iface_unref(struct xwii_iface *dev);
727
741 int xwii_iface_get_fd(struct xwii_iface *dev);
742
758 int xwii_iface_watch(struct xwii_iface *dev, bool watch);
759
781 int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces);
782
791 void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces);
792
806 unsigned int xwii_iface_opened(struct xwii_iface *dev);
807
819 unsigned int xwii_iface_available(struct xwii_iface *dev);
820
845 XWII__DEPRECATED
846 int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev);
847
876 int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev,
877 size_t size);
878
890 int xwii_iface_rumble(struct xwii_iface *dev, bool on);
891
906 int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state);
907
921 int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state);
922
936 int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity);
937
951 int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype);
952
967 int xwii_iface_get_extension(struct xwii_iface *dev, char **extension);
968
990 void xwii_iface_set_mp_normalization(struct xwii_iface *dev, int32_t x,
991 int32_t y, int32_t z, int32_t factor);
992
1012 void xwii_iface_get_mp_normalization(struct xwii_iface *dev, int32_t *x,
1013 int32_t *y, int32_t *z, int32_t *factor);
1014
1038 struct xwii_monitor;
1039
1055 struct xwii_monitor *xwii_monitor_new(bool poll, bool direct);
1056
1062 void xwii_monitor_ref(struct xwii_monitor *mon);
1063
1071 void xwii_monitor_unref(struct xwii_monitor *mon);
1072
1089 int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking);
1090
1112 char *xwii_monitor_poll(struct xwii_monitor *monitor);
1113
1116 #ifdef __cplusplus
1117 }
1118 #endif
1119
1120 #endif /* XWII_XWIIMOTE_H */
xwii_iface_get_extension
int xwii_iface_get_extension(struct xwii_iface *dev, char **extension)
Read extension type.
xwii_monitor_ref
void xwii_monitor_ref(struct xwii_monitor *mon)
Increase monitor ref-count by 1.
XWII_KEY_THUMBR
Right thumb button.
Definition: xwiimote.h:504
xwii_iface_watch
int xwii_iface_watch(struct xwii_iface *dev, bool watch)
Watch device for hotplug events.
xwii_event::v
union xwii_event_union v
data payload
Definition: xwiimote.h:570
XWII_EVENT_WATCH
Hotplug Event.
Definition: xwiimote.h:444
xwii_event_key::state
unsigned int state
key state copied from kernel (0: up, 1: down, 2: auto-repeat)
Definition: xwiimote.h:525
xwii_iface_set_mp_normalization
void xwii_iface_set_mp_normalization(struct xwii_iface *dev, int32_t x, int32_t y, int32_t z, int32_t factor)
Set MP normalization and calibration.
xwii_iface_available
unsigned int xwii_iface_available(struct xwii_iface *dev)
Return bitmask of available interfaces.
xwii_iface_new
int xwii_iface_new(struct xwii_iface **dev, const char *syspath)
Create new device object from syspath path.
xwii_event_types
xwii_event_types
Event Types.
Definition: xwiimote.h:351
xwii_event_union
Event Payload.
Definition: xwiimote.h:545
xwii_iface_poll
XWII__DEPRECATED int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev)
Read incoming event-queue.
xwii_iface_get_fd
int xwii_iface_get_fd(struct xwii_iface *dev)
Return file-descriptor.
XWII_KEY_NUM
Number of key identifiers.
Definition: xwiimote.h:513
xwii_monitor_new
struct xwii_monitor * xwii_monitor_new(bool poll, bool direct)
Create a new monitor.
xwii_event
Event Object.
Definition: xwiimote.h:563
XWII_EVENT_NUM
Number of available event types.
Definition: xwiimote.h:452
xwii_iface_ref
void xwii_iface_ref(struct xwii_iface *dev)
Increase ref-count by 1.
xwii_monitor_poll
char * xwii_monitor_poll(struct xwii_monitor *monitor)
Read incoming events.
xwii_iface_type
xwii_iface_type
Interfaces.
Definition: xwiimote.h:640
xwii_event::time
struct timeval time
timestamp when this event was generated (copied from kernel)
Definition: xwiimote.h:565
xwii_iface_get_led
int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state)
Read LED state.
XWII_EVENT_IR
IR-Camera event.
Definition: xwiimote.h:385
xwii_event_key::code
unsigned int code
key identifier defined as enum xwii_event_keys
Definition: xwiimote.h:523
XWII_IFACE_CORE
Core interface.
Definition: xwiimote.h:642
xwii_iface_get_devtype
int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype)
Read device type.
XWII_EVENT_ACCEL
Accelerometer event.
Definition: xwiimote.h:371
xwii_event_union::reserved
uint8_t reserved[128]
reserved; do not use!
Definition: xwiimote.h:551
XWII_KEY_THUMBL
Left thumb button.
Definition: xwiimote.h:495
xwii_iface_set_led
int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state)
Set LED state.
xwii_iface_get_battery
int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity)
Read battery state.
xwii_iface_get_mp_normalization
void xwii_iface_get_mp_normalization(struct xwii_iface *dev, int32_t *x, int32_t *y, int32_t *z, int32_t *factor)
Read MP normalization and calibration.
XWII_IFACE_MOTION_PLUS
MotionPlus extension interface.
Definition: xwiimote.h:649
XWII_IFACE_ALL
Special flag ORed with all valid interfaces.
Definition: xwiimote.h:660
XWII_EVENT_KEY
Core-interface key event.
Definition: xwiimote.h:360
XWII_EVENT_PRO_CONTROLLER_MOVE
Pro-Controller movement event.
Definition: xwiimote.h:428
xwii_event_keys
xwii_event_keys
Key Event Identifiers.
Definition: xwiimote.h:469
xwii_event::type
unsigned int type
event type ref xwii_event_types
Definition: xwiimote.h:567
XWII_IFACE_ACCEL
Accelerometer interface.
Definition: xwiimote.h:644
xwii_iface_open
int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces)
Open interfaces on this device.
XWII_IFACE_NUNCHUK
Nunchuk extension interface.
Definition: xwiimote.h:651
XWII_IFACE_IR
IR interface.
Definition: xwiimote.h:646
xwii_iface_rumble
int xwii_iface_rumble(struct xwii_iface *dev, bool on)
Toggle rumble motor.
XWII_IFACE_CLASSIC_CONTROLLER
ClassicController extension interface.
Definition: xwiimote.h:653
xwii_monitor_unref
void xwii_monitor_unref(struct xwii_monitor *mon)
Decrease monitor ref-count by 1.
xwii_event_union::abs
struct xwii_event_abs abs[4]
absolute motion event payload
Definition: xwiimote.h:549
XWII_IFACE_BALANCE_BOARD
BalanceBoard extension interface.
Definition: xwiimote.h:655
XWII_IFACE_PRO_CONTROLLER
ProController extension interface.
Definition: xwiimote.h:657
XWII_EVENT_BALANCE_BOARD
Balance-Board event.
Definition: xwiimote.h:396
xwii_event_key
Key Event Payload.
Definition: xwiimote.h:521
xwii_iface_unref
void xwii_iface_unref(struct xwii_iface *dev)
Decrease ref-count by 1.
xwii_led
xwii_led
LEDs.
Definition: xwiimote.h:677
xwii_iface_opened
unsigned int xwii_iface_opened(struct xwii_iface *dev)
Return bitmask of opened interfaces.
XWII_EVENT_MOTION_PLUS
Motion-Plus event.
Definition: xwiimote.h:407
xwii_event_union::key
struct xwii_event_key key
key event payload
Definition: xwiimote.h:547
XWII_IFACE_WRITABLE
Special flag which causes the interfaces to be opened writable.
Definition: xwiimote.h:669
xwii_iface_close
void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces)
Close interfaces on this device.
XWII_EVENT_PRO_CONTROLLER_KEY
Pro-Controller key event.
Definition: xwiimote.h:418
xwii_monitor_get_fd
int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking)
Return internal fd.
xwii_iface_dispatch
int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev, size_t size)
Read incoming event-queue.
xwii_event_abs
Absolute Motion Payload.
Definition: xwiimote.h:534