Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous motion plus init & OSX Refactoring #30

Merged
merged 60 commits into from Dec 12, 2012

Conversation

lysannschlegel
Copy link
Collaborator

Includes all changes from #14 and #26.
Yes, there were several of conflicts, but I am confident I resolved them all correctly.

This branch also moves all platform-specific read and write code into wiiuse_os_read and wiiuse_os_write.
This ensures that the same interface is used for all wiiuse_io_read and wiiuse_io_write implementations. Especially inserting the SET_OUTPUT_REPORT byte on Mac and Linux is handled within these functions now, and not outside. The callers of these functions never see this first byte.

I tested with a Wiimote and Nunchuk with and without M+ on Mac and Windows, but I don't have a Linux box with Bluetooth available.

janoc and others added 30 commits January 16, 2012 13:35
Made the Motion+ init a lot more robust
Code cleanup
-This ensures the function can be called outside of motion_plus.c
-Also eliminates an explicit declaration warning on events.c
-wiiuse_internal.h was already included via motion_plus.h
-io.h is needed for wiiuse_read
-According to the new signature for wiiuse_io_read
@rpavlik
Copy link
Collaborator

rpavlik commented Dec 10, 2012

Seems to build and work on Ubuntu 10.04 x64 with GCC and a MotionPlus, and with MXE cross-compiling for windows and running on Windows 7.

On Linux, I sometimes get the warning [WARNING] Transmitting data packet when no request was made.

On Windows, with the accelerometers turned on in the example, I occasionally get three WARNING Packet ignored. This may indicate a problem (timeout is 10 ms). messages right in a row after reporting accel. numbers. Also, on connection, I get WARNING id 1 dropping report X, waiting for 0x21 twice, where X is first 0x22, then 0x30. (This is an original wiimote that was sold with a motion plus, I'm pairing it while the motion plus is attached)

Can't test with a nunchuk because @jscasallas still has mine, if I recall correctly.

With Clang I get these build errors, fixable by adding this line to the top of os_nix.c:

#include <sys/time.h>                   /* for struct timeval */

Not so sure about the warnings about "implicit declarations"...

/home/rpavlik/src/wiiuse/src/util.c:46:2: warning: implicit declaration of function 'usleep' is invalid in C99 [-Wimplicit-function-declaration]
        usleep(durationMilliseconds * 1000);
        ^

/home/rpavlik/src/wiiuse/src/os_nix.c:236:17: error: variable has incomplete type 'struct timeval'
        struct timeval tv;
                       ^
/home/rpavlik/src/wiiuse/src/os_nix.c:236:9: note: forward declaration of 'struct timeval'
        struct timeval tv;
               ^
/home/rpavlik/src/wiiuse/src/os_nix.c:237:2: error: use of undeclared identifier 'fd_set'
        fd_set fds;
        ^
/home/rpavlik/src/wiiuse/src/os_nix.c:250:2: warning: implicit declaration of function 'FD_ZERO' is invalid in C99 [-Wimplicit-function-declaration]
        FD_ZERO(&fds);
        ^
/home/rpavlik/src/wiiuse/src/os_nix.c:250:11: error: use of undeclared identifier 'fds'
        FD_ZERO(&fds);
                 ^
/home/rpavlik/src/wiiuse/src/os_nix.c:255:4: warning: implicit declaration of function 'FD_SET' is invalid in C99 [-Wimplicit-function-declaration]
                        FD_SET(wm[i]->in_sock, &fds);
                        ^
/home/rpavlik/src/wiiuse/src/os_nix.c:255:28: error: use of undeclared identifier 'fds'
                        FD_SET(wm[i]->in_sock, &fds);
                                                ^
/home/rpavlik/src/wiiuse/src/os_nix.c:269:6: warning: implicit declaration of function 'select' is invalid in C99 [-Wimplicit-function-declaration]
        if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
            ^
/home/rpavlik/src/wiiuse/src/os_nix.c:269:30: error: use of undeclared identifier 'fds'
        if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
                                    ^
/home/rpavlik/src/wiiuse/src/os_nix.c:281:7: warning: implicit declaration of function 'FD_ISSET' is invalid in C99 [-Wimplicit-function-declaration]
                if (FD_ISSET(wm[i]->in_sock, &fds)) {
                    ^
/home/rpavlik/src/wiiuse/src/os_nix.c:281:33: error: use of undeclared identifier 'fds'
                if (FD_ISSET(wm[i]->in_sock, &fds)) {
                                              ^
/home/rpavlik/src/wiiuse/src/os_nix.c:307:6: warning: unused variable 'i' [-Wunused-variable]
        int i;
            ^

@janoc
Copy link
Collaborator

janoc commented Dec 10, 2012

Hello,

On 12/10/2012 09:00 PM, Ryan Pavlik wrote:

Seems to build and work on Ubuntu 10.04 x64 with GCC and a MotionPlus,
and with MXE cross-compiling for windows and running on Windows 7.

On Linux, I sometimes get the warning |[WARNING] Transmitting data
packet when no request was made.|

That looks like a spurious message. The function event_data_write()
where this comes from is called from only a single place: events.c:276
when the report type is WM_RPT_WRITE. According to the doc, it is an
unsolicited report intended to signal acknowledgements, failures or
function results of other output reports:

http://wiibrew.org/wiki/Wiimote#0x22:_Acknowledge_output_report.2C_return_function_result

On Windows, with the accelerometers turned on in the example, I
occasionally get three |WARNING Packet ignored. This may indicate a
problem (timeout is 10 ms).| messages right in a row after reporting
accel. numbers. Also, on connection, I get |WARNING id 1 dropping report
X, waiting for 0x21| twice, where X is first 0x22, then 0x30. (This is
an original wiimote that was sold with a motion plus, I'm pairing it
while the motion plus is attached)

I have seen this too, I strongly suspect this is very much due to the
bugs in the Windows BT stack.

0x22 is the unsolicited report described above, 0x30 is buttons report.

The message on connection is probably just too verbose, I suspect it
happens when some data (probably calibration or expansion ID) from the
Wiimote's memory is being read (waiting for report 0x21) but some other
report has arrived first and was dropped. I have seen that a lot when
debugging the Motion+ - you send a request to read some data from the
Wiimote and expect a reply. However, in the meantime you get several
unrelated reports, such as buttons or IR and only after some time the
correct report arrives. That was the main reason why the synchronous
init was required - if those other reports were processed before the
init was concluded, it was throwing off the state machine and performing
calculations with uninitialized data (such as the calibration).

Not so sure about the warnings about "implicit declarations"...

Looks like a missing header: #include <unistd.h>
I don't have Clang installed so I cannot test it, but usleep is declared
there.

Regards,

Jan

@rpavlik
Copy link
Collaborator

rpavlik commented Dec 11, 2012

The catch is that I'm pretty sure #include <unistd.h> is there...

@janoc
Copy link
Collaborator

janoc commented Dec 11, 2012

On 12/11/2012 01:25 AM, Ryan Pavlik wrote:

The catch is that I'm pretty sure #include is there...

Could it be that the #include relies on some "gcc-ism" that Clang
doesn't implement? Like #import or some preprocessor symbol not defined
by Clang?

It is system header, so it would not surprise me all that much.

Jan

@rpavlik
Copy link
Collaborator

rpavlik commented Dec 11, 2012

You can pull my updates to your pull request from my osx-refactor_sync-mplus branch. Thanks so much for working on this!

Still get these warnings that make no sense to me given that I've got an #include <unistd.h> in there, but I'm not going to worry about it right now:

/home/rpavlik/src/wiiuse/src/util.c:46:2: warning: implicit declaration of function 'usleep' is invalid in C99 [-Wimplicit-function-declaration]
        usleep(durationMilliseconds * 1000);
        ^

/home/rpavlik/src/wiiuse/example-sdl/sdl.c:371:2: warning: implicit declaration of function 'usleep' is invalid in C99 [-Wimplicit-function-declaration]
        usleep(200000);
        ^
/home/rpavlik/src/wiiuse/example/example.c:454:2: warning: implicit declaration of function 'usleep' is invalid in C99 [-Wimplicit-function-declaration]
        usleep(200000);
        ^

cac13f1 Add CMakePackageConfigHelpers as a backported module from 2.8.10
44e17a5 Update help
92f9405 Add FindDirectShow from VRPN
a93bf46 Update FindVRPN
edf459d clean up some modules
0bf8b53 Update documentation/help
900ae37 Improvements to findcppdom
bcdd5ed Adrienne timecode generator finder
fc14864 IDLJ finder/script
5fa91d4 Finder for windows/platform SDK
835a160 Add module to find perl modules: pass them as components
7dc76c3 cleanup
38e2a0d Create a doc_open target to open html docs
e8de008 Improved directx finding
787900c Conditionally use libuuid for VPR22
1c73e35 Add a helper error message to findcppcheck.
9e8b357 Generate, rather than enumerate, juggler lib names.
d42ae48 Add another compiler flag for warnings.
911f522 Just a little cleanup.
a466ea5 Update help
30af184 Add two new scripts written for VR Juggler
09ccc48 Update VR Juggler finders for 3.0.1
f9a5b86 VR JuggLua is no longer unreleased research software - ditch the scary warning.
1adb75e Update GetGitRevisionDescription to handle new submodules a little better.
187b7b2 Add new FindViewPoint
d1ec683 Enhance FindOpenHaptics to handle 3.1
de68fc0 Restore some tabs that went missing
feb11f6 Improve GHOST finder.
b922e06 Update help
7ff9c53 Run cmake-bulk-decrufter.
0873f79 Merge branch 'jscasallas/master'
e2ec7cd Add helpful comment about use as submodule
2a42dc5 Simplify FindQVRPN.
8ddcb84 Windows compatibility for the pull request just merged
4fcc618 Merge pull request wiiuse#6 from phire/cmake-modules
fa1ef4c Add additional versions of cppdom and gmtl.
7db0714 Regenerate help
39c0f2f Add find directinput
d2e2a74 Update copyright year
5c05172 Update module help
5b62638 Rename to UseMarkdown and add rename feature
f92055a Add markdown scripts (finding and targets)
00cefbe GetGitRevisionDescription: Search parent dirs for .git/
0fb259a New module: FindQVRPN.cmake
9616f6e Find jccl and vrjuggler plugins, and split between debug and release
4856978 Set WIIUSE_RUNTIME_LIBRARY in Wiiuse even not on Windows
d94b209 make FindWinHID work on MinGW.
4c110cb Fix copy-pasteo in findcppunit
8be460a fix doc typo
6a78da3 Handle other compilers better by using compiler ID
a90f87b Use compiler behavior, not identity, to decide what warning flags to use
f03d7a8 Properly check the various arguments to cppcheck rather than assume based on a few tests.
d3ffd8a get git revision more robustly
1fb0e41 update ghost fake stl to simplify header
6fbe007 No more checking the stdc++ version for openhaptics
db11bb9 make sure we actually link against HDU/HLU nested targets!
a6580e9 remove unused variables in test file
f4a26c5 update copyright
16a6266 fix dcubed nested target
ca5cd7a mark luac item as advanced
f131cbe actually use the jttk root dir specified
501dbb2 improve dcubed include dirs
ae8764f improve splitting osg plugins into debug and release

git-subtree-dir: cmake
git-subtree-split: cac13f1c3225555cec9ae06a1ba47baa8c90442a
Merge commit 'dd2c7e902aa095fd7844329e38bca7cd7c51e6d9' into osx-refactor_sync-mplus

Conflicts:
	cmake/FindWinHID.cmake
@rpavlik
Copy link
Collaborator

rpavlik commented Dec 12, 2012

OK, well, I've tested this (with my modifications - @lysannkessler please pull from my same-named branch and push it to this pull request) fairly well - see https://github.com/rpavlik/wiiuse/wiki/Compatibility for the nitty-gritty. If someone else could test, particularly with some non-official peripherals and/or a Mac, that would be great. (I'd really like to merge this and release 0.15!)

@lysannkessler - please also add yourself to the README and update the changelog how you see fit. Once it's been merged, we'll get @janoc to add to the changelog, etc.

@lysannschlegel
Copy link
Collaborator Author

Also, on connection, I get "WARNING id 1 dropping report X, waiting for 0x21" twice, where X is first 0x22, then 0x30. (This is an original wiimote that was sold with a motion plus, I'm pairing it while the motion plus is attached)

0x22 is the unsolicited report described above, 0x30 is buttons report.
The message on connection is probably just too verbose, I suspect it happens when some data (probably calibration or expansion ID) from the Wiimote's memory is being read (waiting for report 0x21) but some other report has arrived first and was dropped. I have seen that a lot when debugging the Motion+ - you send a request to read some data from the Wiimote and expect a reply. However, in the meantime you get several unrelated reports, such as buttons or IR and only after some time the correct report arrives. That was the main reason why the synchronous init was required - if those other reports were processed before the init was concluded, it was throwing off the state machine and performing calculations with uninitialized data (such as the calibration).

I added the warning in the case messages are dropped in wiiuse_wait_report, mainly for debugging purposes. Would you suggest to change the log too WIIUSE_DEBUG instead of WIIUSE_WARNING?

@rpavlik
Copy link
Collaborator

rpavlik commented Dec 12, 2012

On Wed, Dec 12, 2012 at 1:34 PM, Lysann Schlegel
notifications@github.comwrote:

I added the warning in the case messages are dropped in
wiiuse_wait_report, mainly for debugging purposes. Would you suggest to
change the log too WIIUSE_DEBUG instead of WIIUSE_WARNING?

Probably a good idea, since it seems like occasional messages of this type
are harmless, and a debug build would be the approach for troubleshooting
anyway.

Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik@iastate.edu
http://academic.cleardefinition.com

@lysannschlegel
Copy link
Collaborator Author

Still get these usleep warnings that make no sense to me given that I've got an #include <unistd.h> in there, but I'm not going to worry about it right now.

I want add this to the discussion, but probably we don't want to bother about the warnings right now.

@rpavlik
Copy link
Collaborator

rpavlik commented Dec 12, 2012

I've "moved" the issue about warnings to #36 to be tracked separately.

@lysannschlegel
Copy link
Collaborator Author

I pulled your changes and added myself to the list of contributors :)
The changelog looks fine to me.

@rpavlik
Copy link
Collaborator

rpavlik commented Dec 12, 2012

Great, thanks!

rpavlik added a commit that referenced this pull request Dec 12, 2012
Synchronous motion plus init & OSX Refactoring.

Incorporates work by lysannkessler, janoc, and jscasallas.
@rpavlik rpavlik merged commit c60b58d into wiiuse:master Dec 12, 2012
@rpavlik
Copy link
Collaborator

rpavlik commented Dec 12, 2012

@lysannkessler I've added you as a collaborator on this repo. You're still welcome to use pull requests (within this repo between branches, if you like, for easier collaboration), but at the same time also welcome to just commit if you wish (just as @janoc and @jscasallas can)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants