/// <summary> /// Parse data returned from a read report /// </summary> /// <param name="buff">Data buffer</param> private void ParseReadData(byte[] buff) { if ((buff[3] & 0x08) != 0) { Exception ex = new WiimoteException("Error reading data from Wiimote: Bytes do not exist."); WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(ex)); return; } if ((buff[3] & 0x07) != 0) { Debug.WriteLine("*** read from write-only"); LastReadStatus = LastReadStatus.ReadFromWriteOnlyMemory; mReadDone.Set(); return; } // get our size and offset from the report int size = (buff[3] >> 4) + 1; int offset = (buff[4] << 8 | buff[5]); // add it to the buffer Array.Copy(buff, 6, mReadBuff, offset - mAddress, size); // if we've read it all, set the event if (mAddress + mSize == offset + size) { mReadDone.Set(); } LastReadStatus = LastReadStatus.Success; }
/// <summary> /// </summary> private void ThrowException(Exception ex) { Disconnect(); WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(ex)); }
// Called by Wiimote private void RaiseWiimoteException(Exception ex) { WiimoteManager.RaiseWiimoteException(this, ex); WiimoteException?.Invoke(this, new WiimoteExceptionEventArgs(this, ex)); }
// Called by Wiimote internal static void RaiseWiimoteException(Wiimote wiimote, Exception ex) { Debug.WriteLine($"{wiimote} Exception: {ex}"); WiimoteException?.Invoke(null, new WiimoteExceptionEventArgs(wiimote, ex)); }