Example #1
0
        /// <summary>
        /// Called when an accelerometer sensor's data is updated.
        /// </summary>
        public void OnDataUpdated(Sensor sensor, SensorDataReport newData)
        {
            if (sensor == _sensor)
            {
                Accelerometer3DReport a3dReport = (Accelerometer3DReport)newData;
                Vector3 vector = Vector3.Zero;
                vector.X = a3dReport.AxisX_G;
                vector.Y = a3dReport.AxisY_G;
                vector.Z = a3dReport.AxisZ_G;

                if (vector != Vector3.Zero)
                {
                    this.Vector = vector;
                    if (VectorChanged != null)
                    {
                        VectorChanged(this, EventArgs.Empty);
                    }

                    CalculateOrientation(vector);
                }
                else
                {
                    // The accelerometer is providing no value so
                    // set Vector to null and reset the orientation
                    this.Vector = null;
                    Orientation?oldOrientation = Orientation;
                    Orientation newOrientation = Orientation.Angle0;
                    Orientation = newOrientation;
                    if (OrientationChanged != null)
                    {
                        OrientationChanged(this, EventArgs.Empty);
                    }
                }
            }
        }
Example #2
0
        protected override void SpecificDataUpdated(SensorDataReport dataReport)
        {
            UInt32 arrayState = (UInt32)dataReport.GetDataField(SensorPropertyKeys.SENSOR_DATA_TYPE_BOOLEAN_SWITCH_ARRAY_STATE);

            ParseSwitchState(0, arrayState);
            ParseSwitchState(1, arrayState);
            ParseSwitchState(2, arrayState);
            ParseSwitchState(3, arrayState);

            //if ((arrayState & 0x1) != 0)    // first switch pressed
            //    switchStates[0].State = true;
            //else
            //    switchStates[0].State = false;

            //if ((arrayState & 0x2) != 0)    // second switch pressed
            //    switchStates[1].State = true;
            //else
            //    switchStates[1].State = false;

            //if ((arrayState & 0x4) != 0)    // third switch pressed
            //    switchStates[2].State = true;
            //else
            //    switchStates[2].State = false;

            //if ((arrayState & 0x8) != 0)    // fourth switch pressed
            //    switchStates[3].State = true;
            //else
            //    switchStates[3].State = false;
        }
Example #3
0
        /// <summary>
        /// Fired when sensor data is updated.
        /// </summary>
        void OnDataUpdated(Sensor sensor, SensorDataReport newData)
        {
            AmbientLightSensorDataReport alsReport = (AmbientLightSensorDataReport)newData;

            System.Diagnostics.Debug.WriteLine("Data event timestamp: " + alsReport.Timestamp.ToString());

            // get the illuminance property value
            double lightLux = alsReport.IlluminanceLux;

            // Get the sensor id so we can associate the sensor lux value
            // with a specific sensor id in our collection
            Guid sensorId = sensor.SensorID;

            if (sensorId != Guid.Empty)
            {
                // Set the sensor light value
                SetSensorLightLuxValue(sensorId, lightLux);
            }
        }
Example #4
0
        /// <summary>
        /// Called when any new sensor is attached to the system.
        /// </summary>
        public void OnSensorEnter(Sensor pSensor, SensorState state)
        {
            // The sensor paramater should not be null
            System.Diagnostics.Debug.Assert(pSensor != null);
            // If we are currently using a sensor we don't want to stop using it and
            // use a new one so we only use a new sensor if we don't have one already.
            if (_sensor == null)
            {
                Guid sensorType = Guid.Empty;
                try
                {
                    sensorType = pSensor.TypeID;
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
                if (sensorType == SensorType)
                {
                    _sensor = (Accelerometer3D)pSensor;
                    try
                    {
                        pSensor.DataUpdated   += new SensorDataUpdatedEventHandler(OnDataUpdated);
                        pSensor.EventReceived += new SensorEventHandler(OnEvent);
                        pSensor.SensorLeave   += new SensorLeaveEventHandler(OnLeave);
                        pSensor.StateChanged  += new SensorStateChangedEventHandler(OnStateChanged);
                    }
                    catch (COMException ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }

                    state = pSensor.State;

                    if (state == SensorState.Ready)
                    {
                        SetupSensorProperties(pSensor);

                        SensorDataReport data = null;
                        try
                        {
                            data = pSensor.GetDataReport();
                        }
                        catch (COMException ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                        }
                        if (data != null)
                        {
                            OnDataUpdated(pSensor, data);
                        }
                    }
                    else if (state == SensorState.AccessDenied)
                    {
                        if (RequestSensorAccess(pSensor))
                        {
                            SetupSensorProperties(pSensor);
                        }
                    }
                }
            }
        }
Example #5
0
 /// <summary>
 /// Called when an accelerometer sensor fires an event.
 /// </summary>
 public void OnEvent(Sensor sensor, Guid eventID, SensorDataReport newData)
 {
 }
Example #6
0
 void CommonDataUpdated(SensorDataReport dataReport)
 {
 }
Example #7
0
 abstract protected void SpecificDataUpdated(SensorDataReport dataReport);