Esempio n. 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            using I2cDevice i2c  = I2cDevice.Create(new I2cConnectionSettings(1, 0x27));
            using Pcf8574 driver = new Pcf8574(i2c);

            lcd = new Lcd1602(registerSelectPin: 0,
                              enablePin: 2,
                              dataPins: new int[] { 4, 5, 6, 7 },
                              backlightPin: 3,
                              backlightBrightness: 1f,
                              readWritePin: 1,
                              controller: new GpioController(PinNumberingScheme.Logical, driver));

            while (!stoppingToken.IsCancellationRequested)
            {
                TemperatureDto interiorTemp = await _temperatureReadingService.GetLatestInteriorReadingAsync();

                lcd.Clear();
                string output = string.Empty;

                DisplayLcdText(
                    interiorTemp != null ?
                    $"In: {interiorTemp.Fahrenheit.ToString()}F {interiorTemp.Celsius.ToString()}C" :
                    "No Data",
                    DateTime.Now.ToString("ddd MM/dd HH:mm")
                    );

                await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken);

                TemperatureDto minInteriorTemp = await _temperatureReadingService.GetMinInteriorReadingAsync();

                TemperatureDto maxInteriorTemp = await _temperatureReadingService.GetMaxInteriorReadingAsync();

                output = string.Empty;

                DisplayLcdText(
                    minInteriorTemp != null ?
                    $"Min: {minInteriorTemp.Fahrenheit.ToString()}F {minInteriorTemp.Celsius.ToString()}C" :
                    string.Empty,
                    maxInteriorTemp != null ?
                    $"Max: {maxInteriorTemp.Fahrenheit.ToString()}F {maxInteriorTemp.Celsius.ToString()}C" :
                    string.Empty
                    );

                await Task.Delay(TimeSpan.FromSeconds(DelaySeconds), stoppingToken);
            }
        }
 public async Task <IActionResult> GetLatestInteriorTemperature()
 {
     return(Ok(await _temperatureReadingService.GetLatestInteriorReadingAsync()));
 }