Ejemplo n.º 1
0
        private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, busAttachment, args.SessionPort);

            if (aboutData != null && !string.IsNullOrWhiteSpace(aboutData.DeviceId))
            {
                // Join session with the producer of the LampState interface.
                LampStateJoinSessionResult joinSessionResult = await LampStateConsumer.JoinSessionAsync(args, sender);

                if (joinSessionResult.Status == AllJoynStatus.Ok)
                {
                    if (string.Equals(aboutData.DeviceId, lampDeviceId))
                    {
                        consumer = joinSessionResult.Consumer;
                        LampFound?.Invoke(this, new EventArgs());
                        consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived;
                    }

                    if (!arrLamp.Contains(joinSessionResult.Consumer))
                    {
                        arrLamp.Add(joinSessionResult.Consumer);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void StartWatchers()
        {
            var lampStateWatcher = new LampStateWatcher(_allJoynBusAttachment);

            lampStateWatcher.Added += LampStateWatcher_Added;
            lampStateWatcher.Start();
        }
Ejemplo n.º 3
0
        public MBWatcher()
        {
            if (bus == null)
            {
                bus = new AllJoynBusAttachment();
                bus.StateChanged         += Bus_StateChanged;
                bus.CredentialsRequested += Bus_CredentialsRequested;
            }

            if (bus1 == null)
            {
                bus1                      = new AllJoynBusAttachment();
                bus.StateChanged         += Bus_StateChanged;
                bus.CredentialsRequested += Bus_CredentialsRequested;
            }

            if (stateWatcher == null)
            {
                stateWatcher        = new LampStateWatcher(bus);
                stateWatcher.Added += Watcher_Added;
                stateWatcher.Start();
            }

            if (detailsWatcher == null)
            {
                detailsWatcher        = new LampDetailsWatcher(bus1);
                detailsWatcher.Added += Details_Added;
                detailsWatcher.Start();
            }
        }
Ejemplo n.º 4
0
        public void FindLamp()
        {
            Debug.WriteLine("Starting consumer ...");

            AllJoynBusAttachment busAttachment = new AllJoynBusAttachment();
            LampStateWatcher watcher = new LampStateWatcher(busAttachment);
            watcher.Added += LampFound;
            watcher.Start();
        }
Ejemplo n.º 5
0
        public void FindLamp()
        {
            Debug.WriteLine("Starting consumer ...");

            AllJoynBusAttachment busAttachment = new AllJoynBusAttachment();
            LampStateWatcher     watcher       = new LampStateWatcher(busAttachment);

            watcher.Added += LampFound;
            watcher.Start();
        }
Ejemplo n.º 6
0
        public LampHandler()
        {
            Consumers = new Dictionary<string, LampStateConsumer>();
            _busAttachment = new AllJoynBusAttachment();
            _watcher = new LampStateWatcher(_busAttachment);
            _watcher.Added += OnWatcherAdded;
            _watcher.Start();

            _defaulsWhenOff = new LampValue() { On = false, Brightness = 100, ColorTemp = 9000, Hue = 260, Saturation = 100 };
            _defaulsWhenOn = new LampValue() { On = true, Brightness = 100, ColorTemp = 9000, Hue = 260, Saturation = 100 };
            _defaulsBeforeBlink = new LampValue() { On = true, Brightness = 100, ColorTemp = 9000, Hue = 260, Saturation = 100 };
            _lastValues = null;
        }
Ejemplo n.º 7
0
        private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status != AllJoynStatus.Ok)
            {
                return;
            }

            _consumer = joinResult.Consumer;

            await _consumer.SetOnOffAsync(false);
        }
Ejemplo n.º 8
0
        public LampHelper()
        {
            // Initialize AllJoyn bus attachment.
            busAttachment = new AllJoynBusAttachment();

            // Initialize LampState watcher.
            LampStateWatcher watcher = new LampStateWatcher(busAttachment);

            // Subscribe to watcher added event - to watch for any producers with LampState interface.
            watcher.Added += Watcher_Added;

            // Start the LampState watcher.
            watcher.Start();
            setUpLightSensor();
        }
Ejemplo n.º 9
0
        private async void LampStateWatcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status != AllJoynStatus.Ok)
            {
                return;
            }

            // success
            _lampStateConsumers.Add(joinResult.Consumer);
            await SetLampColorAsync(joinResult.Consumer);

            System.Diagnostics.Debug.WriteLine("LampStateConsumer successfully added.");
        }
Ejemplo n.º 10
0
        private void FindLamp()
        {
            LampStateWatcher watcher = new LampStateWatcher(new AllJoynBusAttachment());

            watcher.Added += async(sender, args) =>
            {
                var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

                if (joinResult.Status == AllJoynStatus.Ok)
                {
                    this._lamp   = joinResult.Consumer;
                    txtLamp.Text = "LIFX Color 1000 BR30: найдена";
                }
                ;
            };
            watcher.Start();
        }
Ejemplo n.º 11
0
        private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.Write("Watcher_Added");

            string name = args.UniqueName;

            var session = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (session.Status == AllJoynStatus.Ok)
            {
                AllJoynAboutDataView about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, bus, args.SessionPort);

                if (about != null)
                {
                    FoundLight(session.Consumer, about);
                }
            }
        }
Ejemplo n.º 12
0
        private async void LampFound(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Lamp found, attempt to join session..");

            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lampState = joinResult.Consumer;
                Debug.WriteLine("Consumer has been susccessfully initialized");

                await _lampState.SetOnOffAsync(PowerSwitch.IsOn);
                await _lampState.SetBrightnessAsync(/* 10% */ Convert.ToUInt32(UInt32.MaxValue * 0.1));
            }
            else
            {
                Debug.WriteLine("Ubable to join session");
            }
        }
Ejemplo n.º 13
0
        private async void LampStateWatcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, _lampStateBusAttachment, args.SessionPort);

            if (aboutData.Manufacturer.ToLower().Contains("philips"))
            {
                var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

                if (joinResult.Status == AllJoynStatus.Ok)
                {
                    _lampStateConsumer              = joinResult.Consumer;
                    _lampStateConsumer.SessionLost += this.Consumer_SessionLost;

                    // subscribe to value changes
                    _lampStateConsumer.Signals.LampStateChangedReceived += this.lampStateConsumer_LampStateChangedReceived;

                    // populate initial values
                    this.GetCurrentValuesAsync();

                    this.IsConnected = true;
                }
            }
        }
Ejemplo n.º 14
0
        private async void LampStateWatcher_Added(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinResult.Status != AllJoynStatus.Ok)
            {
                return;
            }

            // success
            var consumer = (LampStateConsumer)joinResult.Consumer;

            consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived;
            _lampStateConsumers.Add(consumer);

            try
            {
                await SetLampStateAsync();
            }
            catch { } // TODO: For some reason this sometimes blows up during startup. Investigate better way to handle.

            System.Diagnostics.Debug.WriteLine("LampStateConsumer successfully added.");
        }
Ejemplo n.º 15
0
        private async void LampFound(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Attempt to join session..");

            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            AJNetwork.Mode   = BindingMode.OneTime;
            AJNetwork.Source = "Test Network";
            //Debug.WriteLine(AJnetworkData.AppId.ToString(), "AppID");


            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lampState = joinResult.Consumer;
                Debug.WriteLine("Consumer has been susccessfully initialized");
                await _lampState.SetOnOffAsync(true);

                PowerSwitch.IsOn = true;
            }
            else
            {
                Debug.WriteLine("Join session has failed");
            }
        }
Ejemplo n.º 16
0
        private async void OnWatcherAdded(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            LampStateJoinSessionResult joinSessionResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            if (joinSessionResult.Status == AllJoynStatus.Ok)
            {
                Consumers.Add(args.UniqueName,joinSessionResult.Consumer);
                joinSessionResult.Consumer.SessionLost += OnConsumerSessionLost;
                if(_lastValues != null)
                {
                    await SetValuesAsync(joinSessionResult.Consumer, _lastValues);
                }
                Debug.WriteLine("New Lamp joined. ID:" + args.UniqueName + " Lamp count: " + Consumers.Count);
                if (NewEventReceived != null)
                {
                    NewEventReceived(this, "New Lamp joined. ID:" + args.UniqueName + " Lamp count: " + Consumers.Count);
                }
            }
        }
Ejemplo n.º 17
0
 protected override void OnStart()
 {
     _lampStateWatcher        = new LampStateWatcher(this.CreateBusAttachment(ref _lampStateBusAttachment));
     _lampStateWatcher.Added += this.LampStateWatcher_Added;
     _lampStateWatcher.Start();
 }
Ejemplo n.º 18
0
        private async void LampFound(LampStateWatcher sender, AllJoynServiceInfo args)
        {
            Debug.WriteLine("Attempt to join session..");

            var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender);

            AJNetwork.Mode = BindingMode.OneTime;
            AJNetwork.Source = "Test Network";
            //Debug.WriteLine(AJnetworkData.AppId.ToString(), "AppID");
          

            if (joinResult.Status == AllJoynStatus.Ok)
            {
                _lampState = joinResult.Consumer;
                Debug.WriteLine("Consumer has been susccessfully initialized");
                await _lampState.SetOnOffAsync(true);
                PowerSwitch.IsOn = true;

            }
            else
            {
                Debug.WriteLine("Join session has failed");
            }
        }