Пример #1
0
        /// <summary>
        /// Helper function for updating the user interface.
        /// </summary>
        private void UpdateUI()
        {
            // Read the temperature sensor.

            // Make sure the sensor object is valid.
            if (_sensor == null)
            {
                _sensor = new SpiTemperatureSensor();
            }

            // Read the value from the sensor.
            double temp = _sensor.ReadTemperature();

            if (_tempMode == TempMode.Fahrenheit)
            {
                temp = (temp * 1.8) + 32;
            }

            // Round off the value so it will match the emulator, because of
            // rounding errors during Celsius conversion.
            temp = System.Math.Round(temp);

            // Set the current temperature text control value based on the
            // temperature mode of celcius or fahrenheit
            if (_tempMode == TempMode.Celcius)
            {
                _textCurrentTemp.TextContent = temp.ToString() + " C";
                _textTargetTemp.TextContent  = _targetTemp.ToString() + " C";
            }
            else
            {
                _textCurrentTemp.TextContent = temp.ToString() + " F";
                _textTargetTemp.TextContent  = _targetTemp.ToString() + " F";
            }

            // See if we need to turn on the heater or cooler.
            if (temp > _targetTemp)
            {
                // Turn on the cooler.
                _statusIndicator.Status = StatusIndicator.StatusType.Cool;
            }
            else if (temp < _targetTemp)
            {
                // Turn on the heater.
                _statusIndicator.Status = StatusIndicator.StatusType.Heat;
            }
            else
            {
                // Turn off both.
                _statusIndicator.Status = StatusIndicator.StatusType.Off;
            }
        }
Пример #2
0
        /// <summary>
        /// Helper function for updating the user interface.
        /// </summary>
        private void UpdateUI()
        {

            // Read the temperature sensor.

            // Make sure the sensor object is valid.
            if (_sensor == null)
                _sensor = new SpiTemperatureSensor();

            // Read the value from the sensor.
            double temp = _sensor.ReadTemperature();
            if (_tempMode == TempMode.Fahrenheit)
                temp = (temp * 1.8) + 32;

            // Round off the value so it will match the emulator, because of 
            // rounding errors during Celsius conversion.
            temp = System.Math.Round(temp);

            // Set the current temperature text control value based on the 
            // temperature mode of celcius or fahrenheit
            if (_tempMode == TempMode.Celcius)
            {
                _textCurrentTemp.TextContent = temp.ToString() + " C";
                _textTargetTemp.TextContent = _targetTemp.ToString() + " C";
            }
            else
            {
                _textCurrentTemp.TextContent = temp.ToString() + " F";
                _textTargetTemp.TextContent = _targetTemp.ToString() + " F";
            }

            // See if we need to turn on the heater or cooler.
            if (temp > _targetTemp)
            {
                // Turn on the cooler.
                _statusIndicator.Status = StatusIndicator.StatusType.Cool;
            }
            else if (temp < _targetTemp)
            {
                // Turn on the heater.
                _statusIndicator.Status = StatusIndicator.StatusType.Heat;
            }
            else
            {
                // Turn off both.
                _statusIndicator.Status = StatusIndicator.StatusType.Off;
            }
        }