コード例 #1
0
        /// <summary>
        /// Reading temperature in desired format
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public override double ReadTemperature(TemperatureFormat format)
        {
            I2CDevice.I2CTransaction[] i2cTx = new I2CDevice.I2CTransaction[2];
            byte[] register = new byte[1];
            byte[] data     = new byte[2];

            register[0] = TEMPERATURE_REG_ADDR;
            i2cTx[0]    = I2CDevice.CreateWriteTransaction(register);
            i2cTx[1]    = I2CDevice.CreateReadTransaction(data);

            int result = i2cDevice.Execute(i2cTx, TIMEOUT);

            //converting 12-bit temperature to double
            int rawTemperature = (data[0] << 4) | (data[1] >> 4);

            double temperature = 0;

            if (register.Length + data.Length == result)
            {
                if ((rawTemperature & 0x0800) > 0)
                {
                    rawTemperature = (rawTemperature ^ 0xffff) + 1;
                    temperature    = -1;
                }
                temperature *= rawTemperature * 0.0625f;
            }
            return(temperature + ((format == TemperatureFormat.KELVIN) ? 273.15 : 0.0));
        }
コード例 #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TemperatureFormat format = (TemperatureFormat)value;

            if (format == TemperatureFormat.Celsius)
            {
                return(Visibility.Visible);
            }

            return(Visibility.Collapsed);
        }
コード例 #3
0
        public static float convertTemperature(float kTemp, TemperatureFormat format)
        {
            if (format == TemperatureFormat.Fahrenheit)
            {
                return(1.8f * (kTemp - 273.15f) + 32.0f);
            }

            else if (format == TemperatureFormat.Celsius)
            {
                return(kTemp - 273.15f);
            }

            return(kTemp);
        }
コード例 #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + Humidity.GetHashCode();
         hash = hash * 23 + IconUrl.GetHashCode();
         hash = hash * 23 + Pressure.GetHashCode();
         hash = hash * 23 + Temperature.GetHashCode();
         hash = hash * 23 + TemperatureFormat.GetHashCode();
         hash = hash * 23 + WeatherDescription.GetHashCode();
         hash = hash * 23 + WindSpeed.GetHashCode();
         return(hash);
     }
 }
コード例 #5
0
ファイル: Temperature.cs プロジェクト: mrees791/weather-app
        public Temperature(double temperature, TemperatureFormat format)
        {
            TemperatureServices temperatureServices = new TemperatureServices();

            switch (format)
            {
            case TemperatureFormat.Fahrenheit:
                fahrenheit = temperature;
                celsius    = temperatureServices.ConvertFahrenheitToCelsuis(fahrenheit);
                break;

            case TemperatureFormat.Celsius:
                celsius    = temperature;
                fahrenheit = temperatureServices.ConvertCelsiusToFahrenheit(celsius);
                break;
            }
        }
コード例 #6
0
ファイル: SettingsFile.cs プロジェクト: mrees791/weather-app
 public override void SetDefaults()
 {
     activeTemperatureFormat = TemperatureFormat.Fahrenheit;
     activeSkinName          = "Light Blue";
     activeFontName          = defaultFont.Name;
 }
コード例 #7
0
 public HourlyChartViewModel(TemperatureFormat temperatureFormat)
 {
     this.temperatureFormat = temperatureFormat;
     SeriesCollection       = new SeriesCollection();
 }
コード例 #8
0
 /// <summary>
 /// Function reading temperature in desired format
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public abstract double ReadTemperature(TemperatureFormat format);
コード例 #9
0
 /// <summary>
 /// Reading temperature - 0 mV + 10mv\*C
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public override double ReadTemperature(TemperatureFormat format)
 {
     return(temperatureInput.Read() * 100
            + ((format == TemperatureFormat.KELVIN) ? 273.15 : 0.0));
 }
コード例 #10
0
 public ConverterValueContext(TemperatureFormat tempFormat, PropertyName property)
 {
     this.TempFormat = tempFormat;
     this.Property   = property;
 }
コード例 #11
0
        /// <summary>
        /// Reading temperature
        /// </summary>
        /// <param name="format"> desired format</param>
        /// <returns></returns>
        public override double ReadTemperature(TemperatureFormat format)
        {
            int rawTemperature = 0;

            //if tere is only one device
            if (address == null)
            {
                if (oneWire.TouchReset() > 0)
                {
                    oneWire.WriteByte((int)OneWireCommands.SkipRom);
                    oneWire.WriteByte((int)OneWireCommands.MeasureTemperature);

                    while (oneWire.ReadByte() == 0)
                    {
                        ;
                    }

                    oneWire.TouchReset();

                    oneWire.WriteByte((int)OneWireCommands.SkipRom);
                    oneWire.WriteByte((int)OneWireCommands.ReadRom);

                    rawTemperature = (UInt16)((UInt16)oneWire.ReadByte() | (UInt16)(oneWire.ReadByte() << 8));
                }
                else
                {
                    throw new Exception("Device not found");
                }
            }
            //else if there is device address provided
            else
            {
                bool   match = false;
                byte[] found = null;
                //find device with provided address
                var devices = oneWire.FindAllDevices();
                foreach (byte[] codes in devices)
                {
                    match = true;
                    for (int i = 0; i < codes.Length; i++)
                    {
                        if (codes[i] != address[i])
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                    {
                        found = codes;
                        break;
                    }
                }
                if (found == null)
                {
                    throw new Exception("Device with specified address not found");
                }
                else
                {
                    if (oneWire.TouchReset() > 0)
                    {
                        oneWire.WriteByte((int)OneWireCommands.MatchRom);
                        foreach (byte codePart in found)
                        {
                            oneWire.WriteByte((int)codePart);
                        }
                        oneWire.WriteByte((int)OneWireCommands.MeasureTemperature);

                        while (oneWire.ReadByte() == 0)
                        {
                            ;
                        }

                        oneWire.WriteByte((int)OneWireCommands.MatchRom);
                        foreach (byte codePart in found)
                        {
                            oneWire.WriteByte((int)codePart);
                        }
                        oneWire.WriteByte((int)OneWireCommands.ReadRom);

                        rawTemperature = (UInt16)((UInt16)oneWire.ReadByte() | (UInt16)(oneWire.ReadByte() << 8));
                    }
                }
            }

            //conversion
            double result = 1;

            if ((rawTemperature & 0x8000) > 0)
            {
                rawTemperature = (rawTemperature ^ 0xffff) + 1;
                result         = -1;
            }
            result *= (6 * rawTemperature + rawTemperature / 4) / 100;
            return(result + ((format == TemperatureFormat.KELVIN) ? 273.15 : 0.0));
        }