Add EnvironmentSensor settings

This commit is contained in:
Denis-Cosmin Nutiu 2019-11-11 17:58:46 +02:00
parent 9bc5a462f6
commit 8a6094b8a3
3 changed files with 20 additions and 4 deletions

View file

@ -9,20 +9,31 @@ namespace NucuCar.Sensors.EnvironmentSensor
{
public class BackgroundWorker : BackgroundService
{
private readonly bool _serviceEnabled;
private readonly bool _telemetryEnabled;
private readonly int _measurementDelay;
private readonly ILogger<BackgroundWorker> _logger;
public BackgroundWorker(ILogger<BackgroundWorker> logger, IConfiguration config)
{
_logger = logger;
var configSection = config.GetSection("EnvironmentSensor");
_serviceEnabled = configSection.GetValue<bool>("Enabled");
_telemetryEnabled = configSection.GetValue<bool>("Telemetry");
_measurementDelay = configSection.GetValue<int>("MeasurementDelay");
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (!_serviceEnabled)
{
return;
}
using var sensor = Sensor.Instance;
sensor.SetLogger(_logger);
sensor.InitializeSensor();
while (!stoppingToken.IsCancellationRequested)
{
if (sensor.GetState() == SensorStateEnum.Initialized)
@ -36,7 +47,7 @@ namespace NucuCar.Sensors.EnvironmentSensor
sensor.InitializeSensor();
}
await Task.Delay(1000, stoppingToken);
await Task.Delay(_measurementDelay, stoppingToken);
}
}
}

View file

@ -1,4 +1,9 @@
{
"EnvironmentSensor": {
"Enabled": true,
"Telemetry": false,
"MeasurementDelay": 1000
},
"Logging": {
"LogLevel": {
"Default": "Information",

View file

@ -5,14 +5,14 @@
You can build the project then run them as you would run an executable file.
```$xslt
dotnet build --runtime debian-arm
dotnet build --runtime linux-arm
```
Milestones:
-
- [X] Make a working BME680 module. ~~(Unit tests?)~~
- [ ] Add settings: gRPC enabled, Telemetry Enabled, Sensor Enabled.
- [X] Add settings: ~~gRPC enabled~~, Telemetry Enabled, Sensor Enabled, Measurement Delay
- [X] Make a gRPC test project to test the modules.
- [ ] Add systemd config file.
- [ ] Add makefile for easy building & installing.