private void InputPipeReportHandler(byte[] report) { HidDataReceivedEventArgs ea = new HidDataReceivedEventArgs(report); try { if (DataReceived != null) { controller.Invoke(DataReceived, new object[] { this, ea }); } } catch { } }
///////////////////// // Private methods // ///////////////////// /// <summary> /// Handles HidDataReceived events and processes incoming raw data from the /// Device. Fills BitArray m_KeyDownList with key press data. /// At the end fire KeyDown or KeyUp to notify clients. /// </summary> /// <param name="sender"></param> /// <param name="p_HidDataReceivedEventArgs"></param> private void HidDataReceived(object sender, HidDataReceivedEventArgs p_HidDataReceivedEventArgs) { //////////////////////////// // handling the buttons //// //////////////////////////// if (p_HidDataReceivedEventArgs[0] == c_Button) { try { byte[] buffer = { p_HidDataReceivedEventArgs[1], // Needed for more keys than 8 /* p_HidDataReceivedEventArgs[2], p_HidDataReceivedEventArgs[3], p_HidDataReceivedEventArgs[4], p_HidDataReceivedEventArgs[5], p_HidDataReceivedEventArgs[6], */ }; // s. a. /* System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length); System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); byte tmp = reader.ReadByte(); */ BitArray bufferArray = new BitArray(buffer); /////////////////////////////// // Step through each key and // // check if it has changed // /////////////////////////////// for (int keycode = 0; keycode < m_Keys; keycode++) { // Fire event iff state of the button has changed if (bufferArray[keycode] ^ m_KeyDownList[keycode]) { // Fire KeyDown if (bufferArray[keycode]) { // Fire event thread save _IKeyboardEvents_KeyDownEventHandler KeyDownEventHandler = null; lock (m_lock) { KeyDownEventHandler = m_KeyDown; if (KeyDownEventHandler != null) { KeyDownEventHandler(keycode); Console.WriteLine("KeyDown fired for {0}", keycode); } } #region old stuff /* lock (KeyDown) { KeyDown(keycode); //Console.WriteLine("KeyDown fired for {0}", keycode); } */ #endregion } // Fire KeyUp else if (!(bufferArray[keycode])) { // Fire event thread save _IKeyboardEvents_KeyUpEventHandler KeyUpEventHandler = null; lock (m_lock) { KeyUpEventHandler = m_KeyUp; if (KeyUpEventHandler != null) { KeyUpEventHandler(keycode); Console.WriteLine("KeyUp fired for {0}", keycode); } } #region old stuff /* lock (KeyUp) { KeyUp(keycode); //Console.WriteLine("KeyUp fired for {0}", keycode); } */ #endregion } } } // Update KeyDownList m_KeyDownList = bufferArray; } catch (Exception e) { Console.Out.WriteLine("Exception: {0}, {1}, {2}", e.GetType(), e.Message, e.StackTrace); } } }
/// <summary> /// Handles HidDataReceived events and processes incoming raw data from the /// Device. Fills m_Translation and m_Rotation objects with the filtered and /// scaled raw data. At the end fire SensorInput to notify clients. /// </summary> /// <param name="sender"></param> /// <param name="p_HidDataReceivedEventArgs"></param> private void HidDataReceived(object sender, HidDataReceivedEventArgs p_HidDataReceivedEventArgs) { short x = 0; short y = 0; short z = 0; /////////////////////////////// // set Length of translation // // movement to 0 zeroes also // // x, y and z components // /////////////////////////////// m_Translation.Length = 0; /////////////////////////////// // set Angle of rotation // // movement to 0 zeroes also // // x, y and z components // /////////////////////////////// m_Rotation.Angle = 0; /////////////////////////////// // handling the translation // /////////////////////////////// if (p_HidDataReceivedEventArgs[0] == c_Translation) { try { byte[] buffer = { p_HidDataReceivedEventArgs[1], p_HidDataReceivedEventArgs[2], p_HidDataReceivedEventArgs[3], p_HidDataReceivedEventArgs[4], p_HidDataReceivedEventArgs[5], p_HidDataReceivedEventArgs[6], }; System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length); System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); x = reader.ReadInt16(); y = reader.ReadInt16(); z = reader.ReadInt16(); /* Console.Out.WriteLine("transX: {0}", x); Console.Out.WriteLine("transY: {0}", y); Console.Out.WriteLine("transZ: {0}", z); */ //////////////////////////////////////// // Filtering and scaling is done here // // X value of Aerion Input data must // // be multiplied with -1 // //////////////////////////////////////// m_Translation.X = m_TranslationFunction(System.Convert.ToDouble(x), c_MaxValueTranslation) * XScaleFactor; m_Translation.Y = m_TranslationFunction(System.Convert.ToDouble(y), c_MaxValueTranslation) * YScaleFactor; m_Translation.Z = m_TranslationFunction(System.Convert.ToDouble(z), c_MaxValueTranslation) * ZScaleFactor; } catch (Exception e) { Console.Out.WriteLine("Exception: {0}, {1}, {2}", e.GetType(), e.Message, e.StackTrace); } } /////////////////////////// // handling the rotation // /////////////////////////// else if (p_HidDataReceivedEventArgs[0] == c_Rotation) { try { byte[] buffer = { p_HidDataReceivedEventArgs[1], p_HidDataReceivedEventArgs[2], p_HidDataReceivedEventArgs[3], p_HidDataReceivedEventArgs[4], p_HidDataReceivedEventArgs[5], p_HidDataReceivedEventArgs[6], }; System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length); System.IO.BinaryReader reader = new System.IO.BinaryReader(stream); x = reader.ReadInt16(); y = reader.ReadInt16(); z = reader.ReadInt16(); /* Console.Out.WriteLine("rotX: {0}", x); Console.Out.WriteLine("rotY: {0}", y); Console.Out.WriteLine("rotZ: {0}", z); */ //////////////////////////////////////// // Filtering and scaling is done here // //////////////////////////////////////// m_Rotation.X = m_RotationFunction(System.Convert.ToDouble(x), c_MaxValueRotation) * XRotScaleFactor; //Rotation um X-Achse = rot m_Rotation.Y = m_RotationFunction(System.Convert.ToDouble(y), c_MaxValueRotation) * YRotScaleFactor; //Rotation um Y-Achse = gr�n m_Rotation.Z = m_RotationFunction(System.Convert.ToDouble(z), c_MaxValueRotation) * ZRotScaleFactor; //Rotation um Z-Achse = blau } catch (Exception e) { Console.Out.WriteLine("Exception: {0}, {1}, {2}", e.GetType(), e.Message, e.StackTrace); } #region old stuff... /* _xRot = (ushort)(p_HidDataReceivedEventArgs[1]); _xRot += (ushort)(p_HidDataReceivedEventArgs[2] << 8); xRot = (short)(_xRot); m_Rotation.X = xRot * XRotScaleFactor; //Console.Out.WriteLine("rotX: {0}", rotX); _yRot = (ushort)(p_HidDataReceivedEventArgs[3]); _yRot += (ushort)(p_HidDataReceivedEventArgs[4] << 8); yRot = (short)(_yRot); m_Rotation.Y = yRot * YRotScaleFactor; //Console.Out.WriteLine("rotY: {0}", rotY); _zRot = (ushort)(p_HidDataReceivedEventArgs[5]); _zRot += (ushort)(p_HidDataReceivedEventArgs[6] << 8); zRot = (short)(_zRot); m_Rotation.Z = zRot * ZRotScaleFactor; //Console.Out.WriteLine("angle_internal: {0}", m_Rotation.Angle); */ #endregion } /////////////////////////////////////// // Fire SensorInput iff // // Angle > RotationThreshold // // and Length > TranslationThreshold // /////////////////////////////////////// if ((m_Rotation.Angle > m_RotationThreshold) || m_Translation.Length > m_TranslationThreshold) { // Scale down Ticks m_Period = Convert.ToDouble(System.DateTime.Now.Ticks)/1000000000 - m_Period; // Fire event thread save _ISensorEvents_SensorInputEventHandler SensorEventHandler = null; lock (m_lock) { SensorEventHandler = m_SensorInput; if (SensorEventHandler != null) { SensorEventHandler(); } } #region old stuff /* if (SensorInput != null) { lock (m_lock) { //SensorInput(this, new EventArgs()); SensorInput(); } } */ #endregion } }