-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
approvedAn enhancement has been approved and PRs are welcomeAn enhancement has been approved and PRs are welcomeenhancementNew feature or requestNew feature or request
Milestone
Description
A layer is needed to combine:
- Instantiating a sensor -> theme -> display graph based on configuration.
- Hosting a Control API and managing when it changes config.
- Hosting a BLE Control API that forwards to the Control API.
This will functionally replace the hard-coded implementation:
Lines 16 to 57 in b936a31
| // 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; | |
| }); |
Metadata
Metadata
Assignees
Labels
approvedAn enhancement has been approved and PRs are welcomeAn enhancement has been approved and PRs are welcomeenhancementNew feature or requestNew feature or request