WIP: checkpoint Wii native IMU and upstream IR bridge
Pause Wii pointing work with firmware 0.33-wii-trace installed. Preserve the pinned libogc IR pipeline, calibrated native IMU, software BOOTSEL, and standard camera sensitivity trial. Tracking instability, tracking loss, and ineffective vertical movement remain unresolved. Level-2 camera filtering is not hardware-qualified. Nine targeted regression tests pass; firmware and persistent storage were verified after flashing.
This commit is contained in:
parent
3040c9d294
commit
9f6dddb790
41 changed files with 7990 additions and 150 deletions
76
external/libogc_ir/NOTICE.txt
vendored
Normal file
76
external/libogc_ir/NOTICE.txt
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
libogc Wiiuse IR math component port
|
||||
|
||||
Upstream: https://github.com/devkitPro/libogc
|
||||
Pinned commit: a4064a86487c46d8ab76d4fdf99e8059a62c4fa2
|
||||
Modified for switch-pico on 2026-09-11.
|
||||
|
||||
This directory is a source extraction from the Wiiuse component of libogc,
|
||||
not an independent reimplementation and not a copy of ordinary Wiiuse from
|
||||
another repository. Original sources in upstream/ are byte-for-byte copies
|
||||
from the pin; UPSTREAM.json records their URLs, checksums and retained ranges.
|
||||
|
||||
LICENSE AND ATTRIBUTION
|
||||
|
||||
The full, unchanged wiiuse/license_libogc.txt from that libogc revision is
|
||||
provided here as license_libogc.txt. It contains GNU GPL version 3 plus the
|
||||
section 18 exception for linking with independent modules. The opening scope
|
||||
restriction (libogc and its covered or combined works) is retained. This is a
|
||||
modified port of that libogc component; we explicitly extend and retain the
|
||||
section 18 linking exception for this version, including the portable header
|
||||
and generated IR translation unit. This component is not offered under MIT.
|
||||
The surrounding independent switch-pico project is not relicensed.
|
||||
|
||||
Section 18 permits linking this library with independent modules under their
|
||||
own licenses and distributing the executable under terms of your choice,
|
||||
provided each independent module's license is satisfied. An independent
|
||||
module is not derived from or based on this library. The exception does not
|
||||
remove the GPL obligations for this component itself, including provision of
|
||||
its corresponding source when distributing it in object-code form. The
|
||||
original component, extraction script and portable header are supplied in
|
||||
source form. Recipients should retain these notices and the full license.
|
||||
|
||||
The original Wiiuse notice in upstream/wiiuse_internal.h credits Michael
|
||||
Laforest, copyright 2006-2007, grants GPL version 3 or later, and disclaims
|
||||
warranty. It is retained intact in that file, the portable header, and the
|
||||
generated C. There is no copyright/license preamble in the pinned ir.c,
|
||||
ir.h, definitions.h or gc/wiiuse/wiiuse.h; none has been invented for them.
|
||||
|
||||
The root libogc notice is preserved verbatim as libogc_license.txt. It credits
|
||||
Michael Wiedenbauer (shagkur) and Dave Murphy (WinterMute), copyright 2004-2009,
|
||||
and grants permission subject to origin, altered-source marking and notice
|
||||
retention restrictions. This root notice does not replace the Wiiuse-specific
|
||||
GPL plus exception. There is no root LICENSE file at the pinned revision;
|
||||
UPSTREAM.json records the failed LICENSE URL and the actual pinned root file.
|
||||
|
||||
EXACT PORTABILITY CHANGES
|
||||
|
||||
1. Keep upstream/ir.c untouched. tools/prepare_libogc_ir.py selects the exact
|
||||
declared byte-preserving line ranges rather than rewriting any algorithm.
|
||||
No function body, algorithm constant, comparison, arithmetic expression or
|
||||
math-library call in the retained functions is changed.
|
||||
2. Omit transport, report decoding, device setup and platform includes. No
|
||||
unused transport function is compiled, and no fake Wiiuse I/O implementation
|
||||
is supplied. The caller supplies decoded dots and orientation.
|
||||
3. Supply a narrow C/C++ header instead of the Bluetooth/GEKKO headers. Keep
|
||||
the original ubyte, orient_t, ir_dot_t, fdot_t, sb_t, aspect_t, ir_position_t
|
||||
and ir_t declarations verbatim; supply the platform primitive f32 as float.
|
||||
Copy the original anonymous IR state enum and original aspect-size macros
|
||||
into this header. Add a unique include guard, C linkage and declarations
|
||||
for the two already-external functions find_sensorbar/apply_ir_smoothing.
|
||||
Retain the original calc_yaw/interpret_ir_data declarations.
|
||||
4. Generated C starts with #include "libogc_ir/ir.h", includes standard math.h,
|
||||
and copies the original PI/angle conversion macros. The original disabled
|
||||
WIIUSE_DEBUG(fmt, ...) definition is retained, then redefined as
|
||||
WIIUSE_DEBUG(...) with the same empty expansion. This makes one-argument
|
||||
debug calls valid strict C11 without enabling logging, changing call sites,
|
||||
suppressing compiler warnings, or modifying algorithm bodies/constants.
|
||||
5. Add dated modification/license comments, blank separators and #line
|
||||
directives around unchanged source sections. File names in those directives
|
||||
are repository-relative, so output is independent of the build directory.
|
||||
The extraction has no runtime dependency on Python or the filesystem.
|
||||
|
||||
The native relative-output adapter is separate from these upstream math
|
||||
functions. It handles camera coordinate conventions, gravity units, camera
|
||||
sequence consumption, configurable relative scale and USB delta baselines.
|
||||
Those adaptations are not changes to the algorithm in this directory and do
|
||||
not provide absolute host cursor synchronization.
|
||||
326
external/libogc_ir/UPSTREAM.json
vendored
Normal file
326
external/libogc_ir/UPSTREAM.json
vendored
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
{
|
||||
"format_version": 1,
|
||||
"repository": "https://github.com/devkitPro/libogc",
|
||||
"commit": "a4064a86487c46d8ab76d4fdf99e8059a62c4fa2",
|
||||
"modified_date": "2026-09-11",
|
||||
"ir_git_blob_sha1": "d9659f5da575861f574d3d0480887955ef8f8faf",
|
||||
"sources": {
|
||||
"wiiuse/ir.c": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/wiiuse/ir.c",
|
||||
"local_path": "upstream/ir.c",
|
||||
"sha256": "12b3a21bcbe92fa2ae3ba262ff4bff94f385978062b7f33f65956e11ec4c2ff2",
|
||||
"git_blob_sha1": "d9659f5da575861f574d3d0480887955ef8f8faf",
|
||||
"bytes": 23568,
|
||||
"lines": 834
|
||||
},
|
||||
"gc/wiiuse/wiiuse.h": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/gc/wiiuse/wiiuse.h",
|
||||
"local_path": "upstream/wiiuse.h",
|
||||
"sha256": "21f890f417d3504999175692860f8994038c9127936f872d63405f2824e2c8d5",
|
||||
"git_blob_sha1": "7be2a7d9e9cc4b506516b73a659b52feb59d507b",
|
||||
"bytes": 22507,
|
||||
"lines": 748
|
||||
},
|
||||
"wiiuse/wiiuse_internal.h": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/wiiuse/wiiuse_internal.h",
|
||||
"local_path": "upstream/wiiuse_internal.h",
|
||||
"sha256": "ea2485eb06e4423b7f1ddd584e4c1157aeb0cf79212c74c2bb93bef1afa7be3e",
|
||||
"git_blob_sha1": "ade44da594289d79c4c9769f1f871198df09144e",
|
||||
"bytes": 8678,
|
||||
"lines": 277
|
||||
},
|
||||
"wiiuse/definitions.h": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/wiiuse/definitions.h",
|
||||
"local_path": "upstream/definitions.h",
|
||||
"sha256": "a625020c657d2369ea99e2044aa4298ba92e3bfb9d7a5801eb4b2ca0ff20bb90",
|
||||
"git_blob_sha1": "04dc5be6d8437ac4e3ab9f923610246ab1f8b95e",
|
||||
"bytes": 1680,
|
||||
"lines": 55
|
||||
},
|
||||
"wiiuse/ir.h": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/wiiuse/ir.h",
|
||||
"local_path": "upstream/ir.h",
|
||||
"sha256": "4fd4009c1b4c81d8b121f233693bd4248d567ce641d19f2fb2bcd60a85f9f9e1",
|
||||
"git_blob_sha1": "f90cfc89c53167bb494a090024fd0698c0f0cbdd",
|
||||
"bytes": 413,
|
||||
"lines": 22
|
||||
},
|
||||
"wiiuse/license_libogc.txt": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/wiiuse/license_libogc.txt",
|
||||
"local_path": "license_libogc.txt",
|
||||
"sha256": "6bbd4837fe3fd232883e27c606cce94f17aa4fd23a9f981c68149e4ec4c7cae1",
|
||||
"git_blob_sha1": "a149fce1ce2915d22fc30eda8e691607d21335b4",
|
||||
"bytes": 33495,
|
||||
"lines": 641
|
||||
},
|
||||
"libogc_license.txt": {
|
||||
"url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/libogc_license.txt",
|
||||
"local_path": "libogc_license.txt",
|
||||
"sha256": "8be3bc1cad868fae35498ce049c60b4263e57184a7d23df99ea1f7ba2d338a2f",
|
||||
"git_blob_sha1": "a3dfd0581becdeaea787614ec3ed6b75287164b3",
|
||||
"bytes": 942,
|
||||
"lines": 20
|
||||
}
|
||||
},
|
||||
"root_license_lookup": {
|
||||
"requested_url": "https://raw.githubusercontent.com/devkitPro/libogc/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2/LICENSE",
|
||||
"status": "HTTP 404: no LICENSE entry in the pinned root tree",
|
||||
"tree_url": "https://api.github.com/repos/devkitPro/libogc/git/trees/a4064a86487c46d8ab76d4fdf99e8059a62c4fa2",
|
||||
"actual_source": "libogc_license.txt"
|
||||
},
|
||||
"license": {
|
||||
"component_license": "GNU GPL version 3 with libogc section 18 independent-module linking exception",
|
||||
"upstream_internal_header_notice": "Michael Laforest, Copyright 2006-2007; GNU GPL version 3 or (at your option) any later version; no warranty",
|
||||
"exception_extended_to_this_modified_component": true,
|
||||
"full_component_license": "license_libogc.txt",
|
||||
"full_root_notice": "libogc_license.txt",
|
||||
"modification_notice": "NOTICE.txt",
|
||||
"project_relicensed": false,
|
||||
"inputs": "Only this pinned devkitPro/libogc component; no ordinary Wiiuse GPL-only repository inputs"
|
||||
},
|
||||
"extraction": {
|
||||
"line_numbering": "1-based inclusive; bytes split with keepends=True, no newline or whitespace normalization",
|
||||
"c_sections": [
|
||||
{
|
||||
"source": "wiiuse/wiiuse_internal.h",
|
||||
"first_line": 1,
|
||||
"last_line": 27,
|
||||
"first_line_text": "/*",
|
||||
"last_line_text": " */",
|
||||
"sha256": "e78f559543e0d48e5f54d5316c55c98520e583ff16f0b9fecd2bb65efc3a97e9",
|
||||
"purpose": "Wiiuse copyright, GPLv3-or-later and warranty notice"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/definitions.h",
|
||||
"first_line": 6,
|
||||
"last_line": 6,
|
||||
"first_line_text": "#define WIIMOTE_PI\t\t\t3.14159265f",
|
||||
"last_line_text": "#define WIIMOTE_PI\t\t\t3.14159265f",
|
||||
"sha256": "3c8132e59374a2aa64f38839677a5eda20286d0488f4b989ff2d60a00d15a501",
|
||||
"purpose": "WIIMOTE_PI"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/definitions.h",
|
||||
"first_line": 31,
|
||||
"last_line": 31,
|
||||
"first_line_text": "\t#define WIIUSE_DEBUG(fmt, ...)",
|
||||
"last_line_text": "\t#define WIIUSE_DEBUG(fmt, ...)",
|
||||
"sha256": "3eb11daa6ec4902683edfbebb54fdad73cf2f4c3933f69dbc9b247f579206283",
|
||||
"purpose": "upstream disabled WIIUSE_DEBUG definition"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/definitions.h",
|
||||
"first_line": 44,
|
||||
"last_line": 46,
|
||||
"first_line_text": "/* Convert between radians and degrees */",
|
||||
"last_line_text": "#define DEGREE_TO_RAD(d)\t(d * (WIIMOTE_PI / 180.0f))",
|
||||
"sha256": "87d7ef0bdfb09bc9f8be97e6938bb3cd0cd48836114aa398e6152fffb05c5739",
|
||||
"purpose": "RAD_TO_DEGREE, DEGREE_TO_RAD"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 15,
|
||||
"last_line": 16,
|
||||
"first_line_text": "static int ir_correct_for_bounds(float* x, float* y, enum aspect_t aspect, int offset_x, int offset_y);",
|
||||
"last_line_text": "static void ir_convert_to_vres(float* x, float* y, enum aspect_t aspect, unsigned int vx, unsigned int vy);",
|
||||
"sha256": "c20c25c89c31d8bddd6a885163d9c91e351e71c218731efb54af55a5edaec2e7",
|
||||
"purpose": "original private helper prototypes"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 55,
|
||||
"last_line": 144,
|
||||
"first_line_text": "static void rotate_dots(struct fdot_t* in, struct fdot_t *out, int count, float ang) {",
|
||||
"last_line_text": "}",
|
||||
"sha256": "cd6b24d0cb478cdc61270a45a7410a614ac6678c821a91e1ad9cac9d3809fac2",
|
||||
"purpose": "rotate_dots, ir_correct_for_bounds, ir_convert_to_vres"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 438,
|
||||
"last_line": 833,
|
||||
"first_line_text": "// half-height of the IR sensor if half-width is 1",
|
||||
"last_line_text": "}",
|
||||
"sha256": "2e8465a163a1d35a1781136d1078d3532b75995cb07cedfb96e9759daca5e7c2",
|
||||
"purpose": "all sensorbar, smoothing and interpretation constants; find_sensorbar, apply_ir_smoothing, interpret_ir_data, calc_yaw"
|
||||
}
|
||||
],
|
||||
"header_sections": [
|
||||
{
|
||||
"source": "wiiuse/wiiuse_internal.h",
|
||||
"first_line": 1,
|
||||
"last_line": 27,
|
||||
"first_line_text": "/*",
|
||||
"last_line_text": " */",
|
||||
"sha256": "e78f559543e0d48e5f54d5316c55c98520e583ff16f0b9fecd2bb65efc3a97e9",
|
||||
"purpose": "Wiiuse copyright, GPLv3-or-later and warranty notice"
|
||||
},
|
||||
{
|
||||
"source": "gc/wiiuse/wiiuse.h",
|
||||
"first_line": 187,
|
||||
"last_line": 187,
|
||||
"first_line_text": "typedef unsigned char ubyte;",
|
||||
"last_line_text": "typedef unsigned char ubyte;",
|
||||
"sha256": "584753f151dc6fdb69bac85ef521ebe77f0c01de4e2801dc26f292bb24d0d305",
|
||||
"purpose": "ubyte primitive"
|
||||
},
|
||||
{
|
||||
"source": "gc/wiiuse/wiiuse.h",
|
||||
"first_line": 108,
|
||||
"last_line": 112,
|
||||
"first_line_text": "/* IR correction types */",
|
||||
"last_line_text": "} ir_position_t;",
|
||||
"sha256": "495c0b4599ec31e4189f2ccedf640a76dc71868cc238ba339fc137cd5863514a",
|
||||
"purpose": "ir_position_t"
|
||||
},
|
||||
{
|
||||
"source": "gc/wiiuse/wiiuse.h",
|
||||
"first_line": 297,
|
||||
"last_line": 310,
|
||||
"first_line_text": "/**",
|
||||
"last_line_text": "} orient_t;",
|
||||
"sha256": "073eab21f91deb1eb460d80c85e8e9f4de7d0340715ca86113a76d0e56d5c79b",
|
||||
"purpose": "orient_t"
|
||||
},
|
||||
{
|
||||
"source": "gc/wiiuse/wiiuse.h",
|
||||
"first_line": 336,
|
||||
"last_line": 405,
|
||||
"first_line_text": "/**",
|
||||
"last_line_text": "} ir_t;",
|
||||
"sha256": "d1f7c5c93665b760c86bf1e3591a7b8c88cf82b4ad79a2ecfcf8af31d7d14474",
|
||||
"purpose": "ir_dot_t, fdot_t, sb_t, aspect_t, ir_t"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 431,
|
||||
"last_line": 436,
|
||||
"first_line_text": "enum {",
|
||||
"last_line_text": "};",
|
||||
"sha256": "672444f503b33a4bcd7e52c99ac9ca938f2410b99969ff6008d6e54b074cfe74",
|
||||
"purpose": "IR_STATE_DEAD, IR_STATE_GOOD, IR_STATE_SINGLE, IR_STATE_LOST enum"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/wiiuse_internal.h",
|
||||
"first_line": 154,
|
||||
"last_line": 158,
|
||||
"first_line_text": "/* aspect ratio */",
|
||||
"last_line_text": "#define WM_ASPECT_4_3_Y\t\t420",
|
||||
"sha256": "8a6b6501b9b4e8645b3201c03fa6c114e5e557cac64d7659a0ce7358cbb4f8fc",
|
||||
"purpose": "original viewport dimensions"
|
||||
},
|
||||
{
|
||||
"source": "wiiuse/ir.h",
|
||||
"first_line": 15,
|
||||
"last_line": 16,
|
||||
"first_line_text": "float calc_yaw(struct ir_t* ir);",
|
||||
"last_line_text": "void interpret_ir_data(struct ir_t* ir, struct orient_t *orient);",
|
||||
"sha256": "1b6d1fa3431f094bd6f25e1c9d9bbba3f4fd73183581cfb6685902b43e067dd9",
|
||||
"purpose": "calc_yaw and interpret_ir_data prototypes"
|
||||
}
|
||||
],
|
||||
"retained_functions": [
|
||||
{
|
||||
"name": "rotate_dots",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 55,
|
||||
"last_line": 79,
|
||||
"sha256": "b7f1437819b636ec237b451c38bfeb1aff1819b0994c608ce40cb448bcd08991"
|
||||
},
|
||||
{
|
||||
"name": "ir_correct_for_bounds",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 95,
|
||||
"last_line": 122,
|
||||
"sha256": "f303a51195d05355d3e699fa9a6e72f08c6ed1db6a57c95c0cc295b5475c6c68"
|
||||
},
|
||||
{
|
||||
"name": "ir_convert_to_vres",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 128,
|
||||
"last_line": 144,
|
||||
"sha256": "69a457776dadbec16cf6b71213943751814992d1f4b56c9bd96ad5473ea6797e"
|
||||
},
|
||||
{
|
||||
"name": "find_sensorbar",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 488,
|
||||
"last_line": 719,
|
||||
"sha256": "e0cb1843e92043a86705dd19bcbb248d4fb977fd8e3a4f2a215e9532d2ebfba9"
|
||||
},
|
||||
{
|
||||
"name": "apply_ir_smoothing",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 730,
|
||||
"last_line": 751,
|
||||
"sha256": "9ab2e0cef3167f5a1b156c32b0972766d704e69d12a1b492e14870034d7f84f6"
|
||||
},
|
||||
{
|
||||
"name": "interpret_ir_data",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 766,
|
||||
"last_line": 819,
|
||||
"sha256": "05c9ec6b4da39697dfd3c2fba20b99822bff64db57dc4df4fec0cb55bd6e758a"
|
||||
},
|
||||
{
|
||||
"name": "calc_yaw",
|
||||
"source": "wiiuse/ir.c",
|
||||
"first_line": 826,
|
||||
"last_line": 833,
|
||||
"sha256": "fc6d1a163837cf6dda45db67c2c4cc9de9a263aed53a987a8d0d03bc4c073d48"
|
||||
}
|
||||
],
|
||||
"omitted_ir_c_ranges": [
|
||||
{
|
||||
"first_line": 1,
|
||||
"last_line": 14,
|
||||
"reason": "platform/transport includes replaced by portable header and math.h"
|
||||
},
|
||||
{
|
||||
"first_line": 18,
|
||||
"last_line": 53,
|
||||
"reason": "get_ir_sens device sensitivity helper"
|
||||
},
|
||||
{
|
||||
"first_line": 146,
|
||||
"last_line": 429,
|
||||
"reason": "device mode/enable/configuration/sensitivity and basic/extended Bluetooth report decoding"
|
||||
}
|
||||
],
|
||||
"debug": "Original disabled macro is retained, then equivalently redefined as WIIUSE_DEBUG(...) for strict C11 calls with only a format argument; logging remains disabled"
|
||||
},
|
||||
"portable_header": {
|
||||
"path": "ir.h",
|
||||
"sha256": "73bb59ab64183b943e206687883095723a39fd8a5d160dc32a6e8526f6ca1b7b",
|
||||
"local_additions": [
|
||||
"dated provenance/license comment",
|
||||
"SWITCH_PICO_LIBOGC_IR_H include guard",
|
||||
"typedef float f32;",
|
||||
"extern C wrapper for the four public functions",
|
||||
"find_sensorbar and apply_ir_smoothing declarations matching upstream definitions"
|
||||
]
|
||||
},
|
||||
"generated_c": {
|
||||
"first_line": "#include \"libogc_ir/ir.h\"",
|
||||
"standard_include": "#include <math.h>",
|
||||
"local_additions": [
|
||||
"dated provenance/license comment",
|
||||
"blank separators",
|
||||
"repository-relative #line directives before unchanged C sections",
|
||||
"equivalent disabled WIIUSE_DEBUG(...) macro replaces GNU empty variadic-tail syntax for strict C11"
|
||||
],
|
||||
"body_and_constant_rewrites": [],
|
||||
"io_stubs": [],
|
||||
"compile_language": "C11",
|
||||
"include_root": "external/",
|
||||
"math_library": "link the platform math library when required"
|
||||
},
|
||||
"helper": {
|
||||
"path": "tools/prepare_libogc_ir.py",
|
||||
"cli": "python tools/prepare_libogc_ir.py --output build/libogc_ir.c",
|
||||
"python_api": "prepare(output: pathlib.Path) -> pathlib.Path",
|
||||
"dependencies": "Python standard library only; vendored local inputs; no network or Git needed",
|
||||
"writes": "Requested output only, and only when generated bytes differ"
|
||||
},
|
||||
"adaptation_boundary": "The native relative-output adapter supplies decoded dots and orientation, consumes each camera sequence once, maps unbounded smoothed coordinates into relative USB scale and manages output baselines. No such behavior is inserted into these upstream algorithm bodies."
|
||||
}
|
||||
162
external/libogc_ir/ir.h
vendored
Normal file
162
external/libogc_ir/ir.h
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
* Portable extraction of the libogc Wiiuse IR component, modified 2026-09-11.
|
||||
* Original declarations are copied verbatim from the pinned libogc sources.
|
||||
* This component remains under the GNU GPL with the libogc section 18 linking
|
||||
* exception, explicitly extended to this modified version. See
|
||||
* license_libogc.txt, libogc_license.txt, NOTICE.txt and UPSTREAM.json beside
|
||||
* this header. The surrounding independent project is not relicensed.
|
||||
* The original Wiiuse notice below is from upstream/wiiuse_internal.h.
|
||||
*/
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header: /lvm/shared/ds/ds/cvs/devkitpro-cvsbackup/libogc/wiiuse/wiiuse_internal.h,v 1.8 2008-12-10 16:16:40 shagkur Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SWITCH_PICO_LIBOGC_IR_H
|
||||
#define SWITCH_PICO_LIBOGC_IR_H
|
||||
|
||||
typedef unsigned char ubyte;
|
||||
typedef float f32;
|
||||
|
||||
/* IR correction types */
|
||||
typedef enum ir_position_t {
|
||||
WIIUSE_IR_ABOVE,
|
||||
WIIUSE_IR_BELOW
|
||||
} ir_position_t;
|
||||
|
||||
/**
|
||||
* @struct orient_t
|
||||
* @brief Orientation struct.
|
||||
*
|
||||
* Yaw, pitch, and roll range from -180 to 180 degrees.
|
||||
*/
|
||||
typedef struct orient_t {
|
||||
float roll; /**< roll, this may be smoothed if enabled */
|
||||
float pitch; /**< pitch, this may be smoothed if enabled */
|
||||
float yaw;
|
||||
|
||||
float a_roll; /**< absolute roll, unsmoothed */
|
||||
float a_pitch; /**< absolute pitch, unsmoothed */
|
||||
} orient_t;
|
||||
|
||||
/**
|
||||
* @struct ir_dot_t
|
||||
* @brief A single IR source.
|
||||
*/
|
||||
typedef struct ir_dot_t {
|
||||
ubyte visible; /**< if the IR source is visible */
|
||||
|
||||
short rx; /**< raw X coordinate (0-1023) */
|
||||
short ry; /**< raw Y coordinate (0-767) */
|
||||
|
||||
ubyte size; /**< size of the IR dot (0-15) */
|
||||
} ir_dot_t;
|
||||
|
||||
|
||||
typedef struct fdot_t {
|
||||
float x,y;
|
||||
} fdot_t;
|
||||
|
||||
typedef struct sb_t {
|
||||
fdot_t dots[2];
|
||||
fdot_t acc_dots[2];
|
||||
fdot_t rot_dots[2];
|
||||
float angle;
|
||||
float off_angle;
|
||||
float score;
|
||||
} sb_t;
|
||||
|
||||
/**
|
||||
* @enum aspect_t
|
||||
* @brief Screen aspect ratio.
|
||||
*/
|
||||
typedef enum aspect_t {
|
||||
WIIUSE_ASPECT_4_3,
|
||||
WIIUSE_ASPECT_16_9
|
||||
} aspect_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_t
|
||||
* @brief IR struct. Hold all data related to the IR tracking.
|
||||
*/
|
||||
typedef struct ir_t {
|
||||
struct ir_dot_t dot[4]; /**< IR dots */
|
||||
ubyte num_dots; /**< number of dots at this time */
|
||||
|
||||
int state; /**< keeps track of the IR state */
|
||||
|
||||
int raw_valid; /**< is the raw position valid? */
|
||||
sb_t sensorbar; /**< sensor bar, detected or guessed */
|
||||
float ax; /**< raw X coordinate */
|
||||
float ay; /**< raw Y coordinate */
|
||||
float distance; /**< pixel width of the sensor bar */
|
||||
float z; /**< calculated distance in meters */
|
||||
float angle; /**< angle of the wiimote to the sensor bar*/
|
||||
|
||||
int smooth_valid; /**< is the smoothed position valid? */
|
||||
float sx; /**< smoothed X coordinate */
|
||||
float sy; /**< smoothed Y coordinate */
|
||||
float error_cnt; /**< error count, for smoothing algorithm*/
|
||||
float glitch_cnt; /**< glitch count, same */
|
||||
|
||||
int valid; /**< is the bounded position valid? */
|
||||
float x; /**< bounded X coordinate */
|
||||
float y; /**< bounded Y coordinate */
|
||||
enum aspect_t aspect; /**< aspect ratio of the screen */
|
||||
enum ir_position_t pos; /**< IR sensor bar position */
|
||||
unsigned int vres[2]; /**< IR virtual screen resolution */
|
||||
int offset[2]; /**< IR XY correction offset */
|
||||
|
||||
} ir_t;
|
||||
|
||||
enum {
|
||||
IR_STATE_DEAD = 0,
|
||||
IR_STATE_GOOD,
|
||||
IR_STATE_SINGLE,
|
||||
IR_STATE_LOST,
|
||||
};
|
||||
|
||||
/* aspect ratio */
|
||||
#define WM_ASPECT_16_9_X 660
|
||||
#define WM_ASPECT_16_9_Y 370
|
||||
#define WM_ASPECT_4_3_X 560
|
||||
#define WM_ASPECT_4_3_Y 420
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
void interpret_ir_data(struct ir_t* ir, struct orient_t *orient);
|
||||
void find_sensorbar(struct ir_t* ir, struct orient_t *orient);
|
||||
void apply_ir_smoothing(struct ir_t *ir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SWITCH_PICO_LIBOGC_IR_H */
|
||||
20
external/libogc_ir/libogc_license.txt
vendored
Normal file
20
external/libogc_ir/libogc_license.txt
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Copyright (C) 2004 - 2009
|
||||
Michael Wiedenbauer (shagkur)
|
||||
Dave Murphy (WinterMute)
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any
|
||||
damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose, including commercial applications, and to alter it and
|
||||
redistribute it freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you
|
||||
must not claim that you wrote the original software. If you use
|
||||
this software in a product, an acknowledgment in the product
|
||||
documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and
|
||||
must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
641
external/libogc_ir/license_libogc.txt
vendored
Normal file
641
external/libogc_ir/license_libogc.txt
vendored
Normal file
|
|
@ -0,0 +1,641 @@
|
|||
This license is valid ONLY for libogc and what this license
|
||||
defines as a "covered work" or a "combined work" with libogc.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an officialder
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
18. Exceptions
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give
|
||||
you permission to link this library with independent modules to produce
|
||||
an executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from or
|
||||
based on this library. If you modify this library, you may extend this
|
||||
exception to your version of the library, but you are not obligated to
|
||||
do so. If you do not wish to do so, delete this exception statement from
|
||||
your version.
|
||||
|
||||
55
external/libogc_ir/upstream/definitions.h
vendored
Normal file
55
external/libogc_ir/upstream/definitions.h
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef __DEFINITIONS_H__
|
||||
#define __DEFINITIONS_H__
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#define WIIMOTE_PI 3.14159265f
|
||||
|
||||
//#define WITH_WIIUSE_DEBUG
|
||||
|
||||
/* Error output macros */
|
||||
#define WIIUSE_ERROR(fmt, ...) fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Warning output macros */
|
||||
#define WIIUSE_WARNING(fmt, ...) fprintf(stderr, "[WARNING] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Information output macros */
|
||||
#define WIIUSE_INFO(fmt, ...) fprintf(stderr, "[INFO] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WIN32
|
||||
#define WIIUSE_DEBUG(fmt, ...) do { \
|
||||
char* file = __FILE__; \
|
||||
int i = strlen(file) - 1; \
|
||||
for (; i && (file[i] != '\\'); --i); \
|
||||
fprintf(stderr, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#define WII_DEBUG(fmt, ...) do { \
|
||||
printf("[WDEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__); \
|
||||
usleep(3000000); \
|
||||
} while (0)
|
||||
#else
|
||||
#define WII_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
/* Convert between radians and degrees */
|
||||
#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
|
||||
#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
|
||||
|
||||
/* Convert to big endian */
|
||||
#define BIG_ENDIAN_LONG(i) (htonl(i))
|
||||
#define BIG_ENDIAN_SHORT(i) (htons(i))
|
||||
|
||||
#define absf(x) ((x >= 0) ? (x) : (x * -1.0f))
|
||||
#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x)))
|
||||
|
||||
#endif
|
||||
834
external/libogc_ir/upstream/ir.c
vendored
Normal file
834
external/libogc_ir/upstream/ir.c
vendored
Normal file
|
|
@ -0,0 +1,834 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef GEKKO
|
||||
#include <ogcsys.h>
|
||||
#endif
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
|
||||
static int ir_correct_for_bounds(float* x, float* y, enum aspect_t aspect, int offset_x, int offset_y);
|
||||
static void ir_convert_to_vres(float* x, float* y, enum aspect_t aspect, unsigned int vx, unsigned int vy);
|
||||
|
||||
/**
|
||||
* @brief Get the IR sensitivity settings.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param block1 [out] Pointer to where block1 will be set.
|
||||
* @param block2 [out] Pointer to where block2 will be set.
|
||||
*
|
||||
* @return Returns the sensitivity level.
|
||||
*/
|
||||
static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2) {
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL1)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL1;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL1;
|
||||
return 1;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL2)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL2;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL2;
|
||||
return 2;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL3)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL3;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL3;
|
||||
return 3;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL4)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL4;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL4;
|
||||
return 4;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL5)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL5;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL5;
|
||||
return 5;
|
||||
}
|
||||
|
||||
*block1 = NULL;
|
||||
*block2 = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rotate_dots(struct fdot_t* in, struct fdot_t *out, int count, float ang) {
|
||||
float s, c;
|
||||
int i;
|
||||
|
||||
if (ang == 0) {
|
||||
for (i = 0; i < count; ++i) {
|
||||
out[i].x = in[i].x;
|
||||
out[i].y = in[i].y;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
s = sin(DEGREE_TO_RAD(ang));
|
||||
c = cos(DEGREE_TO_RAD(ang));
|
||||
|
||||
/*
|
||||
* [ cos(theta) -sin(theta) ][ ir->rx ]
|
||||
* [ sin(theta) cos(theta) ][ ir->ry ]
|
||||
*/
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
out[i].x = (c * in[i].x) + (-s * in[i].y);
|
||||
out[i].y = (s * in[i].x) + (c * in[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Correct for the IR bounding box.
|
||||
*
|
||||
* @param x [out] The current X, it will be updated if valid.
|
||||
* @param y [out] The current Y, it will be updated if valid.
|
||||
* @param aspect Aspect ratio of the screen.
|
||||
* @param offset_x The X offset of the bounding box.
|
||||
* @param offset_y The Y offset of the bounding box.
|
||||
*
|
||||
* @return Returns 1 if the point is valid and was updated.
|
||||
*
|
||||
* Nintendo was smart with this bit. They sacrifice a little
|
||||
* precision for a big increase in usability.
|
||||
*/
|
||||
static int ir_correct_for_bounds(float* x, float* y, enum aspect_t aspect, int offset_x, int offset_y) {
|
||||
float x0, y0;
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
x0 = ((1024 - xs) / 2) + offset_x;
|
||||
y0 = ((768 - ys) / 2) + offset_y;
|
||||
|
||||
if ((*x >= x0)
|
||||
&& (*x <= (x0 + xs))
|
||||
&& (*y >= y0)
|
||||
&& (*y <= (y0 + ys)))
|
||||
{
|
||||
*x -= offset_x;
|
||||
*y -= offset_y;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interpolate the point to the user defined virtual screen resolution.
|
||||
*/
|
||||
static void ir_convert_to_vres(float* x, float* y, enum aspect_t aspect, unsigned int vx, unsigned int vy) {
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
*x -= ((1024-xs)/2);
|
||||
*y -= ((768-ys)/2);
|
||||
|
||||
*x = (*x / (float)xs) * vx;
|
||||
*y = (*y / (float)ys) * vy;
|
||||
}
|
||||
|
||||
void wiiuse_set_ir_mode(struct wiimote_t *wm)
|
||||
{
|
||||
ubyte buf = 0x00;
|
||||
|
||||
if(!wm) return;
|
||||
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
|
||||
|
||||
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP)) buf = WM_IR_TYPE_BASIC;
|
||||
else buf = WM_IR_TYPE_EXTENDED;
|
||||
wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1, NULL);
|
||||
}
|
||||
|
||||
void wiiuse_set_ir(struct wiimote_t *wm,int status)
|
||||
{
|
||||
ubyte buf = 0x00;
|
||||
int ir_level = 0;
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
|
||||
if(!wm) return;
|
||||
|
||||
/*
|
||||
* Wait for the handshake to finish first.
|
||||
* When it handshake finishes and sees that
|
||||
* IR is enabled, it will call this function
|
||||
* again to actually enable IR.
|
||||
*/
|
||||
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE)) {
|
||||
WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes.\n");
|
||||
if(status)
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_INIT);
|
||||
else
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR_INIT);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure a sensitivity setting is selected.
|
||||
*/
|
||||
ir_level = get_ir_sens(wm, &block1, &block2);
|
||||
if (!ir_level) {
|
||||
WIIUSE_ERROR("No IR sensitivity setting selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
/* if already enabled then stop */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR) || WIIMOTE_IS_SET(wm, WIIMOTE_STATE_WIIU_PRO)) {
|
||||
wiiuse_status(wm,NULL);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
/* if already disabled then stop */
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
wiiuse_status(wm,NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
buf = (status ? 0x04 : 0x00);
|
||||
wiiuse_sendcmd(wm,WM_CMD_IR,&buf,1,NULL);
|
||||
wiiuse_sendcmd(wm,WM_CMD_IR_2,&buf,1,NULL);
|
||||
|
||||
if (!status) {
|
||||
WIIUSE_DEBUG("Disabled IR cameras for wiimote id %i.", wm->unid);
|
||||
wiiuse_status(wm,NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* enable IR, set sensitivity */
|
||||
buf = 0x08;
|
||||
wiiuse_write_data(wm,WM_REG_IR,&buf,1,NULL);
|
||||
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (ubyte*)block1, 9, NULL);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (ubyte*)block2, 2, NULL);
|
||||
|
||||
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP)) buf = WM_IR_TYPE_BASIC;
|
||||
else buf = WM_IR_TYPE_EXTENDED;
|
||||
wiiuse_write_data(wm,WM_REG_IR_MODENUM, &buf, 1, NULL);
|
||||
|
||||
wiiuse_status(wm,NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the virtual screen resolution for IR tracking.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.vres[0] = (x-1);
|
||||
wm->ir.vres[1] = (y-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the XY position for the IR cursor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.pos = pos;
|
||||
|
||||
switch (pos) {
|
||||
|
||||
case WIIUSE_IR_ABOVE:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100;
|
||||
|
||||
return;
|
||||
|
||||
case WIIUSE_IR_BELOW:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 70;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 100;
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the aspect ratio of the TV/monitor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
||||
*/
|
||||
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.aspect = aspect;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_4_3) {
|
||||
wm->ir.vres[0] = WM_ASPECT_4_3_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_4_3_Y;
|
||||
} else {
|
||||
wm->ir.vres[0] = WM_ASPECT_16_9_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_16_9_Y;
|
||||
}
|
||||
|
||||
/* reset the position offsets */
|
||||
wiiuse_set_ir_position(wm, wm->ir.pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the IR sensitivity.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param level 1-5, same as Wii system sensitivity setting.
|
||||
*
|
||||
* If the level is < 1, then level will be set to 1.
|
||||
* If the level is > 5, then level will be set to 5.
|
||||
*/
|
||||
void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
|
||||
if (!wm) return;
|
||||
|
||||
if (level > 5) level = 5;
|
||||
if (level < 1) level = 1;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL3 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL4 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL5));
|
||||
|
||||
switch (level) {
|
||||
case 1:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL1);
|
||||
break;
|
||||
case 2:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL2);
|
||||
break;
|
||||
case 3:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL3);
|
||||
break;
|
||||
case 4:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL4);
|
||||
break;
|
||||
case 5:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL5);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
|
||||
|
||||
/* set the new sensitivity */
|
||||
get_ir_sens(wm, &block1, &block2);
|
||||
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (ubyte*)block1, 9,NULL);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (ubyte*)block2, 2,NULL);
|
||||
|
||||
WIIUSE_DEBUG("Set IR sensitivity to level %i (unid %i)", level, wm->unid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Basic IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_basic_ir(struct wiimote_t* wm, ubyte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
dot[0].rx = 1023 - (data[0] | ((data[2] & 0x30) << 4));
|
||||
dot[0].ry = data[1] | ((data[2] & 0xC0) << 2);
|
||||
|
||||
dot[1].rx = 1023 - (data[3] | ((data[2] & 0x03) << 8));
|
||||
dot[1].ry = data[4] | ((data[2] & 0x0C) << 6);
|
||||
|
||||
dot[2].rx = 1023 - (data[5] | ((data[7] & 0x30) << 4));
|
||||
dot[2].ry = data[6] | ((data[7] & 0xC0) << 2);
|
||||
|
||||
dot[3].rx = 1023 - (data[8] | ((data[7] & 0x03) << 8));
|
||||
dot[3].ry = data[9] | ((data[7] & 0x0C) << 6);
|
||||
|
||||
/* set each IR spot to visible if spot is in range */
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].rx = BIG_ENDIAN_SHORT(dot[i].rx);
|
||||
dot[i].ry = BIG_ENDIAN_SHORT(dot[i].ry);
|
||||
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else {
|
||||
dot[i].visible = 1;
|
||||
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
||||
}
|
||||
}
|
||||
#ifndef GEKKO
|
||||
interpret_ir_data(&wm->ir,&wm->orient,WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Extended IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_extended_ir(struct wiimote_t* wm, ubyte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4));
|
||||
dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2);
|
||||
|
||||
dot[i].size = data[(3*i)+2];
|
||||
|
||||
dot[i].rx = BIG_ENDIAN_SHORT(dot[i].rx);
|
||||
dot[i].ry = BIG_ENDIAN_SHORT(dot[i].ry);
|
||||
|
||||
dot[i].size = dot[i].size&0x0f;
|
||||
|
||||
/* if in range set to visible */
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else
|
||||
dot[i].visible = 1;
|
||||
}
|
||||
#ifndef GEKKO
|
||||
interpret_ir_data(&wm->ir,&wm->orient,WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC));
|
||||
#endif
|
||||
}
|
||||
|
||||
enum {
|
||||
IR_STATE_DEAD = 0,
|
||||
IR_STATE_GOOD,
|
||||
IR_STATE_SINGLE,
|
||||
IR_STATE_LOST,
|
||||
};
|
||||
|
||||
// half-height of the IR sensor if half-width is 1
|
||||
#define HEIGHT (384.0f / 512.0f)
|
||||
// maximum sensor bar slope (tan(35 degrees))
|
||||
#define MAX_SB_SLOPE 0.7f
|
||||
// minimum sensor bar width in view, relative to half of the IR sensor area
|
||||
#define MIN_SB_WIDTH 0.1f
|
||||
// reject "sensor bars" that happen to have a dot towards the middle
|
||||
#define SB_MIDDOT_REJECT 0.05f
|
||||
|
||||
// physical dimensions
|
||||
// cm center to center of emitters
|
||||
#define SB_WIDTH 19.5f
|
||||
// half-width in cm of emitters
|
||||
#define SB_DOT_WIDTH 2.25f
|
||||
// half-height in cm of emitters (with some tolerance)
|
||||
#define SB_DOT_HEIGHT 1.0f
|
||||
|
||||
#define SB_DOT_WIDTH_RATIO (SB_DOT_WIDTH / SB_WIDTH)
|
||||
#define SB_DOT_HEIGHT_RATIO (SB_DOT_HEIGHT / SB_WIDTH)
|
||||
|
||||
// dots further out than these coords are allowed to not be picked up
|
||||
// otherwise assume something's wrong
|
||||
//#define SB_OFF_SCREEN_X 0.8f
|
||||
//#define SB_OFF_SCREEN_Y (0.8f * HEIGHT)
|
||||
|
||||
// disable, may be doing more harm than good due to sensor pickup glitches
|
||||
#define SB_OFF_SCREEN_X 0.0f
|
||||
#define SB_OFF_SCREEN_Y 0.0f
|
||||
|
||||
// if a point is closer than this to one of the previous SB points
|
||||
// when it reappears, consider it the same instead of trying to guess
|
||||
// which one of the two it is
|
||||
#define SB_SINGLE_NOGUESS_DISTANCE (100.0 * 100.0)
|
||||
|
||||
// width of the sensor bar in pixels at one meter from the Wiimote
|
||||
#define SB_Z_COEFFICIENT 256.0f
|
||||
|
||||
// distance in meters from the center of the FOV to the left or right edge,
|
||||
// when the wiimote is at one meter
|
||||
#define WIIMOTE_FOV_COEFFICIENT 0.39f
|
||||
|
||||
#define SQUARED(x) ((x)*(x))
|
||||
#define WMAX(x,y) ((x>y)?(x):(y))
|
||||
#define WMIN(x,y) ((x<y)?(x):(y))
|
||||
|
||||
/**
|
||||
* @brief Interpret IR data into more user friendly variables.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void find_sensorbar(struct ir_t* ir, struct orient_t *orient) {
|
||||
struct fdot_t dots[4];
|
||||
struct fdot_t acc_dots[4];
|
||||
struct sb_t cand;
|
||||
struct sb_t candidates[6];
|
||||
struct sb_t sb;
|
||||
|
||||
fdot_t difference;
|
||||
|
||||
int num_candidates = 0;
|
||||
|
||||
int i;
|
||||
int j;
|
||||
int first, second;
|
||||
|
||||
WIIUSE_DEBUG("IR: orient angle: %.02f\n",orient->roll);
|
||||
|
||||
/* count visible dots and populate dots structure */
|
||||
/* dots[] is in -1..1 units for width */
|
||||
ir->num_dots = 0;
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (ir->dot[i].visible) {
|
||||
dots[ir->num_dots].x = (ir->dot[i].rx - 512.0f) / 512.0f;
|
||||
dots[ir->num_dots].y = (ir->dot[i].ry - 384.0f) / 512.0f;
|
||||
WIIUSE_DEBUG("IR: dot %d at (%d,%d) (%.03f,%.03f)\n",ir->num_dots,ir->dot[i].rx,ir->dot[i].ry,dots[ir->num_dots].x,dots[ir->num_dots].y);
|
||||
ir->num_dots++;
|
||||
}
|
||||
}
|
||||
|
||||
WIIUSE_DEBUG("IR: found %d dots\n",ir->num_dots);
|
||||
|
||||
// nothing to track
|
||||
if(ir->num_dots == 0) {
|
||||
if(ir->state != IR_STATE_DEAD)
|
||||
ir->state = IR_STATE_LOST;
|
||||
ir->ax = 0;
|
||||
ir->ay = 0;
|
||||
ir->distance = 0.0f;
|
||||
ir->raw_valid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* ==== Find the Sensor Bar ==== */
|
||||
|
||||
// first rotate according to accelerometer orientation
|
||||
rotate_dots(dots, acc_dots, ir->num_dots, orient->roll);
|
||||
if(ir->num_dots > 1) {
|
||||
WIIUSE_DEBUG("IR: locating sensor bar candidates\n");
|
||||
|
||||
// iterate through all dot pairs
|
||||
for(first=0; first < (ir->num_dots-1); first++) {
|
||||
for(second=(first+1); second < ir->num_dots; second++) {
|
||||
WIIUSE_DEBUG("IR: trying dots %d and %d\n",first,second);
|
||||
// order the dots leftmost first into cand
|
||||
// storing both the raw dots and the accel-rotated dots
|
||||
if(acc_dots[first].x > acc_dots[second].x) {
|
||||
cand.dots[0] = dots[second];
|
||||
cand.dots[1] = dots[first];
|
||||
cand.acc_dots[0] = acc_dots[second];
|
||||
cand.acc_dots[1] = acc_dots[first];
|
||||
} else {
|
||||
cand.dots[0] = dots[first];
|
||||
cand.dots[1] = dots[second];
|
||||
cand.acc_dots[0] = acc_dots[first];
|
||||
cand.acc_dots[1] = acc_dots[second];
|
||||
}
|
||||
difference.x = cand.acc_dots[1].x - cand.acc_dots[0].x;
|
||||
difference.y = cand.acc_dots[1].y - cand.acc_dots[0].y;
|
||||
|
||||
// check angle
|
||||
if(fabsf(difference.y / difference.x) > MAX_SB_SLOPE)
|
||||
continue;
|
||||
WIIUSE_DEBUG("IR: passed angle check\n");
|
||||
// rotate to the true sensor bar angle
|
||||
cand.off_angle = -RAD_TO_DEGREE(atan2(difference.y, difference.x));
|
||||
cand.angle = cand.off_angle + orient->roll;
|
||||
rotate_dots(cand.dots, cand.rot_dots, 2, cand.angle);
|
||||
WIIUSE_DEBUG("IR: off_angle: %.02f, angle: %.02f\n", cand.off_angle, cand.angle);
|
||||
// recalculate x distance - y should be zero now, so ignore it
|
||||
difference.x = cand.rot_dots[1].x - cand.rot_dots[0].x;
|
||||
|
||||
// check distance
|
||||
if(difference.x < MIN_SB_WIDTH)
|
||||
continue;
|
||||
// middle dot check. If there's another source somewhere in the
|
||||
// middle of this candidate, then this can't be a sensor bar
|
||||
|
||||
for(i=0; i<ir->num_dots; i++) {
|
||||
float wadj, hadj;
|
||||
struct fdot_t tdot;
|
||||
if(i==first || i==second) continue;
|
||||
hadj = SB_DOT_HEIGHT_RATIO * difference.x;
|
||||
wadj = SB_DOT_WIDTH_RATIO * difference.x;
|
||||
rotate_dots(&dots[i], &tdot, 1, cand.angle);
|
||||
if( ((cand.rot_dots[0].x + wadj) < tdot.x) &&
|
||||
((cand.rot_dots[1].x - wadj) > tdot.x) &&
|
||||
((cand.rot_dots[0].y + hadj) > tdot.y) &&
|
||||
((cand.rot_dots[0].y - hadj) < tdot.y))
|
||||
break;
|
||||
}
|
||||
// failed middle dot check
|
||||
if(i < ir->num_dots) continue;
|
||||
WIIUSE_DEBUG("IR: passed middle dot check\n");
|
||||
|
||||
cand.score = 1 / (cand.rot_dots[1].x - cand.rot_dots[0].x);
|
||||
|
||||
// we have a candidate, store it
|
||||
WIIUSE_DEBUG("IR: new candidate %d\n",num_candidates);
|
||||
candidates[num_candidates++] = cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(num_candidates == 0) {
|
||||
int closest = -1;
|
||||
int closest_to = 0;
|
||||
float best = 999.0f;
|
||||
float d;
|
||||
float dx[2];
|
||||
struct sb_t sbx[2];
|
||||
// no sensor bar candidates, try to work with a lone dot
|
||||
WIIUSE_DEBUG("IR: no candidates\n");
|
||||
switch(ir->state) {
|
||||
case IR_STATE_DEAD:
|
||||
WIIUSE_DEBUG("IR: we're dead\n");
|
||||
// we've never seen a sensor bar before, so we're screwed
|
||||
ir->ax = 0.0f;
|
||||
ir->ay = 0.0f;
|
||||
ir->distance = 0.0f;
|
||||
ir->raw_valid = 0;
|
||||
return;
|
||||
case IR_STATE_GOOD:
|
||||
case IR_STATE_SINGLE:
|
||||
case IR_STATE_LOST:
|
||||
WIIUSE_DEBUG("IR: trying to keep track of single dot\n");
|
||||
// try to find the dot closest to the previous sensor bar position
|
||||
for(i=0; i<ir->num_dots; i++) {
|
||||
WIIUSE_DEBUG("IR: checking dot %d (%.02f, %.02f)\n",i, acc_dots[i].x,acc_dots[i].y);
|
||||
for(j=0; j<2; j++) {
|
||||
WIIUSE_DEBUG(" to dot %d (%.02f, %.02f)\n",j, ir->sensorbar.acc_dots[j].x,ir->sensorbar.acc_dots[j].y);
|
||||
d = SQUARED(acc_dots[i].x - ir->sensorbar.acc_dots[j].x);
|
||||
d += SQUARED(acc_dots[i].y - ir->sensorbar.acc_dots[j].y);
|
||||
if(d < best) {
|
||||
best = d;
|
||||
closest_to = j;
|
||||
closest = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
WIIUSE_DEBUG("IR: closest dot is %d to %d\n",closest,closest_to);
|
||||
if(ir->state != IR_STATE_LOST || best < SB_SINGLE_NOGUESS_DISTANCE) {
|
||||
// now work out where the other dot would be, in the acc frame
|
||||
sb.acc_dots[closest_to] = acc_dots[closest];
|
||||
sb.acc_dots[closest_to^1].x = ir->sensorbar.acc_dots[closest_to^1].x - ir->sensorbar.acc_dots[closest_to].x + acc_dots[closest].x;
|
||||
sb.acc_dots[closest_to^1].y = ir->sensorbar.acc_dots[closest_to^1].y - ir->sensorbar.acc_dots[closest_to].y + acc_dots[closest].y;
|
||||
// get the raw frame
|
||||
rotate_dots(sb.acc_dots, sb.dots, 2, -orient->roll);
|
||||
if((fabsf(sb.dots[closest_to^1].x) < SB_OFF_SCREEN_X) && (fabsf(sb.dots[closest_to^1].y) < SB_OFF_SCREEN_Y)) {
|
||||
// this dot should be visible but isn't, since the candidate section failed.
|
||||
// fall through and try to pick out the sensor bar without previous information
|
||||
WIIUSE_DEBUG("IR: dot falls on screen, falling through\n");
|
||||
} else {
|
||||
// calculate the rotated dots frame
|
||||
// angle tends to drift, so recalculate
|
||||
sb.off_angle = -RAD_TO_DEGREE(atan2(sb.acc_dots[1].y - sb.acc_dots[0].y, sb.acc_dots[1].x - sb.acc_dots[0].x));
|
||||
sb.angle = ir->sensorbar.off_angle + orient->roll;
|
||||
rotate_dots(sb.acc_dots, sb.rot_dots, 2, ir->sensorbar.off_angle);
|
||||
WIIUSE_DEBUG("IR: kept track of single dot\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
WIIUSE_DEBUG("IR: lost the dot and new one is too far away\n");
|
||||
}
|
||||
// try to find the dot closest to the sensor edge
|
||||
WIIUSE_DEBUG("IR: trying to find best dot\n");
|
||||
for(i=0; i<ir->num_dots; i++) {
|
||||
d = WMIN(1.0f - fabsf(dots[i].x), HEIGHT - fabsf(dots[i].y));
|
||||
if(d < best) {
|
||||
best = d;
|
||||
closest = i;
|
||||
}
|
||||
}
|
||||
WIIUSE_DEBUG("IR: best dot: %d\n",closest);
|
||||
// now try it as both places in the sensor bar
|
||||
// and pick the one that places the other dot furthest off-screen
|
||||
for(i=0; i<2; i++) {
|
||||
sbx[i].acc_dots[i] = acc_dots[closest];
|
||||
sbx[i].acc_dots[i^1].x = ir->sensorbar.acc_dots[i^1].x - ir->sensorbar.acc_dots[i].x + acc_dots[closest].x;
|
||||
sbx[i].acc_dots[i^1].y = ir->sensorbar.acc_dots[i^1].y - ir->sensorbar.acc_dots[i].y + acc_dots[closest].y;
|
||||
rotate_dots(sbx[i].acc_dots, sbx[i].dots, 2, -orient->roll);
|
||||
dx[i] = WMAX(fabsf(sbx[i].dots[i^1].x),fabsf(sbx[i].dots[i^1].y / HEIGHT));
|
||||
}
|
||||
if(dx[0] > dx[1]) {
|
||||
WIIUSE_DEBUG("IR: dot is LEFT: %.02f > %.02f\n",dx[0],dx[1]);
|
||||
sb = sbx[0];
|
||||
} else {
|
||||
WIIUSE_DEBUG("IR: dot is RIGHT: %.02f < %.02f\n",dx[0],dx[1]);
|
||||
sb = sbx[1];
|
||||
}
|
||||
// angle tends to drift, so recalculate
|
||||
sb.off_angle = -RAD_TO_DEGREE(atan2(sb.acc_dots[1].y - sb.acc_dots[0].y, sb.acc_dots[1].x - sb.acc_dots[0].x));
|
||||
sb.angle = ir->sensorbar.off_angle + orient->roll;
|
||||
rotate_dots(sb.acc_dots, sb.rot_dots, 2, ir->sensorbar.off_angle);
|
||||
WIIUSE_DEBUG("IR: found new dot to track\n");
|
||||
break;
|
||||
}
|
||||
sb.score = 0;
|
||||
ir->state = IR_STATE_SINGLE;
|
||||
} else {
|
||||
int bestidx = 0;
|
||||
float best = 0.0f;
|
||||
WIIUSE_DEBUG("IR: finding best candidate\n");
|
||||
// look for the best candidate
|
||||
// for now, the formula is simple: pick the one with the smallest distance
|
||||
for(i=0; i<num_candidates; i++) {
|
||||
if(candidates[i].score > best) {
|
||||
bestidx = i;
|
||||
best = candidates[i].score;
|
||||
}
|
||||
}
|
||||
WIIUSE_DEBUG("IR: best candidate: %d\n",bestidx);
|
||||
sb = candidates[bestidx];
|
||||
ir->state = IR_STATE_GOOD;
|
||||
}
|
||||
|
||||
ir->raw_valid = 1;
|
||||
ir->ax = ((sb.rot_dots[0].x + sb.rot_dots[1].x) / 2) * 512.0 + 512.0;
|
||||
ir->ay = ((sb.rot_dots[0].y + sb.rot_dots[1].y) / 2) * 512.0 + 384.0;
|
||||
ir->sensorbar = sb;
|
||||
ir->distance = (sb.rot_dots[1].x - sb.rot_dots[0].x) * 512.0;
|
||||
|
||||
}
|
||||
|
||||
#define SMOOTH_IR_RADIUS 8.0f
|
||||
#define SMOOTH_IR_SPEED 0.25f
|
||||
#define SMOOTH_IR_DEADZONE 2.5f
|
||||
|
||||
/**
|
||||
* @brief Smooth the IR pointer position
|
||||
*
|
||||
* @param ir Pointer to an ir_t structure.
|
||||
*/
|
||||
void apply_ir_smoothing(struct ir_t *ir) {
|
||||
f32 dx, dy, d, theta;
|
||||
|
||||
WIIUSE_DEBUG("Smooth: OK (%.02f, %.02f) LAST (%.02f, %.02f) ", ir->ax, ir->ay, ir->sx, ir->sy);
|
||||
dx = ir->ax - ir->sx;
|
||||
dy = ir->ay - ir->sy;
|
||||
d = sqrtf(dx*dx + dy*dy);
|
||||
if (d > SMOOTH_IR_DEADZONE) {
|
||||
if (d < SMOOTH_IR_RADIUS) {
|
||||
WIIUSE_DEBUG("INSIDE\n");
|
||||
ir->sx += dx * SMOOTH_IR_SPEED;
|
||||
ir->sy += dy * SMOOTH_IR_SPEED;
|
||||
} else {
|
||||
WIIUSE_DEBUG("OUTSIDE\n");
|
||||
theta = atan2f(dy, dx);
|
||||
ir->sx = ir->ax - cosf(theta) * SMOOTH_IR_RADIUS;
|
||||
ir->sy = ir->ay - sinf(theta) * SMOOTH_IR_RADIUS;
|
||||
}
|
||||
} else {
|
||||
WIIUSE_DEBUG("DEADZONE\n");
|
||||
}
|
||||
}
|
||||
|
||||
// max number of errors before cooked data drops out
|
||||
#define ERROR_MAX_COUNT 8
|
||||
// max number of glitches before cooked data updates
|
||||
#define GLITCH_MAX_COUNT 5
|
||||
// squared delta over which we consider something a glitch
|
||||
#define GLITCH_DIST (150.0f * 150.0f)
|
||||
|
||||
/**
|
||||
* @brief Interpret IR data into more user friendly variables.
|
||||
*
|
||||
* @param ir Pointer to an ir_t structure.
|
||||
* @param orient Pointer to an orient_t structure.
|
||||
*/
|
||||
void interpret_ir_data(struct ir_t* ir, struct orient_t *orient) {
|
||||
|
||||
float x,y;
|
||||
float d;
|
||||
|
||||
find_sensorbar(ir, orient);
|
||||
|
||||
if(ir->raw_valid) {
|
||||
ir->angle = ir->sensorbar.angle;
|
||||
ir->z = SB_Z_COEFFICIENT / ir->distance;
|
||||
orient->yaw = calc_yaw(ir);
|
||||
if(ir->error_cnt >= ERROR_MAX_COUNT) {
|
||||
ir->sx = ir->ax;
|
||||
ir->sy = ir->ay;
|
||||
ir->glitch_cnt = 0;
|
||||
} else {
|
||||
d = SQUARED(ir->ax - ir->sx) + SQUARED(ir->ay - ir->sy);
|
||||
if(d > GLITCH_DIST) {
|
||||
if(ir->glitch_cnt > GLITCH_MAX_COUNT) {
|
||||
apply_ir_smoothing(ir);
|
||||
ir->glitch_cnt = 0;
|
||||
} else {
|
||||
ir->glitch_cnt++;
|
||||
}
|
||||
} else {
|
||||
ir->glitch_cnt = 0;
|
||||
apply_ir_smoothing(ir);
|
||||
}
|
||||
}
|
||||
ir->smooth_valid = 1;
|
||||
ir->error_cnt = 0;
|
||||
} else {
|
||||
if(ir->error_cnt >= ERROR_MAX_COUNT) {
|
||||
ir->smooth_valid = 0;
|
||||
} else {
|
||||
ir->smooth_valid = 1;
|
||||
ir->error_cnt++;
|
||||
}
|
||||
}
|
||||
if(ir->smooth_valid) {
|
||||
x = ir->sx;
|
||||
y = ir->sy;
|
||||
if (ir_correct_for_bounds(&x, &y, ir->aspect, ir->offset[0], ir->offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, ir->aspect, ir->vres[0], ir->vres[1]);
|
||||
ir->x = x;
|
||||
ir->y = y;
|
||||
ir->valid = 1;
|
||||
} else {
|
||||
ir->valid = 0;
|
||||
}
|
||||
} else {
|
||||
ir->valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate yaw given the IR data.
|
||||
*
|
||||
* @param ir IR data structure.
|
||||
*/
|
||||
float calc_yaw(struct ir_t* ir) {
|
||||
float x;
|
||||
|
||||
x = ir->ax - 512;
|
||||
x *= WIIMOTE_FOV_COEFFICIENT / 512.0;
|
||||
|
||||
return RAD_TO_DEGREE( atanf(x) );
|
||||
}
|
||||
|
||||
22
external/libogc_ir/upstream/ir.h
vendored
Normal file
22
external/libogc_ir/upstream/ir.h
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef __IR_H__
|
||||
#define __IR_H__
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define WII_VRES_X 560
|
||||
#define WII_VRES_Y 340
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_basic_ir(struct wiimote_t* wm, ubyte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, ubyte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
void interpret_ir_data(struct ir_t* ir, struct orient_t *orient);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
748
external/libogc_ir/upstream/wiiuse.h
vendored
Normal file
748
external/libogc_ir/upstream/wiiuse.h
vendored
Normal file
|
|
@ -0,0 +1,748 @@
|
|||
#ifndef __WIIUSE_H__
|
||||
#define __WIIUSE_H__
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* windows */
|
||||
#include <windows.h>
|
||||
#elif defined(GEKKO)
|
||||
/* wii */
|
||||
#include <bte/bte.h>
|
||||
#elif defined(__linux__)
|
||||
/* nix */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_INTERNAL_H_INCLUDED
|
||||
#define WCONST
|
||||
#else
|
||||
#define WCONST const
|
||||
#endif
|
||||
|
||||
/* led bit masks */
|
||||
#define WIIMOTE_LED_NONE 0x00
|
||||
#define WIIMOTE_LED_1 0x10
|
||||
#define WIIMOTE_LED_2 0x20
|
||||
#define WIIMOTE_LED_3 0x40
|
||||
#define WIIMOTE_LED_4 0x80
|
||||
|
||||
/* button codes */
|
||||
#define WIIMOTE_BUTTON_TWO 0x0001
|
||||
#define WIIMOTE_BUTTON_ONE 0x0002
|
||||
#define WIIMOTE_BUTTON_B 0x0004
|
||||
#define WIIMOTE_BUTTON_A 0x0008
|
||||
#define WIIMOTE_BUTTON_MINUS 0x0010
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
|
||||
#define WIIMOTE_BUTTON_HOME 0x0080
|
||||
#define WIIMOTE_BUTTON_LEFT 0x0100
|
||||
#define WIIMOTE_BUTTON_RIGHT 0x0200
|
||||
#define WIIMOTE_BUTTON_DOWN 0x0400
|
||||
#define WIIMOTE_BUTTON_UP 0x0800
|
||||
#define WIIMOTE_BUTTON_PLUS 0x1000
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
|
||||
#define WIIMOTE_BUTTON_UNKNOWN 0x8000
|
||||
#define WIIMOTE_BUTTON_ALL 0x1F9F
|
||||
|
||||
/* nunchul button codes */
|
||||
#define NUNCHUK_BUTTON_Z 0x01
|
||||
#define NUNCHUK_BUTTON_C 0x02
|
||||
#define NUNCHUK_BUTTON_ALL 0x03
|
||||
|
||||
/* classic controller button codes */
|
||||
#define CLASSIC_CTRL_BUTTON_UP 0x0001
|
||||
#define CLASSIC_CTRL_BUTTON_LEFT 0x0002
|
||||
#define CLASSIC_CTRL_BUTTON_ZR 0x0004
|
||||
#define CLASSIC_CTRL_BUTTON_X 0x0008
|
||||
#define CLASSIC_CTRL_BUTTON_A 0x0010
|
||||
#define CLASSIC_CTRL_BUTTON_Y 0x0020
|
||||
#define CLASSIC_CTRL_BUTTON_B 0x0040
|
||||
#define CLASSIC_CTRL_BUTTON_ZL 0x0080
|
||||
#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
|
||||
#define CLASSIC_CTRL_BUTTON_PLUS 0x0400
|
||||
#define CLASSIC_CTRL_BUTTON_HOME 0x0800
|
||||
#define CLASSIC_CTRL_BUTTON_MINUS 0x1000
|
||||
#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
|
||||
#define CLASSIC_CTRL_BUTTON_DOWN 0x4000
|
||||
#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
|
||||
#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
|
||||
|
||||
/* guitar hero 3 button codes */
|
||||
#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
|
||||
#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
|
||||
#define GUITAR_HERO_3_BUTTON_GREEN 0x0010
|
||||
#define GUITAR_HERO_3_BUTTON_BLUE 0x0020
|
||||
#define GUITAR_HERO_3_BUTTON_RED 0x0040
|
||||
#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
|
||||
#define GUITAR_HERO_3_BUTTON_PLUS 0x0400
|
||||
#define GUITAR_HERO_3_BUTTON_MINUS 0x1000
|
||||
#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
|
||||
#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
|
||||
|
||||
/* guitar hero world tour touch bar codes */
|
||||
#define GUITAR_HERO_3_TOUCH_AVAILABLE 0x1000
|
||||
#define GUITAR_HERO_3_TOUCH_GREEN 0x1001
|
||||
#define GUITAR_HERO_3_TOUCH_RED 0x1002
|
||||
#define GUITAR_HERO_3_TOUCH_YELLOW 0x1004
|
||||
#define GUITAR_HERO_3_TOUCH_BLUE 0x1008
|
||||
#define GUITAR_HERO_3_TOUCH_ORANGE 0x1010
|
||||
|
||||
/* wiimote option flags */
|
||||
#define WIIUSE_SMOOTHING 0x01
|
||||
#define WIIUSE_CONTINUOUS 0x02
|
||||
#define WIIUSE_ACCEL_THRESH 0x04
|
||||
#define WIIUSE_IR_THRESH 0x08
|
||||
#define WIIUSE_JS_THRESH 0x10
|
||||
#define WIIUSE_INIT_FLAGS WIIUSE_SMOOTHING
|
||||
|
||||
#define WIIUSE_ORIENT_PRECISION 100.0f
|
||||
|
||||
/* expansion codes */
|
||||
#define EXP_NONE 0
|
||||
#define EXP_NUNCHUK 1
|
||||
#define EXP_CLASSIC 2
|
||||
#define EXP_GUITAR_HERO_3 3
|
||||
#define EXP_WII_BOARD 4
|
||||
#define EXP_MOTION_PLUS 5
|
||||
|
||||
/* IR correction types */
|
||||
typedef enum ir_position_t {
|
||||
WIIUSE_IR_ABOVE,
|
||||
WIIUSE_IR_BELOW
|
||||
} ir_position_t;
|
||||
|
||||
/**
|
||||
* @brief Check if a button is pressed.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is pressed, 0 if not.
|
||||
*/
|
||||
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button is being held.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is held, 0 if not.
|
||||
*/
|
||||
#define IS_HELD(dev, button) ((dev->btns_held & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button is released on this event. \n\n
|
||||
* This does not mean the button is not pressed, it means \n
|
||||
* this button was just now released.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is released, 0 if not.
|
||||
*
|
||||
*/
|
||||
#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button has just been pressed this event.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is pressed, 0 if not.
|
||||
*/
|
||||
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
|
||||
|
||||
/**
|
||||
* @brief Return the IR sensitivity level.
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param lvl [out] Pointer to an int that will hold the level setting.
|
||||
* If no level is set 'lvl' will be set to 0.
|
||||
*/
|
||||
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x01000) == 0x01000) *lvl = 1; \
|
||||
else if ((wm->state & 0x02000) == 0x02000) *lvl = 2; \
|
||||
else if ((wm->state & 0x04000) == 0x04000) *lvl = 3; \
|
||||
else if ((wm->state & 0x08000) == 0x08000) *lvl = 4; \
|
||||
else if ((wm->state & 0x10000) == 0x10000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x00100) == 0x00100)
|
||||
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x00200) == 0x00200)
|
||||
#define WIIUSE_USING_IR(wm) ((wm->state & 0x00400) == 0x00400)
|
||||
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x00800) == 0x00800)
|
||||
|
||||
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
|
||||
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 2 for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* This is left over from an old hack, but it may actually
|
||||
* be a useful feature to keep so it wasn't removed.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
#define WIIMOTE_DEFAULT_TIMEOUT 100
|
||||
#define WIIMOTE_EXP_TIMEOUT 100
|
||||
#endif
|
||||
|
||||
typedef unsigned char ubyte;
|
||||
typedef char sbyte;
|
||||
typedef unsigned short uword;
|
||||
typedef short sword;
|
||||
typedef unsigned int uint;
|
||||
typedef char sint;
|
||||
|
||||
|
||||
struct wiimote_t;
|
||||
struct vec3b_t;
|
||||
struct orient_t;
|
||||
struct gforce_t;
|
||||
|
||||
#ifdef GEKKO
|
||||
typedef void (*wii_event_cb)(struct wiimote_t*, s32 event);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* @see wiiuse_init()
|
||||
*
|
||||
* A registered function of this type is called automatically by the wiiuse
|
||||
* library when the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*/
|
||||
typedef void (*wiiuse_data_cb)(struct wiimote_t* wm, ubyte* data, unsigned short len);
|
||||
|
||||
typedef enum data_req_s
|
||||
{
|
||||
REQ_READY = 0,
|
||||
REQ_SENT,
|
||||
REQ_DONE
|
||||
} data_req_s;
|
||||
|
||||
/**
|
||||
* @struct data_req_t
|
||||
* @brief Data read request structure.
|
||||
*/
|
||||
struct data_req_t {
|
||||
lwp_node node;
|
||||
ubyte data[48]; /**< buffer where read data is written */
|
||||
unsigned int len;
|
||||
data_req_s state; /**< set to 1 if not using callback and needs to be cleaned up */
|
||||
wiiuse_data_cb cb; /**< read data callback */
|
||||
struct data_req_t *next;
|
||||
};
|
||||
|
||||
typedef void (*cmd_blk_cb)(struct wiimote_t *wm,ubyte *data,uword len);
|
||||
|
||||
typedef enum cmd_blk_s
|
||||
{
|
||||
CMD_READY = 0,
|
||||
CMD_SENT,
|
||||
CMD_DONE
|
||||
} cmd_blk_s;
|
||||
|
||||
struct cmd_blk_t
|
||||
{
|
||||
lwp_node node;
|
||||
|
||||
ubyte data[48];
|
||||
uint len;
|
||||
|
||||
cmd_blk_s state;
|
||||
cmd_blk_cb cb;
|
||||
|
||||
struct cmd_blk_t *next;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec2b_t
|
||||
* @brief Unsigned x,y byte vector.
|
||||
*/
|
||||
typedef struct vec2b_t {
|
||||
ubyte x, y;
|
||||
} vec2b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3b_t
|
||||
* @brief Unsigned x,y,z byte vector.
|
||||
*/
|
||||
typedef struct vec3b_t {
|
||||
ubyte x, y, z;
|
||||
} vec3b_t;
|
||||
|
||||
/**
|
||||
* @struct vec3b_t
|
||||
* @brief Unsigned x,y,z byte vector.
|
||||
*/
|
||||
typedef struct vec3w_t {
|
||||
uword x, y, z;
|
||||
} vec3w_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3f_t
|
||||
* @brief Signed x,y,z float struct.
|
||||
*/
|
||||
typedef struct vec3f_t {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct orient_t
|
||||
* @brief Orientation struct.
|
||||
*
|
||||
* Yaw, pitch, and roll range from -180 to 180 degrees.
|
||||
*/
|
||||
typedef struct orient_t {
|
||||
float roll; /**< roll, this may be smoothed if enabled */
|
||||
float pitch; /**< pitch, this may be smoothed if enabled */
|
||||
float yaw;
|
||||
|
||||
float a_roll; /**< absolute roll, unsmoothed */
|
||||
float a_pitch; /**< absolute pitch, unsmoothed */
|
||||
} orient_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct gforce_t
|
||||
* @brief Gravity force struct.
|
||||
*/
|
||||
typedef struct gforce_t {
|
||||
float x, y, z;
|
||||
} gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct accel_t
|
||||
* @brief Accelerometer struct. For any device with an accelerometer.
|
||||
*/
|
||||
typedef struct accel_t {
|
||||
struct vec3w_t cal_zero; /**< zero calibration */
|
||||
struct vec3w_t cal_g; /**< 1g difference around 0cal */
|
||||
|
||||
float st_roll; /**< last smoothed roll value */
|
||||
float st_pitch; /**< last smoothed roll pitch */
|
||||
float st_alpha; /**< alpha value for smoothing [0-1] */
|
||||
} accel_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_dot_t
|
||||
* @brief A single IR source.
|
||||
*/
|
||||
typedef struct ir_dot_t {
|
||||
ubyte visible; /**< if the IR source is visible */
|
||||
|
||||
short rx; /**< raw X coordinate (0-1023) */
|
||||
short ry; /**< raw Y coordinate (0-767) */
|
||||
|
||||
ubyte size; /**< size of the IR dot (0-15) */
|
||||
} ir_dot_t;
|
||||
|
||||
|
||||
typedef struct fdot_t {
|
||||
float x,y;
|
||||
} fdot_t;
|
||||
|
||||
typedef struct sb_t {
|
||||
fdot_t dots[2];
|
||||
fdot_t acc_dots[2];
|
||||
fdot_t rot_dots[2];
|
||||
float angle;
|
||||
float off_angle;
|
||||
float score;
|
||||
} sb_t;
|
||||
|
||||
/**
|
||||
* @enum aspect_t
|
||||
* @brief Screen aspect ratio.
|
||||
*/
|
||||
typedef enum aspect_t {
|
||||
WIIUSE_ASPECT_4_3,
|
||||
WIIUSE_ASPECT_16_9
|
||||
} aspect_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_t
|
||||
* @brief IR struct. Hold all data related to the IR tracking.
|
||||
*/
|
||||
typedef struct ir_t {
|
||||
struct ir_dot_t dot[4]; /**< IR dots */
|
||||
ubyte num_dots; /**< number of dots at this time */
|
||||
|
||||
int state; /**< keeps track of the IR state */
|
||||
|
||||
int raw_valid; /**< is the raw position valid? */
|
||||
sb_t sensorbar; /**< sensor bar, detected or guessed */
|
||||
float ax; /**< raw X coordinate */
|
||||
float ay; /**< raw Y coordinate */
|
||||
float distance; /**< pixel width of the sensor bar */
|
||||
float z; /**< calculated distance in meters */
|
||||
float angle; /**< angle of the wiimote to the sensor bar*/
|
||||
|
||||
int smooth_valid; /**< is the smoothed position valid? */
|
||||
float sx; /**< smoothed X coordinate */
|
||||
float sy; /**< smoothed Y coordinate */
|
||||
float error_cnt; /**< error count, for smoothing algorithm*/
|
||||
float glitch_cnt; /**< glitch count, same */
|
||||
|
||||
int valid; /**< is the bounded position valid? */
|
||||
float x; /**< bounded X coordinate */
|
||||
float y; /**< bounded Y coordinate */
|
||||
enum aspect_t aspect; /**< aspect ratio of the screen */
|
||||
enum ir_position_t pos; /**< IR sensor bar position */
|
||||
unsigned int vres[2]; /**< IR virtual screen resolution */
|
||||
int offset[2]; /**< IR XY correction offset */
|
||||
|
||||
} ir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct joystick_t
|
||||
* @brief Joystick calibration structure.
|
||||
*
|
||||
* The angle \a ang is relative to the positive y-axis into quadrant I
|
||||
* and ranges from 0 to 360 degrees. So if the joystick is held straight
|
||||
* upwards then angle is 0 degrees. If it is held to the right it is 90,
|
||||
* down is 180, and left is 270.
|
||||
*
|
||||
* The magnitude \a mag is the distance from the center to where the
|
||||
* joystick is being held. The magnitude ranges from 0 to 1.
|
||||
* If the joystick is only slightly tilted from the center the magnitude
|
||||
* will be low, but if it is closer to the outter edge the value will
|
||||
* be higher.
|
||||
*/
|
||||
typedef struct joystick_t {
|
||||
struct vec2b_t max; /**< maximum joystick values */
|
||||
struct vec2b_t min; /**< minimum joystick values */
|
||||
struct vec2b_t center; /**< center joystick values */
|
||||
struct vec2b_t pos; /**< raw position values */
|
||||
|
||||
float ang; /**< angle the joystick is being held */
|
||||
float mag; /**< magnitude of the joystick (range 0-1) */
|
||||
} joystick_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct nunchuk_t
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
typedef struct nunchuk_t {
|
||||
struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
|
||||
int* flags; /**< options flag (points to wiimote_t.flags) */
|
||||
|
||||
ubyte btns; /**< what buttons have just been pressed */
|
||||
ubyte btns_last; /**< what buttons have just been pressed */
|
||||
ubyte btns_held; /**< what buttons are being held down */
|
||||
ubyte btns_released; /**< what buttons were just released this */
|
||||
|
||||
struct vec3w_t accel; /**< current raw acceleration data */
|
||||
struct orient_t orient; /**< current orientation on each axis */
|
||||
struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
} nunchuk_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct classic_ctrl_t
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
typedef struct classic_ctrl_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_last; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
ubyte rs_raw;
|
||||
ubyte ls_raw;
|
||||
|
||||
float r_shoulder; /**< right shoulder button (range 0-1) */
|
||||
float l_shoulder; /**< left shoulder button (range 0-1) */
|
||||
|
||||
struct joystick_t ljs; /**< left joystick calibration */
|
||||
struct joystick_t rjs; /**< right joystick calibration */
|
||||
ubyte type; /**< original, pro, wiiu pro */
|
||||
} classic_ctrl_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct guitar_hero_3_t
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
typedef struct guitar_hero_3_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_last; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
ubyte wb_raw;
|
||||
float whammy_bar; /**< whammy bar (range 0-1) */
|
||||
|
||||
ubyte tb_raw;
|
||||
int touch_bar; /**< touch bar */
|
||||
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
} guitar_hero_3_t;
|
||||
|
||||
/**
|
||||
* @struct wii_board_t
|
||||
* @brief Wii Balance Board expansion device.
|
||||
*/
|
||||
typedef struct wii_board_t {
|
||||
float tl; /* Interpolated */
|
||||
float tr;
|
||||
float bl;
|
||||
float br; /* End interp */
|
||||
short rtl; /* RAW */
|
||||
short rtr;
|
||||
short rbl;
|
||||
short rbr; /* /RAW */
|
||||
short ctl[3]; /* Calibration */
|
||||
short ctr[3];
|
||||
short cbl[3];
|
||||
short cbr[3]; /* /Calibration */
|
||||
float x;
|
||||
float y;
|
||||
} wii_board_t;
|
||||
|
||||
typedef struct motion_plus_t
|
||||
{
|
||||
short rx, ry, rz;
|
||||
ubyte status;
|
||||
ubyte ext;
|
||||
} motion_plus_t;
|
||||
|
||||
/**
|
||||
* @struct expansion_t
|
||||
* @brief Generic expansion device plugged into wiimote.
|
||||
*/
|
||||
typedef struct expansion_t {
|
||||
int type; /**< type of expansion attached */
|
||||
|
||||
union {
|
||||
struct nunchuk_t nunchuk;
|
||||
struct classic_ctrl_t classic;
|
||||
struct guitar_hero_3_t gh3;
|
||||
struct wii_board_t wb;
|
||||
struct motion_plus_t mp;
|
||||
};
|
||||
} expansion_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum win32_bt_stack_t
|
||||
* @brief Available bluetooth stacks for Windows.
|
||||
*/
|
||||
typedef enum win_bt_stack_t {
|
||||
WIIUSE_STACK_UNKNOWN,
|
||||
WIIUSE_STACK_MS,
|
||||
WIIUSE_STACK_BLUESOLEIL
|
||||
} win_bt_stack_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct wiimote_state_t
|
||||
* @brief Significant data from the previous event.
|
||||
*/
|
||||
typedef struct wiimote_state_t {
|
||||
unsigned short btns;
|
||||
|
||||
struct ir_t ir;
|
||||
struct vec3w_t accel;
|
||||
struct expansion_t exp;
|
||||
} wiimote_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum WIIUSE_EVENT_TYPE
|
||||
* @brief Events that wiiuse can generate from a poll.
|
||||
*/
|
||||
typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_NONE = 0,
|
||||
WIIUSE_EVENT,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_CONNECT,
|
||||
WIIUSE_DISCONNECT,
|
||||
WIIUSE_UNEXPECTED_DISCONNECT,
|
||||
WIIUSE_READ_DATA,
|
||||
WIIUSE_ACK,
|
||||
WIIUSE_NUNCHUK_INSERTED,
|
||||
WIIUSE_NUNCHUK_REMOVED,
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
WIIUSE_CLASSIC_CTRL_REMOVED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
|
||||
WIIUSE_WII_BOARD_INSERTED,
|
||||
WIIUSE_WII_BOARD_REMOVED,
|
||||
WIIUSE_MOTION_PLUS_ACTIVATED,
|
||||
WIIUSE_MOTION_PLUS_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
* @struct wiimote_t
|
||||
* @brief Wiimote structure.
|
||||
*/
|
||||
typedef struct wiimote_t {
|
||||
WCONST int unid; /**< user specified id */
|
||||
|
||||
#if defined(_WIN32)
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST ubyte normal_timeout; /**< normal timeout */
|
||||
WCONST ubyte exp_timeout; /**< timeout for expansion handshake */
|
||||
#elif defined(GEKKO)
|
||||
WCONST lwp_queue cmdq;
|
||||
WCONST struct bd_addr bdaddr; /**< bt address */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST struct bte_pcb *sock; /**< output socket */
|
||||
WCONST wii_event_cb event_cb; /**< event callback */
|
||||
#elif defined(unix)
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
#endif
|
||||
|
||||
WCONST int state; /**< various state flags */
|
||||
WCONST ubyte leds; /**< currently lit leds */
|
||||
#ifdef GEKKO
|
||||
WCONST ubyte battery_level; /**< battery level */
|
||||
#else
|
||||
WCONST float battery_level; /**< battery level */
|
||||
#endif
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST ubyte handshake_state; /**< the state of the connection handshake */
|
||||
WCONST ubyte expansion_state; /**< the state of the expansion handshake */
|
||||
|
||||
WCONST struct data_req_t* data_req; /**< list of data read requests */
|
||||
|
||||
WCONST struct cmd_blk_t *cmd_head;
|
||||
WCONST struct cmd_blk_t *cmd_tail;
|
||||
|
||||
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
|
||||
WCONST struct expansion_t exp; /**< wiimote expansion device */
|
||||
|
||||
WCONST struct vec3w_t accel; /**< current raw acceleration data */
|
||||
WCONST struct orient_t orient; /**< current orientation on each axis */
|
||||
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
|
||||
WCONST struct ir_t ir; /**< IR data */
|
||||
|
||||
WCONST unsigned short btns; /**< what buttons are down */
|
||||
WCONST unsigned short btns_last; /**< what buttons were down before */
|
||||
WCONST unsigned short btns_held; /**< what buttons are and were held down */
|
||||
WCONST unsigned short btns_released; /**< what buttons were just released */
|
||||
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
|
||||
WCONST ubyte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
|
||||
WCONST ubyte motion_plus_id[6];
|
||||
} wiimote;
|
||||
|
||||
#if defined(GEKKO)
|
||||
/**
|
||||
* @struct wiimote_listen_t
|
||||
* @brief Wiimote listen structure.
|
||||
*/
|
||||
typedef struct wiimote_listen_t {
|
||||
WCONST struct bd_addr bdaddr;
|
||||
WCONST struct bte_pcb *sock;
|
||||
WCONST struct wiimote_t *(*assign_cb)(struct bd_addr *bdaddr);
|
||||
WCONST struct wiimote_t *wm;
|
||||
} wiimote_listen;
|
||||
#endif
|
||||
|
||||
/*****************************************
|
||||
*
|
||||
* Include API specific stuff
|
||||
*
|
||||
*****************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
|
||||
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define WIIUSE_EXPORT_DECL
|
||||
#define WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_COMPILE_LIB
|
||||
#define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
|
||||
#else
|
||||
#define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
|
||||
#ifndef GEKKO
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
#else
|
||||
WIIUSE_EXPORT extern int wiiuse_register(struct wiimote_listen_t *wml, struct bd_addr *bdaddr, struct wiimote_t *(*assign_cb)(struct bd_addr *bdaddr));
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb);
|
||||
WIIUSE_EXPORT extern void wiiuse_sensorbar_enable(int enable);
|
||||
#endif
|
||||
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds,cmd_blk_cb cb);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, ubyte* buffer, unsigned int offset, unsigned short len, cmd_blk_cb cb);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t *wm,unsigned int addr,ubyte *data,ubyte len,cmd_blk_cb cb);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t *wm,cmd_blk_cb cb);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, ubyte normal_timeout, ubyte exp_timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_streamdata(struct wiimote_t *wm,ubyte *data,ubyte len,cmd_blk_cb cb);
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_mode(struct wiimote_t *wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* motion_plus.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status);
|
||||
|
||||
/* speaker.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_speaker(struct wiimote_t *wm, int status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
277
external/libogc_ir/upstream/wiiuse_internal.h
vendored
Normal file
277
external/libogc_ir/upstream/wiiuse_internal.h
vendored
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header: /lvm/shared/ds/ds/cvs/devkitpro-cvsbackup/libogc/wiiuse/wiiuse_internal.h,v 1.8 2008-12-10 16:16:40 shagkur Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General internal wiiuse stuff.
|
||||
*
|
||||
* Since Wiiuse is a library, wiiuse.h is a duplicate
|
||||
* of the API header.
|
||||
*
|
||||
* The code that would normally go in that file, but
|
||||
* which is not needed by third party developers,
|
||||
* is put here.
|
||||
*
|
||||
* So wiiuse_internal.h is included by other files
|
||||
* internally, wiiuse.h is included only here.
|
||||
*/
|
||||
|
||||
#ifndef WIIUSE_INTERNAL_H_INCLUDED
|
||||
#define WIIUSE_INTERNAL_H_INCLUDED
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <arpa/inet.h> /* htons() */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
/* wiiuse version */
|
||||
#define WIIUSE_VERSION "0.12"
|
||||
|
||||
/********************
|
||||
*
|
||||
* Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* Communication channels */
|
||||
#define WM_OUTPUT_CHANNEL 0x11
|
||||
#define WM_INPUT_CHANNEL 0x13
|
||||
|
||||
#define WM_SET_REPORT 0x50
|
||||
#define WM_DATA 0xA0
|
||||
|
||||
/* commands */
|
||||
#define WM_CMD_RUMBLE 0x10
|
||||
#define WM_CMD_LED 0x11
|
||||
#define WM_CMD_REPORT_TYPE 0x12
|
||||
#define WM_CMD_IR 0x13
|
||||
#define WM_CMD_SPEAKER_ENABLE 0x14
|
||||
#define WM_CMD_CTRL_STATUS 0x15
|
||||
#define WM_CMD_WRITE_DATA 0x16
|
||||
#define WM_CMD_READ_DATA 0x17
|
||||
#define WM_CMD_STREAM_DATA 0x18
|
||||
#define WM_CMD_SPEAKER_MUTE 0x19
|
||||
#define WM_CMD_IR_2 0x1A
|
||||
|
||||
/* input report ids */
|
||||
#define WM_RPT_CTRL_STATUS 0x20
|
||||
#define WM_RPT_READ 0x21
|
||||
#define WM_RPT_ACK 0x22
|
||||
#define WM_RPT_BTN 0x30
|
||||
#define WM_RPT_BTN_ACC 0x31
|
||||
#define WM_RPT_BTN_ACC_IR 0x33
|
||||
#define WM_RPT_BTN_EXP 0x34
|
||||
#define WM_RPT_BTN_ACC_EXP 0x35
|
||||
#define WM_RPT_BTN_IR_EXP 0x36
|
||||
#define WM_RPT_BTN_ACC_IR_EXP 0x37
|
||||
|
||||
#define WM_BT_INPUT 0x01
|
||||
#define WM_BT_OUTPUT 0x02
|
||||
|
||||
/* Identify the wiimote device by its class */
|
||||
#define WM_DEV_CLASS_0 0x04
|
||||
#define WM_DEV_CLASS_1 0x25
|
||||
#define WM_DEV_CLASS_2 0x00
|
||||
#define WM_VENDOR_ID 0x057E
|
||||
#define WM_PRODUCT_ID 0x0306
|
||||
|
||||
/* controller status stuff */
|
||||
#define WM_MAX_BATTERY_CODE 0xC8
|
||||
|
||||
/* offsets in wiimote memory */
|
||||
#define WM_MEM_OFFSET_CALIBRATION 0x16
|
||||
#define WM_EXP_MEM_BASE 0x04A40000
|
||||
#define WM_EXP_MEM_ENABLE1 0x04A400F0
|
||||
#define WM_EXP_MEM_ENABLE2 0x04A400FB
|
||||
#define WM_EXP_MEM_KEY 0x04A40040
|
||||
#define WM_EXP_MEM_CALIBR 0x04A40020
|
||||
#define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE
|
||||
#define WM_EXP_ID 0x04A400FA
|
||||
|
||||
#define WM_REG_IR 0x04B00030
|
||||
#define WM_REG_IR_BLOCK1 0x04B00000
|
||||
#define WM_REG_IR_BLOCK2 0x04B0001A
|
||||
#define WM_REG_IR_MODENUM 0x04B00033
|
||||
|
||||
#define WM_REG_SPEAKER_REG1 0x04A20001
|
||||
#define WM_REG_SPEAKER_REG2 0x04A20008
|
||||
#define WM_REG_SPEAKER_REG3 0x04A20009
|
||||
#define WM_REG_SPEAKER_BLOCK 0x04A20001
|
||||
|
||||
/* ir block data */
|
||||
#define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
|
||||
#define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
|
||||
#define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
|
||||
#define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
|
||||
#define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
|
||||
#define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
|
||||
#define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
|
||||
#define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
|
||||
|
||||
#define WM_IR_TYPE_BASIC 0x01
|
||||
#define WM_IR_TYPE_EXTENDED 0x03
|
||||
#define WM_IR_TYPE_FULL 0x05
|
||||
|
||||
/* controller status flags for the first message byte */
|
||||
/* bit 1 is unknown */
|
||||
#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
|
||||
#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
|
||||
#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_1 0x10
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_2 0x20
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_3 0x40
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_4 0x80
|
||||
|
||||
/* aspect ratio */
|
||||
#define WM_ASPECT_16_9_X 660
|
||||
#define WM_ASPECT_16_9_Y 370
|
||||
#define WM_ASPECT_4_3_X 560
|
||||
#define WM_ASPECT_4_3_Y 420
|
||||
|
||||
|
||||
/**
|
||||
* Expansion stuff
|
||||
*/
|
||||
|
||||
/* encrypted expansion id codes (located at 0x04A400FC) */
|
||||
#define EXP_ID_CODE_NUNCHUK 0xa4200000
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0xa4200101
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING 0x90908f00
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING2 0x9e9f9c00
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING3 0x908f8f00
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC 0xa5a2a300
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC2 0x98999900
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC3 0xa0a1a000
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC4 0x8d8d8e00
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC5 0x93949400
|
||||
#define EXP_ID_CODE_CLASSIC_WIIU_PRO 0xa4200120
|
||||
#define EXP_ID_CODE_GUITAR 0xa4200103
|
||||
#define EXP_ID_CODE_WIIBOARD 0xa4200402
|
||||
#define EXP_ID_CODE_MOTION_PLUS 0xa4200405
|
||||
|
||||
#define EXP_HANDSHAKE_LEN 224
|
||||
|
||||
/********************
|
||||
*
|
||||
* End Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* wiimote state flags - (some duplicated in wiiuse.h)*/
|
||||
#define WIIMOTE_STATE_DEV_FOUND 0x00001
|
||||
//#define WIIMOTE_STATE_DEV_REGISTER 0x00002
|
||||
#define WIIMOTE_STATE_HANDSHAKE 0x00004 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x00008 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_CONNECTED 0x00010
|
||||
#define WIIMOTE_STATE_EXP_HANDSHAKE 0x00020 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_EXP_FAILED 0x00040 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_RUMBLE 0x00080
|
||||
#define WIIMOTE_STATE_ACC 0x00100
|
||||
#define WIIMOTE_STATE_EXP 0x00200
|
||||
#define WIIMOTE_STATE_IR 0x00400
|
||||
#define WIIMOTE_STATE_SPEAKER 0x00800
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL1 0x01000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL2 0x02000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL3 0x04000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL4 0x08000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL5 0x10000
|
||||
#define WIIMOTE_STATE_IR_INIT 0x20000
|
||||
#define WIIMOTE_STATE_SPEAKER_INIT 0x40000
|
||||
#define WIIMOTE_STATE_WIIU_PRO 0x80000
|
||||
|
||||
#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
|
||||
|
||||
/* macro to manage states */
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
||||
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||
|
||||
#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
|
||||
#define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
|
||||
|
||||
#define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
|
||||
|
||||
/* misc macros */
|
||||
#define WIIMOTE_ID(wm) (wm->unid)
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
|
||||
/*
|
||||
* Smooth tilt calculations are computed with the
|
||||
* exponential moving average formula:
|
||||
* St = St_last + (alpha * (tilt - St_last))
|
||||
* alpha is between 0 and 1
|
||||
*/
|
||||
#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.3f
|
||||
|
||||
#define SMOOTH_ROLL 0x01
|
||||
#define SMOOTH_PITCH 0x02
|
||||
|
||||
#include <wiiuse/wiiuse.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct op_t
|
||||
{
|
||||
ubyte cmd;
|
||||
union {
|
||||
struct {
|
||||
uint addr;
|
||||
uword size;
|
||||
} readdata;
|
||||
struct {
|
||||
uint addr;
|
||||
ubyte size;
|
||||
ubyte data[16];
|
||||
} writedata;
|
||||
ubyte __data[MAX_PAYLOAD];
|
||||
};
|
||||
|
||||
void *buffer;
|
||||
int wait;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* not part of the api */
|
||||
void wiiuse_init_cmd_queue(struct wiimote_t *wm);
|
||||
void wiiuse_send_next_command(struct wiimote_t *wm);
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm,cmd_blk_cb cb);
|
||||
int wiiuse_sendcmd(struct wiimote_t *wm,ubyte report_type,ubyte *msg,int len,cmd_blk_cb cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WIIUSE_INTERNAL_H_INCLUDED */
|
||||
Loading…
Add table
Add a link
Reference in a new issue