Powered by SmartDoc

C++��C#�ł܂Ȃ�WiiRemote�v���O���~���O

����ŕF�{�����V
shirai at mail.com
http://akihiko.shirai.as/projects/BookWii/

�ڎ�

����͂ł�WiimoteLib�Ƃ���API�𗘗p����AWiiRemote�̃v���O���~���O�̊�b��������Ă����܂��B�v���O���~���O�‹��Ƃ���A�����ŗ��p�ł���uVisual C++ 2008 Express Edition�v��������uVisual C# 2008 Express Edition�v���g���܂��B�‚܂�v���O���~���O����Ƃ���AC++��C#�𓯎��ɕ��񂵂Ĉ����܂��B

�܂��A�{�͂�C#.NET�ɂ��v���O���~���O�T���v���͋���H�������w�Z������V��(http://www.kosaka-lab.com/)�̋��͂ɂ����̂ł��B�v���O���~���O���S�҂ł��킩��₷�������ł���悤��A�ł��邾�������̃T���v���𒚔J�����ǂ��ĉ�����邱�Ƃ�AWiiRemote�v���O���~���O��̌����邱�Ƃ��ł���悤�ɂȂ��Ă��܂��B

�v���O���~���O�‹��̃Z�b�g�A�b�v

���̃Z�N�V�����ł�A�����ŗ��p�ł���uVisual C++ 2008 Express Edition�v��uVisual C# 2008 Express Edition�v���Z�b�g�A�b�v���܂��B���ɂ�������i���ʃo�[�W����(Standard Edition�Ȃ�)���C���X�g�[������Ă������AC++�AC#�̂����ꂩ�����K�v�łȂ�����A�K�v�ȂƂ��낾���Q�Ƃ��Ă��������B

Visual C# 2008 Express Edition�̃Z�b�g�A�b�v

Visual C# 2008 Express Edition�̃Z�b�g�A�b�v�ɂ‚��Ă�A�}�C�N���\�t�g�̌����T�C�g�ɒ��J�ɉ������Ă���܂��B

http://www.microsoft.com/japan/msdn/vstudio/express/beginners/2008/vcsharp.aspx

Express Edition��Web�C���X�g�[�����_�E�����[�h���A���v��\������A�v���P�[�V���������ۂ����Ă݂邱�Ƃ��ł��܂��BC#�͂��΂炭�g���\��͂Ȃ�����ǂ��A�C���X�g�[�����Ă݂悤�A�Ƃ���������񎎂��Ă݂Ă��������B

Visual C++ 2008 Express Edition�̃Z�b�g�A�b�v

�����ł�Microsoft Visual C++ 2008 Express Edition�̃Z�b�g�A�b�v�A�T���v���J���ɂ‚��ĉ�����܂��B����Visual C++��.NET�Ƃ������J���‹������g���̕���A�ǂݔ�΂��Ă��������Ă���肠��܂���B

�܂��}�C�N���\�t�g�̃z�[���y�[�W����Microsoft Visual C++ 2008 Express Edition���_�E�����[�h���܂��B

Visual C++ 2008 Express Edition

http://www.microsoft.com/japan/msdn/vstudio/express/

Microsoft Visual Studio Express�»•i‚̃z�[ƒ€ƒy�[ƒW

�uWeb�C���X�g�[��(�_�E�����[�h)�v���N���b�N�����AWeb�C���X�g�[���ŃZ�b�g�A�b�v�t�@�C���uvcsetup.exe�v���_�E�����[�h���邱�Ƃ��ł��܂��B���̃z�[���y�[�W�ɂ�Visual Studio���i���g����ł̖��ɗ����񂪂������񂠂�܂��B�Ƃ肠����VC2008���g���Ă݂�������u�͂��߂Ă̕��̂��߂̃C���X�g�[�����@�v��ǂ�ł݂�Ƃ���Ɨǂ��ł��傤�B

�K�v�ȃn�[�h�f�B�X�N�e�ʂ̊m�F�A�N�����̃A�v���P�[�V������I���Ȃǂ��s���Ă���C���X�g�[���E�B�U�[�h�uvcsetup.exe�v���N�����܂��B

VC2008ƒCƒ“ƒXƒg�[ƒ‹ ƒEƒBƒU�[ƒh(step1)

�u�Z�b�g�A�b�v�̕i������v���O�����v�̓`�F�b�N���Ă����Ȃ��Ă��A�ǂ���ł����܂��܂���B�u����v���N���b�N����i�݂܂��B

VC2008ƒCƒ“ƒXƒg�[ƒ‹ ƒEƒBƒU�[ƒh(step2)

���C�Z���X�������悭�ǂ��u���ӂ���v��I��ł��������B�܂��uVisual Studio�ŃI�����C����RSS�R���e���c����M���ĕ\���ł���悤�ɂ���v�����ɖ�肪�Ȃ���΃`�F�b�N���܂��傤�B�C�x���g��T�[�r�X�p�b�N�Ȃǂ�X�V���VC2008�N������ɕ\�������X�^�[�g�y�[�W�Ɏ����I�ɕ\�������悤�ɂȂ�܂��i�����ł�RSS��M��ݒ�͌�ł��I�v�V�������‹����X�^�[�g�A�b�v�ŕ�X�ł��܂��j�B�u����v���N���b�N����i�݂܂��B

VC2008ƒCƒ“ƒXƒg�[ƒ‹ ƒEƒBƒU�[ƒh(step3)

�u�C���X�g�[���I�v�V�����v��I�����܂��B�����ŕ\������Ă���3�‚̃I�v�V������A�ǂ���C���X�g�[�����Ȃ��Ă���肠��܂���B�uMSDN Express���C�u�����v��F1�L�[�ŌĂ�o����h�L�������g��A�I�����C���ł̕����[�����Ă���̂ł����A�M�҂͓d�Ԃ̒��ŃR�[�f�B���O�����邱�Ƃ������̂ŃC���X�g�[�����Ă��܂��i�I�����C���łƓ������ė��p�ł��܂��j�B�uSQL Server 2005�v�A�uSilverlight�v�͎g���\�肪�Ȃ���΃C���X�g�[�����Ȃ��ėǂ��ł��傤�B�u����v���N���b�N����i�݂܂��B

VC2008ƒCƒ“ƒXƒg�[ƒ‹ ƒEƒBƒU�[ƒh(step4)

�u�R�s�[��t�H���_�v�ƃ_�E�����[�h�p�b�P�[�W�̃��X�g�ł��B�u�C���X�g�[������t�H���_�v�͖{���ł̓f�t�H���g�̂܂܂Ƃ��ĉ�����܂��B�_�E�����[�h���X�g�̒���uWindows SDK�v�������Ă���̂�������܂�(�ȑO��Express Edition�ł͕ʓr�C���X�g�[������K�v������܂���)�B�u�C���X�g�[���v���N���b�N����ƃ_�E�����[�h�ƃC���X�g�[�������s����܂��B

VC2008ƒCƒ“ƒXƒg�[ƒ‹ ƒEƒBƒU�[ƒh(step5)

����WindowsXP�V���[�Y�ɂ�����VC2008�Z�b�g�A�b�v�̗���ł��iWindows Vista�����u�Ǘ��Ҍ����Ŏ��s�v������K�v������_�Ȃǂ����‚��ׂ����_���قȂ�܂����قړ�������ł��j�B�������������VC2008�̃E�B�U�[�h��I�����C���`���[�g���A���Ȃǂ��g���ĊȒP�ȃv���O���~���O�������Ă݂�Ɨǂ��ł��傤�B

�R�����FVC���݊‹�����������Version Selector

�����A����Visual C++��Visual Studio�̉ߋ��̃o�[�W����(.NET2003/2005�Ȃ�)�����g����A����2008�N���_���V�łł���Visual C++ 2008 Express�i�ȉ�VC2008�j�������Ă݂����̓ǎ҂�A�����ł�����Ɖ�蓹�����Ď����Ă݂邱�Ƃ��������߂��܂��BVC2008��Version Selector�Ƃ����@�\������A�قȂ�o�[�W������Visual Studio���i����݂��”\�ɂ��܂��B�e�o�[�W�����ɂ����ă\�����[�V�����t�@�C���͊g���q�u.sln�v�ƕς��܂���A�����I�ɂ��̊g���q�u.sln�v�Ɋ֘A�Â���ꂽ�A�v���P�[�V�����ł���uVersion Selector�v���t�@�C�������̃o�[�W�����L�q�������I�ɓǂݎ��A�t�@�C�����_�u���N���b�N���ꂽ�Ƃ��͓K�؂ȃo�[�W������VC���N�����܂��B���̋@�\�̂������ŕ����̃o�[�W�����̊J���‹������S���ăC���X�g�[���ł���悤�ɂȂ�܂��B

WiimoteLib�̊T�v

WiimoteLib��Brian Peek(http://www.brianpeek.com/)�ɂ��.NET�‹��ŗ��p�ł���API�I�[�v���\�[�X�v���W�F�N�g�ł��BMicrosoft���x������I�[�v���\�[�X�v���W�F�N�g�x���T�C�g�uCodePlex�v(http://www.codeplex.com/)�Ō��J����Ă��܂��BWiimoteLib��p���邱�Ƃ�A.NET�‹��ŊȒP��WiiRemote�𗘗p����A�v���P�[�V�������J�����邱�Ƃ��ł��܂��BVersion1.6.0.0�����WiiRemote�����łȂ�Wii Fit�o�����X�{�[�h�ɂ��Ή����Ă��܂��B

WiimoteLib��.NET�ŊJ�����ꂽAPI�ł���A����Ɉˑ����܂���AC#��Visual Basic�����C���̃^�[�Q�b�g�̂悤�ł��BC++�ł̃T���v���͔z�z����Ă��炸�A�܂��l�b�g���������܂葶�݂��Ȃ��̂ł����A�{�͂�ǂ�i�߂Ă������Ƃ�A������ԂŖ��Ȃ����p�ł��邱�Ƃ��킩��ł��傤�B

C++����ɂ͂��܂��܂Ȍ���d�l�����݂��܂����A�{�͂ł͓���.NET�v���O���~���O�Ƃ��Ĉ����₷���uC++/CLI�v�������܂��BCLI�Ƃ�uCommon Language Infrastructure(���ʌ�����)�v�̗���AC++�Ɋ���e���񂾃v���O���}�[�ɂ��A��a������Ȃ��`���i�I��.NET�v���O���~���O�‹���񋟂��Ă��܂��B�{�͂ł͂��̓����𗘗p���A������{�I�ȃv���O���~���O��C++��C#�Ƃ���2�‚̌���ʼn������Ƃ����킯�ł��B

WiimoteLib�̃��C�Z���X

WiimoteLib�̃��C�Z���X��uMicrosoft Permissive License (Ms-PL)�v�ł��BMs-PL��A�ł������̊ɂ��}�C�N���\�t�g�̃\�[�X�R�[�h���C�Z���X��A�\�[�X�R�[�h�����p�܂��͔�p�̖ړI�ŕ\���A��X�A�ĔЕz�ł��܂��B�܂���]�������A��X�����\�[�X�R�[�h�ɑ΂��ă��C�Z���X�����ۋ����邱�Ƃ��ł��܂��B�ȉ���𕶂̓��{��Q�l������p���Ă����܂�(http://www.microsoft.com/japan/resources/sharedsource/licensingbasics/permissivelicense.mspx)�B

Microsoft Permissive License (Ms-PL)�@���J��: 2007�N7��9��

�{���C�Z���X��A�t������\�t�g�E�F�A�̎g�p�ɓK�p����܂��B�{�\�t�g�E�F�A���g�p�������A�{���C�Z���X�ɓ��ӂ������̂Ƃ݂Ȃ��܂��B�{���C�Z���X�ɓ��ӂ��Ȃ����A�{�\�t�g�E�F�A���g�p���邱�Ƃ͂ł��܂���B

1.��`

�{���C�Z���X�ł�A"��������"�A"����"�A"�񎟓I���앨"�A�����"�Еz"�Ƃ����p���A����̒��쌠�@�̉��Ŏg������Ɠ����Ӗ���L���܂��B"�R���g���r���[�V����"�Ƃ�A�I���W�i���̃\�t�g�E�F�A�A�܂��̓\�t�g�E�F�A�ɑ΂���lj��������͕�X���Ӗ����܂��B"�R���g���r���[�^�["�Ƃ�A�{���C�Z���X�̉��Ŏ���̃R���g���r���[�V������Еz����҂��Ӗ����܂��B"��ۓ���"�Ƃ�A�R���g���r���[�V���������ڒ�G����A�R���g���r���[�^�[�̗L���������������͈͂��Ӗ����܂��B

2.�����̕t�^

(A)���쌠�Ɋւ��鋖��-��3���u�������������v���܂ޖ{���C�Z���X�������]����A�e�R���g���r���[�^�[�͎g�p�҂ɑ΂��A�R���g���r���[�V����������A�R���g���r���[�V�����̓񎟓I���앨�������A�R���g���r���[�V�����܂���������񎟓I���앨��Еz����A����I�A���E�S��A�����̒��쌠���C�Z���X��t�^���܂��B(B)�������Ɋւ��鋖��-��3���u�������������v���܂ޖ{���C�Z���X�������]����A�e�R���g���r���[�^�[�͎g�p�҂ɑ΂��A�{�\�t�g�E�F�A�̃R���g���r���[�V�����܂��͖{�\�t�g�E�F�A�̃R���g���r���[�V�����̓񎟓I���앨�������A�������A�g�p���A�̔����A�̔����Ă��A�A�����A�����/�܂��͂��̑��̕��@���������A��ۓ����Ɋ�Â�����I�A���E�S��A�����̓��������C�Z���X��t�^���܂��B

3.������������

(A)���W����O-�{���C�Z���X�ł�A�R���g���r���[�^�[�̖��O�A���S�A�܂�����W���g�p���錠���͗^�����܂���B

(B)�g�p�҂��A�{�\�t�g�E�F�A�ɂ��N�Q���咣��������Ɋւ��A�R���g���r���[�^�[�ɑ΂��ē����N�Q���咣������A���Y�R���g���r���[�^�[�ɂ��{�\�t�g�E�F�A�ɂ‚��Ă̎g�p�҂ɑ΂���������C�Z���X�͎����I��I�����܂��B

(C)�{�\�t�g�E�F�A�̑S���܂��͈ꕔ��Еz������A�{�\�t�g�E�F�A�ɕt�����邷�ׂĂ̒��쌠�A�������A���W�A�����o���̕\����ێ�����K�v������܂��B

(D)�{�\�t�g�E�F�A�̑S���܂��͈ꕔ���\�[�X�R�[�h�̌`���ŔЕz�������A�Еz���ɖ{���C�Z���X�̊��S�Ȏʂ����܂߂����A�{���C�Z���X������̉��ł̂ݔЕz���邱�Ƃ��ł��܂��B�{�\�t�g�E�F�A�̑S���܂��͈ꕔ���R���p�C���ς݂܂��̓I�u�W�F�N�g�R�[�h�`���ŔЕz�������A�{���C�Z���X�ɒ�G���Ȃ������̃��C�Z���X�̉��ł̂ݔЕz���邱�Ƃ��ł��܂��B

(E)�{�\�t�g�E�F�A�͌���L�p�ɂă��C�Z���X����܂��B�{�\�t�g�E�F�A�̎g�p�ɔ����댯��A���ׂĎg�p�҂��������̂Ƃ��܂��B�R���g���r���[�^�[����̖����I�ȕ�؂܂�������͈�؂���܂���B�g�p�n�̖@���Ɋ�Â��A�{���C�Z���X�ł͕�X�ł��Ȃ����̑������҂̌��������݂����������܂��B�g�p�n�̖@���Ɋ�Â��ċ��‚����͈͂�A�R���g���r���[�^�[��A���i���A����ړI�ɑ΂���K�����A��N�Q�ɂ‚���A�َ��I�ȕ�؂�ے肵�܂��B

(�{�T�C�g��http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx�̎Q�l��ł�)

WiimoteLib�̃Z�b�g�A�b�v

���C�Z���X���m�F������AWiimoteLib���_�E�����[�h���܂��B���e�o�Ŏ��_�ł��V�ł�2009�N1��19���Ɍ��J���ꂽWiimoteLib v1.7�ł��B

http://www.codeplex.com/WiimoteLib

WiimoteLib‚̃z�[ƒ€ƒy�[ƒW

�z�[���y�[�W�㕔�ɂ���uDownload�v�̃����N���N���b�N�����A�_�E�����[�h�y�[�W���{���ł��܂��B�z�z�p�̃p�b�P�[�W�ƃ\�[�X�R�[�h���z�z����Ă��܂����A�\�[�X�R�[�h�ł͂Ȃ��ق��uWiimoteLib V1.7 (787K)�v���_�E�����[�h���Ă��������B

ƒ_ƒEƒ“ƒ��[ƒh‚·‚éƒtƒ@ƒCƒ‹

�N���b�N�����A���C�Z���X�𕶂��p��ŕ\������܂��̂�(�m�F������)�uI Agree�v�N���b�N���A�_�E�����[�h���J�n���܂��B

WiimoteLib1.7‚Ì“¯�«ƒtƒ@ƒCƒ‹

�_�E�����[�h����ZIP�t�@�C����W�J������A�܂��͓���m�F�����܂��B���g����Bluetooth�X�^�b�N�Ǘ��\�t�g�E�F�A���N������AWiiRemote��1��ڑ����܂��B�ڑ��ł�����A�W�J�����t�H���_�̒��ɂ���uWiimoteTest.exe�v���_�u���N���b�N���Ď��s���Ă݂Ă��������B

WiimoteLib‚̃fƒ‚ƒvƒ�ƒOƒ‰ƒ€�uWiimoteTest.exe�v

���������s�ł����A���b�Ԃ�������̌�A�}�̂悤�Ȏ��s��ʂ��\�������͂��ł��BWiiRemote��U������A�{�^�����������Ƃ�A���A���^�C���Œl���擾�ł��Ă��邱�Ƃ��m�F�ł��܂��B

�t�H�[���̉E��u×�v���N���b�N����Æ�I�����܂��B�����茳�ɕ�����WiiRemote��Z���T�[�o�[�A�k���`���N�A�M�^�[�R���g���[���[�AWiiFit�o�����X�{�[�h�Ȃǂ���܂�����A���Ð�ڑ����ē���������Ă݂Ă��������B

�����WiimoteLib���g���邱�Ƃ��m�F�ł��܂����B�G���[�������������A����uError reading data from Wiimote...is it connected?�v�ƕ\�����ꂽ����ABluetooth�ł�ڑ��ɖ�肪����܂��BBluetooth�X�^�b�N��������WiiRemote��ڑ����Ă��邩�ǂ����A�m�F���Ă݂Ă��������B

�uWiimoteTest.exe�v‚Ì‹N“®‚ÉŽ¸”s‚µ‚½‚ç�Ú‘±‚ðŠm”F‚µ‚悤

����A�W�J�����t�@�C���̂����uWiimoteLib.dll�v�����d�v�ȃt�@�C���ł��B�uWiimoteTest.ext�v������DLL�������f�B���N�g���ɑ��݂��Ȃ������������삵�܂���B�Ȃ�WiimoteLib���J���ŗ��p����ɂ�����A���ɃC���X�g�[���[�Ȃǂ͂���܂���̂�A�W�J�����t�H���_����u�}�C�h�L�������g\Visual Studio 2008\Projects\WiimotLib_1.7�v�Ɉړ����Ă����Ƃ��̂��Ƃ��Ƃ��y�ɂȂ�ł��傤�iWiimoteLib.dll�����ł������̂ł����A�w���v�╡���̃o�[�W������DLL�����݂���ƌ�X���ł��j�B�Ȃ��udocs�v�t�H���_�ɂ���uWiimoteLib.chm�v���w���v�t�@�C���ł��B�h�L�������g������������������Ă��܂��B

����ŃZ�b�g�A�b�v��I���ł��I����߂���͎��ۂ�A�܂���Visual C#��p����WiiRemote��䂵�Ă����܂��B

WiimoteLib���v���W�F�N�g�ɑg�����yC#��z

����߂ł�AVisual C# 2008 Express(�Ȍ�uC#�v�ƕW�L)���g����AWiimoteLib�ł̃v���O���~���O��̌����Ă����܂��B

��̃v���W�F�N�g���

Visual C# 2008 Express Edition���N�����܂��B

Visual C#‚ð‹N“®‚µ‚½‚Æ‚±‚ë

[�t�@�C��(F)]��[�V�����v���W�F�N�g(P)]��[Windows�t�H�[���A�v���P�[�V����]��I�����܂��B

�V‚µ‚¢ƒvƒ�ƒWƒFƒNƒg‚ð�ì�¬

�u�v���W�F�N�g���v��uWiimoteLib01�v�Ƃ������O��t����[OK]�{�^�����N���b�N���܂��B

�uƒvƒ�ƒWƒFƒNƒg–¼�v‚É�uWiimoteLib01�v‚Æ‚¢‚¤–¼‘O‚ð•t‚¯‚Ä[OK]

���b�҂‚�V�����v���W�F�N�g��������܂��B����������΂�����[F5]�L�[��������A���s���Ă݂�Ɨǂ��ł��傤�B

�V‚µ‚¢ƒvƒ�ƒWƒFƒNƒg‚ª�ì�¬‚³‚ꂽ‚Æ‚±‚ë

WiimoteLib�̒lj�(C#��)

��ق��������̃v���W�F�N�g��WiimoteLib��g�����ł����܂��傤�B�E���ɕ\������Ă���A�\�����[�V�����G�N�X�v���[����[�Q��ݒ�]���E�N���b�N�A[�Q�Ƃ̒lj�(R)...]��I�����܂��B

[ŽQ�Æ�Ý’è]‚ð‰EƒNƒŠƒbƒN

�Q�Ƃ̒lj�����[�Q��]��I�����AWiimoteLib.dll��I�����܂��B�}�C�h�L�������g��uVisual Studio 2008\Projects�v�ɂ������uWiimoteLib_1.7\WiimoteLib.dll�v��I����[OK]�{�^�����N���b�N���܂��B

WiimoteLib.dll‚̃tƒ@ƒCƒ‹‚ðŽw’è‚·‚é

����Ń\�����[�V�����G�N�X�v���[���̎Q��ݒ��WiimoteLib���lj����ꂽ�͂��ł��B

ƒ\ƒŠƒ…�[ƒVƒ‡ƒ“ƒGƒNƒXƒvƒ��[ƒ‰�[‚ÉŒ»‚ꂽWiimoteLib

����ł������̃v���O�����̎��s���ʂ�\�����邽�߂̃t�H�[���������܂��傤�B�\�����[�V�����G�N�X�v���[����uForm.cs�v���E�N���b�N����u�R�[�h�̕\���v�ŕ\�������C#�̃R�[�h��A�ł��d�v������1�s�uusing WiimoteLib;�v��lj����܂��B

  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;

| using WiimoteLib;    //������1�s�lj����܂�

  namespace WiimoteLib01  {  //���w�肵���v���W�F�N�g��
    public partial class Form1 : Form {

    public Form1() {
      InitializeComponent();
    }

  }
}

��オC#�‹���WiimoteLib��p���邽�߂����̈���̑���ł��B�܂�WiiRemote�炵�����Ƃ͉����ł��܂���A�����WiimoteLib�̃N���X�����p�ł���悤�ɂȂ�܂����B���̃X�e�b�v��A���ۂɓ�����m�F���Ă݂܂��傤�B

�v���O�����̎��s

[F5]�L�[�A�܂���A[�f�o�b�N(D)]��[�f�o�b�N�J�n(F5)]�������ăv���O���������s�����Ă݂܂��傤�B

[ƒfƒoƒbƒO(D)]�¨[ƒfƒoƒbƒOŠJŽn(S)]

�v���O�����ɃG���[���Ȃ���Ή��}�̂悤�ɕ\�������͂��ł��B

‰½‚à‚È‚¢ƒtƒH�[ƒ€‚ª•\ަ‚³‚ꂽ

���̃v���O�����͒P�Ƀt�H�[���ð�¶������v���O�����ł��B�u×�v�{�^���������ăt�H�[����‚��ăv���O�������I�������܂��傤�B�Ȍ�A���̃v���O�������x�[�X��WiiRemote�ð�§Œä‚·ï¿½ï¿½v���O������lj����Ă����܂��B

WiimoteLib���v���W�F�N�g�ɑg�����yC++��z

����Visual C++ 2008 Express(�Ȍ�uC++�v�ƕW�L)���g����AWiimoteLib�ł̃v���O���~���O��̌����Ă����܂��B��x������o������A�Ȍ�͋��ʂł��B�����C++��C#�A�ǂ���ł����܂��܂���B�����g���g���₷�������I��ł݂Ă��������B

��̃v���W�F�N�g���

Visual C++ 2008 Express Edition���N�����܂��B

�V‹Kƒvƒ�ƒWƒFƒNƒg‚Ì�ì�¬[C++]

[�t�@�C��(F)]��[�V�����v���W�F�N�g(P)]����A[CLR]��[Windows�t�H�[���A�v���P�[�V����]��I�����܂��B

�u�v���W�F�N�g���v��uWiimoteLib01cpp�v�Ƃ������O��t����[OK]�{�^�����N���b�N���܂��B

�V�����v���W�F�N�g���ì�¬ï¿½ï¿½ï¿½ï¿½Ü‚����B����������΂�����[F5]�L�[�������Ä�A���s���Ă݂�Ɨǂ��ł��傤�B�����Ȃ��t�H�[�����\������A�u×�v�{�^���������Æ�I�����܂��B

WiimoteLib�̒lj�[C++]

��ق�������v���W�F�N�g��WiimoteLib��g�����ł����܂��傤�B�\�����[�V�����G�N�X�v���[���Ńv���W�F�N�g(�����ł�uWiimoteLib01cpp�v)���E�N���b�N����[�Q��]��I�����܂��B

ƒvƒ�ƒWƒFƒNƒg‚ð‰EƒNƒŠƒbƒN‚µ‚Ä[ŽQ�Æ]�Ý’è

�v���W�F�N�g�̃v���p�e�B�y�[�W����[�V�����Q�Ƃ̒lj�(N)...]���N���b�N���A[�Q��]�^�u���N���b�N���A�t�@�C���I���_�C�A���O��A�}�C�h�L�������g��uVisual Studio 2008\Projects�v�ɂ������uWiimoteLib_1.7\WiimoteLib.dll�v��I����[OK]�{�^�����N���b�N���܂��B

WiimoteLib‚ð’ljÁ
WiimoteLib‚ªŽQ�Æ�Ý’è‚ɒljÁ‚³‚ꂽ

����AWiimoteLib��������R�[�h�������܂��B�\�����[�V�����G�N�X�v���[����uForm1.h�v���E�N���b�N����u�R�[�h�̕\���v��I�Ԃ�AForm1.h�̃R�[�h���\������܂��B���̃R�[�h��擪12�s�ڂɈȉ��̂悤��A�K�v��1�s�����������Ă��������B

WiimoteLib�N���X��錾(Form1.h)
#pragma once

namespace WiimoteLib01cpp { //���w�肵���v���W�F�N�g��

  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;

| using namespace WiimoteLib;  //�����1�s�lj����܂�

���ȉ�����

��オC++/CLI��WiimoteLib��p���邽�߂̕K�v�Œ���̃v���O�����ł��B[F5]�L�[�������ăv���O���������s�����Ă݂܂��傤�B

�v���O�����ɃG���[���Ȃ����C#�Ɠ��l�A�����Ȃ��t�H�[�����\�������͂��ł��B���܂̂Ƃ���A���̃v���O�����͒P�Ƀt�H�[��������邾���̃v���O�����ł����AWiimoteLib�̃N���X��using namespace�錾�ɂ���Ė��Ȃ��g����܂�Ă��邱�Ƃ��킩��܂��B�Ȍ�A���̃v���O�������x�[�X��WiiRemote��䂷��v���O������lj����Ă����܂��B

�o�C�u���[�^��ON/OFF

���������A�����WiimoteLib��API��p���ăv���O���~���O���s���Ă����܂��B�����C++��C#����񂵂ĉ�����Ă����܂����A.NET�t���[�����[�N�̂�������GUI��݌v�Ȃǂ͂܂�������������ŊJ����i�߂邱�Ƃ��ł��܂��B

�܂��APC����ɕ\�������Form�{�^���ɂ����AWiiRemote��U���@�\(�o�C�u���[�^�[)�̓��������‚邷��v���O���������܂��B

WiimoteLib��錾��ڑ�

�O�߂̂Ƃ���AWiimoteLib��g����񂾃v���W�F�N�g�̃��C���̃R�[�h�iForm1.cs��������Form1.h�j�Ɉȉ���3�s��lj����܂��B

Form1.cs[C#]
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
|   using WiimoteLib;	//WiimoteLib��錾

    namespace WiimoteLib01 {
     public partial class Form1 : Form {

|       Wiimote wm = new Wiimote();	//Wiimote�N���X���

      public Form1() {
       InitializeComponent();
|       wm.Connect();      	//Wiimote��ڑ�
      }
     }
    }
���ȉ�����
Form1.h[C++]
#pragma once
namespace WiimoteLib01cpp {
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
|	using namespace WiimoteLib;	//WiimoteLib��錾
��������
	public ref class Form1 : public System::Windows::Forms::Form
	{
|	public:	Wiimote^ wm;	//Wiimote�N���X�̓��ꕨ
	public:
		Form1(void)
		{
|			wm = gcnew Wiimote(); //Wiimote�N���X���;
			InitializeComponent();
			//
			//TODO: �����ɃR���X�g���N�^ �R�[�h��lj����܂�
			//
|			wm->Connect();	//Wiimote��ڑ�
			
		}
���ȉ�����

C#��C++�������̋L����\���͈Ⴆ��A�قƂ�Ǔ����ł��邱�Ƃ��������肢���������ł��傤���HC++�ł�wm�Ƃ������ꕨ��Form1�N���X��Public�����o�[�Ƃ��ėp�ӂ��Ă��܂��B

�o�C�u���[�^�[ON/OFF�{�^�����

�܂��A�t�H�[���Ƀ{�^����\��t���Ă��������BC#�ł�A�c�[���{�b�N�X����h���b�O����Form1��D���Ȉʒu�ɔz�u���܂��B(C++�ł����l�ł�)�\������Ă��Ȃ����A[�\��]����[�f�U�C�i]�Ƃ���Form1�̃f�U�C����\�����A�ēx[�\��]����[�c�[���{�b�N�X]��I�Ԃ��ƂʼnE���Ƀc�[���{�b�N�X�E�B���h�E������܂�(C++�����)�B�u�R�����R���g���[���v��uButton�v������܂��̂�A�t�H�[�����Ƀh���b�O���Ă��������B

ƒc�[ƒ‹ƒ{ƒbƒNƒX‚©‚çƒ{ƒ^ƒ“‚ðƒhƒ‰ƒbƒO‚µ‚Ä”z’u

����A�\��t�����ubutton1�v�̃v���p�e�B�V�[�g��uText�v���ubutton1�v����uON�v�ɕ�X���܂��B����Ńt�H�[����̃{�^���������Ă���e�L�X�g���uON�v�ɕς��͂��ł��B

Text‚̃vƒ�ƒpƒeƒB‚ð�ubutton1�v‚©‚ç�uON�v‚É�‘‚«Š·‚¦‚é

Form1��ɔz�u�����{�^���uON�v���_�u���N���b�N�����A�{�^���N���b�N���̃C�x���g���w�肷��R�[�h�������I�ɕ\������܂��̂ʼn��L�̂悤�ɋL�q���܂��B

Form1.cs[C#]
  private void button1_Click(object sender, EventArgs e) {
   wm.SetRumble(true);  //�o�C�u�[�V����ON
  }
Form1.h[C++]
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
    wm->SetRumble(true);  //�o�C�u�[�V����ON
  }
 };
}

�C���͂����͂�����[F5]�L�[�����������Ȃ邩������܂���A�����͎̂��̃X�e�b�v�܂�i��ł���ɂ��܂��傤�I���̂܂܂ł�ABluetooth�ڑ�����Ă��܂���A�o�C�u���[�^�[���쓮���Ă��܂��~�߂���@���������Ă��܂���̂�A�u���u���‚���ςȂ����������ԂɂȂ��Ă��܂��܂��B

�o�C�u���[�^�[���~������uOFF�v�{�^���������܂��B��قǂƓ��l��A�c�[���{�b�N�X����{�^����z�u���܂��B

�uOFF�v‚Ì‚½‚߂̃{ƒ^ƒ“‚ðƒhƒ‰ƒbƒO‚Å”z’u

��قǂƓ������A�\��t�����ubutton2�v�̃v���p�e�B��Text���ubutton2�v����uOFF�v�ɕ�X���܂��B

Text‚̃vƒ�ƒpƒeƒB‚ð�ubutton2�v‚©‚ç�uOFF�v‚É�‘‚«Š·‚¦‚é

�Ō��A�\��t�����ubutton2�v���_�u���N���b�N���A���L�̂悤�ȃR�[�h���L�q���܂��B

Form1.cs[C#]
  private void button2_Click(object sender, EventArgs e) {
    wm.SetRumble(false);  //�o�C�u�[�V����OFF
 }
Form1.cs[C#]
private: System::Void button2_Click(System::Object^ sender, \
    System::EventArgs^ e) {
    wm->SetRumble(false);	//�o�C�u���[�V����OFF
  }

����I���ł��B���ꂾ���̃v���O������WiiRemote�̃o�C�u���[�V�����@�\��ON/OFF���䂪�”\�ɂȂ�܂��B

Form1.cs��C#�\�[�X(�S��)
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
| using WiimoteLib;	//WiimoteLib�̓ǂ����

 namespace WiimoteLib01  {
  public partial class Form1 : Form {
|   Wiimote wm = new Wiimote();   //Wiimote��錾
   public Form1() {
    InitializeComponent();
|    wm.Connect();	//Wiimote��ڑ�
   }

   private void button1_Click(object sender, EventArgs e) {
|    wm.SetRumble(true);    //�o�C�u�[�V����ON
   }

   private void button2_Click(object sender, EventArgs e) {
|    wm.SetRumble(false);   //�o�C�u�[�V����OFF
   }
  }
 }
Form1.h��C++�\�[�X(��X�_�̂ݔ���)
#pragma once

������
|	using namespace WiimoteLib; //WiimoteLib��錾
������
  public ref class Form1 : public System::Windows::Forms::Form
  {
| public: Wiimote^ wm;        //Wiimote�N���X�̓��ꕨ
  public:
    Form1(void)
    {
|     wm = gcnew Wiimote();   //Wiimote�N���X���;
      InitializeComponent();
      //
      //TODO: �����ɃR���X�g���N�^ �R�[�h��lj����܂�
      //
|     wm->Connect();	//Wiimote��ڑ�

    }
������
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|     wm->SetRumble(true);   //�o�C�u�[�V����ON
  }
private: System::Void button2_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|     wm->SetRumble(false);  //�o�C�u���[�V����OFF
  }
 };
}

���s���Ă݂悤

�܂��A���g����Bluetooth�X�^�b�N����WiiRemote��ڑ����܂��B

Bluetooth�Ú‘±(�}‚Í“ŒŽÅ�»ƒXƒ^ƒbƒN)

������AVisual C#/C++����uF5�v�L�[�������ăv���O�������N�����܂��B�G���[���Ȃ���Ή��̂悤�ȃt�H�[�����N������͂��ł��B

�uON�v‚Æ�uOFF�v‚ð‚à‚ƒtƒH�[ƒ€‚ª•\ަ‚³‚ê‚é

�������̂悤�ȃG���[�������������WiiRemote���������ڑ�����Ă��邩�m�F���Ă��������B

�Ú‘±Ž¸”s�FBluetooth�Ú‘±‚ðŠm”F‚µ‚悤

�����ɋN���ł������A�uON�v�{�^�����N���b�N�����A�o�C�u���[�V������ON�ɂȂ�WiiRemote���U�����܂��B����Ă��������uOFF�v�{�^�����N���b�N����AWiiRemote��U�����Ƃ߂܂��傤�B

�ǂ��ł��傤���H���ɊȒP��WiiRemote�̃o�C�u���[�V��������v���O���������܂����B���̂悤��WiimoteLib��C++/CLI��C#.NET�̑g����킹��A�ȒP�ɃA�v���P�[�V�������J�����Ă������Ƃ��ł��܂��B

WiimoteLib�ɂ̓o�C�u���[�^�[�����ȊO�ɂ�WiiRemote�����䂷�邽�߂̊�����������񑵂��Ă��܂��B

�ȒP�Ƀv���O�����̗����������܂���A�܂��uConnect()����v��WiiRemote�Ƃ�ڑ����s���܂��B���̂Ƃ�WiiRemote���������ڑ��A�F������Ă��Ȃ��������A��O(Exception)���������܂��B����͗�O�������s���Ă��܂���̂�A���ۂ̃A�v���P�[�V�����ł͕K�v�ɉ����ė�O������lj����Ă��������B�{�^�����������Ƃ���A�uSetRumble()����v��WiiRemote�̃o�C�u���[�V������䂵�܂��B()�̈�����utrue�v������ƃo�C�u���[�V�������U�����A�ufalse�v������ƃo�C�u���[�V��������~���܂��BPWM����(�p���X���ϒ�:Pulse With Modulation)��p���邱�Ƃɂ���ăo�C�u���[�V�����ɋ����t���邱�Ƃ��ł��܂��B�ȒP���������������ON��OFF���J��Ԃ����Ƃɂ���ăo�C�u���[�V�����ɋ�����‚�������@�ł��B�����ł͂�����������܂���A�]�͂̂���l�̓`�������W���Ă݂Ă��������B

����FAPI���

�ȉ��A���̃v���O�����Ŏg����WiimoteLib��API����ł��B

C# C++ ���
using WiimoteLib; using namespace WiimoteLib; �l�[���X�y�[�X�錾
public Wiimote wm; public: Wiimote^ wm; �N���X��錾
wm = new Wiimote(); Wiimote^ wm = gcnew Wiimote(); �N���X�V�K��
wm.Connect(); wm->Connect(); WiiRemote��ڑ�
wm.SetRumble(true); wm->SetRumble(true); �o�C�u���[�^�[�쓮
wm.SetRumble(false); wm->SetRumble(false); �o�C�u���[�^�[��~

�������ł��傤�A.NET�‹��ɂ�����AC#��C++�ł͉������̂Ȃ����Ƃ��悭�킩��܂��BGUI�ɂ��t�H�[�������A�}�E�X�h���b�O�ƃv���p�e�B��ݒ�A�_�u���N���b�N�ɂ��Y���R�[�h�̎�������������܂��̂Ŕ��ɉ��K�ɃR�[�f�B���O�ł��܂��B���̃X�e�b�v�ł͓����v�̂�ALED�̓_����䂵�Ă����܂��B

LED�̓_�������

����WiiRemote��LED����ɂ‚��ăv���O���~���O���s���Ă����܂��B�����ł�AForm�{�^�����N���b�N���閈��WiiRemote��u�v���C���[�C���W�P�[�^�[�v�ƌĂ΂���FLED���J�E���g�A�b�v�����Ă����܂��B

�����ɂ������Ă̊�{�I�ȃv���O���~���O�̗���͑O�߂̃o�C�u���[�^�[��������Ɠ����ł��B�V�����v���W�F�N�g�������A�v���W�F�N�g�̃N���X�̎Q��ݒ��WiimoteLib��lj����A�ȉ���������R�[�h�����������Ă��������B

WiimoteLib��錾��ڑ�

Form1.cs�Ɉȉ��̕�����lj�[C#]
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
|using WiimoteLib;  //WiimoteLib�̎g�p��錾

namespace WindowsFormsApplication1 { //���v���W�F�N�g���ɂ���ĈقȂ�
 public partial class Form1 : Form {

|Wiimote wm = new Wiimote();   //Wiimote��錾
|int count=0;                  //�J�E���g��錾

  public Form1() {
   InitializeComponent();
|      wm.Connect();	//WiiRemote��ڑ�
  }
 }
}
Form1.h�Ɉȉ��̕�����lj�[C++]
#pragma once
namespace WLCLED { //���v���W�F�N�g���ɂ���ĈقȂ�

  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;

| using namespace WiimoteLib;	 //WiimoteLib�̎g�p��錾
������
  public ref class Form1 : public System::Windows::Forms::Form
  {
| public: Wiimote^ wm;  //Wiimote�I�u�W�F�N�gwm��錾
| public: int count;    //LED�J�E���g�p�̕��count��錾
  public:
    Form1(void)
    {
|     wm = gcnew Wiimote(); //Wiimote�C���X�^���X���
      InitializeComponent();
      //
      //TODO: �����ɃR���X�g���N�^ �R�[�h��lj����܂�
      //
|     wm->Connect();	//WiiRemote��ڑ�
    }

  protected:
������
 

�m�F�̂��߂ɂ�����WiiRemote��Bluetooth�ڑ����s���A[F5]�L�[�Ŏ��s�������Ă݂邱�Ƃ������߂��܂��B�R���p�C���G���[��WiimoteLib.dll�̒lj��킷��Ȃ�A�����̋󔒂̃t�H�[�����\������邾�����Ԃł����A�m�F�͑厖�ł��B������A����������R�[�h���܂ł̗��ꉽ�x���s���܂��̂�A�J���_�Ŋo���Ă��܂��܂��傤�B

�Ȃ�C++�ł�Aint�^�̕��count��AWiimote�I�u�W�F�N�g���i�[����wm��錾���AForm1�̃C���X�^���X�Ƃ͕ʂ�s���K�v������܂��B�������Ȃ���Α��̃��\�b�h���爵�����Ƃ��ł��܂���B����A�ׂ����Ƃ����C#�ƈႢ���o�Ă��܂��̂Œ��ӂ��Ă��������i�����̂���l��A�킴�ƊԈႦ�Ă݂�̂��׋��ɂȂ��Ă�����������܂���j�B

LED�J�E���g�A�b�v�{�^�����

����C#/C++�ŋ��ʂ��Ƃł��B��قǂ̃o�C�u���[�^�[�̗�Ɠ��l�Ƀt�H�[���uForm1�v�Ƀ{�^����\��t���Ă��������B�{�^�����������ѕ\�����ς��d�g�݂�������܂��̂�A�{�^��������傫��A�����ɂ��Ă����Ɨǂ��ł��傤�B

ƒtƒH�[ƒ€‚ɑ傫‚߂ȃ{ƒ^ƒ“‚ð”z’u[C#]
ƒtƒH�[ƒ€‚ɑ傫‚߂ȃ{ƒ^ƒ“‚ð”z’u[C++]

���ɓ\��t�����ubutton1�v���_�u�����b�N����A�ȉ��̃R�[�h��lj����܂��B

�{�^���N���b�N���������lj�[C#]
   private void button1_Click(object sender, EventArgs e) {
    this.button1.Text ="wm.SetLEDs("+ count+") ��\����";
   this.wm.SetLEDs(count);
   count++;
}
�{�^���N���b�N���������lj�[C++]
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
	button1->Text = "wm->SetLEDs("+ count +")��\����";
	wm->SetLEDs(count);
	count++;
}

���ŃR�[�f�B���O��I���ł��B���������ꂾ���̃v���O������WiiRemote��LED���䂪�”\�ɂȂ�܂��B

��������Form1.cs[C#]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
|using WiimoteLib;

namespace WL_LED
{
    public partial class Form1 : Form
    {
|        Wiimote wm = new Wiimote();
|        int count = 0;
        public Form1()
        {
            InitializeComponent();
|            wm.Connect();
        }
        private void button1_Click(object sender, EventArgs e)
        {
|            this.button1.Text = "wm.SetLEDs(" + count + ")��\����";
|            wm.SetLEDs(count);
|            count++;
        }
    }
}
��������Form1.h[C++]
#pragma once
namespace WLCLED { //�������v���W�F�N�g���A���R�B
  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;
| using namespace WiimoteLib;
  /// <summary>
������
  /// </summary>
  public ref class Form1 : public System::Windows::Forms::Form
  {
|  public: Wiimote^ wm;	//Wiimote�I�u�W�F�N�gwm��錾
|  public: int count;    //LED�J�E���g�p�̕��count��錾
   public:
    Form1(void)
    {
|    wm = gcnew Wiimote();
     InitializeComponent();
      //
      //TODO: �����ɃR���X�g���N�^ �R�[�h��lj����܂�
      //
|     wm->Connect();	//WiiRemote��ڑ�
    }
  protected:
    /// <summary>
    /// �g�p���̃��\�[�X�����ׂăN���[���A�b�v���܂��B
    /// </summary>
   ~Form1()
   {
   if (components)
    {
     delete components;
    }
   }
    private: System::Windows::Forms::Button^  button1;
    protected: 
������
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|   button1->Text = "wm->SetLEDs("+ count +")��\����";
|   wm->SetLEDs(count);
|   count++;
   }
  };
}

�኱C++�̂ق����R�[�h�������Ȃ�܂����A�����Œlj����ꂽ�ȊO�̉���̈Ӗ�������C#�ł�C++�ł��A�قړ����ł��邱�Ƃ��킩��܂��B

���s���Ă݂悤

����ł͑������s���Ă݂܂��傤�B

����AVisual C#/C++��[F5]�L�[�������Ď��s���Ă��������B���s����Ɖ��}�̂悤�ȃA�v���P�[�V�������N�����܂��B

‘å‚«‚ȃ{ƒ^ƒ“‚ª‚ЂƂ‚¾‚¯‚̃tƒH�[ƒ€‚ª•\ަ‚³‚ê‚é

�������}�̂悤�ȃG���[�������������WiiRemote���������ڑ�����Ă��邩�m�F���Ă��������B

Bluetooth�Ú‘±‚ð–Y‚ê‚邯ƒGƒ‰�[‚ɂȂé

�t�H�[���ɕ\�������{�^�����N���b�N���Ă�����AWiiRemote������LED�����X�ƌ����Ă����܂��B

ƒtƒH�[ƒ€‚É•¶Žš‚ª•\ަ‚³‚ê‚é

�u×�v���N���b�N���Ä�I�����܂��B

����FLED�̓_������

LED�̓_��������͂���API�𗘗p���܂��B

 SetLEDs(int32 leds); 

���̊���̈����uleds�v��int32�`������l�������邱�Ƃ�A�Ή�����LED���ω����܂��B���̃v���O�����ł͕��count�̒l�����uSetLEDs(count);�v�Ƃ��Ă��܂��BForm�ɔz�u���ꂽ�{�^�����N���b�N�����Acount�l��+1����Ă����܂��B

���������(int32�`��)�ŗ^���܂����A�����WiiRemote���t���܂ɂ�����Ԃ̊eLED��4�r�b�g��2�i���ŕ\������A�e�r�b�g��0����15�܂ő����Ă��������̂ł��B2�i���ɓ���݂��Ȃ����̂��߂�A�\�ŕ\�����Ă݂܂����i���������A�����_���ł��j�B

LED�̓_���ł܂Ȃ�A2�i���Ή��\
10�i��(int) LED4 LED3 LED2 LED1
0 �� �� �� ��
1 �� �� �� ��
2 �� �� �� ��
3 �� �� �� ��
4 �� �� �� ��
5 �� �� �� ��
6 �� �� �� ��
7 �� �� �� ��
8 �� �� �� ��
9 �� �� �� ��
10 �� �� �� ��
11 �� �� �� ��
12 �� �� �� ��
13 �� �� �� ��
14 �� �� �� ��
15 �� �� �� ��

�t�H�[����̃{�^��������������Acount��10�i����16�ɂȂ��ALED0�`LED4�̌��͂��ꂼ��0�ɂȂ�LED�͑S������܂����A������̒l(17,18,19,...)�������Ă��A�܂����ʃr�b�g�ɒl������܂��̂�ALED�̓J�E���g�A�b�v���‚Â��܂��B

�v���O�����ɂ���Ă�2�i����10�i���ł͂Ȃ��A��X��LED���w�肵�Č��点�����Ƃ�������ł��傤�B�����������Ƃ���A����t�H�[�}�b�g���قȂ�ȉ��̌`���𗘗p���܂��F

 SetLEDs(bool led1 ,bool led2 ,bool led3,bool led4); 

��������ł��A������4�Žw�肷�邱�Ƃ�A�e�X��LED��䂷�邱�Ƃ��”\�ɂȂ�܂��B(�v���O���~���O�p��ł�A���̂悤�Ȋ���̗��p�̎d�����I�[�o�[���[�h�Ƃ����܂��j

����LED������I���܂��B���ɃV���v���ł����A�A�C�f�B�A����ł��낢��Ȃ��Ƃ��ł��܂��̂�A���Д��z��L���ɂ��ĉ��Ɏg���邩�l���Ă݂Ă��������B�܂����̕\������킹���֗���o�͗p���������Ă݂�Ƃ悢�ł��傤�B�Ⴆ��A�M�҂�uSetLEDbyValue(int)�v�Ƃ�������������A4�i�K�̒l��\���ł���悤�ɂ��܂����B�u���[�X�Q�[���ł̃V�[���h�c��v��u�󂯂��_���[�W�̕\���v�A���ꂩ�����̒i�K��\���v���O���X�o�[�ɂ�LED���g���܂��B

�w���v�t�@�C�������p���悤

��L��uSetLEDs�v�̂悤��WiimoteLib�Ɏ�������Ă���API������ꂼ��̋@�\��AWiimoteLib��udocs�v�t�H���_�ɂ���w���v�t�@�C���uWiimoteLib.chm�v���Q�Ƃ��邱�ƂŒT�����Ƃ��ł��܂��B�Ⴆ��A����API�������͈ȉ��̂悤�ɋL�ڂ���Ă��܂��B

��Wiimote.SetLEDs Method��Overload List

Name Description
SetLEDs(Int32) Set the LEDs on the Wiimote
SetLEDs(Boolean Boolean Boolean Boolean) Set the LEDs on the Wiimote

See Also Wiimote Class Wiimote Members WiimoteLib Namespace

�‚܂����uSetLEDs()�v�ɂ�A����̂悤��Int32�̒l1�‚Ŏw�肷�������ABoolean�‚܂�_�����邩�ǂ�����^�U(true/false)��4�‚Ŏw�肷����@��2��ނ��p�ӂ���Ă���Ƃ������Ƃł��B�ǂ�����������ʂł͂���̂ł����A���̂悤�ɂ���AWiimoteLib�Ȃǂ�API��������l�͕֗��ɃA�N�Z�X�ł���悤��A��������̋C�̗�����������J�����Ă���Ƃ������Ƃł���B����uSee Also�v�ɂ�������Ă���N���X�����o�[����Ȃǂւ̃����N������܂��B

�킩��Ȃ����Ƃ���������u����ȋ@�\�Ȃ�����H�v�Ǝv�����Ƃ���A���̃w���v�t�@�C�������p���܂��傤�B���̃w���v�t�@�C���̓v���O�����R�[�h���玩����������Ă���悤�ł����A�����@�\�������Ă���AC#��VB�̃R�[�h���܂܂�Ă���A�׋��ɂȂ�܂��B

�{�^���C�x���g�̎擾

���̃X�e�b�v�ł�WiiRemote�̃{�^�����͂ɂ‚��Ċw�т܂��B�{�^����ON/OFF���擾����A�t�H�[���ɕ\������V���v���ȃv���O�����������܂��B

���x�����

�����قǂ܂ł̃v���O�����Ɠ��l��A�V�����v���W�F�N�g�������A�Q��ݒ��WiimoteLib��lj�����������ł�����A�uForm1�v�Ƀ��x��(Label�R���g���[��)��4�“\��t���Ă��������B

�V‚µ‚¢ƒvƒ�ƒWƒFƒNƒg‚Ƀ‰ƒxƒ‹‚ð4‚”z’u

����Label�̕�����A��قǃv���O�����������������܂��̂�ݒ�͕s�v�ł��B

�v���O����

WiiRemote�̃{�^�����������Ƃ��ɔ�������C�x���g�𗘗p����A���̃��x����\������l���X���邱�Ƃ�A���݂̃{�^�����͂��Ԃ�\������Ƃ����݌v�Ńv���O����������Ă����܂��B

Form1.cs(C#)��������Form1.h(C++)�Ɉȉ��̕�����lj����܂��B

�{�^�����͂ɑΉ�������(Form1.cs)[C#]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
|using WiimoteLib;    //WimoteLib�̎g�p��錾

namespace WiimoteLib_Sample  //���������v���W�F�N�g��
{
  public partial class Form1 : Form
  {
|   Wiimote wm = new Wiimote(); //Wiimote�N���X����
    public Form1()
    {
|    Control.CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
     InitializeComponent();
|    wm.WiimoteChanged += wm_WiimoteChanged;  //�C�x���g����̓o�^
|    wm.Connect();                          //WiiRemote��ڑ�
    }
|   //Wii�����R���̒l���ω������Ƃ��ɌĂ΂����
|   void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
|   {
|    WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
|    this.DrawForms(ws);            //�t�H�[���`�ʊ����
|   }
|   //�t�H�[���`�ʊ��
|   public void DrawForms(WiimoteState ws)
|   {
|    this.label1.Text = "Button A:" + (ws.ButtonState.A);  //�{�^��A
|    this.label2.Text = "Button B:" + (ws.ButtonState.B);  //�{�^��B
|    this.label3.Text = "Button 1:" + (ws.ButtonState.One);//�{�^��1
|    this.label4.Text = "Button 2:" + (ws.ButtonState.Two);//�{�^��2
|   }
  }
}
�{�^�����͂ɑΉ�������(Form1.h)[C++]
#pragma once
namespace WiimoteLib_Sample {     //���������v���W�F�N�g��
  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾
	/// <summary>
������
	/// </summary>
  public ref class Form1 : public System::Windows::Forms::Form
  {
|  public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
   public:
   Form1(void)
    {
|    Control::CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
|    wm = gcnew Wiimote();  //Wiimote�N���X����
     InitializeComponent();
|    //�C�x���g����̓o�^
|    wm->WiimoteChanged +=
|    gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|     this, &Form1::wm_WiimoteChanged);
|    wm->SetReportType(InputReport::Buttons, true); //���|�[�g�^�C�v��ݒ�
|    wm->Connect(); //WiiRemote��ڑ�
|   }
  public:
| void wm_WiimoteChanged(Object^ \
    sender,WiimoteLib::WiimoteChangedEventArgs^ args){
|    WiimoteState^ ws;
|    ws = args->WiimoteState;
|    this->DrawForms(ws);
|   }
| public: void DrawForms(WiimoteState^ ws) {
|    this->label1->Text = "Button A:" + (ws->ButtonState.A); 
|    this->label2->Text = "Button B:" + (ws->ButtonState.B);
|    this->label3->Text = "Button 1:" + (ws->ButtonState.One);
|    this->label4->Text = "Button 2:" + (ws->ButtonState.Two);
| }
 protected:
������

���s���Ă݂悤

����A���s���Ă݂܂��傤�B�܂����g����Bluetooth�X�^�b�N����AWiiRemote��Bluetooth��PC��ڑ����܂��B�ڑ����m�F�ł�����AVisual C#/C++���[F5]�L�[�������Ď��s���܂��B�R���p�C�����Ƃ���A���������s�����Ɖ��}�̂悤�ȃA�v���P�[�V�������N�����܂��B���������ŃG���[������������A�قƂ�ǂ�Bluetooth�ڑ������܂��ڑ�����Ă��Ȃ��P�[�X�ł��BWiiRemote���������ڑ�����Ă��邩�m�F���Ă��������B

ŽÀ�s’¼Œã�Aƒ‰ƒxƒ‹‚Ì•\ަ‚É’�–Ú

WiiRemote��A�{�^�������������܂��B

ƒ‰ƒxƒ‹‚Ì•\ަ‚ª•Ï‚í‚é

�t�H�[�����uLabel1�v�̉����uButton A: True�v�ƕ\������������ł��B�����WiiRemote�̂��ׂẴ{�^�������𗣂���A���ׂẴ{�^���������Ȃ���Ԃɂ����Ƃ��A�t�H�[����̃{�^���̃X�e�[�^�X��\���\�����S��uFalse�v�ɂȂ������ł��B

ƒ{ƒ^ƒ“‚©‚çŽè‚𗣂·‚Æ�A‚·‚ׂÄFalse‚ɂȂé

WiiRemote��A�{�^����B�{�^���𓯎��ɉ�������ł݂܂��B

A,B‚ªTrue‚ɂȂé

�Ō��AWiiRemote��1�{�^����2�{�^���𓯎��ɉ�������ł݂܂��B

1,2‚ªTrue‚ɂȂé

��ʂ�̎������I�������A�}�E�X�Å�u×�v���N���b�N���邩�A�L�[�{�[�h����[Alt+F4]�������Ä�A�v���O�������I�������܂��B

����F�{�^���C�x���g�̎擾

Wii�����R���̃{�^����ON/OFF�ɂ����Form�̃��x����ω������Ă��܂��BFalse��OFF(��𗣂������), True��ON(����)�ɑΉ����Ă��܂��B�ȉ��A���p����API�����������܂��B

�C�x���g����̓o�^
[C#]  wm.WiimoteChanged += wm_WiimoteChanged;
[C++] wm->WiimoteChanged +=
            gcnew System::EventHandler<WiimoteChangedEventArgs^>(
            this, &Form1::wm_WiimoteChanged);

WiiRemote�̃{�^���������ꂽ�A�����x�Z���T�[�̒l���ς�����A�Ȃ�A��Ԃɕω����������Ƃ��ɌĂ΂������o�^���Ă��܂��B�v���O���~���O�p���u�R�[���o�b�N����v�Ƃ����A�������o�^���邱�Ƃ�A���̃C�x���g�����������Ƃ��Ɏ����I�ɂ��̊�������s�����悤�Ɍ��߂�ꂽ���@�Ŏw�肵�܂��B�����ł�AWiiRemote�̃{�^����Ԃɕω������������uwm_WiimoteChanged�v�Ƃ���������Ă΂��悤��ݒ肵�Ă��܂��B�J�b�R������Ȃǂ͂��炩���ߋK�肳�ꂽ�`���ɉ����Ă��܂��̂�A�������n�������ł����ł悢�̂ł�(C++�̃R�[�h�����������̂͂��̂��߂ł�)�B

WiimoteState�̒l���擾
[C#]  WiimoteState ws = args.WiimoteState;
[C++] WiimoteState^ ws;
      ws = args->WiimoteState;

������Wii�����R���̃X�e�[�^�X(���)��ws�Ƃ������O��"�C�����m"�ɂƂ肱��ł��܂��B�����ɂ͂����Ŏg���Ă���WiimoteState�̓N���X�ł����A���̖��O����z���ł���悤��A�C�x���g�Ŕ��������{�^���Ȃǂ̒l������܂�܂��B�ȉ��A�g���������Ă݂܂��傤�B

�{�^�����Ԃ��擾
[C#]  this.label1.Text   = "Button A: " + (ws.ButtonState.A);
[C++] this->label1->Text = "Button A:" + (ws->ButtonState.A); 

WiiRemote��A�{�^���̒l��label1�ɕ\�����Ă��܂��B�{�^����������Ă�����ATrue��\�����܂��B�{�^����������Ă�����AFalse��\�����܂��B���ۂɂ�uws.ButtonState.A�v���Ӗ�����l��True��False�Ƃ����^�U�̒l�ł����A�������ulabel1.Text�v�Ȃ̂Ŏ����I�ɕ�����ɕϊ�����Ă��܂�(.ToString()����K�v�͂Ȃ�)�B

���l��uws.ButtonState.b�v�ȂǂƂ��邱�Ƃ�WiiRemote��B�{�^���A���̑��S�Ẵ{�^�����Ԃ��擾���邱�Ƃ��ł��܂��B

�ǂ��ł��傤�H�Ƃ��Ă��ȒP�ł���I���̃C�x���g�̃R�[���o�b�N����ŃX�e�[�g���擾������@�͑��̂��낢��ȓ��͂ɉ��p�ł��܂��B�������A���̊��������R�[���o�b�N�̎d�g�݂��ȒP�ɗ��p�ł���w�i�ɂ�A�l�X�ȕ��G�ȃv���O���~���O�̓����̋Z�p������܂��B���̓t�H�[���̃R���X�g���N�^��A1�‚����A���܂��Ȃ������Ă��܂����B

���܂��Ȃ�
[C#]  Control.CheckForIllegalCrossThreadCalls  = false;
[C++] Control::CheckForIllegalCrossThreadCalls = false;

�]�T�̂���l��A����s���R�����g�A�E�g����A���s���Ă݂Ă��������B�Ȃ������s���Ƀ{�^���������ƃG���[���o�Ă��܂��܂��B�����A�}���`�X���b�h(�X���b�h;Thread�������̗���)�Ɋւ����ł��B��̃{�^�����Ԃ�ǂ����WiimoteLib�̃X���b�h��A�t�H�[��������������s���X���b�h�����ꂼ��قȂ�̂�u�X���b�h�Z�[�t�łȂ��v�‚܂�A�����̃X���b�h�ɂ�������������Ȃǂ���؂ł��Ȃ����ߎ��s���G���[�ɂȂ��Ă��܂��܂��BWiimoteLib�̌�����Љ��Ă�����@��A

Invoke(),delegate()���g�����@
//Wii�����R���̒l���ω������Ƃ��ɌĂ΂����[C#]
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args){
  WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
  if (this.IsHandleCreated) {
    this.Invoke( (MethodInvoker)delegate() {
    this.DrawForms( ws );            //�t�H�[���`�ʊ����
  });
 }
}

���̂悤��AInvoke()�Ƃ������\�b�h���g�����@������܂����A���������S�҂ɂ͕s���Ă�������ł��B�����N���Ă���A�ǂ�ȃ��X�N�����邩(�t�H�[��������������X���b�h�Z�[�t�łȂ����������)�Ƃ������Ƃ��킩���Ă���Ȃ�

Control.CheckForIllegalCrossThreadCalls=false;

�Ƃ���A�s���ȃX���b�h�ԃR�[���̃`�F�b�N�����Ȃ��A��錾������@������̂�A�{�͂ł�u���܂��Ȃ��v�Ƃ��ĈȌケ�̕��@���̗p���邱�Ƃɂ��܂��B

WiimoteState�̃����o�[

������WiimoteState�ŎQ�Ƃł������o�[��\��Љ�Ă����܂��B

WiimoteState�̃����o(WiimoteLib ver.1.7)
���� ���
AccelCalibrationInfo ���݂̉����x�Z���T�[�̃L�����u���[�V�������
AccelState ���݂̉����x�Z���T�[����
BalanceBoardState ���݂�WiiFit�o�����X�{�[�h����
Battery �Z�o���ꂽ���݂̃o�b�e���[���x��
BatteryRaw ���݂̃o�b�e���[���x���̌v�Z�O�̒l(���l)
ButtonState ���݂̃{�^������
ClassicControllerState ���݂̊g���N���V�b�N�R���g���[���[����
DrumsState ���݂̊g���h�����R���g���[���[����
Extension �g���R���g���[���[���}������Ă��邩
ExtensionType �g���R���g���[���[���}������Ă�������̎��
GuitarState ���݂�GuitarHero�g���M�^�[�R���g���[���[����
IRState ���݂�ԊO���Z���T�[����
LEDState ���݂�LED����
NunchukState ���݂̊g���k���`���N�R���g���[���[����
Rumble ���݂̃o�C�u���[�^�[����

WiimoteLib�ɂ͎��ɗl�X�Ȋg���R���g���[���[����������Ă���A���̃����o�[�����Ԃ��擾�ł��邱�Ƃ��킩��܂��B�����̒l���\�b�h�Ȃǂ�AVisual Studio��Intellisense�@�\���g���Ăǂ�ǂ���������Ă����܂��傤�B��قǂ̃{�^���̗�Ȃǂ��A�uws.ButtonState.�v��u.�v���������u�Ԃɂ�������W�L�̑I����������܂��B�{�^���̖��̂Ȃǂ͂��������o���Ă����܂���̂�A���ɕ֗��ł��B�Ȃ�Intellisense��Ctrl+Space�ł��‚ł��ǂ��ł��Ă�o���܂��B�S�ẴO���[�o���ȃI�u�W�F�N�g���\������܂��B��������Ɏg���Ƃ悢�ł��傤�B

Intellisense‚É‚æ‚é•⊮‹@”\‚ðŽg‚¢‚±‚È‚»‚¤

�����`���[�����

����A����܂�WiimoteLib���g����A��{�I�ȓ��o�͂��w��ł��܂����B���̂������A���p�I�ȃv���O�����̗�Ƃ���u�����`���[�v�������Ă݂܂��傤�B�{�^�����������т�AWindows�̃A�N�Z�T���u�������v��u�d��v�ȂNJO���v���O�������N������v���O�����ł��B

�O���v���O�����̋N��

�O�߂�u�{�^���C�x���g�̎擾�v�Ɗ�{�͓����ł��BWiimoteLib��錾���s���A�R�[���o�b�N������ŊO���v���O�������N��������A�A�v���P�[�V�������g���I���������肵�܂��B

�V�����v���W�F�N�g�������AWiimoteLib���Q�Ƃɒlj����AForm1���E�N���b�N����u�R�[�h��\���v���A���̃R�[�h���L�q���܂��B�O�߂̃v���O�����̉�������n�߂Ă��ǂ��ł��傤�B

�{�^���C�x���g�ŊO���v���O�������N������(Form1.cs)[C#]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
|using WiimoteLib;    //WimoteLib�̎g�p��錾

namespace WL_Launcher
{
    public partial class Form1 : Form
    {
|        Wiimote wm = new Wiimote(); //Wiimote�N���X����
        public Form1()
        {
|            Control.CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
            InitializeComponent();
|            wm.WiimoteChanged += wm_WiimoteChanged;  //�C�x���g����̓o�^
|            wm.Connect();                          //WiiRemote��ڑ�
        }
|        //Wii�����R���̒l���ω������Ƃ��ɌĂ΂����
| void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
|        {
|            WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
|            //A�{�^���������ꂽ���������N��
|            if (ws.ButtonState.A == true)
|            {
|                System.Diagnostics.Process.Start("notepad.exe");
|            }
|            //B�{�^���������ꂽ��d����N��
|            if (ws.ButtonState.B == true)
|            {
|                System.Diagnostics.Process.Start("calc.exe");
|            }
|            //HOME�{�^���������ꂽ�炱�̃A�v�����I��
|            if (ws.ButtonState.Home == true)
|            {
|                Environment.Exit(0);
|            }
|        }
    }
}
�{�^�����͂ɑΉ�������(Form1.h)[C++]
#pragma once

namespace WLCLauncher {
  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾

  public ref class Form1 : public System::Windows::Forms::Form
  {
| public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
  public:
   Form1(void)
    {
|    Control::CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
|    wm = gcnew Wiimote();  //Wiimote�N���X����
     InitializeComponent();
|    //�C�x���g����̓o�^
|    wm->WiimoteChanged +=
|      gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|        this, &Form1::wm_WiimoteChanged);
|    wm->SetReportType(InputReport::Buttons, true); //���|�[�g�^�C�v��ݒ�
|    wm->Connect(); //WiiRemote��ڑ�
|   }
  public:
void wm_WiimoteChanged(Object^ sender,WiimoteLib::WiimoteChangedEventArgs^ \
    args){
|     WiimoteState^ ws;
|     ws = args->WiimoteState;
|     //A�{�^���������ꂽ���������N��
|     if (ws->ButtonState.A) {
|       System::Diagnostics::Process::Start("notepad.exe");
|     }
|     //B�{�^���������ꂽ��d����N��
|     if (ws->ButtonState.B) {
|       System::Diagnostics::Process::Start("calc.exe");
|     }
|     //HOME�{�^���������ꂽ�炱�̃A�v�����I��
|     if (ws->ButtonState.Home) {
|       Environment::Exit(0);
|     }
|   }
���ȉ�����

���s���Ă݂悤

�܂���A���‚��ʂ�WiiRemote��ڑ����Ă��������B������Visual Studio��[F5]�L�[��������A�������v���O���������s���܂��B���������ŃG���[�������������WiiRemote���������ڑ�����Ă��邩�m�F���Ă��������B

WiiRemote��A�{�^����������A���������N�����AB�{�^����������A�d�삪�N�����܂��B

WiiRemote��B�{�^����񂨂���A������������A�d�삪�N�����܂��B

Bƒ{ƒ^ƒ“‚ð‰Ÿ‚µ‚½‰ñ�”‚¾‚¯“d‘삪‹N“®‚·‚é

WiiRemote��Home�{�^����������A�����`���[�v���O�������I�����܂��B

���̃v���O������unotepad.exe�v��ucalc.exe�v���D���ȊO���v���O����������������A���ł��N���ł���Ƃ����킯�ł���B�Ȃ񂾂����낢��Ȃ��Ƃ��ł������ł��B�y�����Ȃ��Ă��܂���H

����F�{�^���C�x���g�ɂ��A�v���N��

WiiRemote�̃{�^����������邱�Ƃɂ����ݒ肵���A�v���P�[�V�������N�����邽�߂ɂ�A��قǂ̃v���O������DrawForm()����������悤��A���x���̃e�L�X�g����������������A.NET�ŗp�ӂ���Ă���d�g�݂𗘗p����A�O���v���O�������N�����܂��B

if (ws.ButtonState.A == true) {
     //A�{�^���������ꂽ���������N��
      System.Diagnostics.Process.Start("notepad.exe");
}

�uSystem.Diagnostics.Process.Start()�v�ɂ‚��Ă͂��낢��ȉ��p������܂��B�e�L�X�g�t�@�C���Ȃǂ��w�肷�邱�ƂŊ֘A�Â���ꂽ�v���O�������g���ĊJ�����ƂȂǂ��”\�ł��B�ڂ����̓C���^�[�l�b�g�Ō��J����Ă���.NET Framework�N���X���C�u�����̃}�j���A����uProcess.Start�v���L�[���[�h�Ɍ������Ă݂�Ɨǂ��ł��傤�B

����AC#�ł̋L�q�ł����AC++/CLI�ł��S����a���Ȃ��݊������ۂ���Ă��܂��BC++��Home�{�^����������I���������̃R�[�h�����Ă݂܂��傤�B

 //HOME�{�^���������ꂽ�炱�̃A�v�����I��
 if (ws->ButtonState.Home) {
   Environment::Exit(0);
 }

���̂悤��uEnvironment::Exit(0);�v��A�������g�̃A�v���P�[�V�������I���ł��܂��B

����A����ȕ֗��ȃR�[�����o�����A�����`���[�ŋN�������v���O������I���Ȃǂ�����Ă݂����Ȃ�Ǝv���܂��B

������ԊO���|�C���^��p���ă}�E�X�����������w�K���Ă���A�������@�\�ɉ������Ă݂�Ƃ悢�ł��傤�B

�����x�Z���T�[���g��

�����x�Z���T�[�ɂ‚���

����AWiiRemote�̉����x�Z���T�[���g�����v���O���~���O���������Ă����܂��B2�͂ʼn�������Ƃ���AWiiRemote�ɂ�X���AY���AZ���ɑΉ�����3���̉����x�Z���T�[����������Ă��܂��B

‰Á‘¬“xƒZƒ“ƒT�[(�šhttp://www.wiili.org‚æ‚èŽØ—p)

WiiRemote�ɓ������ꂽ3���}�C�N�������x�Z���T�[��A���ꂼ��̎��ɑ΂���8bit�A�‚܂�0�`255�̒l�������܂��B���̃Z�N�V�����ł�A�܂��l���Ƃ��v���O�����������A���̌�A���p�A�v���P�[�V�����̊J����ʂ���A�����x�Z���T�[�̊�{�I�ȗ��p�ɒ��킵�܂��B

�����x�Z���T�[�̒l��\��

�����ł�A�܂���n�߂�AWiiRemote�̉����x���擾����v���O�����������܂��B��قǂ܂łƓ��l�AVisual Studio(C#/C++�ǂ���ł����܂��܂���I)��A�V�����v���W�F�N�g�������A�Q�Ƃ�uWiimoteLib�v��lj����܂��B�����I���������Ă���t�H�[���uForm1�v��A�c�[���{�b�N�X���烉�x��(Label)��3�“\��t���Ă��������B�����ɉ����x�Z���T�[X,Y,Z�̃��A���^�C������l��\�����܂��B

�����ăR�[�f�B���O�ł��BForm1���E�N���b�N����u�R�[�h��\���v����A�ȉ��̃v���O�����̃R�����g�A�E�g���Ă����������������Ă����܂�(�����������ꂽ�R�����g�s�͊������Ă��܂�)�B�܂��`����using��ɂ��N���X��錾�ł����A������K�v�ȕ��݂̂ɂ��Ă��܂��B

�����x�Z���T�[�̒l��\������(Form1.cs)[C#]
  using System;
  using System.Windows.Forms; 
| using WiimoteLib;    //WimoteLib�̎g�p��錾

namespace WL_Accel
{
  public partial class Form1 : Form
  {
|   Wiimote wm = new Wiimote(); //Wiimote�N���X����
    public Form1()
    {
|     Control.CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
      InitializeComponent();
|     wm.WiimoteChanged += wm_WiimoteChanged;  //�C�x���g����̓o�^
|     wm.SetReportType(InputReport.ButtonsAccel, true); //���|�[�g�^�C�v��ݒ�
|     wm.Connect();                          //WiiRemote��ڑ�
    }
|   //Wii�����R���̒l���ω������Ƃ��ɌĂ΂����
|   void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
|     WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
|     this.DrawForms(ws); //�t�H�[���`������
|   }
|   //�t�H�[���`����
|   public void DrawForms(WiimoteState ws)  {
|     this.label1.Text = "X��:" + (ws.AccelState.Values.X);
|     this.label2.Text = "Y��:" + (ws.AccelState.Values.Y);
|     this.label3.Text = "Z��:" + (ws.AccelState.Values.Z);
|   }
  }
}
�����x�Z���T�[�̒l��\������(Form1.h)[C++]
#pragma once
namespace WLCAccel {
  using namespace System;
  using namespace System::Windows::Forms;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾

  public ref class Form1 : public System::Windows::Forms::Form
  {
| public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
  public:
    Form1(void) {
|     Control::CheckForIllegalCrossThreadCalls = false; //���܂��Ȃ�
|     wm = gcnew Wiimote();  //Wiimote�N���X����
      InitializeComponent();
|     //�C�x���g����̓o�^
|     wm->WiimoteChanged +=
|       gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|       this, &Form1::wm_WiimoteChanged);
|     wm->SetReportType(InputReport::ButtonsAccel, true); //���|�[�g�^�C�v��ݒ�
|     wm->Connect(); //WiiRemote��ڑ�
    }
| public:
| void wm_WiimoteChanged(Object^ \
    sender,WiimoteLib::WiimoteChangedEventArgs^ args){
|     WiimoteState^ ws;
|     ws = args->WiimoteState;
|     this->DrawForms(ws);
|   }
| public:
|   void DrawForms(WiimoteState^ ws) {
|     this->label1->Text = "X��:" + (ws->AccelState.Values.X);
|     this->label2->Text = "Y��:" + (ws->AccelState.Values.Y);
|     this->label3->Text = "Z��:" + (ws->AccelState.Values.Z);
|   }
���ȉ�����

���s���Ă݂悤

����ł͎������Ă݂܂��傤�B�܂�WiiRemote�����g����Bluetooth�X�^�b�N��ڑ����Ă��������B

����Visual Studio���[F5]�L�[�������Ď��s���Ă��������B�������v���O������������Ă��炸�A�G���[�Ȃǂ��o����͂悭�m�F����A�C�����Ă��������B

�t�H�[�����\�����ꂽ��AWiiRemote��U��܂킵�Ă݂Ă��������B���̂Ƃ��A���q������U��񂵂����Ĕ��ł����Ɗ댯�Ȃ̂�A��U�肷��Ƃ��͕K���X�g���b�v�����Ă��������B

�t�H�[���ɒ���t�����A�����x��X,Y,Z�̒l���f���������Ă��邱�Ƃ��킩��܂��B

�y����z�N������3�‚̒l���[���̂܂܂��������A��U�������A�v���P�[�V�������I��������AWiimoteLib�̃T���v���uWiimoteTest.exe�v�����s���Ă݂Ă��������B��x���̃T���v�����N�����Ă���A����������A�v���P�[�V�������N������ƒl���Ƃ�邱�Ƃ�����܂�(�G���[�����������𒚔J�ɂ��Ă��Ȃ����炩������܂���)�A�s�����������Ƃ��͎����Ă݂Ă��������B

�܂��A�I������uDispose�v�Ɋւ���G���[���o��Ƃ�������܂����A��������܂̂Ƃ��떳�����Ă��܂��܂���B

Dispose‚ŃGƒ‰�[‚ª‚ ‚邪�¡‚Í–³Ž‹

����F���|�[�g�^�C�v�Ɖ����x�Z���T�[

WiiRemote��3���̉����x�Z���T�[�̃��A���^�C���l��\�����܂����B

���|�[�g�^�C�v��ݒ�
[C#]   wm.SetReportType(  InputReport.ButtonsAccel, true); 
[C++]  wm->SetReportType(InputReport::ButtonsAccel, true);

���|�[�g�^�C�v�A���Ȃ킿�C�x���g���N�����Ƃ��ɕ����悤��WiiRemote�ɂ��肢����u���v��������ݒ肵�Ă��܂��B�uButtonsAccel�v�͉����x�Z���T�[�ƃ{�^���C�x���g���擾���Ă��܂��B

�����x�Z���T�[����l�擾
[C#]  ws.AccelState.Values.X
[C++] ws->AccelState.Values.X

WiiRemote�ɓ������ꂽ�����x�Z���T�[�e������l��float�Ŏ擾���܂��B

���܂��Ȃ�
[C#]  Control.CheckForIllegalCrossThreadCalls = false;
[C++] Control::CheckForIllegalCrossThreadCalls = false;

�O��Ɠ������A�ʂ̃X���b�h����t�H�[�������������邱�Ƃ����‚��܂��B

���|�[�g�^�C�v�É�uButtonsAccel�v���w�肵�Ă���̂Å�A���Ì��ԂŃ{�^���C�x���g�Ȃǂ��擾�ł��܂��B�]�͂̂���l�͎����Ă݂܂��傤�B�����Ä�A���ۂɂǂꂾ���̒l���o�͂���邩�������Ă݂܂��傤�B�u���u���U���Ă݂�Æ�A�����ł�������±5���x�̒l���v������܂��BWiiRemote�𒼗�������Æ�AX,Z�Ȃ�2�‚̒l�̓[���ɂȂ�܂����A�����ЂƂ‚̎��A���Ƃ���Y���ɂ͂��Ȃ炸±0.9���x�̒l���c��܂��B

Y޲‚ÉŒŸ�o‚³‚ê‚Ä‚¢‚é‚Ì‚Í...�u�d—͉Á‘¬“x�v

����͉��ł��傤�c�c�H�����ł��A�d�͉����x�ł��I���i�͖ڂɌ����Ȃ��d�͉����x��ڂŌ��邱�Ƃ��ł��܂��B

�R�����F���|�[�g�^�C�v�Ƃ�H

�u���|�[�g�^�C�v�v�Ƃ�WiiRemote�ɖ₢���킹����Ƃ��̃��[�h�̂��Ƃ�A���̃��|�[�g�^�C�v�ɂ����AWiiRemote���Ԃ��Ԏ����قȂ�܂��B

WiimoteLib1.7�ł�InputReport���ňȉ��̃��|�[�g�^�C�v����`����Ă���悤�ł��B

���|�[�g�^�C�v��A�f�[�^�̃t�H�[�}�b�g��ݒ肷��ړI�̑��ɂ��A���肠���M�ш�������x���œK��ݒ肷��ړI������悤�ł��B��L��WiimoteLib�Ŏ�������Ă��郌�|�[�g�^�C�v�ȊO�ɂ��A�킩���Ă��邾���ł��A�{�^���݂̂̓��o�͂���A�����x�Z���T�[3��A�k���`���N�t��6��A�ԊO���t�����ǂ����A�Ƃ�����������ŃV���v���ȓ��o�̓��[�h����A��������̒l�����Ƃ肷�郂�[�h�܂�A�e�푵���Ă��܂��B�܂��ԊO���Z���T�[�ɂ‚��Ă��A�ő�4�_�܂ň����郂�[�h�ɑ΂���2�_�������[�h�Ȃ�A�B�����[�h�I�ȃ��|�[�g�^�C�v�����݂���悤�ł�(WiimoteLib�ł�4�_�̂݃T�|�[�g���Ă��܂�)�B

�����x�Z���T�[����WiiRemote����

��������WiiRemote�̓����̂ЂƂ‚ł�������x�Z���T�[�̒l���擾�ł���悤�ɂȂ����̂Å�u���ۂ��ǂ��v������Ă݂܂��傤�B���ۂƌĂԂɂ͑傰����������܂��ñ‚ª�A�����x�Z���T�[�ɓ��͂��ꂽ����������苭���Ȃ��...���Ƃ��Î��قǂ̎�����±5���x�̒l������ł��܂����̂Å�A���̒l�𒴂����ê�‡ï¿½É�AWAV�t�@�C�����Ä�����邱�Ƃɂ��܂��B

���p�F�U���WAV�t�@�C�������

��قǂ̉����x�Z���T�[���g���v���O�����̑�������n�߂�Ɨǂ��ł��傤�B�t�H�[���uForm1�v�̃R�[�h��\������A�ȉ��̂悤�ɒNjL���܂��B

�U���WAV�t�@�C�������(Form1.cs)[C#]
  using System;
  using System.Windows.Forms;
| using WiimoteLib;    //WimoteLib�̎g�p��錾
| using System.Media;  //System.Media��錾

namespace WL_Taiko
{
  public partial class Form1 : Form
    {
|     Wiimote wm = new Wiimote(); //Wiimote�N���X����
|     string path = null;         //Wav�t�@�C����
|     SoundPlayer wavePlayer;     //SoundPlayer��錾

      public Form1() {
        InitializeComponent();
|       wm.WiimoteChanged += wm_WiimoteChanged;  //�C�x���g����̓o�^
|       wm.SetReportType(InputReport.ButtonsAccel, true); //���|�[�g�^�C�v��ݒ�
|       wm.Connect();                           //WiiRemote��ڑ�
|       path = @"C:\WINDOWS\Media\chord.wav";   //�������WAV�t�@�C�����w��
|       wavePlayer = new SoundPlayer(path);     //�v���C���[��WAV�t�@�C����n��
      }
|     //Wii�����R���̒l���ω������Ƃ��ɌĂ΂����
|     void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
|       WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
|       //WAV�t�@�C�����ǂ���܂�Ă��邩�m�F
|       if (this.path != null) {
|         float AX = Math.Abs(ws.AccelState.Values.X); //X�����Βl
|         float AY = Math.Abs(ws.AccelState.Values.Y); //Y�����Βl
|         float AZ = Math.Abs(ws.AccelState.Values.Z); //Z�����Βl
|         //X,Y,Z���̉����x�Z���T���Βl����v��5�𒴂��鎞��A�U�����Ɣ���
|         if ((AX+AY+AZ) >= 5) {
|           wavePlayer.PlaySync();  //����‚炷
|         }
|       }
|     }
    }
}
�U���WAV�t�@�C�������(Form1.h)[C++]
#pragma once
namespace WLCTaiko {
  using namespace System;
  using namespace System::Windows::Forms;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾
| using namespace System::Media;  //System.Media��錾

  public ref class Form1 : public System::Windows::Forms::Form
  {
|   public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
|   public: String^ path;         //WAV�t�@�C���p�X�i�[�p
|   public: SoundPlayer^ wavePlayer;  //SoundPlayer��錾
    public:
      Form1(void) {
|       wm = gcnew Wiimote();  //Wiimote�N���X����
        InitializeComponent();
|       //�C�x���g����̓o�^
|       wm->WiimoteChanged +=
|         gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|           this, &Form1::wm_WiimoteChanged);
|       wm->SetReportType(InputReport::ButtonsAccel, true); //���|�[�g�^�C�v��ݒ�
|       wm->Connect(); //WiiRemote��ڑ�
|       path ="C:\\WINDOWS\\Media\\achord.wav";   //�������WAV�t�@�C�����w��
|       wavePlayer = gcnew SoundPlayer(path);     //�v���C���[��WAV�t�@�C����n��
      }
  public:
void wm_WiimoteChanged(Object^ sender,WiimoteLib::WiimoteChangedEventArgs^ \
    args){
|       WiimoteState^ ws;
|       float AX, AY, AZ;
|       ws = args->WiimoteState;
|       if (this->path!=nullptr) {
|         AX = Math::Abs(ws->AccelState.Values.X); //X�����Βl
|         AY = Math::Abs(ws->AccelState.Values.Y); //Y�����Βl
|         AZ = Math::Abs(ws->AccelState.Values.Z); //Z�����Βl
|         //X,Y,Z���̉����x�Z���T���Βl����v��5�𒴂��鎞��A�U�����Ɣ���
|         if ((AX+AY+AZ)>=5) {
|           wavePlayer->PlaySync();		//����‚炷
|         }
|       }
|     }
���ȉ�����

Visual C#��[F6]�AVisual C++��[F7]�L�[�������ăR���p�C���G���[���Ȃ����ƂȂǂ��m�F������ABluetooth�X�^�b�N����WiiRemote��ڑ����Ă�������(�ؒf����Ă��Ȃ���΂��̂܂ܑ��s���Ă��܂��܂���)�B

Visual Studio��[F5]�L�[�������Ď��s���Ă��������B�����ɃG���[�Ȃ����s������A�t�H�[�����\������܂��B���̃t�H�[�������g�p���܂���AWiiRemote��U���Ă݂��A�U�����킹��A�Ȃ񂾂��������������Ƃ̂��鉹���‚�܂��B

���

WiiRemote��3���̉����x�Z���T�̒l���擾����A�w�肵�������x�����o����Ǝw�肵��WAV�t�@�C����‚炵�܂��B

�������WAV�t�@�C�����w��
[C#]   path = @"C:\WINDOWS\Media\achord.wav"; 
[C++]  path ="C:\\WINDOWS\\Media\\achord.wav"; 

����u@�v��u@-quoted string�v�Ƃ�����A���ꂪ�擪�ɒ����Ă��镶�����u\�v���o�b�N�X���b�V�������ȕ����Ƃ��Ăł͂Ȃ��A�t�@�C���p�X�Ƃ��ĊȒP������ł��܂��BC++�ɂ͂���ɊY������W�L���Ȃ��悤�Ȃ̂�u\\�v�Ƃ���u\�v����ʂ�1�����Ƃ��Ĉ����Ă��܂��B

���Ă�����������t�@�C�����w�肵�Ă��܂��B�‚炵����WAV�t�@�C�����w�肵�Ă��������B���̃v���O�����ł�Windows�ɗp�ӂ��ꂽWAV�t�@�C���Ƃ���AWindows�̃V�X�e��������������Ă���WAV���w�肵�܂������A�����g�ŗp�ӂ��ꂽ���y����ʉ����w�肵�Ă��ǂ��ł��傤�B

��Βl
[c#]  float AX = Math.Abs(ws.AccelState.Values.X); //X�����Βl
[c++] AY = Math::Abs(ws->AccelState.Values.Y);     //Y�����Βl

WiiRemote��X,Y,Z���̒l���擾���A�����Βl���Ƃ�܂��B

����
//X,Y,Z���̉����x�Z���T���Βl����v��5�𒴂��鎞��A�U�����Ɣ���
if ((AX+AY+AZ)>= 5) {
	wavePlayer.PlaySync();
}

X,Y,Z���̉����x���Βl�̘a��[5]�𒴂���Ɖ���‚炷�Ƃ�A�����ɂ��ȒP�ł��B����[5]�Ƃ����l���A�������������Ȃ�����Ŕ������܂��B���΂ɑ��₹��A�傫������Ŕ������܂��B������D�݂�����ɒu�������Ă݂�A�������Ă݂Ă��������B�Ȃ������A�����������WiiRemote��U���Ă��������܂���(������ɂ�����A��������������̓X���b�h�����Ȃǂ�p����K�v������܂�)�B

�ԊO���Z���T�[���g��

����A�����x�Z���T�[���Ђƒʂ�g�����Ȃ������Ƃ�A�ԊO���Z���T�[�ɒ��킵�Ă݂܂��傤�B�ԊO����l�Ԃ̖ڂŌ��邱�Ƃ��ł��܂���B����������������v���O�����u�ԊO���T�m�@�v��A�ԊO����WiiRemote�̎��E�ɂ͂����A�o�C�u���[�^�[��‚炷���Ƃ��ł��܂��B����ő�4�_��ԊO���������J�E���g���A���̌��ʂ�LED�ɕ\������v���O���������܂��B����ɂ�������p���A�O���t�B�b�N�X�ɑg����ފ�b���w��A�Ō��ԊO���Z���T�[���g�����}�E�X����v���O�������X�e�b�v��ǂ��ĊJ�����Ă����܂��B�ڂɌ����Ȃ��ԊO�����A�ƂĂ��ʔ�������`�����f�B�A�ɂȂ邱�Ƃ�̊����Ă����܂��傤�I

�ԊO���T�m�@

�����v���O���~���O���n�߂܂��傤�B������O�������������x�Z���T�[�̃v���O���������҂��Ă��悢�̂ł����A�V�K����ق����׋��ɂȂ��Ă悢�ł��傤�B�\�����[�V������V����������K�v�͂Ȃ��A�\�����[�V�������E�N���b�N����u�lj��v���u�V�����v���W�F�N�g�v��V�����v���W�F�N�g��(�����ł�uIR1�v)��^����A�v���W�F�N�g���ł�����������A�v���W�F�N�g���E�N���b�N����u�X�^�[�g�A�b�v�v���W�F�N�g��ݒ�v���A�Q��ݒ��WiimoteLib��lj����܂��B���̃v���W�F�N�g�̃R�[�h��t�H�[�����ԈႦ�ĕ�W���Ȃ��悤�A��U�J���Ă���\�[�X�R�[�h�̃E�B���h�E�����ׂĕ‚��܂��B���������͂ł�������ł��B����m�F�̂��߂�[F5]�L�[�������Ď��s���Ă݂Ă��悢�ł��傤�B

���̃v���W�F�N�g�ł͂܂��AWiiRemote�ւ�u�ڑ��v�u�ؒf�v�{�^���������܂��B�t�H�[���Ƀ{�^��2�’���t���Ă��������B

ƒtƒH�[ƒ€‚Ƀ{ƒ^ƒ“‚ð2‚”z’u‚·‚é

�\��t������A�ubutton1�v�̃v���p�e�B��Text���u�ڑ��v��A�ubutton2�v�̃v���p�e�B��Text���u�ؒf�v��ݒ肵�܂��B

�ubutton1�v‚Ìtextƒvƒ�ƒpƒeƒB‚ð�u�Ú‘±�v‚É
�ubutton2�v‚Ìtextƒvƒ�ƒpƒeƒB‚ð�u�Ø’f�v‚É
ƒ{ƒ^ƒ“‚ÌŠ®�¬

�t�H�[���uForm1�v���E�N���b�N����u�R�[�h�̕\���v������錾��A�ڑ���������A�ԊO�����������Ƃ��̃o�C�u���[�^�[����������������܂��傤�B

�ԊO���T�m�@(Form1.cs)[C#]
//�s�v��using�錾������Ă��܂��܂���
  using System;
  using System.Windows.Forms;
| using WiimoteLib;    //WimoteLib�̎g�p��錾

namespace IR1
{
  public partial class Form1 : Form
  {
|   Wiimote wm = new Wiimote(); //Wiimote�N���X����
    public Form1()
    {
      InitializeComponent();
|     //���X���b�h����̃R���g���[���Ă�o������
|     Control.CheckForIllegalCrossThreadCalls = false;
    }
|   //�ڑ��{�^���������ꂽ��
    private void button1_Click(object sender, EventArgs e) {
|     wm.Connect();                            //Wiimote��ڑ�
|     wm.WiimoteChanged += wm_WiimoteChanged;  //�C�x���g����̓o�^
|     wm.SetReportType(InputReport.IRExtensionAccel, true);//���|�[�g�^�C�v��ݒ�
    }
|   //�ؒf�{�^���������ꂽ��
    private void button2_Click(object sender, EventArgs e) {
|     wm.WiimoteChanged -= wm_WiimoteChanged; //�C�x���g����̓o�^����
|     wm.Disconnect();  //Wiimote�ؒf
|     wm.Dispose();     //�I�u�W�F�N�g�̔j��
    }
|   //Wii�����R���̒l���ω�����x�ɌĂ΂��
|   void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)  {
|     WiimoteState ws = args.WiimoteState;    //WiimoteState�̒l���擾
|     //�����ԊO�����P�”���������
|     if (ws.IRState.IRSensors[0].Found)  {
|       wm.SetRumble(true);     //�o�C�u���[�^ON
|     } else {
|       wm.SetRumble(false);    //�o�C�u���[�^OFF
|     }
|   }
  }
}
�ԊO���T�m�@(Form1.h)[C++]
#pragma once
namespace IR1 {
  using namespace System;
  using namespace System::Windows::Forms;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾
  public ref class Form1 : public System::Windows::Forms::Form
  {
| public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
  public:
    Form1(void)
    {
|     wm = gcnew Wiimote();  //Wiimote�N���X����
      InitializeComponent();
|     //���X���b�h����̃R���g���[���Ă�o������
|     Control::CheckForIllegalCrossThreadCalls = false; 
    }
  protected:
    ~Form1()
���ȗ���
#pragma endregion
| //�ڑ��{�^���������ꂽ��
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|   wm->Connect(); //WiiRemote��ڑ�
|   wm->WiimoteChanged +=
|     gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|       this, &Form1::wm_WiimoteChanged);
|   wm->SetReportType(InputReport::IRExtensionAccel, true); //���|�[�g�^�C�v��ݒ�
  }
|   //�ؒf�{�^���������ꂽ��
private: System::Void button2_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|   wm->WiimoteChanged -=
|     gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|        this, &Form1::wm_WiimoteChanged); //�C�x���g����̓o�^����
|     wm->Disconnect();  //Wiimote�ؒf
|     wm->Dispose();     //�I�u�W�F�N�g�̔j��
  }

| //WiiRemote�̒l���ω�����x�ɌĂ΂��
| public:
| void wm_WiimoteChanged(Object^ \
    sender,WiimoteLib::WiimoteChangedEventArgs^ args){		
|     WiimoteState^ ws = args->WiimoteState;         //WiimoteState�̒l���擾
|     //�����ԊO�����P�”���������
|     if (ws->IRState.IRSensors[0].Found) {
|       wm->SetRumble(true);     //�o�C�u���[�^ON
|     } else  {
|       wm->SetRumble(false);    //�o�C�u���[�^OFF
|     }
|   }
  };
}

�����F�ԊO�������Ă݂悤

����A���s���Ă݂܂��B�܂����͂�ԊO��������p�ӂ��Ă��������BWii�{�̕t���̃Z���T�[�o�[������Ύ��������̂ł����A�Ȃ����͎���ɂ���Ɩ��A���z���Ȃǂɂ�������‚��Ă݂܂��傤�BBluetooth�X�^�b�N����WiiRemote��ڑ�����AVisual Studio��[F5]�L�[�������Ď��s���Ă��������B�t�H�[�����\�����ꂽ��A[�ڑ�]�{�^���������Ă��������BWiiRemote���Z���T�[�o�[�Ȃ�ԊO�������Ɍ����Ă��������B�Z���T�[�o�[���Ȃ�����A���z�A�n���Q�������v�Ȃǂ̔M���Ɩ��A���C�^�[�̉�A�e���r�̃����R���A�g�ѓd�b��ԊO����M�ȂǂɌ����Ă݂Ă��������B��肭���o�ł����A�o�C�u���[�^�[���‚�܂��B�o�C�u���[�^�[���‚��Ă��Ȃ���Ԃ�[�ؒf]�{�^���������Ă���I�����܂��傤�B

���C�^�[���E�\�N�Ȃǂ�p����ԊO�������ɂ������A�Ύ������Ȃǂ�\���C���‚��Ď������s���Ă��������B�܂��A�e���r�����R����p�������A�{�^���������ꂽ�Ƃ��ɂ����ԊO����M���܂���̂�A���x���A�ł��Ċm�F�������Ȃ��Ƃ悢�ł��傤�B

���낢��ȕ����Ɍ����Ă݂܂��悤�B���i�͌����Ȃ��ԊO���ł����A�g�̉��ɂ���l�X�ȕ��ɗ��p����Ă��邱�ƂɋC���‚����Ƃł��傤�B

�{�^���������Ă������N���Ȃ�����H

��L�̃R�[�h�����̂܂܃R�s�[���Ă��܂���H�{�^�����������Ƃ��������AForm1���ɂ���{�^�����_�u���N���b�N����AWindows�t�H�[���f�U�C�i����������������R�[�h���g��������Ă����̂��m���ł��B�����P��A��L�̃R�[�h���R�s�[�����A�ڑ��{�^���������Ă��A�K�؂�����Ƀv���O����������Ă����܂���B���̎d�g�݂�w�ǂ�����!?�x�Ǝv�����l��A�v���W�F�N�g�̒��ɂ���uForm1.Designer.cs�v��`���Ă݂܂��傤�B������u#region Windows�t�H�[���f�U�C�i��������ꂽ�R�[�h�v�Ƃ����f�t�H���g�Ŕ�\���ɂȂ��Ă���p�[�g������܂��B

Form1.Designer.cs�Ŏ�����������Ă���R�[�h[C#]
#region Windows �t�H�[�� �f�U�C�i��������ꂽ�R�[�h
�c
this.button1.Click += new System.EventHandler(this.button1_Click_1);
�c
this.button2.Click += new System.EventHandler(this.button2_Click);

�����ɂ�AGUI��������t�H�[���ɂ‚��Ă̈ʒu��傫���Ȃǂ̃v���p�e�B���L�ڂ���Ă��܂��B�厖�Ȃ̂�A�{�^�����������Ƃ��̃C�x���g�̔����ł��B

this.button1.Click+=new System.EventHandler(this.button1_Click_1);

�܂���WiiRemote�̃C�x���g�̒lj��Ɠ����悤��A�N���b�N���̃C�x���g��lj����Ă��܂��B�������A��̗�ł�ubutton1_Click_1�v�Ƃ�������ɂȂ��Ă��܂��B�u_1�v�̕�����A���̊����̊���Ɩ��O���Փ˂��Ȃ��悤�A�������������܂��B�‚܂����ubutton1_Click�v�Ƃ�������������Ă����Ƃ��Ă��A�{�^�����������Ƃ��̃C�x���g�Ƃ��ăR�[������邱�Ƃ͂���܂���B

�w�Ȃ�A�킴�킴GUI�Ń_�u���N���b�N���Ȃ��Ƃ����Ȃ��̂��I�x�Ǝv���邩������܂���A�Ǘ����ʓ|�ȃC�x���g�n���Ȃǂ�����������E�Ǘ����Ă����A.NET�X�^�C���̊J�����u�����܂ŗ�������v�g�����Ȃ��A�Ƃ����̂��J�b�R�C�C�̂ł͂Ȃ��ł��傤���B

���:���|�[�g��ݒ�^�ԊO��4�_���o

���̃v���O�����̎d�g�݂͒P���ł��B�R�[���o�b�N�����ݒ肵��AWiiRemote��ԊO���Z���T�[���ЂƂ‚ł����‚�������A�o�C�u���[�^�[��ON�ɂ��܂��B

���|�[�g�^�C�v��ݒ�
[C#]  wm.SetReportType ( InputReport.IRExtensionAccel, true); 
[C++] wm->SetReportType(InputReport::IRExtensionAccel, true);

���|�[�g�^�C�v���uIRExtensionAccel�v(�ԊO���{�g���{�����x)�擾���[�h��ݒ肵�܂��B���̃R�[���͂��Ȃ炸wm.Connect();�̌�ɋL�q���Ă��������Bwm.Connect();���O�ɋL�q�����ԊO���Z���T�[�����������삵�܂���B

�ԊO���̌��o
[C#]    ws.IRState.IRSensors[0].Found
[C++]  ws->IRState.IRSensors[0].Found

���̃v���p�e�B��True/False��Ԃ��܂��̂�Aif�����g����ԊO�������o���邱�Ƃ��ł��܂��B�܂�WiimoteLib��A������4�_�܂�ԊO�����������o���邱�Ƃ��ł��܂��B��X�̌�������肷�邱�Ƃ͂ł��܂���uIRSensors[3].Found�v���ꂪTrue�Ȃ�4�‚�ԊO�������������Ă���A�Ƃ������Ƃł��B

�ԊO�������

������A��������{�I�ȃv���O���������p����A�ԊO���̌�������v���O�����Ɋg�����܂��BWiimoteLib�ɂ͓�����4�_�܂ł�ԊO�����v�����邱�Ƃ��ł��܂��B�����܂ł̃v���O�����ł�1�_�ł��ԊO���������Z���T�[�̎��E�ɓ����A�o�C�u���[�^�[���U������悤�ɂȂ��Ă��܂������A��FLED(�v���C���[�C���W�Q�[�^�[)���‚�����A���_���o���Ă��邩��\������v���O������lj����܂��B

�ԊO���T�mLED�\��(Form1.cs, ����)[C#]
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
{
  WiimoteState ws = args.WiimoteState;  //WiimoteState�̒l���擾
  //�����ԊO�����P�”���������
  if (ws.IRState.IRSensors[0].Found)  {
     wm.SetRumble(true);     //�o�C�u���[�^ON
  }  else  {
     wm.SetRumble(false);    //�o�C�u���[�^OFF
  }
| //���o���ꂽ�ԊO�������Wii�����R����LED�ɕ\������
| wm.SetLEDs(ws.IRState.IRSensors[0].Found, ws.IRState.IRSensors[1].Found,
|            ws.IRState.IRSensors[2].Found, ws.IRState.IRSensors[3].Found);
}
�ԊO���T�mLED�\��(Form1.h, ����)[C++]
public:
void wm_WiimoteChanged(Object^ sender,WiimoteLib::WiimoteChangedEventArgs^ \
    args){		
 WiimoteState^ ws = args->WiimoteState;  //WiimoteState�̒l���擾

  //�����ԊO�����P�”���������
  if (ws->IRState.IRSensors[0].Found) {
    wm->SetRumble(true);     //�o�C�u���[�^ON
  } else {
    wm->SetRumble(false);    //�o�C�u���[�^OFF
  }
| //���o���ꂽ�ԊO�������Wii�����R����LED�ɕ\������
| wm->SetLEDs(ws->IRState.IRSensors[0].Found, \
    ws->IRState.IRSensors[1].Found,
| ws->IRState.IRSensors[2].Found, ws->IRState.IRSensors[3].Found );
}

�����ł��ق�LED�̓_������Ŏg�����uSetLED��()�v����̂����A4�����̂��̂��g���Ă��܂��BWiiRemote��ԊO���Z���T�[�ɕ�����ԊO��������������A�o�C�u���[�^�[��U���Ƌ���LED�C���W�Q�[�^�[���g����ԊO�����o�����\�����܂��B

���W��`��

����A�ԊO�������̗L����A���̃J�E���g���ł���悤�ɂȂ����̂�A����ԊO���Z���T�[�ɂ��������W�̎擾���s���A�t�H�[�����ɃO���t�B�b�N�X�@�\���g���ĕ`�悵�܂��B��قǂ̃v���W�F�N�g�����̂܂܉��ǂ��ĊJ�����邱�Ƃɂ��܂��傤�B

PictureBox‚ÌSizeƒvƒ�ƒpƒeƒB

�܂��A�t�H�[���̃f�U�C�����X���܂��B�͂��߂Ďg���V�����R���g���[����z�u���܂��B�u�c�[���{�b�N�X�v��u�R�����R���g���[���v����uPictureBox�v��Form1�ɒ���t���܂��B�v���p�e�B��uSize�v���u200, 200�v�ɂ��܂��B���̃{�^����t�H�[���̃o�����X���Ƃ��Ĕz�u���܂��B

Form1‚É”z’u‚µ‚½PictureBox‚ƃ{ƒ^ƒ“

�v���O�����̂ق��͂܂��A�`����using�錾��uSystem.Drawing�v���錾����Ă��邱�Ƃ��m�F���Ă��������B��������{�^���C�x���g�͂��̂܂܂�AWiiRemote���Ԃ��ω������Ƃ��ɌĂ΂�����uwm_WiimoteChanged()�v�ƃt�H�[���`�����uDrawForms(ws)�v��A�`��̂��߂̃R�[�h�����M���܂��B

�ԊO���|�C���^�`��(Form1.cs)[C#]
  using System;
  using System.Windows.Forms;
| using System.Drawing; //�`��̂��߂ɕK�v
| using WiimoteLib;     //WimoteLib�̎g�p��錾

  namespace IR4 {       //�������v���W�F�N�g����
    public partial class Form1 Form {
|     Wiimote wm = new Wiimote(); //Wiimote�N���X����
    public Form1) {
     InitializeComponent();
|    //���X���b�h����̃R���g���[���Ă�o������
|    Control.CheckForIllegalCrossThreadCalls = false;
    }

|   //WiiRemote���Ԃ��ω������Ƃ��ɌĂ΂����
|   void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) {
|     WiimoteState ws = args.WiimoteState;  //WiimoteState�̒l���擾 
|     DrawForms(ws);                        //�t�H�[���`�ʊ����
|   }
�����F�{�^���C�x���g�֌W��
|   //�t�H�[���`�ʊ��
|   public void DrawForms(WiimoteState ws) {
|     Graphics g =this.pictureBox1.CreateGraphics(); //�O���t�B�b�N�X�擾
|     g.Clear(Color.Black);                          //��ʂ����F�ɃN���A
|     //�����ԊO�����P�”���������
|     if (ws.IRState.IRSensors[0].Found) {
|       //��F�Ń}�[�J��`��
|       g.FillEllipse(Brushes.Red,
|       ws.IRState.IRSensors[0].Position.X * 200,
|       ws.IRState.IRSensors[0].Position.Y * 200, 10, 10);
|     }
|     //�����ԊO�����Q�”���������
|     if (ws.IRState.IRSensors[1].Found) {
|       //��F�Ń}�[�J��`��
|       g.FillEllipse(Brushes.Blue,
|       ws.IRState.IRSensors[1].Position.X * 200,
|       ws.IRState.IRSensors[1].Position.Y * 200, 10, 10);
|     }
|     //�����ԊO�����R�”���������
|     if (ws.IRState.IRSensors[2].Found) {
|       //���F�Ń}�[�J��`��
|       g.FillEllipse(Brushes.Yellow,
|       ws.IRState.IRSensors[2].Position.X * 200,
|       ws.IRState.IRSensors[2].Position.Y * 200, 10, 10);
|     }
|     //�����ԊO�����S�”���������
|     if (ws.IRState.IRSensors[3].Found) {
|       //��F�Ń}�[�J��`��
|       g.FillEllipse(Brushes.Green,
|       ws.IRState.IRSensors[3].Position.X * 200,
|       ws.IRState.IRSensors[3].Position.Y * 200, 10, 10);
|     }
|     g.Dispose();//�O���t�B�b�N�X�̉��
| }
 }
}
�ԊO���|�C���^�`��(Form1.h)[C++]
 #pragma once
 namespace IR4 {  //�������v���W�F�N�g����
  using namespace System::Windows::Forms;
| using namespace System::Drawing;
| using namespace WiimoteLib;  //WimoteLib�̎g�p��錾
  public ref class Form1 : public System::Windows::Forms::Form
  {
|   public: Wiimote^ wm; //Wiimote�I�u�W�F�N�gwm����
    public:
     Form1(void) {
|      wm = gcnew Wiimote();  //Wiimote�N���X����
       InitializeComponent();
|      //���X���b�h����̃R���g���[���Ă�o������
|      Control::CheckForIllegalCrossThreadCalls = false; 
     }
    protected:
    /// <summary>
������
#pragma endregion
|   //�ڑ��{�^���������ꂽ��
private: System::Void button1_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|     wm->Connect(); //WiiRemote��ڑ�
|     wm->WiimoteChanged +=
|       gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|         this, &Form1::wm_WiimoteChanged);
|       //���|�[�g�^�C�v��ݒ�
|       wm->SetReportType(InputReport::IRExtensionAccel, true);
    }
|   //�ؒf�{�^���������ꂽ��
private: System::Void button2_Click(System::Object^ sender, \
    System::EventArgs^ e) {
|     wm->WiimoteChanged -=
|       gcnew System::EventHandler<WiimoteChangedEventArgs^>(
|         this, &Form1::wm_WiimoteChanged); //�C�x���g����̓o�^����
|       wm->Disconnect();  //Wiimote�ؒf
    }
|   //WiiRemote�̒l���ω�����x�ɌĂ΂��
|   public:
| void wm_WiimoteChanged(Object^ \
    sender,WiimoteLib::WiimoteChangedEventArgs^ args){		
|       WiimoteState^ ws = args->WiimoteState;  //WiimoteState���擾
|       DrawForms(ws);
|   }
|  public: 
|     void DrawForms(WiimoteState^ ws) {
|       //�O���t�B�b�N�X���擾
|       Graphics^ g = this->pictureBox1->CreateGraphics();
|       g->Clear(Color::Black);//��ʂ����F�ɃN���A

|       if (ws->IRState.IRSensors[0].Found) {  //�ԊO����1�”���������
|         //��F�Ń}�[�J��`��
|         g->FillEllipse( Brushes::Red ,
|           (float)ws->IRState.IRSensors[0].Position.X * 200.0f ,
| (float)ws->IRState.IRSensors[0].Position.Y * 200.0f , 10.0f , 10.0f );
|       }
|       if (ws->IRState.IRSensors[1].Found) {  //�ԊO����2�”���������
|         //��F�Ń}�[�J��`��
|         g->FillEllipse( Brushes::Blue ,
|           (float)ws->IRState.IRSensors[1].Position.X * 200.0f ,
| (float)ws->IRState.IRSensors[1].Position.Y * 200.0f , 10.0f , 10.0f );
|       }
|       if (ws->IRState.IRSensors[2].Found) {  //�ԊO����3�”���������
|         //���F�Ń}�[�J��`��
|         g->FillEllipse( Brushes::Yellow ,
|           (float)ws->IRState.IRSensors[2].Position.X * 200.0f ,
| (float)ws->IRState.IRSensors[2].Position.Y * 200.0f , 10.0f , 10.0f );
|       }
|       if (ws->IRState.IRSensors[3].Found) {  //�ԊO����4�”���������
|         //��F�Ń}�[�J��`��
|         g->FillEllipse( Brushes::Green ,
|           (float)ws->IRState.IRSensors[3].Position.X * 200.0f ,
| (float)ws->IRState.IRSensors[3].Position.Y * 200.0f , 10.0f , 10.0f );
|       }
|     }
  };
}

�������悤

�܂��ԊO��������p�ӂ���ABluetooth�X�^�b�N����WiiRemote��ڑ����Ă��������BVisual Studio����[F5]�L�[�������ăv���O���������s���܂��B�\�����ꂽ�t�H�[����[�ڑ�]�{�^�����N���b�N����AWiiRemote���Z���T�[�o�[��d���Ȃǂ�ԊO�������Ɍ����Ă��������B

�ÔŠO�ü‚ÉŒü‚¯‚邯4�F‚̃}�[ƒJ�[‚ª“®‚­

�ԊO�������o������}�̂悤�Ƀ}�[�J�_���\�����܂��B�}�[�J�̓������������������AWiiRemote�ƃZ���T�[�o�[�Ƃ̋�����2m�`3m�܂ŗ����Ă��������B�����������قLj��肵���������s�����Ƃ��ł��܂��B

�Ȃ�Wii�{�̕t���̕W���̃Z���T�[�o�[�ɂ�ԊO��LED�����E2�O���[�v��������܂���i��������4�_���o�ł���Ƃ����@�\�����݂���Ƃ��낪�����ł��I�j�B������ԊO�������‚���Ȃ�����A�����i���z�Ɍ�����Ȃ�j�ɑ��̊O�Ɍ�����ƕ�����ԊO�������o�ł���Ǝv���܂��B���z�̌�����˂��Ă���l�q�Ȃǂł������_���擾�ł��邱�Ƃ�����܂����A�ԊO���������m���߂�����ƂЂƂ‚̃O���[�v�Ƃ��Č�F������m�C�Y�̌����ɂȂ�܂��̂�A������x���肵�Ď擾�ł�������⋗���𒲂ׂĂ݂�̂��悢�ł��傤�B���}�ł�A�Ƃ���X�܂̓V��ɒ݂��Ă���4�‚̃n���Q�������v�̗l�q�ł��B�I���������A�ؒf�{�^���������Ă���I�������Ă��������B

����F�ԊO�����W�̎擾

WiiRemote��ԊO���J�����̒l���擾����A�ԊO���𔭌��������ʂɕ`�悵�Ă��܂��B

�ԊO�����W�̎擾
[C#]   ws.IRState.IRSensors[0].Position.X 
[C++] ws->IRState.IRSensors[0].Position.X

�ԊO������W(x,y)�̈ʒu(Position)��A{0.0�`1.0}�̒l����Ƃ�܂��B�O���t�B�b�N�X�Ƃ̑g����킹���ӊO�ƊȒP�������̂ł͂Ȃ��ł��傤���B�{�v���O�����ł�A���̒l��pictureBox�̉����Ƃ���ݒ肵��200x200������悤��A200���|����o�͂��Ă��܂����A�t�H�[����Size���X�����肵��A���D�݂̉�ʃf�U�C���ɂ��Ă݂�Ƃ悢�ł��傤�B

�Ȃ��AWiiRemote��ԊO���Z���T�[�͔�������\�ł��B�����ł�4�_�̌��o���s���Ă��܂����A���ۂ�ԊO���������W�������Ă���X�s�[�h�͔��ɑ������Ƃɒ��ڂł��B���̃r�f�I�J��������1�b��15-30����x�̎B�e���s���Ă���̂ɑ΂��AWiiRemote��200����x����W�擾�������s���Ă���悤�ł��B�������Q�[���p���̓f�o�C�X�ł��A���x����؂ł��I

�{�͂ł͔�r�I���S�҂̓ǎ҂Ɍ�����AVisual Studio���g���AC#��C++�Ƃ��������̌���‹����g����.NET�ŊJ�����ꂽWiimoteLib��ʂ���A��{�I��WiiRemote�v���O���~���O���w�т܂����BWiimoteLib�͌���ł������x�����API�̂ЂƂ‚�A���Ɉ��肵�ē��삵�܂��B.NET�Ƃ����‹�����uC#��p�H�v��l�����Ă��܂����A�{���Ɍ�����C++/CLI�ɂ����������[�������܂���(�����炭���E���I�ł�)�B

WiimoteLib���g�����T���v���A��̓I�ȊJ�����8�͂ł������Ă����܂��B