Created
December 4, 2019 03:38
-
-
Save adrianstevens/82cb45278b113204907e08c4e7004e7d to your computer and use it in GitHub Desktop.
App class from Meadow Therm reference project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Meadow; | |
using Meadow.Devices; | |
using Meadow.Hardware; | |
using Meadow.Peripherals.Sensors.Temperature; | |
using Meadow.Foundation.Sensors.Temperature; | |
using Meadow.Peripherals.Sensors.Atmospheric; | |
using System.Threading.Tasks; | |
namespace Therm | |
{ | |
public class ThermApp : App<F7Micro, ThermApp> | |
{ | |
AnalogTemperature _tempSensor; | |
ClimateController _climateController; | |
HvacController _hvacController; | |
UXController _uxController; | |
public static ClimateModelManager ModelManager { get => ClimateModelManager.Instance; } | |
public ThermApp() | |
{ | |
// setup our global hardware | |
this.ConfigurePeripherals(); | |
// init our controllers | |
this.InitializeControllers(); | |
// wire things up | |
this.WireUpEventing(); | |
// get things spun up | |
this.Start().Wait(); | |
} | |
protected void ConfigurePeripherals() | |
{ | |
_tempSensor = new AnalogTemperature( | |
IOMap.AnalogTempSensor.Item1, IOMap.AnalogTempSensor.Item2, | |
AnalogTemperature.KnownSensorType.TMP35); | |
} | |
protected void InitializeControllers() | |
{ | |
_climateController = new ClimateController(); | |
_uxController = new UXController(); | |
} | |
/// <summary> | |
/// Glues things together with the subscribers | |
/// </summary> | |
protected void WireUpEventing() | |
{ | |
// subscribe to 1/4º C changes in temp | |
this._tempSensor.Subscribe(new FilterableObserver<AtmosphericConditionChangeResult, AtmosphericConditions>( | |
h => { | |
// probably update screen or something | |
Console.WriteLine($"Update from temp sensor: {h.New.Temperature}ºC"); | |
ModelManager.UpdateAmbientTemp(h.New.Temperature); | |
}, | |
e => { return (Math.Abs(e.Delta.Temperature) > 0.25f); })); | |
} | |
/// <summary> | |
/// Kicks off the app. Starts by doing a temp read and then spins | |
/// up the sensor updating and such. | |
/// </summary> | |
/// <returns></returns> | |
protected async Task Start() | |
{ | |
// take an initial reading of the temp | |
Console.WriteLine("Start"); | |
var conditions = await _tempSensor.Read(); | |
Console.WriteLine($"Initial temp: {conditions.Temperature}"); | |
//ModelManager.UpdateAmbientTemp(20f); | |
Console.WriteLine("Starting up the temp sensor."); | |
_tempSensor.StartUpdating(standbyDuration: 1000); | |
Console.WriteLine("Temp sensor spinning"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment