static async Task <Lamp> GetLamp() { if (CurrentLamp == null) { CurrentLamp = await Lamp.GetDefaultAsync().AsTask(); } return(CurrentLamp); }
public async void GetDefaultLamp() { //<SnippetGetDefaultLamp> lamp = await Lamp.GetDefaultAsync(); if (lamp == null) { ShowErrorMessage("No Lamp device found"); return; } //</SnippetGetDefaultLamp> }
public async void AvailabilityChanged() { //<SnippetAvailabilityChanged> lamp = await Lamp.GetDefaultAsync(); if (lamp == null) { ShowErrorMessage("No Lamp device found"); return; } lamp.AvailabilityChanged += Lamp_AvailabilityChanged; //</SnippetAvailabilityChanged> }
public async Task OnOf() { Lamp lamp = await Lamp.GetDefaultAsync(); if (lamp == null) { throw new Exception("Не удалось получить доступ к фонарику"); } lamp.IsEnabled = !lamp.IsEnabled; //if (lamp.IsEnabled == false) { // lamp.Dispose(); // lamp = null; //} }
private async void Generate() { morsecode.WPM = (int)WPMSlider.Value; morsecode.IsLoop = IsLoop.IsOn; if (SoundSignal.IsSelected) { Player.Stop(); btnGenerate.Content = "Stop"; btnSave.Visibility = Visibility.Collapsed; Player.IsLooping = IsLoop.IsOn; int[] durations = null; bool[] levels = null; morsecode.Synthesize(textbox1.Text, out durations, out levels); StorageFolder tempfolder = ApplicationData.Current.TemporaryFolder; int j = await Sound.SynthesizeAsync(durations, levels, tempfolder.Path.ToString() + "\\MORSECODE.wav"); Windows.Storage.StorageFile file = await tempfolder.GetFileAsync("MORSECODE.wav"); var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Player.SetSource(stream, file.ContentType); } else { if (lamp == null) { lamp = await Lamp.GetDefaultAsync(); } Player.Stop(); ButtonsStackPanel.Visibility = Visibility.Collapsed; textbox1.Visibility = Visibility.Collapsed; ControlsStackPanel.Visibility = Visibility.Collapsed; TitleTextBlock.Visibility = Visibility.Collapsed; btnStop.Visibility = Visibility.Visible; int i = await morsecode.PlayAsync(textbox1.Text); CleanUP(); } }
static async Task LedSetting(string led, string cmd) { if (lamp == null) { lamp = await Lamp.GetDefaultAsync(); } Console.WriteLine("Lamp ID:{0}", lamp.DeviceId.ToString()); if (lamp != null) { //compare Led color foreach (var color in typeof(Colors).GetProperties()) { if (led.ToLower().Contains(color.Name.ToLower())) { //for up have to set color every time then you can trun on/off correctly lamp.Color = (Color)color.GetValue(new Color(), null); if (cmd.ToLower().Contains("on")) { lamp.IsEnabled = true; } else if (cmd.ToLower().Contains("off")) { lamp.IsEnabled = false; } else if (cmd.ToLower().Contains("get")) { Console.WriteLine("{0} LED is {1}", led, lamp.IsEnabled ? "on" : "off"); } else { Console.WriteLine("unknow command {0}", cmd); return; } Console.WriteLine("set {0} {1}", lamp.Color.ToString(), cmd); } } } }
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); }