Ejemplo n.º 1
0
        public async void GetLampUsingSelectionString()
        {
            //<SnippetGetLampWithSelectionString>
            string selectorString = Lamp.GetDeviceSelector();


            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selectorString);

            DeviceInformation deviceInfo =
                devices.FirstOrDefault(di => di.EnclosureLocation != null &&
                                       di.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            if (deviceInfo == null)
            {
                ShowErrorMessage("No Lamp device found");
            }

            lamp = await Lamp.FromIdAsync(deviceInfo.Id);

            //</SnippetGetLampWithSelectionString>
        }
        private static async void EnableFlashlightAsync(WSANativeColour colour = null)
        {
            string selectorString = Lamp.GetDeviceSelector();

            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selectorString);

            DeviceInformation deviceInfo =
                devices.FirstOrDefault(di => di.EnclosureLocation != null &&
                                       di.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            if (deviceInfo != null)
            {
                _lamp = await Lamp.FromIdAsync(deviceInfo.Id);

                if (_lamp.IsColorSettable && colour != null)
                {
                    _lamp.Color = Windows.UI.Color.FromArgb(255, colour.Red, colour.Green, colour.Blue);
                }

                _lamp.IsEnabled = true;
            }
        }
Ejemplo n.º 3
0
        static async Task FindLampAsync()
        {
            // fail fast
            if (hasLoadedLamp)
            {
                return;
            }

            Monitor.Enter(locker);

            // we may have loaded it while this was waiting to enter
            if (hasLoadedLamp)
            {
                return;
            }

            // find all the lamps
            var selector = Lamp.GetDeviceSelector();
            var allLamps = await DeviceInformation.FindAllAsync(selector);

            // find all the back lamps
            var lampInfo = allLamps.FirstOrDefault(di => di.EnclosureLocation?.Panel == Panel.Back);

            if (lampInfo != null)
            {
                // get the lamp
                lamp = await Lamp.FromIdAsync(lampInfo.Id);
            }
            else
            {
                // if there is no back lamp, use the default lamp
                lamp = await Lamp.GetDefaultAsync();
            }

            hasLoadedLamp = true;
            Monitor.Exit(locker);
        }