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
336 
337 #define XWII_NAME_ACCEL XWII__NAME " Accelerometer"
338 
339 #define XWII_NAME_IR XWII__NAME " IR"
340 
342 #define XWII_NAME_MOTION_PLUS XWII__NAME " Motion Plus"
343 
344 #define XWII_NAME_NUNCHUK XWII__NAME " Nunchuk"
345 
346 #define XWII_NAME_CLASSIC_CONTROLLER XWII__NAME " Classic Controller"
347 
348 #define XWII_NAME_BALANCE_BOARD XWII__NAME " Balance Board"
349 
350 #define XWII_NAME_PRO_CONTROLLER XWII__NAME " Pro Controller"
351 
352 #define XWII_NAME_DRUMS XWII__NAME " Drums"
353 
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 
782  uint8_t reserved[128];
783 };
784 
794 struct xwii_event {
796  struct timeval time;
798  unsigned int type;
799 
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_extension(struct xwii_iface *dev, char **extension)
Read extension type.
void xwii_monitor_ref(struct xwii_monitor *mon)
Increase monitor ref-count by 1.
Right thumb button.
Definition: xwiimote.h:632
int xwii_iface_watch(struct xwii_iface *dev, bool watch)
Watch device for hotplug events.
union xwii_event_union v
data payload
Definition: xwiimote.h:801
Hotplug Event.
Definition: xwiimote.h:473
unsigned int state
key state copied from kernel (0: up, 1: down, 2: auto-repeat)
Definition: xwiimote.h:720
Number of drums payloads, may get increased for new ones.
Definition: xwiimote.h:765
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.
unsigned int xwii_iface_available(struct xwii_iface *dev)
Return bitmask of available interfaces.
Bass pressure, just X direction.
Definition: xwiimote.h:761
Drums extension interface.
Definition: xwiimote.h:890
Guitar Strum-bar-down event.
Definition: xwiimote.h:664
int xwii_iface_new(struct xwii_iface **dev, const char *syspath)
Create new device object from syspath path.
Right-most tom pressure, just X direction.
Definition: xwiimote.h:759
xwii_event_types
Event Types.
Definition: xwiimote.h:377
Event Payload.
Definition: xwiimote.h:776
XWII__DEPRECATED int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev)
Read incoming event-queue.
Drums movement event.
Definition: xwiimote.h:539
int xwii_iface_get_fd(struct xwii_iface *dev)
Return file-descriptor.
const char * xwii_iface_get_syspath(struct xwii_iface *dev)
Return device syspath.
Number of key identifiers.
Definition: xwiimote.h:708
struct xwii_monitor * xwii_monitor_new(bool poll, bool direct)
Create a new monitor.
Removal Event.
Definition: xwiimote.h:572
Guitar Strum-bar-up event.
Definition: xwiimote.h:657
Event Object.
Definition: xwiimote.h:794
Number of available event types.
Definition: xwiimote.h:580
void xwii_iface_ref(struct xwii_iface *dev)
Increase ref-count by 1.
char * xwii_monitor_poll(struct xwii_monitor *monitor)
Read incoming events.
xwii_iface_type
Interfaces.
Definition: xwiimote.h:871
Extra Z button.
Definition: xwiimote.h:650
Drums key event.
Definition: xwiimote.h:529
Nunchuk movement event.
Definition: xwiimote.h:520
struct timeval time
timestamp when this event was generated (copied from kernel)
Definition: xwiimote.h:796
Guitar Fret-Low event.
Definition: xwiimote.h:692
int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state)
Read LED state.
IR-Camera event.
Definition: xwiimote.h:411
Guitar key event.
Definition: xwiimote.h:550
Mid-left tom pressure, just X direction.
Definition: xwiimote.h:755
Nunchuk key event.
Definition: xwiimote.h:510
unsigned int code
key identifier defined as enum xwii_event_keys
Definition: xwiimote.h:718
Core interface.
Definition: xwiimote.h:873
int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype)
Read device type.
Accelerometer event.
Definition: xwiimote.h:397
uint8_t reserved[128]
reserved; do not use!
Definition: xwiimote.h:782
const char * xwii_get_iface_name(unsigned int iface)
Return name of a given interface.
Cymbal pressure, just X direction.
Definition: xwiimote.h:753
Left thumb button.
Definition: xwiimote.h:623
Guitar movement event.
Definition: xwiimote.h:561
Guitar Fret-Far-Low event.
Definition: xwiimote.h:699
int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state)
Set LED state.
Classic Controller key event.
Definition: xwiimote.h:485
int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity)
Read battery state.
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.
MotionPlus extension interface.
Definition: xwiimote.h:880
xwii_drums_abs
Absolute Drum-Motion Indices.
Definition: xwiimote.h:747
Special flag ORed with all valid interfaces.
Definition: xwiimote.h:895
Core-interface key event.
Definition: xwiimote.h:386
Pro-Controller movement event.
Definition: xwiimote.h:454
xwii_event_keys
Key Event Identifiers.
Definition: xwiimote.h:597
Guitar extension interface.
Definition: xwiimote.h:892
unsigned int type
event type ref xwii_event_types
Definition: xwiimote.h:798
Accelerometer interface.
Definition: xwiimote.h:875
int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces)
Open interfaces on this device.
Nunchuk extension interface.
Definition: xwiimote.h:882
Guitar Fret-Mid event.
Definition: xwiimote.h:685
Guitar Fret-Up event.
Definition: xwiimote.h:678
#define XWII_ABS_NUM
Number of ABS values in an xwii_event_union.
Definition: xwiimote.h:769
IR interface.
Definition: xwiimote.h:877
int xwii_iface_rumble(struct xwii_iface *dev, bool on)
Toggle rumble motor.
Hi-Hat pressure, just X direction.
Definition: xwiimote.h:763
ClassicController extension interface.
Definition: xwiimote.h:884
Cymbal pressure, just X direction.
Definition: xwiimote.h:751
Classic Controller movement event.
Definition: xwiimote.h:499
void xwii_monitor_unref(struct xwii_monitor *mon)
Decrease monitor ref-count by 1.
BalanceBoard extension interface.
Definition: xwiimote.h:886
ProController extension interface.
Definition: xwiimote.h:888
struct xwii_event_abs abs[XWII_ABS_NUM]
absolute motion event payload
Definition: xwiimote.h:780
Balance-Board event.
Definition: xwiimote.h:422
Key Event Payload.
Definition: xwiimote.h:716
void xwii_iface_unref(struct xwii_iface *dev)
Decrease ref-count by 1.
xwii_led
LEDs.
Definition: xwiimote.h:927
Mid-right tom pressure, just X direction.
Definition: xwiimote.h:757
unsigned int xwii_iface_opened(struct xwii_iface *dev)
Return bitmask of opened interfaces.
Motion-Plus event.
Definition: xwiimote.h:433
struct xwii_event_key key
key event payload
Definition: xwiimote.h:778
Special flag which causes the interfaces to be opened writable.
Definition: xwiimote.h:906
void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces)
Close interfaces on this device.
Control pad motion.
Definition: xwiimote.h:749
Pro-Controller key event.
Definition: xwiimote.h:444
int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking)
Return internal fd.
Extra C button.
Definition: xwiimote.h:641
int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev, size_t size)
Read incoming event-queue.
Absolute Motion Payload.
Definition: xwiimote.h:729
Guitar Fret-Far-Up event.
Definition: xwiimote.h:671