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
17extern "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
315#define XWII_NAME_ACCEL XWII__NAME " Accelerometer"
317#define XWII_NAME_IR XWII__NAME " IR"
318
320#define XWII_NAME_MOTION_PLUS XWII__NAME " Motion Plus"
322#define XWII_NAME_NUNCHUK XWII__NAME " Nunchuk"
324#define XWII_NAME_CLASSIC_CONTROLLER XWII__NAME " Classic Controller"
326#define XWII_NAME_BALANCE_BOARD XWII__NAME " Balance Board"
328#define XWII_NAME_PRO_CONTROLLER XWII__NAME " Pro Controller"
329
361
372
386
397
408
419
429
445
454
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
496
505
515
523 unsigned int code;
525 unsigned int state;
526};
527
535 int32_t x;
536 int32_t y;
537 int32_t z;
538};
539
551 uint8_t reserved[128];
552};
553
565 struct timeval time;
567 unsigned int type;
568
571};
572
581static inline bool xwii_event_ir_is_valid(const struct xwii_event_abs *abs)
582{
583 return abs->x != 1023 || abs->y != 1023;
584}
585
631struct xwii_iface;
632
642 XWII_IFACE_CORE = 0x000001,
646 XWII_IFACE_IR = 0x000004,
647
658
670};
671
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
708int xwii_iface_new(struct xwii_iface **dev, const char *syspath);
709
715void xwii_iface_ref(struct xwii_iface *dev);
716
726void xwii_iface_unref(struct xwii_iface *dev);
727
741int xwii_iface_get_fd(struct xwii_iface *dev);
742
758int xwii_iface_watch(struct xwii_iface *dev, bool watch);
759
781int xwii_iface_open(struct xwii_iface *dev, unsigned int ifaces);
782
791void xwii_iface_close(struct xwii_iface *dev, unsigned int ifaces);
792
806unsigned int xwii_iface_opened(struct xwii_iface *dev);
807
819unsigned int xwii_iface_available(struct xwii_iface *dev);
820
845XWII__DEPRECATED
846int xwii_iface_poll(struct xwii_iface *dev, struct xwii_event *ev);
847
876int xwii_iface_dispatch(struct xwii_iface *dev, struct xwii_event *ev,
877 size_t size);
878
890int xwii_iface_rumble(struct xwii_iface *dev, bool on);
891
906int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state);
907
921int xwii_iface_set_led(struct xwii_iface *dev, unsigned int led, bool state);
922
936int xwii_iface_get_battery(struct xwii_iface *dev, uint8_t *capacity);
937
951int xwii_iface_get_devtype(struct xwii_iface *dev, char **devtype);
952
967int xwii_iface_get_extension(struct xwii_iface *dev, char **extension);
968
990void xwii_iface_set_mp_normalization(struct xwii_iface *dev, int32_t x,
991 int32_t y, int32_t z, int32_t factor);
992
1012void xwii_iface_get_mp_normalization(struct xwii_iface *dev, int32_t *x,
1013 int32_t *y, int32_t *z, int32_t *factor);
1014
1038struct xwii_monitor;
1039
1055struct xwii_monitor *xwii_monitor_new(bool poll, bool direct);
1056
1062void xwii_monitor_ref(struct xwii_monitor *mon);
1063
1071void xwii_monitor_unref(struct xwii_monitor *mon);
1072
1089int xwii_monitor_get_fd(struct xwii_monitor *monitor, bool blocking);
1090
1112char *xwii_monitor_poll(struct xwii_monitor *monitor);
1113
1116#ifdef __cplusplus
1117}
1118#endif
1119
1120#endif /* XWII_XWIIMOTE_H */
int xwii_iface_get_led(struct xwii_iface *dev, unsigned int led, bool *state)
Read LED state.
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:640
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.
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:677
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:642
@ XWII_IFACE_PRO_CONTROLLER
ProController extension interface.
Definition: xwiimote.h:657
@ XWII_IFACE_BALANCE_BOARD
BalanceBoard extension interface.
Definition: xwiimote.h:655
@ XWII_IFACE_ALL
Special flag ORed with all valid interfaces.
Definition: xwiimote.h:660
@ XWII_IFACE_CLASSIC_CONTROLLER
ClassicController extension interface.
Definition: xwiimote.h:653
@ XWII_IFACE_MOTION_PLUS
MotionPlus extension interface.
Definition: xwiimote.h:649
@ XWII_IFACE_NUNCHUK
Nunchuk extension interface.
Definition: xwiimote.h:651
@ XWII_IFACE_WRITABLE
Special flag which causes the interfaces to be opened writable.
Definition: xwiimote.h:669
@ XWII_IFACE_IR
IR interface.
Definition: xwiimote.h:646
@ XWII_IFACE_ACCEL
Accelerometer interface.
Definition: xwiimote.h:644
xwii_event_keys
Key Event Identifiers.
Definition: xwiimote.h:469
xwii_event_types
Event Types.
Definition: xwiimote.h:351
@ XWII_KEY_THUMBR
Right thumb button.
Definition: xwiimote.h:504
@ XWII_KEY_NUM
Number of key identifiers.
Definition: xwiimote.h:513
@ XWII_KEY_THUMBL
Left thumb button.
Definition: xwiimote.h:495
@ XWII_EVENT_KEY
Core-interface key event.
Definition: xwiimote.h:360
@ XWII_EVENT_PRO_CONTROLLER_KEY
Pro-Controller key event.
Definition: xwiimote.h:418
@ XWII_EVENT_NUM
Number of available event types.
Definition: xwiimote.h:452
@ XWII_EVENT_ACCEL
Accelerometer event.
Definition: xwiimote.h:371
@ XWII_EVENT_MOTION_PLUS
Motion-Plus event.
Definition: xwiimote.h:407
@ XWII_EVENT_BALANCE_BOARD
Balance-Board event.
Definition: xwiimote.h:396
@ XWII_EVENT_PRO_CONTROLLER_MOVE
Pro-Controller movement event.
Definition: xwiimote.h:428
@ XWII_EVENT_WATCH
Hotplug Event.
Definition: xwiimote.h:444
@ XWII_EVENT_IR
IR-Camera event.
Definition: xwiimote.h:385
void xwii_monitor_ref(struct xwii_monitor *mon)
Increase monitor ref-count by 1.
char * xwii_monitor_poll(struct xwii_monitor *monitor)
Read incoming events.
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.
Absolute Motion Payload.
Definition: xwiimote.h:534
Key Event Payload.
Definition: xwiimote.h:521
unsigned int state
key state copied from kernel (0: up, 1: down, 2: auto-repeat)
Definition: xwiimote.h:525
unsigned int code
key identifier defined as enum xwii_event_keys
Definition: xwiimote.h:523
Event Object.
Definition: xwiimote.h:563
union xwii_event_union v
data payload
Definition: xwiimote.h:570
struct timeval time
timestamp when this event was generated (copied from kernel)
Definition: xwiimote.h:565
unsigned int type
event type ref xwii_event_types
Definition: xwiimote.h:567
Event Payload.
Definition: xwiimote.h:545
struct xwii_event_abs abs[4]
absolute motion event payload
Definition: xwiimote.h:549
struct xwii_event_key key
key event payload
Definition: xwiimote.h:547
uint8_t reserved[128]
reserved; do not use!
Definition: xwiimote.h:551