wiiuse
dynamics.h
Go to the documentation of this file.
1 /*
2  * wiiuse
3  *
4  * Written By:
5  * Michael Laforest < para >
6  * Email: < thepara (--AT--) g m a i l [--DOT--] com >
7  *
8  * Copyright 2006-2007
9  *
10  * This file is part of wiiuse.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  * $Header$
26  *
27  */
28 
38 #ifndef DYNAMICS_H_INCLUDED
39 #define DYNAMICS_H_INCLUDED
40 
41 #include "wiiuse_internal.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
50 /* Extra precision bits the Wii Remote's accelerometer has per axis (10-bit X / 9-bit Y / 9-bit Z);
51  * always defined, unlike the shifts below. */
52 #define WIIMOTE_ACCEL_XBITS 2
53 #define WIIMOTE_ACCEL_YBITS 1
54 #define WIIMOTE_ACCEL_ZBITS 1
55 
56 /*
57  * Per-axis shift calculate_orientation()/calculate_gforce() apply to the
58  * 8-bit calibration data (accel_t.cal_zero/cal_g) to bring it up to the
59  * same scale as the raw accel value they're compared against. Differs
60  * per device: the Wiimote is a 10-bit X / 9-bit Y / 9-bit Z split, the
61  * Nunchuk is a full 10 bits on every axis - matching each decode site
62  * (handle_wm_accel(), nunchuk_event()).
63  *
64  * Under WIIUSE_ACCEL_10BIT the shift is the decode width above;
65  * without it raw accel is a plain byte and the shift collapses to 0, so
66  * callers (including the accel_threshold comparison in events.c) reduce
67  * to byte-only arithmetic.
68  *
69  * The Wii Remote's own calibration also gets its real EEPROM extra bits
70  * ORed in by wiiuse_scale_calibration(); other sources are zero-padded.
71  */
72 #ifdef WIIUSE_ACCEL_10BIT
73 #define WIIMOTE_ACCEL_XSHIFT WIIMOTE_ACCEL_XBITS
74 #define WIIMOTE_ACCEL_YSHIFT WIIMOTE_ACCEL_YBITS
75 #define WIIMOTE_ACCEL_ZSHIFT WIIMOTE_ACCEL_ZBITS
76 
77 #define NUNCHUK_ACCEL_XSHIFT 2
78 #define NUNCHUK_ACCEL_YSHIFT 2
79 #define NUNCHUK_ACCEL_ZSHIFT 2
80 #else
81 #define WIIMOTE_ACCEL_XSHIFT 0
82 #define WIIMOTE_ACCEL_YSHIFT 0
83 #define WIIMOTE_ACCEL_ZSHIFT 0
84 
85 #define NUNCHUK_ACCEL_XSHIFT 0
86 #define NUNCHUK_ACCEL_YSHIFT 0
87 #define NUNCHUK_ACCEL_ZSHIFT 0
88 #endif
89 
90 /* The Motion+ Nunchuk-passthrough path (motion_plus.c) never decodes
91  * extra precision bits, so it must never be shifted either, regardless
92  * of WIIUSE_ACCEL_10BIT. */
93 #define NUNCHUK_PASSTHROUGH_ACCEL_XSHIFT 0
94 #define NUNCHUK_PASSTHROUGH_ACCEL_YSHIFT 0
95 #define NUNCHUK_PASSTHROUGH_ACCEL_ZSHIFT 0
96 
97 struct vec3i_t
98 {
99  int x, y, z;
100 };
101 
102 /* Test seam: un-static'd so tests can exercise the real scaling. */
103 struct vec3i_t wiiuse_scale_calibration(const struct vec3b_t *cal, const struct vec3b_t *cal_lsb, int accel_xshift,
104  int accel_yshift, int accel_zshift);
105 void calculate_orientation(struct accel_t *ac, struct vec3w_t *accel, struct orient_t *orient, int smooth,
106  int accel_xshift, int accel_yshift, int accel_zshift);
107 void calculate_gforce(struct accel_t *ac, struct vec3w_t *accel, struct gforce_t *gforce, int accel_xshift,
108  int accel_yshift, int accel_zshift);
109 void calc_joystick_state(struct joystick_t *js, float x, float y);
110 void apply_smoothing(struct accel_t *ac, struct orient_t *orient, int type);
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* DYNAMICS_H_INCLUDED */
void calc_joystick_state(struct joystick_t *js, float x, float y)
Calculate the angle and magnitude of a joystick.
Definition: dynamics.c:219
Definition: dynamics.h:97
Accelerometer struct.
Definition: wiiuse.h:477
General internal wiiuse stuff.
void calculate_gforce(struct accel_t *ac, struct vec3w_t *accel, struct gforce_t *gforce, int accel_xshift, int accel_yshift, int accel_zshift)
Calculate the gravity forces on each axis.
Definition: dynamics.c:187
Unsigned x,y,z 16-bit vector.
Definition: wiiuse.h:446
Gravity force struct.
Definition: wiiuse.h:469
Orientation struct.
Definition: wiiuse.h:456
void calculate_orientation(struct accel_t *ac, struct vec3w_t *accel, struct orient_t *orient, int smooth, int accel_xshift, int accel_yshift, int accel_zshift)
Calculate the roll, pitch, yaw.
Definition: dynamics.c:102
Joystick calibration structure.
Definition: wiiuse.h:560