コード例 #1
0
        private byte[] _ReadData(int address, short size)
        {
            _ClearReport();

            _ReadBuff = new byte[size];
            _Address  = address & 0xffff;
            _Size     = size;

            _Buff[0] = (byte)EOutputReport.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);
        }
コード例 #2
0
        private void _ReaderLoop()
        {
            var buff = new byte[_ReportLength];

            while (Connected)
            {
                int bytesRead;
                try
                {
                    bytesRead = CHIDApi.ReadTimeout(_Handle, ref buff, _ReportLength, 400);
                    if (bytesRead == -1)
                    {
                        Connected = false; //Disconnected
                        Connect();
                        break;
                    }
                }
                catch (Exception e)
                {
                    CLog.Error("(WiiMoteLib) Error reading from device: " + e);
                    Connected = false;
                    break;
                }

                if (bytesRead > 0 && _ParseInputReport(buff))
                {
                    if (WiiMoteChanged != null)
                    {
                        WiiMoteChanged.Invoke(this, new CWiiMoteChangedEventArgs(_WiiMoteState));
                    }
                }
                Thread.Sleep(5);
            }
            CHIDApi.Close(_Handle);
        }
コード例 #3
0
        public void SetReportType(EInputReport type, EIRSensitivity irSensitivity, bool continuous)
        {
            if (!Connected)
            {
                return;
            }

            switch (type)
            {
            case EInputReport.IRAccel:
                _EnableIR(EIRMode.Extended, irSensitivity);
                break;

            default:
                _DisableIR();
                break;
            }

            _ClearReport();
            _Buff[0] = (byte)EOutputReport.Type;
            _Buff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(_WiiMoteState.Rumble ? 0x01 : 0x00));
            _Buff[2] = (byte)type;

            CHIDApi.Write(_Handle, _Buff);
        }
コード例 #4
0
        public CWiiMoteLib()
        {
            if (!CHIDApi.Init())
            {
                CLog.Error("WiiMoteLib: Can't initialize HID API");
                CLog.Error("Please install the Visual C++ Redistributable Packages 2008!");

                _Error = true;
            }
        }
コード例 #5
0
        private void _DisableIR()
        {
            _WiiMoteState.IRState.Mode = EIRMode.Off;

            _ClearReport();
            _Buff[0] = (byte)EOutputReport.IR;
            _Buff[1] = _RumbleBit;
            CHIDApi.Write(_Handle, _Buff);

            _ClearReport();
            _Buff[0] = (byte)EOutputReport.IR2;
            _Buff[1] = _RumbleBit;
            CHIDApi.Write(_Handle, _Buff);
        }
コード例 #6
0
 private void _TryConnect(ushort pid)
 {
     //We might have had a reader thread, that is not finished yet, so let it finish and close it's handle first or it will close the new one
     _WaitForReader();
     Connected = CHIDApi.Open(_VID, pid, out _Handle);
     if (Connected)
     {
         _StartReader();
         if (!_ReadCalibration())
         {
             Connected = false;
         }
     }
 }
コード例 #7
0
        private void _WriteData(int address, byte size, byte[] buff)
        {
            _ClearReport();

            _Buff[0] = (byte)EOutputReport.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);
        }
コード例 #8
0
        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)EOutputReport.LEDs;
            _Buff[1] = (byte)((led1 ? 0x10 : 0x00) |
                              (led2 ? 0x20 : 0x00) |
                              (led3 ? 0x40 : 0x00) |
                              (led4 ? 0x80 : 0x00) |
                              _RumbleBit);

            CHIDApi.Write(_Handle, _Buff);
        }
コード例 #9
0
        private void _EnableIR(EIRMode mode, EIRSensitivity sensitivity)
        {
            _WiiMoteState.IRState.Mode = mode;

            _ClearReport();
            _Buff[0] = (byte)EOutputReport.IR;
            _Buff[1] = (byte)(0x04 | _RumbleBit);
            CHIDApi.Write(_Handle, _Buff);
            Thread.Sleep(50);

            _ClearReport();
            _Buff[0] = (byte)EOutputReport.IR2;
            _Buff[1] = (byte)(0x04 | _RumbleBit);
            CHIDApi.Write(_Handle, _Buff);
            Thread.Sleep(50);

            _WriteData(_RegisterIR, 0x08);
            Thread.Sleep(50);

            switch (sensitivity)
            {
            case EIRSensitivity.Level1:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0x64, 0x00, 0xfe });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0xfd, 0x05 });
                break;

            case EIRSensitivity.Level2:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0x96, 0x00, 0xb4 });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0xb3, 0x04 });
                break;

            case EIRSensitivity.Level3:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0xaa, 0x00, 0x64 });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0x63, 0x03 });
                break;

            case EIRSensitivity.Level4:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x02, 0x00, 0x00, 0x71, 0x01, 0x00, 0xc8, 0x00, 0x36 });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0x35, 0x03 });
                break;

            case EIRSensitivity.Level5:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x07, 0x00, 0x00, 0x71, 0x01, 0x00, 0x72, 0x00, 0x20 });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0x1, 0x03 });
                break;

            case EIRSensitivity.Max:
                _WriteData(_RegisterIRSensitivity1, 9, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0x41 });
                Thread.Sleep(50);
                _WriteData(_RegisterIRSensitivity2, 2, new byte[] { 0x40, 0x00 });
                break;
            }
            Thread.Sleep(50);
            _WriteData(_RegisterIRMode, (byte)mode);
            Thread.Sleep(50);
            _WriteData(_RegisterIR, 0x08);
            Thread.Sleep(50);
        }