xwiimote  2
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 
332 #define XWII__NAME "Nintendo Wii Remote"
333 
335 #define XWII_NAME_CORE XWII__NAME
337 #define XWII_NAME_ACCEL XWII__NAME " Accelerometer"
339 #define XWII_NAME_IR XWII__NAME " IR"
340 
342 #define XWII_NAME_MOTION_PLUS XWII__NAME " Motion Plus"
344 #define XWII_NAME_NUNCHUK XWII__NAME " Nunchuk"
346 #define XWII_NAME_CLASSIC_CONTROLLER XWII__NAME " Classic Controller"
348 #define XWII_NAME_BALANCE_BOARD XWII__NAME " Balance Board"
350 #define XWII_NAME_PRO_CONTROLLER XWII__NAME " Pro Controller"
352 #define XWII_NAME_DRUMS XWII__NAME " Drums"
354 #define XWII_NAME_GUITAR XWII__NAME " Guitar"
355 
387 
398 
412 
423 
434 
445 
455 
474 
486 
500 
511 
521 
530 
540 
551 
562 
573 
581 };
582 
598  XWII_KEY_LEFT,
599  XWII_KEY_RIGHT,
600  XWII_KEY_UP,
601  XWII_KEY_DOWN,
602  XWII_KEY_A,
603  XWII_KEY_B,
604  XWII_KEY_PLUS,
605  XWII_KEY_MINUS,
606  XWII_KEY_HOME,
607  XWII_KEY_ONE,
608  XWII_KEY_TWO,
609  XWII_KEY_X,
610  XWII_KEY_Y,
611  XWII_KEY_TL,
612  XWII_KEY_TR,
613  XWII_KEY_ZL,
614  XWII_KEY_ZR,
615 
624 
633 
642 
651 
658 
665 
672 
679 
686 
693 
700 
709 };
710 
718  unsigned int code;
720  unsigned int state;
721 };
722 
730  int32_t x;
731  int32_t y;
732  int32_t z;
733 };
734 
766 };
767 
769 #define XWII_ABS_NUM 8
770 
778  struct xwii_event_key key;
782  uint8_t reserved[128];
783 };
784 
794 struct xwii_event {
796  struct timeval time;
798  unsigned int type;
799 
801  union xwii_event_union v;
802 };
803 
812 static inline bool xwii_event_ir_is_valid(const struct xwii_event_abs *abs)
813 {
814  return abs->x != 1023 || abs->y != 1023;
815 }
816 
862 struct xwii_iface;
863 
873  XWII_IFACE_CORE = 0x000001,
875  XWII_IFACE_ACCEL = 0x000002,
877  XWII_IFACE_IR = 0x000004,
878 
882  XWII_IFACE_NUNCHUK = 0x000200,
890  XWII_IFACE_DRUMS = 0x002000,
892  XWII_IFACE_GUITAR = 0x004000,
893 
897  XWII_IFACE_IR |
907 };
908 
920 const char *xwii_get_iface_name(unsigned int iface);
921 
927 enum xwii_led {
928  XWII_LED1 = 1,
929  XWII_LED2 = 2,
930  XWII_LED3 = 3,
931  XWII_LED4 = 4,
932 };
933 
940 #define XWII_LED(num) (XWII_LED1 + (num) - 1)
941 
958 int xwii_iface_new(struct xwii_iface **dev, const char *syspath);
959 
965 void xwii_iface_ref(struct xwii_iface *dev);
966 
976 void xwii_iface_unref(struct xwii_iface *dev);
977 
989 const char *xwii_iface_get_syspath(struct xwii_iface *dev);
990 
1004 int xwii_iface_get_fd(struct xwii_iface *dev);
1005 
1021 int xwii_iface_watch(struct xwii_iface *dev, bool watch);
1022 
1044 int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces);
1045 
1054 void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces);
1055 
1069 unsigned int xwii_iface_opened(struct xwii_iface *dev);
1070 
1082 unsigned int xwii_iface_available(struct xwii_iface *dev);
1083 
1108 XWII__DEPRECATED
1109 int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev);
1110 
1139 int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev,
1140  size_t size);
1141 
1153 int xwii_iface_rumble(struct xwii_iface *dev, bool on);
1154 
1169 int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state);
1170 
1184 int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state);
1185 
1199 int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity);
1200 
1214 int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype);
1215 
1230 int xwii_iface_get_extension(struct xwii_iface *dev, char **extension);
1231 
1253 void xwii_iface_set_mp_normalization(struct xwii_iface *dev, int32_t x,
1254  int32_t y, int32_t z, int32_t factor);
1255 
1275 void xwii_iface_get_mp_normalization(struct xwii_iface *dev, int32_t *x,
1276  int32_t *y, int32_t *z, int32_t *factor);
1277 
1301 struct xwii_monitor;
1302 
1318 struct xwii_monitor *xwii_monitor_new(bool poll, bool direct);
1319 
1325 void xwii_monitor_ref(struct xwii_monitor *mon);
1326 
1334 void xwii_monitor_unref(struct xwii_monitor *mon);
1335 
1352 int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking);
1353 
1375 char *xwii_monitor_poll(struct xwii_monitor *monitor);
1376 
1379 #ifdef __cplusplus
1380 }
1381 #endif
1382 
1383 #endif /* XWII_XWIIMOTE_H */
int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state)
Read LED state.
const char * xwii_get_iface_name(unsigned int iface)
Return name of a given interface.
int xwii_iface_get_extension(struct xwii_iface *dev, char **extension)
Read extension type.
int xwii_iface_watch(struct xwii_iface *dev, bool watch)
Watch device for hotplug events.
int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces)
Open interfaces on this device.
int xwii_iface_rumble(struct xwii_iface *dev, bool on)
Toggle rumble motor.
int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype)
Read device type.
xwii_iface_type
Interfaces.
Definition: xwiimote.h:871
void xwii_iface_ref(struct xwii_iface *dev)
Increase ref-count by 1.
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.
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.
unsigned int xwii_iface_available(struct xwii_iface *dev)
Return bitmask of available interfaces.
int xwii_iface_new(struct xwii_iface **dev, const char *syspath)
Create new device object from syspath path.
int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev, size_t size)
Read incoming event-queue.
int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state)
Set LED state.
void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces)
Close interfaces on this device.
XWII__DEPRECATED int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev)
Read incoming event-queue.
const char * xwii_iface_get_syspath(struct xwii_iface *dev)
Return device syspath.
int xwii_iface_get_fd(struct xwii_iface *dev)
Return file-descriptor.
int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity)
Read battery state.
xwii_led
LEDs.
Definition: xwiimote.h:927
void xwii_iface_unref(struct xwii_iface *dev)
Decrease ref-count by 1.
unsigned int xwii_iface_opened(struct xwii_iface *dev)
Return bitmask of opened interfaces.
@ XWII_IFACE_CORE
Core interface.
Definition: xwiimote.h:873
@ XWII_IFACE_PRO_CONTROLLER
ProController extension interface.
Definition: xwiimote.h:888
@ XWII_IFACE_GUITAR
Guitar extension interface.
Definition: xwiimote.h:892
@ XWII_IFACE_BALANCE_BOARD
BalanceBoard extension interface.
Definition: xwiimote.h:886
@ XWII_IFACE_ALL
Special flag ORed with all valid interfaces.
Definition: xwiimote.h:895
@ XWII_IFACE_CLASSIC_CONTROLLER
ClassicController extension interface.
Definition: xwiimote.h:884
@ XWII_IFACE_DRUMS
Drums extension interface.
Definition: xwiimote.h:890
@ XWII_IFACE_MOTION_PLUS
MotionPlus extension interface.
Definition: xwiimote.h:880
@ XWII_IFACE_NUNCHUK
Nunchuk extension interface.
Definition: xwiimote.h:882
@ XWII_IFACE_WRITABLE
Special flag which causes the interfaces to be opened writable.
Definition: xwiimote.h:906
@ XWII_IFACE_IR
IR interface.
Definition: xwiimote.h:877
@ XWII_IFACE_ACCEL
Accelerometer interface.
Definition: xwiimote.h:875
xwii_event_keys
Key Event Identifiers.
Definition: xwiimote.h:597
#define XWII_ABS_NUM
Number of ABS values in an xwii_event_union.
Definition: xwiimote.h:769
xwii_event_types
Event Types.
Definition: xwiimote.h:377
xwii_drums_abs
Absolute Drum-Motion Indices.
Definition: xwiimote.h:747
@ XWII_KEY_THUMBR
Right thumb button.
Definition: xwiimote.h:632
@ XWII_KEY_STRUM_BAR_DOWN
Guitar Strum-bar-down event.
Definition: xwiimote.h:664
@ XWII_KEY_FRET_MID
Guitar Fret-Mid event.
Definition: xwiimote.h:685
@ XWII_KEY_FRET_UP
Guitar Fret-Up event.
Definition: xwiimote.h:678
@ XWII_KEY_Z
Extra Z button.
Definition: xwiimote.h:650
@ XWII_KEY_NUM
Number of key identifiers.
Definition: xwiimote.h:708
@ XWII_KEY_FRET_LOW
Guitar Fret-Low event.
Definition: xwiimote.h:692
@ XWII_KEY_FRET_FAR_LOW
Guitar Fret-Far-Low event.
Definition: xwiimote.h:699
@ XWII_KEY_C
Extra C button.
Definition: xwiimote.h:641
@ XWII_KEY_FRET_FAR_UP
Guitar Fret-Far-Up event.
Definition: xwiimote.h:671
@ XWII_KEY_THUMBL
Left thumb button.
Definition: xwiimote.h:623
@ XWII_KEY_STRUM_BAR_UP
Guitar Strum-bar-up event.
Definition: xwiimote.h:657
@ XWII_EVENT_GUITAR_MOVE
Guitar movement event.
Definition: xwiimote.h:561
@ XWII_EVENT_DRUMS_MOVE
Drums movement event.
Definition: xwiimote.h:539
@ XWII_EVENT_NUNCHUK_KEY
Nunchuk key event.
Definition: xwiimote.h:510
@ XWII_EVENT_KEY
Core-interface key event.
Definition: xwiimote.h:386
@ XWII_EVENT_PRO_CONTROLLER_KEY
Pro-Controller key event.
Definition: xwiimote.h:444
@ XWII_EVENT_NUM
Number of available event types.
Definition: xwiimote.h:580
@ XWII_EVENT_GONE
Removal Event.
Definition: xwiimote.h:572
@ XWII_EVENT_CLASSIC_CONTROLLER_KEY
Classic Controller key event.
Definition: xwiimote.h:485
@ XWII_EVENT_ACCEL
Accelerometer event.
Definition: xwiimote.h:397
@ XWII_EVENT_MOTION_PLUS
Motion-Plus event.
Definition: xwiimote.h:433
@ XWII_EVENT_NUNCHUK_MOVE
Nunchuk movement event.
Definition: xwiimote.h:520
@ XWII_EVENT_BALANCE_BOARD
Balance-Board event.
Definition: xwiimote.h:422
@ XWII_EVENT_PRO_CONTROLLER_MOVE
Pro-Controller movement event.
Definition: xwiimote.h:454
@ XWII_EVENT_WATCH
Hotplug Event.
Definition: xwiimote.h:473
@ XWII_EVENT_CLASSIC_CONTROLLER_MOVE
Classic Controller movement event.
Definition: xwiimote.h:499
@ XWII_EVENT_DRUMS_KEY
Drums key event.
Definition: xwiimote.h:529
@ XWII_EVENT_IR
IR-Camera event.
Definition: xwiimote.h:411
@ XWII_EVENT_GUITAR_KEY
Guitar key event.
Definition: xwiimote.h:550
@ XWII_DRUMS_ABS_BASS
Bass pressure, just X direction.
Definition: xwiimote.h:761
@ XWII_DRUMS_ABS_TOM_LEFT
Mid-left tom pressure, just X direction.
Definition: xwiimote.h:755
@ XWII_DRUMS_ABS_TOM_FAR_RIGHT
Right-most tom pressure, just X direction.
Definition: xwiimote.h:759
@ XWII_DRUMS_ABS_CYMBAL_RIGHT
Cymbal pressure, just X direction.
Definition: xwiimote.h:753
@ XWII_DRUMS_ABS_TOM_RIGHT
Mid-right tom pressure, just X direction.
Definition: xwiimote.h:757
@ XWII_DRUMS_ABS_CYMBAL_LEFT
Cymbal pressure, just X direction.
Definition: xwiimote.h:751
@ XWII_DRUMS_ABS_PAD
Control pad motion.
Definition: xwiimote.h:749
@ XWII_DRUMS_ABS_HI_HAT
Hi-Hat pressure, just X direction.
Definition: xwiimote.h:763
@ XWII_DRUMS_ABS_NUM
Number of drums payloads, may get increased for new ones.
Definition: xwiimote.h:765
void xwii_monitor_ref(struct xwii_monitor *mon)
Increase monitor ref-count by 1.
int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking)
Return internal fd.
void xwii_monitor_unref(struct xwii_monitor *mon)
Decrease monitor ref-count by 1.
struct xwii_monitor * xwii_monitor_new(bool poll, bool direct)
Create a new monitor.
char * xwii_monitor_poll(struct xwii_monitor *monitor)
Read incoming events.
Absolute Motion Payload.
Definition: xwiimote.h:729
Key Event Payload.
Definition: xwiimote.h:716
unsigned int state
key state copied from kernel (0: up, 1: down, 2: auto-repeat)
Definition: xwiimote.h:720
unsigned int code
key identifier defined as enum xwii_event_keys
Definition: xwiimote.h:718
Event Object.
Definition: xwiimote.h:794
union xwii_event_union v
data payload
Definition: xwiimote.h:801
struct timeval time
timestamp when this event was generated (copied from kernel)
Definition: xwiimote.h:796
unsigned int type
event type ref xwii_event_types
Definition: xwiimote.h:798
Event Payload.
Definition: xwiimote.h:776
struct xwii_event_key key
key event payload
Definition: xwiimote.h:778
uint8_t reserved[128]
reserved; do not use!
Definition: xwiimote.h:782
struct xwii_event_abs abs[XWII_ABS_NUM]
absolute motion event payload
Definition: xwiimote.h:780