NucuCar/NucuCar.Sensors/Program.cs

48 lines
2.2 KiB
C#
Raw Permalink Normal View History

2019-11-09 13:34:49 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
2020-08-01 15:07:13 +00:00
using NucuCar.Sensors.Abstractions;
2021-08-02 18:13:59 +00:00
using NucuCar.Sensors.Modules.BME680;
using NucuCar.Sensors.Modules.CpuTemperature;
using NucuCar.Sensors.Modules.Heartbeat;
using NucuCar.Sensors.Modules.PMS5003;
using NucuCar.Telemetry;
using NucuCar.Telemetry.Abstractions;
using NucuCar.Telemetry.Publishers;
2019-11-09 13:34:49 +00:00
namespace NucuCar.Sensors
2019-11-09 13:34:49 +00:00
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
2019-11-09 13:34:49 +00:00
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.Configure<Config>(hostContext.Configuration.GetSection("Telemetry"));
2021-08-02 18:13:59 +00:00
services.Configure<Bme680Config>(hostContext.Configuration.GetSection("Bme680Sensor"));
services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("CpuTemperatureSensor"));
services.Configure<HeartbeatConfig>(hostContext.Configuration.GetSection("HeartbeatSensor"));
services.Configure<Pms5003Config>(hostContext.Configuration.GetSection("Pms5003Sensor"));
// Singletons
services.AddSingleton<ITelemetryPublisher, PublisherProxy>();
2019-11-30 16:55:55 +00:00
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
services.AddSingleton<ISensor<Pms5003Sensor>, Pms5003Sensor>();
// Workers
// Telemetry
services.AddHostedService<TelemetryWorker>();
// Sensors
services.AddHostedService<Bme680Worker>();
services.AddHostedService<CpuTempWorker>();
services.AddHostedService<HeartbeatWorker>();
services.AddHostedService<Pms5003Worker>();
2021-08-01 17:35:54 +00:00
});
2019-11-09 13:34:49 +00:00
}
}