예제 #1
0
        /// <summary>
        /// Returns tempeature based on sensor
        /// See http://www.ladyada.net/learn/sensors/tmp36.html
        /// </summary>
        /// <param name="ttype">Should temperature be in Cellsius degrees or Farrenheit</param>
        /// <returns>string containing interpretation of value from CS</returns>
        public TemperatureResult GetTemperature(TemperatureType ttype = TemperatureType.Cellsius)
        {
            //getting the voltage reading from the temperature sensor
            int    reading = GetRaw();
            double voltage = GetVoltage(reading);

            // now calculate the temperature
            //converting from 10 mv per degree with 500 mV offset
            //to degrees ((volatge - 500mV) times 100)
            double temperatureC = (voltage - 0.5) * 100;

            // now convert to Farrenheit
            double temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;

            TemperatureResult result = new TemperatureResult();

            result.Type          = ttype;
            result.Voltage       = voltage;
            result.VoltageString = voltage.ToString("F") + "v";
            if (ttype == TemperatureType.Cellsius)
            {
                result.Temperature       = temperatureC;
                result.TemperatureString = temperatureC.ToString("F") + "C";
            }
            else
            {
                result.Temperature       = temperatureF;
                result.TemperatureString = temperatureC.ToString("F") + "F";
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Returns tempeature based on sensor
        /// See http://www.ladyada.net/learn/sensors/tmp36.html
        /// </summary>
        /// <param name="ttype">Should temperature be in Cellsius degrees or Farrenheit</param>
        /// <returns>string containing interpretation of value from CS</returns>
        public TemperatureResult GetTemperature(TemperatureType ttype = TemperatureType.Cellsius)
        {
            //getting the voltage reading from the temperature sensor
            int reading = GetRaw();
            double voltage = GetVoltage(reading);

            // now calculate the temperature
            //converting from 10 mv per degree with 500 mV offset
            //to degrees ((volatge - 500mV) times 100)
            double temperatureC = (voltage - 0.5) * 100;

            // now convert to Farrenheit
            double temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;

            TemperatureResult result = new TemperatureResult();
            result.Type = ttype;
            result.Voltage = voltage;
            result.VoltageString = voltage.ToString("F") + "v";
            if (ttype == TemperatureType.Cellsius)
            {
                result.Temperature = temperatureC;
                result.TemperatureString = temperatureC.ToString("F") + "C";
            }
            else
            {
                result.Temperature = temperatureF;
                result.TemperatureString = temperatureC.ToString("F") + "F";
            }
            return result;
        }
예제 #3
0
        public async Task <TemperatureResult> GetSystemTemperatureAsync()
        {
            double            output;
            string            stdOut;
            TemperatureResult result = new TemperatureResult {
                Unit = options.Unit.ToString()
            };

            try
            {
                using (SystemProcess process = new())
                {
                    logger.LogInformation("Starting Temperature read process");

                    // Command returns \r\n at the end. We don't need that.
                    stdOut = Regex.Match(await process.RunCommand(options.CommandInterface, options.CommandArgs), @"\d+").Value;

                    // Collect the output.
                    output = Double.Parse(stdOut);
                }

                switch (options.Unit)
                {
                default:
                case Temperature.Celcius:
                    result.Temperature = SystemConverter.SystemTempToCelcius(output);
                    break;

                case Temperature.Fahrenheit:
                    result.Temperature = SystemConverter.SystemTempToFahrenheit(output);
                    break;

                case Temperature.Kelvin:
                    result.Temperature = SystemConverter.SystemTempToKelvin(output);
                    break;
                }

                logger.LogInformation($"Temperature read successful, returning temperature - {result.Temperature} degrees {result.Unit} ");
                return(result);
            }
            catch (OverflowException e)
            {
                // Bubble up exception after catching it here.
                logger.LogError(e, "Overflow when converting terminal result to double");
                throw;
            }
        }
예제 #4
0
        public async Task <ActionResult> SystemTemperatureAsync()
        {
            logger.LogInformation("Received Temps request.");

            try
            {
                TemperatureResult temperature = await temperatureGuage.GetSystemTemperatureAsync();

                string unit = temperatureOptions.Unit.ToString();

                return(Ok(temperature));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
예제 #5
0
        public void HandleTemperatureResultEvent(object sender, TemperatureResult tempertureResult)
        {
            Debug.WriteLine($"TemperatureResult: Index[{tempertureResult.Index}] Value[{tempertureResult.Value}]");

            switch (tempertureResult.Index)
            {
            case 1:
                BeerFactoryModel.Temperature1 = tempertureResult.Value;
                break;

            case 2:
                BeerFactoryModel.Temperature2 = tempertureResult.Value;
                break;

            case 3:
                BeerFactoryModel.Temperature3 = tempertureResult.Value;
                break;
            }
        }
예제 #6
0
        public async Task GetTemperatureTestAsync(Temperature unit, double input, double expected)
        {
            fixture.Customize(new TemperatureGuageCustomization(unit, input))
            .Customize(new TemperatureOptionsCustomization(unit));

            SystemController mockController = fixture.Build <SystemController>()
                                              .OmitAutoProperties()
                                              .Create();

            var result = await mockController.SystemTemperatureAsync();

            Assert.IsType <OkObjectResult>(result);
            OkObjectResult okResult = (OkObjectResult)result;

            Assert.IsType <TemperatureResult>(okResult.Value);
            TemperatureResult tempResult = (TemperatureResult)okResult.Value;

            Assert.Equal(expected, tempResult.Temperature);
            Assert.Equal(unit.ToString(), tempResult.Unit);
        }
예제 #7
0
 public void HandleTemperatureResultEvent(object sender, TemperatureResult tempertureResult)
 {
     System.Console.WriteLine($"TemperatureResult: Index[{tempertureResult.Index}] Value[{tempertureResult.Value}]");
 }