/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnHeadsetStateChanged(object sender, _DeviceListenerEventArgs e) { Debug.WriteLine("OnHeadsetStateChanged " + e.ToString()); _traceContext.Status("OnHeadsetStateChanged " + e.ToString()); if (e.HeadsetStateChange == HeadsetStateChange.HeadsetStateChange_InRange) { _notificationService.Notify("Headset in range", "Headset", NotificationType.Info, TimeSpan.FromSeconds(3)); _statusManager.SetLastStatus(); _interactionManager.PickupHeldCall(); } else if (e.HeadsetStateChange == HeadsetStateChange.HeadsetStateChange_OutofRange) { _notificationService.Notify("Headset out of range", "Headset", NotificationType.Warning, TimeSpan.FromSeconds(3)); _statusManager.SetToAwayFromDesk(); _interactionManager.HoldCall(); } }
void m_deviceListenerEvents_HandlerMethods(object sender, _DeviceListenerEventArgs e) { DebugPrint(MethodInfo.GetCurrentMethod().Name, "Spokes: Received Spokes Event: " + e.ToString()); switch (e.DeviceEventType) { case DeviceEventType.DeviceEventType_HeadsetStateChanged: switch (e.HeadsetStateChange) { case HeadsetStateChange.HeadsetStateChange_Don: OnPutOn(new WearingStateArgs(true, false)); break; case HeadsetStateChange.HeadsetStateChange_Doff: OnTakenOff(new WearingStateArgs(false, false)); break; case HeadsetStateChange.HeadsetStateChange_Near: OnNear(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_Far: OnFar(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_ProximityDisabled: // Note: intepret this event as that the mobile phone has gone out of Bluetooth // range and is no longer paired to the headset. // Lock the PC, but immediately re-enable proximity OnProximityDisabled(EventArgs.Empty); // Immediately re-enable proximity RegisterForProximity(true); break; case HeadsetStateChange.HeadsetStateChange_ProximityEnabled: OnProximityEnabled(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_ProximityUnknown: OnProximityUnknown(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_InRange: OnInRange(EventArgs.Empty); //// Immediately re-enable proximity //RegisterForProximity(true); //// Request headset serial number (maybe user paired with another?) //RequestSingleSerialNumber(SerialNumberTypes.Headset); // New, get all the device state info on inrange trigger: // now poll for current state (proximity, mobile call status, donned status, mute status) GetInitialDeviceState(); // tell app to look again at battery level (headset in range) OnBatteryLevelChanged(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_OutofRange: OnOutOfRange(EventArgs.Empty); OnSerialNumber(new SerialNumberArgs("", SerialNumberTypes.Headset)); // tell app to look again at battery level (headset out of range / disconnected) OnBatteryLevelChanged(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_BatteryLevel: // note; on legend we always get a battery level when docking... // what is in this event, anything we can use to infer docked? DebugPrint(MethodInfo.GetCurrentMethod().Name, String.Format("HeadsetStateChanged: BatteryLevel")); if (!m_ignorenextbattlevevent && (!m_lastdocked && m_battlevEventCount < 10)) // TEST, allow 10 of these thru so it gets docking more quickly on legend! { // Only if we were undocked and there were no battery level events // since we last undocked should we detect batt charge status (docking status). // This is so this only happens once, otherwise we get stuck in a loop // Because looking at the battery info triggers another batterylevel changed // event! m_ignorenextundockedevent = true; m_ignorenextbattlevevent = true; m_lastdocked = DetectLegendDockedState(false); // NOTE: will ALWAYS trigger another batterylevel change event // AND another UnDocked event if we are undocked! m_battlevEventCount++; } else { if (m_ignorenextbattlevevent) m_ignorenextbattlevevent = false; if (m_lastdocked) m_ignorenextundockedevent = false; } // tell app to look at battery level (it has changed) OnBatteryLevelChanged(EventArgs.Empty); break; case HeadsetStateChange.HeadsetStateChange_Docked: case HeadsetStateChange.HeadsetStateChange_DockedCharging: // new, for legend, but is v SLOW, sometimes never comes // only send to app the docked value if it is different to m_lastdocked (i.e. if it has changed) if (!m_lastdocked) OnDocked(new DockedStateArgs(true, false)); m_lastdocked = true; m_battlevEventCount = 0; break; case HeadsetStateChange.HeadsetStateChange_UnDocked: if (!m_ignorenextundockedevent) { // only send to app the docked value if it is different to m_lastdocked (i.e. if it has changed) if (m_lastdocked) OnUnDocked(new DockedStateArgs(false, false)); if (m_lastdocked) m_battlevEventCount = 0; // if we were docked before, set battlev event count to zero // i.e. we would like to check the next battery level event m_lastdocked = false; } m_ignorenextundockedevent = false; break; case HeadsetStateChange.HeadsetStateChange_MuteON: OnMuteChanged(new MuteChangedArgs(true)); break; case HeadsetStateChange.HeadsetStateChange_MuteOFF: OnMuteChanged(new MuteChangedArgs(false)); break; case HeadsetStateChange.HeadsetStateChange_MonoON: OnLineActiveChanged(new LineActiveChangedArgs(true)); break; case HeadsetStateChange.HeadsetStateChange_MonoOFF: OnLineActiveChanged(new LineActiveChangedArgs(false)); break; // LC add handler for headsetstate change serial number // We should be able to extract serial number at this point case HeadsetStateChange.HeadsetStateChange_SerialNumber: DebugPrint(MethodInfo.GetCurrentMethod().Name, String.Format("HeadsetStateChanged: SerialNumber")); ReadSerialNumber(SerialNumberTypes.Headset); break; default: break; } break; default: break; } }