Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Inferno.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Device.Gpio;
using System.Device.Gpio.Drivers;
using System.Device.Spi;
using Inferno.Api.Services;
using Inferno.Api.Devices;
using Inferno.Api.Services;
using Inferno.Api.Settings;
using Inferno.Common.Interfaces;

GpioController _gpio = new GpioController(PinNumberingScheme.Logical, new RaspberryPi3Driver());
Expand All @@ -16,16 +17,20 @@

var builder = WebApplication.CreateBuilder(args);

var smokerSettings = builder.Configuration.GetSection("SmokerSettings").Get<SmokerSettings>() ?? new SmokerSettings();
builder.Services.AddSingleton(smokerSettings);

// Add services to the container.

builder.Services.AddControllers();

builder.Services.AddSingleton<ISmoker>(new Smoker(new Auger(_gpio, 22),
new Blower(_gpio, 21),
new Igniter(_gpio, 23),
new RtdArray(_spi),
new Display()));
builder.Services.AddControllers();
builder.Services.AddSingleton<ISmoker>(sp =>
new Smoker(new Auger(_gpio, smokerSettings.AugerPin),
new Blower(_gpio, smokerSettings.BlowerPin),
new Igniter(_gpio, smokerSettings.IgniterPin),
new RtdArray(_spi),
new Display(),
smokerSettings));

var app = builder.Build();

Expand Down
36 changes: 24 additions & 12 deletions Inferno.Api/Services/Smoker.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics;
using Inferno.Api.Interfaces;
using Inferno.Common.Interfaces;
using Inferno.Common.Models;
using Inferno.Api.Pid;
using Inferno.Api.Settings;
using Inferno.Common.Extensions;
using Inferno.Common.Interfaces;
using Inferno.Common.Models;

namespace Inferno.Api.Services
{
Expand All @@ -15,29 +16,30 @@ public class Smoker : ISmoker
IRelayDevice _igniter;
IRtdArray _rtdArray;
IDisplay _display;
SmokerSettings _settings;

int _setPoint;
/// <summary>
/// Arbitrary factor to determine how much to run the auger each cycle in Smoke mode.
/// Borrowed from Traeger's "P" setting. 1 is the lowest, 5 is the highest.
/// </summary>
int _pValue;
int _maxSetPoint = 400;
int _minSetPoint = 180;
int _maxSetPoint;
int _minSetPoint;

int _maxGrillTemp = 425;
int _maxGrillTemp;

/// <summary>
/// Timeout for the blower to run after shutdown.
/// </summary>
TimeSpan _shutdownBlowerTimeout = TimeSpan.FromMinutes(10);
TimeSpan _shutdownBlowerTimeout;

/// <summary>
/// Hold cycle time. This is the amount of time a Hold iteration takes in total.
/// The PID determines a period of time to run the auger as a percentage of this time.
/// Also used in Sear mode to determine how long to run the auger when the grill is too hot.
/// </summary>
TimeSpan _holdCycle = TimeSpan.FromSeconds(10);
TimeSpan _holdCycle;

CancellationTokenSource _cts = null!;
SmokerPid _pid;
Expand All @@ -46,12 +48,12 @@ public class Smoker : ISmoker
/// <summary>
/// Maximum value for the PID output. This is the maximum amount of the "hold" cycle time that the auger will run.
/// </summary>
double _uMax = 1.0;
double _uMax;
/// <summary>
/// Minimum value for the PID output. This is the minimum amount of the "hold" cycle time that the auger will run.
/// Too low of a value can cause the fire to go out. Too high of a value can result in the fire being too hot.
/// </summary>
double _uMin = 0.175;
double _uMin;

Task _modeLoopTask;
DisplayUpdater _displayUpdater;
Expand All @@ -61,22 +63,32 @@ public Smoker(IRelayDevice auger,
IRelayDevice blower,
IRelayDevice igniter,
IRtdArray rtdArray,
IDisplay display)
IDisplay display,
SmokerSettings settings)
{
_auger = auger;
_blower = blower;
_igniter = igniter;
_rtdArray = rtdArray;
_display = display;
_settings = settings;

_maxSetPoint = settings.MaxSetPoint;
_minSetPoint = settings.MinSetPoint;
_maxGrillTemp = settings.MaxGrillTemp;
_shutdownBlowerTimeout = TimeSpan.FromMinutes(settings.ShutdownBlowerTimeoutMinutes);
_holdCycle = TimeSpan.FromSeconds(settings.HoldCycleSeconds);
_uMax = settings.UMax;
_uMin = settings.UMin;

_mode = SmokerMode.Ready;
_setPoint = _minSetPoint;
_lastModeChange = DateTime.Now;
PValue = 2;

CancellationTokenSource _cts = new CancellationTokenSource();
_cts = new CancellationTokenSource();

_pid = new SmokerPid(60.0, 180.0, 45.0);
_pid = new SmokerPid(settings.PB, settings.Ti, settings.Td);

_displayUpdater = new DisplayUpdater(this, _display);
_fireMinder = new FireMinder(this, _igniter);
Expand Down
21 changes: 21 additions & 0 deletions Inferno.Api/Settings/SmokerSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Inferno.Api.Settings
{
public class SmokerSettings
{
public int AugerPin { get; set; }
public int BlowerPin { get; set; }
public int IgniterPin { get; set; }
public int MaxSetPoint { get; set; } = 400;
public int MinSetPoint { get; set; } = 180;
public int MaxGrillTemp { get; set; } = 425;
public double ShutdownBlowerTimeoutMinutes { get; set; } = 10;
public double HoldCycleSeconds { get; set; } = 10;
public double UMax { get; set; } = 1.0;
public double UMin { get; set; } = 0.175;
public double PB { get; set; } = 60.0;
public double Ti { get; set; } = 180.0;
public double Td { get; set; } = 45.0;
}
}
15 changes: 15 additions & 0 deletions Inferno.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@
"System": "Information",
"Microsoft": "Information"
}
},
"SmokerSettings": {
"AugerPin": 22,
"BlowerPin": 21,
"IgniterPin": 23,
"MaxSetPoint": 400,
"MinSetPoint": 180,
"MaxGrillTemp": 425,
"ShutdownBlowerTimeoutMinutes": 10,
"HoldCycleSeconds": 10,
"UMax": 1.0,
"UMin": 0.175,
"PB": 60.0,
"Ti": 180.0,
"Td": 45.0
}
}
16 changes: 16 additions & 0 deletions Inferno.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,20 @@
}
},
"AllowedHosts": "*"
,
"SmokerSettings": {
"AugerPin": 22,
"BlowerPin": 21,
"IgniterPin": 23,
"MaxSetPoint": 400,
"MinSetPoint": 180,
"MaxGrillTemp": 425,
"ShutdownBlowerTimeoutMinutes": 10,
"HoldCycleSeconds": 10,
"UMax": 1.0,
"UMin": 0.175,
"PB": 60.0,
"Ti": 180.0,
"Td": 45.0
}
}