private void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) { if (aHidEvent.IsStray) { // Stray event just ignore it return; } if (this.InvokeRequired) { // Not in the proper thread, invoke ourselves. // Repeat events usually come from another thread. OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); this.Invoke(d, new object[] { aSender, aHidEvent }); } else { if (HidEvent != null) { foreach (ushort usage in aHidEvent.Usages) { String key = "HID " + usage.ToString("X4"); HidEvent(aSender, key); } } } }
/// <summary> /// Process HID events. /// </summary> /// <param name="aSender"></param> /// <param name="aHidEvent"></param> public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) { if (aHidEvent.IsStray) { //Stray event just ignore it return; } if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves. //Repeat events usually come from another thread. OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); this.Invoke(d, new object[] { aSender, aHidEvent }); } else { //We are in the proper thread listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem()); if (aHidEvent.Device != null) { toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName; } richTextBoxLogs.AppendText(aHidEvent.ToLog()); } }
public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) { if (aHidEvent.IsStray) { //Stray event just ignore it return; } if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves. //Repeat events usually come from another thread. OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); this.Invoke(d, new object[] { aSender, aHidEvent }); } else { //We are in the proper thread Trace.WriteLine(aHidEvent.ToLog().Replace(Environment.NewLine, "")); if (((aHidEvent.IsButtonDown) & (aHidEvent.ToString().Contains("HookSwitch (0x0020)") | aHidEvent.ToString().Contains("LineBusyTone (0x0097)")))) { string ST = CallApi("GET", "astproxy/extension/" + Ext, ""); dynamic data = JObject.Parse(ST); string Status = (string)data.status; Trace.WriteLine("Button click: " + Status + " with " + Ext.ToString()); string Ans, Hang; switch (Status) { case "ringing": if (Type == "webrtc") { Ans = CallApi("POST", "astproxy/answer_webrtc", "{\"endpointId\":\"" + Ext + "\",\"endpointType\":\"extension\"}"); } else { Ans = CallApi("POST", "astproxy/answer", "{\"endpointId\":\"" + Ext + "\",\"endpointType\":\"extension\"}"); } break; case "busy": string Conv = ""; foreach (JProperty Convx in data.conversations.Properties()) { Conv = (string)Convx.Name.ToString(); } Hang = CallApi("POST", "astproxy/hangup", "{\"convid\":\"" + Conv + "\",\"endpointId\":\"" + Ext + "\"}"); break; case "online": break; case "offline": break; } } } }
/// <summary> /// Here we receive HID events from our HID library. /// </summary> /// <param name="aSender"></param> /// <param name="aHidEvent"></param> public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) { if (aHidEvent.IsStray || !aHidEvent.IsValid) { //Stray event just ignore it return; } if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); this.Invoke(d, new object[] { aSender, aHidEvent }); } else { //Trigger corresponding EAR event if any EventHid e = new EventHid(); e.Copy(aHidEvent); Properties.Settings.Default.EarManager.TriggerEvents(e); } }