-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
61 lines (48 loc) · 2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using MPU6050Test;
using MPU6050Test.Service;
using MPUTest6050.Service.Interface;
using System.IO;
// Load configuration from appSettings.json
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
.Build();
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection, configuration);
var serviceProvider = serviceCollection.BuildServiceProvider();
try
{
Console.WriteLine("Starting calibration...");
// Get the accelerometer controller service
var accelerometerController = serviceProvider.GetService<IAccelerometerController>();
// Perform the calibration (replace this with your actual method)
await accelerometerController.CalibrateAsync();
Console.WriteLine("Calibration completed successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
Console.WriteLine(ex.StackTrace);
}
void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
// Configure logging
services.AddLogging(configure => configure.AddConsole());
var accelerometerSettings = new Accelerometer();
configuration.GetSection("Accelerometer").Bind(accelerometerSettings);
// Register IAccelerometerController (for Linux or mock, depending on platform)
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
//{
services.AddSingleton<IAccelerometerController, ImuAccelerometerController>(sp =>
{
var logger = sp.GetRequiredService<ILogger<ImuAccelerometerController>>();
return new ImuAccelerometerController(
logger,
accelerometerSettings.Address,
accelerometerSettings.RecalibrationIntervalInMinutes); // I2C address and recalibration interval
});
//}
}