Пример #1
0
        private void UpdateProximityStateToConnection(PLTProximityType proximitytype)
        {
            lock (m_lastproximitystateLock)
            {
                m_lastproximitystate.m_proximity = proximitytype;
            }

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.PROXIMITY_SVC);
                if (subscr != null)
                {
                    lock (m_lastproximitystateLock)
                    {
                        subscr.LastData = m_lastproximitystate;
                    }

                    // if it is an on change subscription, beam to connected app now
                    // otherwise will happen in the PLTConnection's periodic timer
                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.PROXIMITY_SVC, subscr.LastData));
                    }
                }
            }
        }
Пример #2
0
        private void UpdateWearingStateToConnection(WearingStateArgs e)
        {
            lock (m_lastwornstateLock)
            {
                m_lastwornstate.m_worn = e.m_worn;
                m_lastwornstate.m_isInitialStateEvent = e.m_isInitialStateEvent;
            }

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.WEARING_STATE_SVC);
                if (subscr != null)
                {
                    lock (m_lastwornstateLock)
                    {
                        subscr.LastData = m_lastwornstate;
                    }

                    // if it is an on change subscription, beam to connected app now
                    // otherwise will happen in the PLTConnection's periodic timer
                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.WEARING_STATE_SVC, subscr.LastData));
                    }
                }
            }
        }
Пример #3
0
        void m_spokes_BatteryLevelChanged(object sender, EventArgs e)
        {
            if (m_headsetinrange)
            {
                Interop.Plantronics.DeviceBatteryLevel batlev =
                    m_spokes.GetBatteryLevel();

                lock (m_lastbattstateLock)
                {
                    m_lastbattstate.m_batterylevel = (PLTBatteryLevel)batlev;
                }

                if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
                {
                    PLTServiceSubscription subscr =
                        m_activeConnection.getSubscription(PLTService.CHARGESTATE_SVC);
                    if (subscr != null)
                    {
                        lock (m_lastwornstateLock)
                        {
                            subscr.LastData = m_lastbattstate;
                        }

                        // if it is an on change subscription, beam to connected app now
                        // otherwise will happen in the PLTConnection's periodic timer
                        if (subscr.m_mode == PLTMode.On_Change)
                        {
                            m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.CHARGESTATE_SVC, subscr.LastData));
                        }
                    }
                }
            }
        }
Пример #4
0
        private void UpdateMobileCallerIdToConnection(string mobilecallid)
        {
            lock (m_lastcalleridLock)
            {
                m_lastcallerid.m_calltype = PLTCallerIdType.Mobile; // only this supported at present
                m_lastcallerid.m_callerid = mobilecallid;
            }

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.CALLERID_SVC);
                if (subscr != null)
                {
                    lock (m_lastcalleridLock)
                    {
                        subscr.LastData = m_lastcallerid;
                    }

                    // if it is an on change subscription, beam to connected app now
                    // otherwise will happen in the PLTConnection's periodic timer
                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.CALLERID_SVC, subscr.LastData));
                    }
                }
            }
        }
Пример #5
0
        private void UpdateCallStateToConnection(PLTCallStateType calltype, PLTCallState callstate, int callid = 0, string callsource = "",
                                                 bool incoming = false)
        {
            lock (m_lastcallstateLock)
            {
                m_lastcallstate.m_callstatetype = calltype;
                m_lastcallstate.m_callstate     = callstate;
                m_lastcallstate.m_callid        = callid;
                m_lastcallstate.m_callsource    = callsource;
                m_lastcallstate.m_incoming      = incoming;
            }

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.CALLSTATE_SVC);
                if (subscr != null)
                {
                    lock (m_lastcallstateLock)
                    {
                        subscr.LastData = m_lastcallstate;
                    }

                    // if it is an on change subscription, beam to connected app now
                    // otherwise will happen in the PLTConnection's periodic timer
                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.CALLSTATE_SVC, subscr.LastData));
                    }
                }
            }
        }
Пример #6
0
        private void UpdateDockedStateToConnection(bool docked, bool initial)
        {
            lock (m_lastdockstateLock)
            {
                m_lastdockstate.m_isdocked        = docked;
                m_lastdockstate.m_isinitialstatus = initial;
            }

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.DOCKSTATE_SVC);
                if (subscr != null)
                {
                    lock (m_lastdockstateLock)
                    {
                        subscr.LastData = m_lastdockstate;
                    }

                    // if it is an on change subscription, beam to connected app now
                    // otherwise will happen in the PLTConnection's periodic timer
                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.DOCKSTATE_SVC, subscr.LastData));
                    }
                }
            }
        }
Пример #7
0
        internal PLTServiceSubscription getSubscription(PLTService pLTService)
        {
            PLTServiceSubscription retval = null;

            lock (m_subscribedServicesLock)
            {
                foreach (PLTServiceSubscription subscr in m_subscribedServices)
                {
                    if (subscr.m_service == pLTService)
                    {
                        retval = subscr;
                        break;
                    }
                }
            }
            return(retval);
        }
Пример #8
0
        internal void subscribe(PLTService aService, PLTMode aMode, int aPeriodmilliseconds = 0)
        {
            // cannot subscribe to same service twice
            if (isSubscribed(aService))
            {
                return;
            }

            bool   doSubscribe = false;
            object lastData    = null;

            // work out if we can/should subscribe to the service
            switch (aService)
            {
            case PLTService.MOTION_TRACKING_SVC:
                // TODO add to Spokes knowledge of which device
                // has motion tracking. For now just assume all
                // devices do.
                doSubscribe = true;
                break;

            case PLTService.MOTION_STATE_SVC:
                // TODO: does the headset provide this info?
                throw new Exception("Sorry, motion state service is not yet implemented.");
                doSubscribe = false;
                break;

            case PLTService.SENSOR_CAL_STATE_SVC:
                doSubscribe = true;
                break;

            case PLTService.PEDOMETER_SVC:
                doSubscribe = true;
                break;

            case PLTService.TAP_SVC:
                if (aMode == PLTMode.On_Change)
                {
                    doSubscribe = true;
                }
                else
                {
                    throw new Exception("Sorry, tap service only supports PLTMode.On_Change mode (not PLTMode.Periodic).");
                }
                break;

            case PLTService.WEARING_STATE_SVC:
                if (m_spokes.DeviceCapabilities.HasWearingSensor)
                {
                    doSubscribe = true;
                    lock (m_pltlabsapi.m_lastwornstateLock)
                    {
                        lastData = m_pltlabsapi.m_lastwornstate;
                    }
                }
                else
                {
                    throw new Exception("Sorry, device does not have a wearing sensor. Unable to subscribe to wearing sensor data.");
                }
                break;

            case PLTService.FREE_FALL_SVC:
                if (aMode == PLTMode.On_Change)
                {
                    doSubscribe = true;
                }
                else
                {
                    throw new Exception("Sorry, tap service only supports PLTMode.On_Change mode (not PLTMode.Periodic).");
                }
                break;

            case PLTService.PROXIMITY_SVC:
                // Don't bother checking m_spokes.DeviceCapabilities.HasProximity, as this is
                // generally populated with correct value later asyncronously if enable proximity call
                // succeeded
                doSubscribe = true;
                lock (m_pltlabsapi.m_lastproximitystateLock)
                {
                    lastData = m_pltlabsapi.m_lastproximitystate;
                }
                break;

            case PLTService.CALLERID_SVC:
                doSubscribe = true;
                lock (m_pltlabsapi.m_lastcalleridLock)
                {
                    lastData = m_pltlabsapi.m_lastcallerid;
                }
                break;

            case PLTService.CALLSTATE_SVC:
                if (aMode == PLTMode.On_Change)
                {
                    doSubscribe = true;
                    lock (m_pltlabsapi.m_lastcallstateLock)
                    {
                        lastData = m_pltlabsapi.m_lastcallstate;
                    }
                }
                else
                {
                    throw new Exception("Sorry, call state only supports PLTMode.On_Change mode (not PLTMode.Periodic).");
                }
                break;

            case PLTService.DOCKSTATE_SVC:
                doSubscribe = true;
                lock (m_pltlabsapi.m_lastdockstateLock)
                {
                    lastData = m_pltlabsapi.m_lastdockstate;
                }
                break;

            case PLTService.CHARGESTATE_SVC:
                // todo consider not making wireless devices subcribe - no battery
                doSubscribe = true;
                lock (m_pltlabsapi.m_lastbattstateLock)
                {
                    lastData = m_pltlabsapi.m_lastbattstate;
                }
                break;
                //case PLTService.TEMPERATURE_SVC:
                //    doSubscribe = true;
                //    break;
            }

            if (doSubscribe)
            {
                PLTServiceSubscription subscr;
                subscr = new PLTServiceSubscription(this,
                                                    aService, aMode, aPeriodmilliseconds, lastData);
                lock (m_subscribedServicesLock)
                {
                    m_subscribedServices.Add(subscr);
                }

                // NOTE: for SOME services we want to ship the last known value right
                // away to connected app, because for those services such as wearing sensor
                // the last known value will be the "initial" value. (Does not apply to
                // headtracking).
                if (aService == PLTService.WEARING_STATE_SVC ||
                    aService == PLTService.CHARGESTATE_SVC
                    )
                {
                    ShipLastKnownDataToAppForService(aService, subscr);
                }
            }
        }
Пример #9
0
 // a periodic service subscription timer has fired
 // ship the last known data to the connected app
 internal void ServiceTimerElapsed(PLTService aService, PLTServiceSubscription aSubscription, object lastSubscriptionData)
 {
     ShipLastKnownDataToAppForService(aService, aSubscription);
 }
Пример #10
0
        // Pass lastSubscriptionData to contain reference to last value for this subscription
        // or NULL where no value is available (for instance with wearing sensor before
        // a subcription has been made).
        private void ShipLastKnownDataToAppForService(PLTService aService, PLTServiceSubscription aSubscription)
        {
            if (m_pltlabsapi.
                m_callbackhandler != null && m_pltlabsapi.m_activeConnection != null &&
                aSubscription != null)
            {
                // now work out if we should send the last known value (applies to some services
                // e.g. wearing sensor, so app can receive initial value)
                switch (aService)
                {
                case PLTService.MOTION_TRACKING_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTMotionTrackingData)aSubscription.LastData));
                    break;

                case PLTService.MOTION_STATE_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTMoving)aSubscription.LastData));
                    break;

                case PLTService.SENSOR_CAL_STATE_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTSensorCal)aSubscription.LastData));
                    break;

                case PLTService.PEDOMETER_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTPedometerCount)aSubscription.LastData));
                    break;

                case PLTService.TAP_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTTapInfo)aSubscription.LastData));
                    break;

                case PLTService.WEARING_STATE_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTWearingState)aSubscription.LastData));
                    break;

                case PLTService.FREE_FALL_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTFreeFall)aSubscription.LastData));
                    break;

                case PLTService.PROXIMITY_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTProximityType)aSubscription.LastData));
                    break;

                case PLTService.CALLERID_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTCallerId)aSubscription.LastData));
                    break;

                case PLTService.CALLSTATE_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTCallStateInfo)aSubscription.LastData));
                    break;

                case PLTService.DOCKSTATE_SVC:
                    m_pltlabsapi.
                    m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTDock)aSubscription.LastData));
                    break;

                case PLTService.CHARGESTATE_SVC:
                    m_pltlabsapi.m_callbackhandler.infoUpdated(
                        m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTBatteryState)aSubscription.LastData));
                    break;
                    //case PLTService.TEMPERATURE_SVC:
                    //    m_pltlabsapi.
                    //        m_callbackhandler.infoUpdated(
                    //            m_pltlabsapi.m_activeConnection, new PLTInfo(aService, (PLTTemperature)aSubscription.LastData));
                    //    break;
                }
            }
        }
Пример #11
0
        /// <summary>
        /// This is a method used by the internals of the PLTLabsAPI DLL to receive
        /// Motion Tracking events from the headset and then distribute them to
        /// applications that are subscribed to those data services.
        /// *** DO NOT CALL THIS METHOD ***
        /// </summary>
        /// <param name="headsetData">The data received from headset *** DO NOT CALL THIS METHOD ***</param>
        public void HeadsetTrackingUpdate(HeadsetTrackingData headsetData)
        {
            // todo, if registered for various services (headtracking, pedometer etc )
            // then send back the data to the infoUpdated callback!!!

            if (m_activeConnection != null) // todo only do this if subscribed to relevant service?
            {
                m_activeConnection.vermaj = headsetData.vermaj;
                m_activeConnection.vermin = headsetData.vermin;

                // MOTION_TRACKING_SVC data for motion tracking service...
                PLTServiceSubscription subscr =
                    m_activeConnection.getSubscription(PLTService.MOTION_TRACKING_SVC);
                if (subscr != null)
                {
                    PLTMotionTrackingData data = new PLTMotionTrackingData();
                    data.m_rawreport = headsetData.rawreport;

                    // avoid NaN conditions!
                    if (Double.IsNaN(headsetData.psi_heading))
                    {
                        headsetData.psi_heading = 0.0;
                    }
                    if (Double.IsNaN(headsetData.theta_pitch))
                    {
                        headsetData.theta_pitch = 0.0;
                    }
                    if (Double.IsNaN(headsetData.phi_roll))
                    {
                        headsetData.phi_roll = 0.0;
                    }

                    data.m_orientation[0] = headsetData.psi_heading;
                    data.m_orientation[1] = headsetData.theta_pitch;
                    data.m_orientation[2] = headsetData.phi_roll;

                    data.m_calquaternion[0] = headsetData.quatcalib_q0;
                    data.m_calquaternion[1] = headsetData.quatcalib_q1;
                    data.m_calquaternion[2] = headsetData.quatcalib_q2;
                    data.m_calquaternion[3] = headsetData.quatcalib_q3;

                    data.m_rawquaternion[0] = headsetData.quatraw_q0;
                    data.m_rawquaternion[1] = headsetData.quatraw_q1;
                    data.m_rawquaternion[2] = headsetData.quatraw_q2;
                    data.m_rawquaternion[3] = headsetData.quatraw_q3;

                    // tell app what the quaternion processing config was:
                    data.m_format_config = QuaternionProcessor.m_doCalibrate ? PLTConfiguration.MotionSvc_Offset_Calibrated :
                                           PLTConfiguration.MotionSvc_Offset_Raw;
                    data.m_offset_config = QuaternionProcessor.m_doOrientation ? PLTConfiguration.MotionSvc_Format_Orientation :
                                           PLTConfiguration.MotionSvc_Format_Quaternion;

                    subscr.LastData = data;

                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.MOTION_TRACKING_SVC, data));
                    }
                }

                // MOTION_STATE_SVC
                // TODO: I don't think this data is available

                // SENSOR_CAL_STATE_SVC data for sensor cal state service...
                subscr =
                    m_activeConnection.getSubscription(PLTService.SENSOR_CAL_STATE_SVC);
                if (subscr != null)
                {
                    PLTSensorCal data = new PLTSensorCal();
                    data.m_isgyrocal         = headsetData.gyrocalib == 3;
                    data.m_ismagnetometercal = headsetData.magnetometercalib == 3;

                    subscr.LastData = data;

                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.SENSOR_CAL_STATE_SVC, data));
                    }
                }

                // PEDOMETER_SVC
                subscr =
                    m_activeConnection.getSubscription(PLTService.PEDOMETER_SVC);
                if (subscr != null)
                {
                    PLTPedometerCount data = new PLTPedometerCount();
                    data.m_pedometercount = headsetData.pedometersteps;

                    subscr.LastData = data;

                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.PEDOMETER_SVC, data));
                    }
                }

                // TAP_SVC
                subscr =
                    m_activeConnection.getSubscription(PLTService.TAP_SVC);
                if (subscr != null)
                {
                    PLTTapInfo data = new PLTTapInfo();
                    data.m_tapcount     = headsetData.taps;
                    data.m_tapdirection = (PLTTapDirection)headsetData.tapdir;

                    subscr.LastData = data;

                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.TAP_SVC, data));
                    }
                }

                // FREE_FALL_SVC
                subscr =
                    m_activeConnection.getSubscription(PLTService.FREE_FALL_SVC);
                if (subscr != null)
                {
                    PLTFreeFall data = new PLTFreeFall();
                    data.m_isinfreefall = headsetData.freefall;

                    subscr.LastData = data;

                    if (subscr.m_mode == PLTMode.On_Change)
                    {
                        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.FREE_FALL_SVC, data));
                    }
                }

                //// TEMPERATURE_SVC
                //subscr =
                //    m_activeConnection.getSubscription(PLTService.TEMPERATURE_SVC);
                //if (subscr != null)
                //{
                //    PLTTemperature data = new PLTTemperature();
                //    data.m_temperature = headsetData.temperature;

                //    subscr.LastData = data;

                //    if (subscr.m_mode == PLTMode.On_Change)
                //    {
                //        m_callbackhandler.infoUpdated(m_activeConnection, new PLTInfo(PLTService.TEMPERATURE_SVC, data));
                //    }
                //}
            }
        }