예제 #1
0
파일: UnitTest.cs 프로젝트: cheech36/iotbbq
        public void TestConvertVoltageToResistance2()
        {
            // Got Resistance 235409.820661915 from voltage 2.3161289870739
            double data = TempUtils.GetThermistorResistenceFromVoltage(3.3, 2.3161289870739, 100000);

            Assert.AreEqual(42479, (int)data);
        }
예제 #2
0
파일: UnitTest.cs 프로젝트: cheech36/iotbbq
        public void TestConvertVoltageToResistence()
        {
            // This was checked with https://www.allaboutcircuits.com/tools/voltage-divider-calculator/
            double data = TempUtils.GetThermistorResistenceFromVoltage(3.3, 1.66, 100000);

            Assert.AreEqual(98795, (int)data);
        }
예제 #3
0
        public async Task <Temps> ReadThermometer(int index)
        {
            if (index < 0 || index > 7)
            {
                throw new IndexOutOfRangeException("Index must be from 0-7");
            }

            using (await this.thermometerLock.LockAsync())
            {
                await this.initTask;

                double    sum        = 0;
                const int numSamples = 3;
                for (int i = 0; i < numSamples; i++)
                {
                    var reading = this.mcp.Read(Channels[index]);
                    sum += reading.NormalizedValue;
                    await Task.Delay(100);
                }

                double averageValue = sum / numSamples;

                //Debug.WriteLine($"Reading for thermometer {index} is {reading.RawValue}, Normalized: {reading.NormalizedValue}");

                double voltage    = averageValue * InputVoltage;
                double resistance = TempUtils.GetThermistorResistenceFromVoltage(3.3, voltage, BalancingResistorOhms);
                //Debug.WriteLine($"Got Resistance {resistance} from voltage {voltage}");

                CoefficientSet coefficients = Coefficients[0];

                var temps = new Temps();
                if (double.IsInfinity(resistance))
                {
                    temps.Kelvin = 0;
                }
                else
                {
                    temps.Kelvin = TempUtils.ResistanceToTemp(coefficients.A, coefficients.B, coefficients.C, resistance);
                }

                temps.Celcius     = TempUtils.KelvinToCelcius(temps.Kelvin);
                temps.Farenheight = TempUtils.CelciusToFarenheight(temps.Celcius);

                return(temps);
            }
        }