public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                return("N/A");
            }

            if (values.Length <= 0)
            {
                return("N/A");
            }

            var    temp = (double)values[0];
            string unit;

            if (values[1].Equals("f"))
            {
                unit = "°F";
                temp = ConvertTemp.ConvertCelsiusToFahrenheit(temp);
            }
            else
            {
                unit = "°C";
            }

            return(temp + " " + unit);
        }
Пример #2
0
        private Double GetTemp()
        {
            Double result = 0.0;

            try
            {
                DirectoryInfo devicesDir = new DirectoryInfo("/sys/bus/w1/devices");

                //  Console.WriteLine("dir " + devicesDir.FullName);

                //Console.WriteLine("Address -" + address);
                foreach (var deviceDir in devicesDir.EnumerateDirectories(address))
                {
                    var w1slavetext =
                        deviceDir.GetFiles("w1_slave").FirstOrDefault().OpenText().ReadToEnd();
                    string temptext =
                        w1slavetext.Split(new string[] { "t=" }, StringSplitOptions.RemoveEmptyEntries)[1];

                    //  Console.WriteLine("temp " + temptext);

                    result = ConvertTemp.ConvertCelsiusToFahrenheit(double.Parse(temptext) / 1000);;

                    return(result);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(result);
        }
Пример #3
0
        static void Main(string[] args)
        {
            double answer;

            Console.WriteLine("{0}={1}", 37,
                              answer = ConvertTemp.ConvertCelsiusToFahrenheit(37));
            Console.ReadLine();
        }
Пример #4
0
        private void OnTick(object sender, object e)
        {
            // Status LEDs
            if (i++ % 5 == 0) // this is true every 500ms
            {
                // If you want an LED some where on the external enclosure, use a PWN PIN
                //hat.SetPwmDutyCycle(FEZHAT.PwmPin.Pwm6, AreLedsOn ? 1.0 : 0.0);

                // On-board LED
                hat.DIO24On = AreLedsOn;

                AreLedsOn = !AreLedsOn;
            }

            LightLevelReading = hat.GetLightLevel() * 100;

            TemperatureReading = ConvertTemp.ConvertCelsiusToFahrenheit(hat.GetTemperature());
        }
Пример #5
0
        private async void _timer_Tick(object sender, object e)
        {
            reading = new DhtReading();
            reading = await _dht.GetReadingAsync().AsTask();

            if (reading.IsValid)
            {
                txtTemp.Text = (reading.Temperature).ToString() + " °C" + "       " + (ConvertTemp.ConvertCelsiusToFahrenheit(reading.Temperature).ToString() + " °F");
            }
            else
            {
            }
        }