Defines a structure for a device reading.
Inheritance: IDeviceSensorReading
コード例 #1
0
        /// <summary>
        /// Gets the current sensor reading from the device.
        /// </summary>
        /// <returns>Returns an ISensorReading instance that
        /// indicates current temperature and whether or not
        /// the thresholds have been exceeded.</returns>
        public Task <IDeviceSensorReading> ReadSensor()
        {
            // ***
            // *** Initialize a value to hold the device temperature
            // *** in Celsius
            // ***
            DeviceSensorReading returnValue = new DeviceSensorReading();

            // ***
            // *** The register/command for reading ambient temperature
            // *** from the device is 0x05
            // ***
            byte[] readBuffer = this.ReadFromRegister(Mcp9808Register.AmbientTemperature);

            // ***
            // *** Calculate the temperature value
            // ***
            returnValue.Temperature = RegisterConverter.ToFloat(readBuffer);

            // ***
            // *** Check the flags
            // ***
            returnValue.IsCritical            = (readBuffer[0] & 0x80) == 0x80;
            returnValue.IsAboveUpperThreshold = (readBuffer[0] & 0x40) == 0x40;
            returnValue.IsBelowLowerThreshold = (readBuffer[0] & 0x20) == 0x20;

            // ***
            // *** Return the value
            // ***
            return(Task <IDeviceSensorReading> .FromResult((IDeviceSensorReading)returnValue));
        }
コード例 #2
0
ファイル: Mcp9808.cs プロジェクト: porrey/iot
		/// <summary>
		/// Gets the current sensor reading from the device.
		/// </summary>
		/// <returns>Returns an ISensorReading instance that 
		/// indicates current temperature and whether or not
		/// the thresholds have been exceeded.</returns>
		public Task<IDeviceSensorReading> ReadSensor()
		{
			// ***
			// *** Initialize a value to hold the device temperature 
			// *** in Celsius
			// ***
			DeviceSensorReading returnValue = new DeviceSensorReading();

			// ***
			// *** The register/command for reading ambient temperature
			// *** from the device is 0x05
			// ***
			byte[] readBuffer = this.ReadFromRegister(Mcp9808Register.AmbientTemperature);

			// ***
			// *** Calculate the temperature value
			// ***
			returnValue.Temperature = RegisterConverter.ToFloat(readBuffer);

			// ***
			// *** Check the flags 
			// ***
			returnValue.IsCritical = (readBuffer[0] & 0x80) == 0x80;
			returnValue.IsAboveUpperThreshold = (readBuffer[0] & 0x40) == 0x40;
			returnValue.IsBelowLowerThreshold = (readBuffer[0] & 0x20) == 0x20;

			// ***
			// *** Return the value
			// ***
			return Task<IDeviceSensorReading>.FromResult((IDeviceSensorReading)returnValue);
		}