PDA

View Full Version : Wiimote control - write correct data to human input device



NecroDOME
28-11-2007, 05:28 PM
System: Windows Vista, Wii Remote Controller and bluetooth device
Compiler/IDE: Delphi 2007 for Win32
API: JvHidControllerClass (found somewhere on the internet: http://www.soft-gems.net/supplement/download.php?ID=37)

Hi all,

I gonna need some help. I connected my wii mote to my PC but only some parts work. I can get the button status, but cannot set the player leds or enable the IR sensor.

I need to write some data to my wii mote, but I don't know if I did it correctly.

What I currently have is:

// Buf = Buf: array [0..2] of Byte;

Buf[0] := $52; // With or without doesn't matter, got it from wiili.org
Buf[1] := $11; // Port
Buf[2] := $11; // Test data, first byte is for the leds, 2nd for the rumbler (that is turned off by default af my wii mote cause it eats batteries in no time!)

if not FHidDevice.SetOutputReport(Buf, 2) then
Log('Not set player led');


This should turn on a led on the wii mote but nothing happens.

I found this code on http://www.wiili.org :

BYTE report[2];
led[index] = !led[index];
report[0] = 0x11;
report&#91;1&#93; = led&#91;0&#93; | led&#91;1&#93;<<1 | led&#91;2&#93;<<2 | led&#91;3&#93;<<3;
report&#91;1&#93; = report&#91;1&#93;<<4 | rumble;
if&#40;HidD_SetOutputReport&#40;wiimotehandle, report, 2&#41; == 0&#41;
WShowError&#40;"While setting output report."&#41;;


Some wii mote specs: http://www.wiili.org/index.php/Wiimote


btw: if you want to try it yourself, this is how I read the buttons:



const
HEX_WII_BUTTON_LEFT = 1;
HEX_WII_BUTTON_RIGHT = 2;
HEX_WII_BUTTON_DOWN = 4;
HEX_WII_BUTTON_UP = 8;
HEX_WII_BUTTON_PLUS = 16;
HEX_WII_BUTTON_TWO = 256;
HEX_WII_BUTTON_ONE = 512;
HEX_WII_BUTTON_B = 1024;
HEX_WII_BUTTON_A = 2048;
HEX_WII_BUTTON_Minus = 4096;
HEX_WII_BUTTON_HOME = 32768;

WII_BUTTON_TWO = 0;
WII_BUTTON_ONE = 1;
WII_BUTTON_B = 2;
WII_BUTTON_A = 3;
WII_BUTTON_Minus = 4;
WII_BUTTON_HOME = 5;
WII_BUTTON_LEFT = 6;
WII_BUTTON_RIGHT = 7;
WII_BUTTON_DOWN = 8;
WII_BUTTON_UP = 9;
WII_BUTTON_PLUS = 10;

type
TWiiButtons = record
Buttons : array [0..12] of boolean;
end;


The OnData event from the TJvHidDevice (class from JvHidControllerClass )
procedure TWiiMoteController.DataFromWiiMote(HidDev: TJvHidDevice; ReportID: Byte; const Data: Pointer; Size: Word);
var i: Integer;
Buttons: word;
Str: string;
begin
if ReportID = 48 then // Buttons
begin
Move(PChar(Data)[0], Buttons, 2);

ButtonState.Buttons[WII_BUTTON_LEFT] := Buttons and HEX_WII_BUTTON_LEFT <> 0;
ButtonState.Buttons[WII_BUTTON_RIGHT] := Buttons and HEX_WII_BUTTON_RIGHT <> 0;
ButtonState.Buttons[WII_BUTTON_DOWN] := Buttons and HEX_WII_BUTTON_DOWN <> 0;
ButtonState.Buttons[WII_BUTTON_UP] := Buttons and HEX_WII_BUTTON_UP <> 0;
ButtonState.Buttons[WII_BUTTON_PLUS] := Buttons and HEX_WII_BUTTON_PLUS <> 0;
ButtonState.Buttons[WII_BUTTON_TWO] := Buttons and HEX_WII_BUTTON_TWO <> 0;
ButtonState.Buttons[WII_BUTTON_ONE] := Buttons and HEX_WII_BUTTON_ONE <> 0;
ButtonState.Buttons[WII_BUTTON_B] := Buttons and HEX_WII_BUTTON_B <> 0;
ButtonState.Buttons[WII_BUTTON_A] := Buttons and HEX_WII_BUTTON_A <> 0;
ButtonState.Buttons[WII_BUTTON_Minus] := Buttons and HEX_WII_BUTTON_Minus <> 0;
ButtonState.Buttons[WII_BUTTON_HOME] := Buttons and HEX_WII_BUTTON_HOME <> 0;

end;
end;

JSoftware
28-11-2007, 10:25 PM
wouldn't it make more sense to call it like this:


Buf[0] := $52; // With or without doesn't matter, got it from wiili.org
Buf[1] := $11; // Port
Buf[2] := $F0; // all leds on and rumbler off?

if not FHidDevice.SetOutputReport(Buf, 3) then //<- 3 bytes?
Log('Not set player led');


edited to $F0 instead of $0F

NecroDOME
29-11-2007, 06:15 AM
I didn't try that yet. But it's that $11 didn't do anything, so I'm guessing $F0 will do the same: nothing. Butt I'll give it a try when I get home.

NecroDOME
29-11-2007, 07:50 PM
OK, I solved the problem, it was not my code, but the drivers. I installed the BlueSoleil drivers and it worked :D