Skip to content

Commit

Permalink
Updated display logic for min and max temp; cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
almostengr committed Apr 30, 2022
1 parent 817a2de commit 62f8375
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Almostengr.ThermometerPi.Api.Constants;

namespace Almostengr.ThermometerPi.Api.DataTransferObject
{
Expand Down
2 changes: 0 additions & 2 deletions Almostengr.ThermometerPi.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void ConfigureServices(IServiceCollection services)

# if RELEASE
services.AddScoped<ISensorService, Ds18b20Service>();
services.AddScoped<ILcdService, LcdService>();
services.AddScoped<INwsClient, NwsClient>();
services.AddHostedService<LcdDisplayWorker>();
# else
Expand All @@ -45,7 +44,6 @@ public void ConfigureServices(IServiceCollection services)
# endif

services.AddHostedService<InteriorLatestWorker>();
// services.AddHostedService<NwsLatestWorker>();
services.AddHostedService<DbMaintenanceWorker>();
}

Expand Down
35 changes: 10 additions & 25 deletions Almostengr.ThermometerPi.Api/Workers/LcdDisplayWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,15 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

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

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

if (interiorTemp != null)
{
output += $"In: {interiorTemp.Fahrenheit.ToString()}F ";
}

if (exteriorTemp != null)
{
output += $"Out: {exteriorTemp.Fahrenheit.ToString()}F";
}

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

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

Expand All @@ -63,29 +55,22 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

output = string.Empty;

if (minInteriorTemp != null)
{
output = $"Min: {minInteriorTemp.Fahrenheit.ToString()}F ";
}

if (maxInteriorTemp != null)
{
output += $"Max: {maxInteriorTemp.Fahrenheit.ToString()}F";
}

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

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

private void DisplayLcdText(string line1 = "No data")
private void DisplayLcdText(string line1 = "No data", string line2 = "")
{
lcd.Clear();
lcd.SetCursorPosition(0, 0);
lcd.Write(line1);
lcd.SetCursorPosition(0, 1);
lcd.Write(DateTime.Now.ToString("ddd MM/dd HH:mm"));
lcd.Write(line2);
}

} // end class
Expand Down

0 comments on commit 62f8375

Please sign in to comment.