private byte[] ReadData(int address, short size) { ClearReport(); _ReadBuff = new byte[size]; _Address = address & 0xffff; _Size = size; _Buff[0] = (byte)OutputReport.ReadMemory; _Buff[1] = (byte)(((address & 0xff000000) >> 24) | RumbleBit); _Buff[2] = (byte)((address & 0x00ff0000) >> 16); _Buff[3] = (byte)((address & 0x0000ff00) >> 8); _Buff[4] = (byte)(address & 0x000000ff); _Buff[5] = (byte)((size & 0xff00) >> 8); _Buff[6] = (byte)(size & 0xff); CHIDAPI.Write(_Handle, _Buff); if (!_ReadDone.WaitOne(1000, false)) { _Connected = false; return(null); } return(_ReadBuff); }
private void ReaderLoop() { while (_Active) { Thread.Sleep(5); if (_Handle != IntPtr.Zero && _Connected) { byte[] buff = new byte[REPORT_LENGTH]; try { CHIDAPI.ReadTimeout(_Handle, out buff, REPORT_LENGTH, 100); } catch (Exception e) { CLog.LogError("(WiiMoteLib) Error reading from device: " + e.ToString()); } if (ParseInputReport(buff)) { if (WiiMoteChanged != null) { WiiMoteChanged(this, new WiiMoteChangedEventArgs(_WiiMoteState)); } } } } }
public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous) { if (!_Connected) { return; } switch (type) { case InputReport.IRAccel: EnableIR(IRMode.Extended, irSensitivity); break; default: DisableIR(); break; } ClearReport(); _Buff[0] = (byte)OutputReport.Type; _Buff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(_WiiMoteState.Rumble ? 0x01 : 0x00)); _Buff[2] = (byte)type; CHIDAPI.Write(_Handle, _Buff); }
private void DisableIR() { _WiiMoteState.IRState.Mode = IRMode.Off; ClearReport(); _Buff[0] = (byte)OutputReport.IR; _Buff[1] = RumbleBit; CHIDAPI.Write(_Handle, _Buff); ClearReport(); _Buff[0] = (byte)OutputReport.IR2; _Buff[1] = RumbleBit; CHIDAPI.Write(_Handle, _Buff); }
private void WriteData(int address, byte size, byte[] buff) { ClearReport(); _Buff[0] = (byte)OutputReport.WriteMemory; _Buff[1] = (byte)(((address & 0xff000000) >> 24) | RumbleBit); _Buff[2] = (byte)((address & 0x00ff0000) >> 16); _Buff[3] = (byte)((address & 0x0000ff00) >> 8); _Buff[4] = (byte)(address & 0x000000ff); _Buff[5] = size; Array.Copy(buff, 0, _Buff, 6, size); CHIDAPI.Write(_Handle, _Buff); Thread.Sleep(100); }
public bool Connect() { _Connected = false; if (_Error) { return(false); } CHIDAPI.Exit(); if (!CHIDAPI.Init()) { CLog.LogError("WiiMoteLib: Can't initialize HID API"); string msg = "Please install the Visual C++ Redistributable Packages 2008!"; CLog.LogError(msg); _Active = false; _Error = true; return(false); } //Try WiiMotion if (_Connected = CHIDAPI.Open(VID, PID, out _Handle)) { if (!(_Connected = ReadCalibration())) { CHIDAPI.Close(_Handle); } } if (_Connected) { return(true); } //Try WiiMotion Plus if (_Connected = CHIDAPI.Open(VID, PIDPlus, out _Handle)) { if (!(_Connected = ReadCalibration())) { CHIDAPI.Close(_Handle); } } return(_Connected); }
public void SetLEDs(bool led1, bool led2, bool led3, bool led4) { _WiiMoteState.LEDState.LED1 = led1; _WiiMoteState.LEDState.LED2 = led2; _WiiMoteState.LEDState.LED3 = led3; _WiiMoteState.LEDState.LED4 = led4; if (!_Connected) { return; } ClearReport(); _Buff[0] = (byte)OutputReport.LEDs; _Buff[1] = (byte)( (led1 ? 0x10 : 0x00) | (led2 ? 0x20 : 0x00) | (led3 ? 0x40 : 0x00) | (led4 ? 0x80 : 0x00) | RumbleBit); CHIDAPI.Write(_Handle, _Buff); }
private void EnableIR(IRMode mode, IRSensitivity Sensitivity) { _WiiMoteState.IRState.Mode = mode; ClearReport(); _Buff[0] = (byte)OutputReport.IR; _Buff[1] = (byte)(0x04 | RumbleBit); CHIDAPI.Write(_Handle, _Buff); Thread.Sleep(50); ClearReport(); _Buff[0] = (byte)OutputReport.IR2; _Buff[1] = (byte)(0x04 | RumbleBit); CHIDAPI.Write(_Handle, _Buff); Thread.Sleep(50); WriteData(REGISTER_IR, 0x08); Thread.Sleep(50); switch (Sensitivity) { case IRSensitivity.Level1: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0x64, 0x00, 0xfe }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0xfd, 0x05 }); break; case IRSensitivity.Level2: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0x96, 0x00, 0xb4 }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0xb3, 0x04 }); break; case IRSensitivity.Level3: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0xaa, 0x00, 0x64 }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0x63, 0x03 }); break; case IRSensitivity.Level4: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0xc8, 0x00, 0x36 }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0x35, 0x03 }); break; case IRSensitivity.Level5: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x07, 0x00, 0x00, 0x71, 0x01, 0x00, 0x72, 0x00, 0x20 }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0x1, 0x03 }); break; case IRSensitivity.Max: WriteData(REGISTER_IR_SENSITIVITY_1, 9, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x41 }); Thread.Sleep(50); WriteData(REGISTER_IR_SENSITIVITY_2, 2, new byte[] { 0x40, 0x00 }); break; } Thread.Sleep(50); WriteData(REGISTER_IR_MODE, (byte)mode); Thread.Sleep(50); WriteData(REGISTER_IR, 0x08); Thread.Sleep(50); }
public void Disconnect() { _Connected = false; _Active = false; CHIDAPI.Exit(); }