Esempio n. 1
0
 public SensorKit(string userId)
 {
     UserId = userId;
     // automatically add local model for the local on-phone sensors
     LocalData = new SensorModel(this, Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily.Replace("_", "-"))
     {
         Id          = SensorKit.HUB_SENSOR_ID,                                                      // local
         UserId      = userId,
         Information = Registry.Public.FirstOrDefault(d => d.Capabilities == SensorCapabilities.Hub) // local device is a hub
     };
     Data.Add(LocalData);
     Task.Run(() =>
     {
         // setup watchers on non UI thread
         watcher = new BluetoothLEAdvertisementWatcher {
             ScanningMode = BluetoothLEScanningMode.Active
         };
         // If we haven't seen an advertisement for 3 seconds, consider the device out of range
         watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(3000);
         // If we see an advertisement from a device with an RSSI less than -120, consider it out of range
         watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -120;
         // Register our callbacks
         watcher.Received += DeviceFound;
         //deviceWatcher = DeviceInformation.CreateWatcher();
         //deviceWatcher.Added += DeviceAdded;
         //deviceWatcher.Updated += DeviceUpdated;
     });
     _timerScanning = new TimerHelper();
 }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 public SensorKitConnector(SensorKit controller, SensorModel data)
 {
     Controller = controller;
     Data       = data;
 }