PowerBlocks SDK
 
Loading...
Searching...
No Matches
wiimote.h
1
11
12#pragma once
13
16
18
19#include <stdbool.h>
20#include <stdint.h>
21
22// Flags of the present byte that show what
23// WiiMote data is present in the state.
24// Non present data will just hold its previous state.
25#define WIIMOTE_PRESENT_BUTTONS (1<<0)
26#define WIIMOTE_PRESENT_ACCELEROMETER (1<<1)
27#define WIIMOTE_PRESENT_IR (1<<2)
28#define WIIMOTE_PRESENT_IR_EXTENDED (1<<3)
29#define WIIMOTE_PRESENT_IR_FULL (1<<4)
30#define WIIMOTE_PRESENT_EXTENSION (1<<5)
31#define WIIMOTE_PRESENT_INTERLACED (1<<6) // This signals the data was collected using interlaced input packets
32
33#define WIIMOTE_BUTTONS_DPAD_LEFT (1<<0)
34#define WIIMOTE_BUTTONS_DPAD_RIGHT (1<<1)
35#define WIIMOTE_BUTTONS_DPAD_DOWN (1<<2)
36#define WIIMOTE_BUTTONS_DPAD_UP (1<<3)
37#define WIIMOTE_BUTTONS_PLUS (1<<4)
38#define WIIMOTE_BUTTONS_TWO (1<<8)
39#define WIIMOTE_BUTTONS_ONE (1<<9)
40#define WIIMOTE_BUTTONS_B (1<<10)
41#define WIIMOTE_BUTTONS_A (1<<11)
42#define WIIMOTE_BUTTONS_MINUS (1<<12)
43#define WIIMOTE_BUTTONS_HOME (1<<15)
44
45// Max remotes that can be connected.
46#define WIIMOTE_MAX_REMOTES 4
47
48typedef struct {
49 // True if this wiimote has been connected.
50 void *driver;
51
52 // Holds what kind of data is present.
53 uint32_t present;
54
55 // Include the "Core Buttons" of the wiimote. The ones on the remote itself
56 wiimote_buttons buttons;
57
58 // Accelerometer Data + rotation. Updated if accelerometer is enabled.
59 struct {
60 vec3 rectangular; // X, Y, Z values of acceleration
61 vec3 spherical; // p, theta, phi of acceleration. Similar to magnitude,
62 vec3 orientation; // Like spherical, but only updated when the force is ~1 G, i.e. last usable oriantation before accelerating.
63 } accelerometer;
64
65 // IR Data
66 // Up to 4 IR points tracked. If more than 4 it will switch between them.
67 struct {
68 // Included in all IR modes, 10 bit unsigned
69 bool visible;
70 bool side; // Side of the sensor bar it is on. 0=left, 1=right
71 vec2i position;
72
73 // Included in extended and full mode. Size 0-15
74 int size;
75
76 // Bounding Box, and intensity of point. Included only in full mode.
77 vec2i bbox_top_left;
78 vec2i bbox_bottom_right;
79 uint8_t intensity;
80 } ir_tracking[4];
81
82 // Cursor position, calculated from IR tracking if enabled.
83 // Pixel position on screen. Can extend off screen.
84 struct {
85 vec2i pos;
86 float distance; // distance from dot to dot
87 float z; // Similar to the wiiuse one. Just 1023 - distance
88 float yaw;
89
90 int known_dots; // Dots seen up until loosing tracking.
91 } cursor;
92
93 wiimote_extension_data_t extensions;
94} wiimote_t;
95
96extern wiimote_t WIIMOTES[WIIMOTE_MAX_REMOTES];
97
98// Initializes motes and registers drivers.
99// Bluetooth must be initialized
100// IOS Settings must be initialized
101extern void wiimotes_initialize();
102
103extern void wiimote_poll();
104
105// Get the next empty slot
106// -1 if not slot
107extern int wiimote_find_empty_slot();
108
109// Sets what data the wiimote will report
110// Same thing as the "present" stuff
111extern int wiimote_set_reporting(wiimote_t* wiimote, int present);
Definition vec2.h:17
Definition vec3.h:16
Definition wiimote_extension.h:54
Definition wiimote_extension.h:61
Definition wiimote.h:48
Simple 2D vectors.
Simple 3D vectors.
Handles wiimote extensions.