public SensorModel(SensorKit controller, string name) { Controller = controller; Name = name; // initialize the tag if (SensorKit.Settings.Tags.ContainsKey(SensorKit.GetHashName(Name))) { _tag = SensorKit.Settings.Tags[SensorKit.GetHashName(Name)]; } OnPropertyChanged("Tag"); }
async Task AddSensor(string name, ulong bluetoothAddress) { if (isAddingSensor) { return; } isAddingSensor = true; try { SensorModel sensor = null; await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { //haven't seen this device yet, add it to known devices list sensor = new SensorModel(this, name) { BluetoothAddress = bluetoothAddress, UserId = UserId }; sensor.Information = Registry.Public.FirstOrDefault(s => s.Model == sensor.SensorType); Data.Add(sensor); }); Debug.WriteLine($"SENSOR ADDED {sensor.Name}"); // check for known sensor tag var tagkey = SensorKit.GetHashName(name); if (Settings.Tags.ContainsKey(tagkey)) { var sensorTag = Settings.Tags[tagkey]; if (sensorTag != null) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { sensor.Tag = sensorTag; }); // attempt to reconnect (non UI thread) sensor.Connector = new SensorKitConnector(this, sensor); await sensor.Connector.Subscribe(); } } await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { NotifyPropertyChanged("Data"); }); }catch (Exception x) { Debug.WriteLine(x); } isAddingSensor = false; }
public SensorKitConnector(SensorKit controller, SensorModel data) { Controller = controller; Data = data; }