forked from JRogaishio/WiimoteEmulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiimote.h
174 lines (144 loc) · 3.45 KB
/
wiimote.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef WIIMOTE_H
#define WIIMOTE_H
#include <stdint.h>
#include <stdbool.h>
#include "wm_crypto.h"
enum wiimote_connected_extension_type
{
Nunchuk = 0x0,
Classic = 0x1,
BalanceBoard = 0x2,
NoExtension = 0xff
};
struct wiimote_ir_object
{
uint16_t x;
uint16_t y;
uint8_t size;
uint8_t xmin;
uint8_t ymin;
uint8_t xmax;
uint8_t ymax;
uint8_t intensity;
};
struct wiimote_nunchuk
{
uint16_t accel_x;
uint16_t accel_y;
uint16_t accel_z;
uint8_t x;
uint8_t y;
bool c;
bool z;
};
struct wiimote_classic
{
bool a;
bool b;
bool x;
bool y;
bool minus;
bool plus;
bool rtrigger;
bool ltrigger;
bool home;
bool rz;
bool lz;
bool up;
bool down;
bool left;
bool right;
uint8_t ls_x;
uint8_t ls_y;
uint8_t rs_x;
uint8_t rs_y;
uint8_t lt;
uint8_t rt;
};
struct wiimote_motionplus
{
uint16_t yaw_down;
uint16_t roll_left;
uint16_t pitch_left;
bool yaw_slow;
bool roll_slow;
bool pitch_slow;
};
struct wiimote_state_usr
{
bool a;
bool b;
bool minus;
bool plus;
bool home;
bool one;
bool two;
bool up;
bool down;
bool left;
bool right;
//special buttons
bool sync;
bool power;
//accelerometer (10 bit range)
//0 acceleration is approximately 0x200
uint16_t accel_x;
uint16_t accel_y;
uint16_t accel_z;
struct wiimote_ir_object ir_object[4];
enum wiimote_connected_extension_type connected_extension_type;
struct wiimote_nunchuk nunchuk;
struct wiimote_classic classic;
struct wiimote_motionplus motionplus;
};
void reset_ir_object(struct wiimote_ir_object * object);
void reset_input_ir(struct wiimote_ir_object ir_object[4]);
void reset_input_nunchuk(struct wiimote_nunchuk * nunchuk);
void reset_input_classic(struct wiimote_classic * classic);
void reset_input_motionplus(struct wiimote_motionplus * motionplus);
struct wiimote_state_sys
{
bool led_1;
bool led_2;
bool led_3;
bool led_4;
bool rumble;
bool ircam_enabled;
bool speaker_enabled;
uint8_t battery_level;
bool low_battery;
int extension_hotplug_timer;
bool extension_connected;
enum wiimote_connected_extension_type connected_extension_type;
struct ext_crypto_state extension_crypto_state;
bool extension_report;
bool extension_encrypted;
uint8_t extension_report_type;
uint8_t extension_type;
uint8_t wmp_state; //0 inactive, 1 active, 2 deactivated
uint8_t reporting_mode;
bool reporting_continuous;
bool report_changed;
struct queued_report * queue;
struct queued_report * queue_end;
uint8_t register_a2[10]; //speaker
uint8_t register_a4[256]; //extension
uint8_t register_a6[256]; //wii motion plus
uint8_t register_b0[52]; //ir camera
};
struct wiimote_state
{
struct wiimote_state_sys sys;
struct wiimote_state_usr usr;
};
void wiimote_init(struct wiimote_state *state);
void wiimote_destroy(struct wiimote_state *state);
void wiimote_reset(struct wiimote_state *state);
int process_report(struct wiimote_state *state, const uint8_t *buf, int len);
int generate_report(struct wiimote_state * state, uint8_t * buf);
void read_eeprom(struct wiimote_state * state, uint32_t offset, uint16_t size);
void write_eeprom(struct wiimote_state * state, uint32_t offset, uint8_t size, const uint8_t * buf);
void read_register(struct wiimote_state *state, uint32_t offset, uint16_t size);
void write_register(struct wiimote_state *state, uint32_t offset, uint8_t size, const uint8_t * buf);
void init_extension(struct wiimote_state *state);
#endif //WIIMOTE_H