// metodo especifico para o controle de intensidade dos leds individuais pela cortana public void sliderValorCortana1(string lampada, string valor) { var led = new Led(); int valorReal = int.Parse(valor); if (lampada == "one" || lampada == "One") { if (valorSl1.Value == 0 && botao1.Content.ToString() == "OFF") botao1.Content = "ON"; if (valorSl1.Value != 0 && botao1.Content.ToString() == "ON" && valorReal != 0) botao1.Content = "ON"; if (valorSl1.Value != 0 && botao1.Content.ToString() == "ON" && valorReal == 0) botao1.Content = "OFF"; led.ledIntensidade(valor); retornoValor1.Text = valor; valorSl1.Value = int.Parse(valor); } else if (lampada == "two" || lampada == "Two") { if (valorSl2.Value == 0 && botao2.Content.ToString() == "OFF") botao2.Content = "ON"; if (valorSl2.Value != 0 && botao2.Content.ToString() == "ON" && valorReal != 0) botao2.Content = "ON"; if (valorSl2.Value != 0 && botao2.Content.ToString() == "ON" && valorReal == 0) botao2.Content = "OFF"; valorReal = led.converteIntensidade(valor); led.ledIntensidade2(valor); valorSl2.Value = valorReal; } else if (lampada == "three" || lampada == "Three") { if (valorSl3.Value == 0 && botao3.Content.ToString() == "OFF") botao3.Content = "ON"; if (valorSl3.Value != 0 && botao3.Content.ToString() == "ON" && valorReal != 0) botao3.Content = "ON"; if (valorSl3.Value != 0 && botao3.Content.ToString() == "ON" && valorReal == 0) botao3.Content = "OFF"; valorReal = led.converteIntensidade(valor); led.ledIntensidade3(valor); valorSl3.Value = valorReal; } }
public async void requisitaJson() { Led led = new Led(); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.TryParseAdd("application/json"); string ResponseString = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_1")); //Requisições para verificar status dos led quando abrir o aplicativo ObjetoJson converteJson = JsonConvert.DeserializeObject<ObjetoJson>(ResponseString); if (converteJson.led_1 == "1") { botao1.Content = "ON"; valorSl1.Value = 100; } else if (converteJson.led_1 != "0" && converteJson.led_1 != "255") { botao1.Content = "ON"; valorSl1.Value = led.converteIntensidadeSlider(int.Parse(converteJson.led_1)); } else if (converteJson.led_1 == "0") { botao1.Content = "OFF"; } //REQUISIÇÃO DO LED 2 string ResponseString2 = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_2")); ObjetoJson converteJson2 = JsonConvert.DeserializeObject<ObjetoJson>(ResponseString2); if(converteJson2.led_2 == "1") { botao2.Content = "ON"; botao2.DataContext = "ON"; valorSl2.Value = 100; } else if (converteJson2.led_2 != "0" && converteJson2.led_2 != "255") { botao2.Content = "ON"; valorSl2.Value = led.converteIntensidadeSlider(int.Parse(converteJson2.led_2)); } else if(converteJson2.led_2 == "0") { botao2.Content = "OFF"; } //REQUISIÇÃO DO LED 3 string ResponseString3 = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_3")); ObjetoJson converteJson3 = JsonConvert.DeserializeObject<ObjetoJson>(ResponseString3); if (converteJson3.led_3 == "1") { botao3.Content = "ON"; valorSl3.Value = 100; } else if (converteJson3.led_3 != "0" && converteJson3.led_3 != "255") { botao3.Content = "ON"; valorSl3.Value = led.converteIntensidadeSlider(int.Parse(converteJson3.led_3)); } else if (converteJson3.led_3 == "0") { botao3.Content = "OFF"; } if (converteJson.led_1 == "1" && converteJson2.led_2 == "1" && converteJson3.led_3 == "1") bLDALL.Content = "TUDO LIGADO"; }
//metodo para ligar e desligar tudo public async void botaoLigaDesligaTudo() { Led led = new Led(); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.TryParseAdd("application/json"); string responseString = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_1")); string responseString2 = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_2")); string responseString3 = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_3")); //Requisições ObjetoJson converteJson = JsonConvert.DeserializeObject<ObjetoJson>(responseString); ObjetoJson converteJson2 = JsonConvert.DeserializeObject<ObjetoJson>(responseString2); ObjetoJson converteJson3 = JsonConvert.DeserializeObject<ObjetoJson>(responseString3); if(converteJson.led_1 == "1" && converteJson2.led_2 == "1" && converteJson3.led_3 == "1") { led.ofALL(0); bLDALL.Content = "TUDO APAGADO"; valorSl1.Value = 0; valorSl2.Value = 0; valorSl3.Value = 0; } else { led.ofALL(1); string nome = "TUDO LIGADO"; bLDALL.Content = nome; valorSl1.Value = 100; valorSl2.Value = 100; valorSl3.Value = 100; } }
// metodo especifico para o controle de intensidade de todos os leds pela cortana public void intensidadeTudoCortana(string valor) { var led = new Led(); led.ledIntensidadeCortana(valor); }
//evento para manipulação do slider para o acionamento da intensidade do led - botao 3 private void sliderValor3(object sender, RangeBaseValueChangedEventArgs e) { string valor; valor = valorSl3.Value.ToString(); var led = new Led(); if (valorSl3.Value != 0 && botao3.Content.ToString() == "OFF") botao3.Content = "ON"; if (valorSl3.Value == 0 && botao3.Content.ToString() == "ON") botao3.Content = "OFF"; led.ledIntensidade3(valor); retornoValor3.Text = valor; }
public void bLigaDesliga3() { var led = new Led(); string retornoValor; if (botao3.Content.ToString() == "OFF") { botao3.Content = "ON"; retornoValor = led.ligaLed3().ToString(); valorSl3.Value = 100; } else { botao3.Content = "OFF"; retornoValor = led.desligaLed3().ToString(); valorSl3.Value = 0; } }
public void bLigaDesliga2() { var led = new Led(); if (botao2.Content.ToString() == "OFF") { botao2.Content = "ON"; led.ligaLed2(); valorSl2.Value = 100; } else { botao2.Content = "OFF"; led.desligaLed2(); valorSl2.Value = 0; } }
//metodo para acionar led 1 public async void bLigaDesliga() { var led = new Led(); HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.TryParseAdd("application/json"); string ResponseString = await httpClient.GetStringAsync(new Uri("http://192.168.0.15/led_1")); //Requisições ObjetoJson converteJson = JsonConvert.DeserializeObject<ObjetoJson>(ResponseString); if(converteJson.led_1 == "1") { botao1.Content = "OFF"; led.desligaLed(); valorSl1.Value = 0; } else { botao1.Content = "ON"; led.ligaLed(); valorSl1.Value = 100; } }
protected override void OnActivated(IActivatedEventArgs e) { // Handle when app is launched by Cortana if (e.Kind == ActivationKind.VoiceCommand) { VoiceCommandActivatedEventArgs commandArgs = e as VoiceCommandActivatedEventArgs; SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; string voiceCommandName = speechRecognitionResult.RulePath[0]; string textSpoken = speechRecognitionResult.Text; IReadOnlyList<string> recognizedVoiceCommandPhrases; // instanciando objeto para executar as funções Led led = new Led(); MainPage mPage = new MainPage(); System.Diagnostics.Debug.WriteLine("voiceCommandName: " + voiceCommandName); System.Diagnostics.Debug.WriteLine("textSpoken: " + textSpoken); Window.Current.Activate(); switch (voiceCommandName) { // Ligando todos os Leds case "Active_Light": System.Diagnostics.Debug.WriteLine("Activate_Light command"); mPage.botaoLigaDesligaTudo(); break; // Desligando todas os leds case "Disabling_Light": System.Diagnostics.Debug.WriteLine("Disabling_light command"); mPage.botaoLigaDesligaTudo(); break; // Ascendendo um Led case "Active_One_Lamp": System.Diagnostics.Debug.WriteLine("Active_One_Lamp command"); string lampada; if (speechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("lampada", out recognizedVoiceCommandPhrases)) { lampada = recognizedVoiceCommandPhrases.First(); if (lampada.ToString() == "one" || lampada.ToString() == "One") mPage.bLigaDesliga(); //led.ligaLed(); else if (lampada.ToString() == "two" || lampada.ToString() == "Two") mPage.bLigaDesliga2(); else mPage.bLigaDesliga3(); } break; // Desligando um Led case "Disabling_Lamp": string lampada_desligada; if (speechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("lampada", out recognizedVoiceCommandPhrases)) { lampada_desligada = recognizedVoiceCommandPhrases.First(); if (lampada_desligada.ToString() == "one" || lampada_desligada.ToString() == "One") mPage.bLigaDesliga(); else if (lampada_desligada.ToString() == "two" || lampada_desligada.ToString() == "Two") mPage.bLigaDesliga2(); else mPage.bLigaDesliga3(); } break; // Intensidade de leds individuais case "Brightness_One_Lamp": string valorIntensidade; if (speechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("numero_intensidade", out recognizedVoiceCommandPhrases)) { valorIntensidade = recognizedVoiceCommandPhrases.First(); if (speechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("lampada", out recognizedVoiceCommandPhrases)) { lampada_desligada = recognizedVoiceCommandPhrases.First(); if (lampada_desligada.ToString() == "one" || lampada_desligada.ToString() == "One") mPage.sliderValorCortana1(lampada_desligada, valorIntensidade); else if (lampada_desligada.ToString() == "two" || lampada_desligada.ToString() == "Two") mPage.sliderValorCortana1(lampada_desligada, valorIntensidade); else if (lampada_desligada.ToString() == "three" || lampada_desligada.ToString() == "Three") mPage.sliderValorCortana1(lampada_desligada, valorIntensidade); } } break; // Intensidade de todas as lampdas case "Brightness_All_Lamps" : string valorIntensidade2; if (speechRecognitionResult.SemanticInterpretation.Properties.TryGetValue("numero_intensidade", out recognizedVoiceCommandPhrases)) { valorIntensidade2 = recognizedVoiceCommandPhrases.First(); mPage.intensidadeTudoCortana(valorIntensidade2); } break; // Valor Default default: System.Diagnostics.Debug.WriteLine("Unknown command"); break; } } }