Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glue layer #18

Open
scalablecory opened this issue Oct 4, 2021 · 1 comment
Open

Glue layer #18

scalablecory opened this issue Oct 4, 2021 · 1 comment
Labels
approved An enhancement has been approved and PRs are welcome enhancement New feature or request
Milestone

Comments

@scalablecory
Copy link
Owner

scalablecory commented Oct 4, 2021

A layer is needed to combine:

This will functionally replace the hard-coded implementation:

// TODO: this needs to be replaced by something that reads config, resolves dependencies, etc.
var runDeviceCommand = new Command("run-device", "Runs an Aether device");
runDeviceCommand.Handler = CommandHandler.Create(async () =>
{
// Initialize MS5637.
using I2cDevice ms5637Device = I2cDevice.Create(new I2cConnectionSettings(1, ObservableMs5637.DefaultAddress));
await using ObservableSensor ms5637Driver = ObservableMs5637.OpenSensor(ms5637Device, dependencies: Observable.Empty<Measurement>());
// Initialize SCD4x, taking a dependency on MS5637 for calibration with barometric pressure.
using I2cDevice scd4xDevice = I2cDevice.Create(new I2cConnectionSettings(1, ObservableScd4x.DefaultAddress));
await using ObservableSensor scdDriver = ObservableScd4x.OpenSensor(scd4xDevice, dependencies: ms5637Driver);
// All the measurements funnel through here.
// Multiple sensors can support the same measures. In this case, both devices support teperature. To prevent inconsistencies, only use one.
IObservable<Measurement> measurements = Observable.Merge(
ms5637Driver.Where(x => x.Measure == Measure.BarometricPressure),
scdDriver
);
// Initialize display.
var spiConfig = new System.Device.Spi.SpiConnectionSettings(0, 0)
{
ClockFrequency = 10000000
};
using var gpio = new GpioController(PinNumberingScheme.Logical);
using SpiDevice displayDevice = SpiDevice.Create(spiConfig);
using var displayDriver = new WaveshareEPD2_9inV2(displayDevice, gpio, dcPinId: 25, rstPinId: 17, busyPinId: 24);
// Initialize the theme, which takes all the measurements and renders them to a display.
var lines = new[] { Measure.CO2, Measure.Humidity, Measure.BarometricPressure, Measure.Temperature };
using IDisposable theme = MultiLineTheme.CreateTheme(displayDriver, lines, measurements);
// Wait for Ctrl+C to exit.
var tcs = new TaskCompletionSource();
Console.CancelKeyPress += (s, e) =>
{
Console.WriteLine("Closing...");
e.Cancel = true;
tcs.TrySetResult();
};
await tcs.Task;
});

@scalablecory scalablecory added enhancement New feature or request approved An enhancement has been approved and PRs are welcome labels Oct 4, 2021
@scalablecory scalablecory added this to the 1.0 milestone Oct 4, 2021
@scalablecory
Copy link
Owner Author

scalablecory commented Oct 16, 2021

Here's a general architectural outline to help plan this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved An enhancement has been approved and PRs are welcome enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant