internal static SensorReport FromNativeReport(Sensor originator, ISensorDataReport iReport)
        {
            SystemTime systemTimeStamp = new SystemTime();

            try
            {
                iReport.GetTimestamp(out systemTimeStamp);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                return(null);
            }
            FILETIME ftTimeStamp = new FILETIME();

            SensorNativeMethods.SystemTimeToFileTime(ref systemTimeStamp, out ftTimeStamp);
            long     lTimeStamp = (((long)ftTimeStamp.dwHighDateTime) << 32) + (long)ftTimeStamp.dwLowDateTime;
            DateTime timeStamp  = DateTime.FromFileTime(lTimeStamp);

            SensorReport sensorReport = new SensorReport();

            sensorReport.originator = originator;
            sensorReport.timeStamp  = timeStamp;
            sensorReport.sensorData = SensorData.FromNativeReport(originator.internalObject, iReport);

            return(sensorReport);
        }
예제 #2
0
 void ISensorEvents.OnDataUpdated(ISensor sensor, ISensorDataReport newData)
 {
     this.dataReport = SensorReport.FromNativeReport(this, newData);
     if (DataReportChanged != null)
     {
         DataReportChanged.Invoke(this, EventArgs.Empty);
     }
 }
예제 #3
0
 /// <summary>
 /// Initializes a sensor report to obtain a luminous intensity value.
 /// </summary>
 /// <param name="report">The report name.</param>
 /// <returns></returns>
 public LuminousIntensity(SensorReport report)
 {
     if (report.Values.ContainsKey(SensorPropertyKeys.SENSOR_DATA_TYPE_LIGHT_LUX.FormatId))
     {
         this.intensity =
             (float)report.Values[SensorPropertyKeys.SENSOR_DATA_TYPE_LIGHT_LUX.FormatId][0];
     }
 }
 /// <summary>
 /// Initializes a sensor report to obtain a luminous intensity value.
 /// </summary>
 /// <param name="report">The report name.</param>
 /// <returns></returns>
 public LuminousIntensity(SensorReport report)
 {
     if (report.Values.ContainsKey(SensorPropertyKeys.SENSOR_DATA_TYPE_LIGHT_LUX.FormatId))
     {
         this.intensity =
             (float)report.Values[SensorPropertyKeys.SENSOR_DATA_TYPE_LIGHT_LUX.FormatId][0];
     }
 }
        /// <summary>
        /// Initializes a sensor report to obtain a luminous intensity value.
        /// </summary>
        /// <param name="report">The report name.</param>
        /// <returns></returns>
        public LuminousIntensity(SensorReport report)
        {
            if (report == null) { throw new ArgumentNullException("report"); }

            if (report.Values != null &&
                report.Values.ContainsKey(SensorPropertyKeys.SensorDataTypeLightLux.FormatId))
            {
                Intensity =
                    (float)report.Values[SensorPropertyKeys.SensorDataTypeLightLux.FormatId][0];
            }
        }
예제 #6
0
        /// <summary>
        /// Creates a new instance of this class.
        /// </summary>
        /// <param name="report">The sensor report to evaluate.</param>
        public Acceleration3D(SensorReport report)
        {
            if (report == null) { throw new ArgumentNullException("report"); }

            this.acceleration[(int)AccelerationAxis.XAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationXG.FormatId][0];
            this.acceleration[(int)AccelerationAxis.YAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationYG.FormatId][1];
            this.acceleration[(int)AccelerationAxis.ZAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationZG.FormatId][2];
        }
예제 #7
0
        /// <summary>
        /// Creates a new instance of this class.
        /// </summary>
        /// <param name="report">The sensor report to evaluate.</param>
        public Acceleration3D(SensorReport report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            this.acceleration[(int)AccelerationAxis.XAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationXG.FormatId][0];
            this.acceleration[(int)AccelerationAxis.YAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationYG.FormatId][1];
            this.acceleration[(int)AccelerationAxis.ZAxis] =
                (float)report.Values[SensorPropertyKeys.SensorDataTypeAccelerationZG.FormatId][2];
        }
        /// <summary>Initializes a sensor report to obtain a luminous intensity value.</summary>
        /// <param name="report">The report name.</param>
        /// <returns></returns>
        public LuminousIntensity(SensorReport report)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report");
            }

            if (report.Values != null &&
                report.Values.ContainsKey(SensorPropertyKeys.SensorDataTypeLightLux.FormatId))
            {
                Intensity =
                    (float)report.Values[SensorPropertyKeys.SensorDataTypeLightLux.FormatId][0];
            }
        }
예제 #9
0
        internal static SensorReport FromNativeReport( Sensor originator, ISensorDataReport iReport )
        {
            SYSTEMTIME systemTimeStamp = new SYSTEMTIME( );
            iReport.GetTimestamp( out systemTimeStamp );
            FILETIME ftTimeStamp = new FILETIME( );
            SensorNativeMethods.SystemTimeToFileTime( ref systemTimeStamp, out ftTimeStamp );
            long lTimeStamp = (((long)ftTimeStamp.dwHighDateTime) << 32) + (long)ftTimeStamp.dwLowDateTime;
            DateTime timeStamp = DateTime.FromFileTime( lTimeStamp );

            SensorReport sensorReport = new SensorReport( );
            sensorReport.originator = originator;
            sensorReport.timeStamp = timeStamp;
            sensorReport.sensorData = SensorData.FromNativeReport( originator.internalObject, iReport );

            return sensorReport;
        }
예제 #10
0
        internal static SensorReport FromNativeReport(Sensor originator, ISensorDataReport iReport)
        {
            SystemTime systemTimeStamp = new SystemTime();

            iReport.GetTimestamp(out systemTimeStamp);
            FILETIME ftTimeStamp = new FILETIME();

            SensorNativeMethods.SystemTimeToFileTime(ref systemTimeStamp, out ftTimeStamp);
            long     lTimeStamp = (((long)ftTimeStamp.dwHighDateTime) << 32) + (long)ftTimeStamp.dwLowDateTime;
            DateTime timeStamp  = DateTime.FromFileTime(lTimeStamp);

            SensorReport sensorReport = new SensorReport();

            sensorReport.originator = originator;
            sensorReport.timeStamp  = timeStamp;
            sensorReport.sensorData = SensorData.FromNativeReport(originator.internalObject, iReport);

            return(sensorReport);
        }
예제 #11
0
        internal HRESULT InternalUpdateData()
        {
            ISensorDataReport iReport = null;
            HRESULT           hr      = nativeISensor.GetData(out iReport);

            if (hr == HRESULT.S_OK)
            {
                try
                {
                    this.dataReport = SensorReport.FromNativeReport(this, iReport);
                    if (DataReportChanged != null)
                    {
                        DataReportChanged.Invoke(this, EventArgs.Empty);
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(iReport);
                }
            }
            return(hr);
        }
 public void Construction()
 {
     SensorReport sr = new SensorReport();
     LuminousIntensity li = new LuminousIntensity(sr);
     Assert.Equal<float>(0, li.Intensity);
 }
예제 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WeTabSensorData"/> class.
        /// </summary>
        /// <param name="sensor">The sensor.</param>
        /// <param name="report">The report object.</param>
        public WeTabSensorData(Sensor sensor, SensorReport report)
        {
            // Get the message type
            int message = Convert.ToInt32(report.Values[GetMessage.FormatId][0]);
            switch (message)
            {
                case 0xea:
                    Message = WeTabSensorMessage.RotationChanged;
                    break;
                case 0x94:
                    Message = WeTabSensorMessage.SensorButtonDown;
                    break;
                case 0x95:
                    Message = WeTabSensorMessage.SensorButtonUp;
                    break;
                default:
                    Message = WeTabSensorMessage.Unknown;
                    break;
            }

            // To read the accelerometer rotation we need to update
            // the x,y,z properties
            DataFieldInfo[] info = {
                                       new DataFieldInfo(GetAcceleratorXRotation, "XLRX"),
                                       new DataFieldInfo(GetAcceleratorYRotation, "XLRY"),
                                       new DataFieldInfo(GetAcceleratorZRotation, "XLRZ")
                                   };
            IDictionary<PropertyKey, object> result = sensor.SetProperties(info);
            XRotation = Convert.ToInt32(result[GetAcceleratorXRotation]);
            YRotation = Convert.ToInt32(result[GetAcceleratorYRotation]);
            ZRotation = Convert.ToInt32(result[GetAcceleratorZRotation]);
            Orientation = CalculateOrientation(XRotation, YRotation, ZRotation);
        }