private async void btnMute_Click(object sender, RoutedEventArgs e) { await Task.Run(async() => { try { rv.PJLinkConnection c = connectBeamer(); AVMuteCommand qcmd = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE); if (await c.sendCommand(qcmd) == Command.Response.SUCCESS) { AVMuteCommand acmd; if (qcmd.Status == AVMuteCommand.Action.MUTE) { acmd = new AVMuteCommand(AVMuteCommand.Action.UNMUTE); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _timerMuteBlink.Stop(); btnMute.Background = btndefBack; }); } else { acmd = new AVMuteCommand(AVMuteCommand.Action.MUTE); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _timerMuteBlink.Start(); }); } await c.sendCommand(acmd); } } catch (Exception) { } }); }
async void _timerPowerCheck_Elapsed(object source, object e) { await Task.Run(async() => { try { rv.PJLinkConnection c = connectBeamer(); PowerCommand.PowerStatus powStat = PowerCommand.PowerStatus.UNKNOWN; try { powStat = await c.powerQuery(); } catch (Exception) { try { powStat = await c.powerQuery(); } catch (Exception) { } } switch (powStat) { case PowerCommand.PowerStatus.OFF: case PowerCommand.PowerStatus.COOLING: case PowerCommand.PowerStatus.UNKNOWN: await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.btnPwr.Background = btndefBack; this.btnMute.IsEnabled = false; _startupRoundCntr++; if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && powStat != PowerCommand.PowerStatus.UNKNOWN) { _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min _startupRoundCntr = 0; _timerPowerBlink.Stop(); this.btnPwr.Background = btndefBack; } }); break; case PowerCommand.PowerStatus.ON: case PowerCommand.PowerStatus.WARMUP: await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { this._timerPowerBlink.Stop(); this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen); this.btnMute.IsEnabled = true; AVMuteCommand qcmd = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE); if (await c.sendCommand(qcmd) == Command.Response.SUCCESS) { if (qcmd.Status == AVMuteCommand.Action.MUTE) { _timerMuteBlink.Start(); } else { _timerMuteBlink.Stop(); btnMute.Background = btndefBack; } } _startupRoundCntr++; if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && _startupRoundCntr == 10) { _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min _startupRoundCntr = 0; _timerPowerBlink.Stop(); this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen); } }); break; } await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (_timerPowerCheck.Interval == new TimeSpan(0, 0, 5) && _startupRoundCntr == 10) { _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min _startupRoundCntr = 0; _timerPowerBlink.Stop(); this.btnPwr.Background = btndefBack; } }); } catch (Exception) { } }); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { if (!LoadConfig()) { tmrTimer.Stop(); txtTime.Text = "Invalid Config"; btnMute.Visibility = Visibility.Collapsed; btnPwr.Visibility = Visibility.Collapsed; btnInfo.Visibility = Visibility.Collapsed; } btndefBack = btnPwr.Background; // Hook up the Elapsed event for the timer. _timerMuteBlink.Tick += _timerMuteBlink_Elapsed; // Set the Interval to 0.5 seconds (500 milliseconds). _timerMuteBlink.Interval = new TimeSpan(0, 0, 0, 0, 500); _timerPowerCheck.Tick += _timerPowerCheck_Elapsed; _timerPowerCheck.Interval = new TimeSpan(0, 1, 0); // 1min _timerPowerCheck.Start(); _timerPowerBlink.Tick += _timerPowerBlink_Elapsed; _timerPowerBlink.Interval = new TimeSpan(0, 0, 0, 0, 500); // 0.5sec rv.PJLinkConnection c = connectBeamer(); PowerCommand.PowerStatus powStat = PowerCommand.PowerStatus.UNKNOWN; try { powStat = await c.powerQuery(); } catch (Exception) { try { powStat = await c.powerQuery(); } catch (Exception) { } } switch (powStat) { case PowerCommand.PowerStatus.OFF: case PowerCommand.PowerStatus.COOLING: case PowerCommand.PowerStatus.UNKNOWN: this.btnPwr.Background = btndefBack; this.btnMute.IsEnabled = false; break; case PowerCommand.PowerStatus.ON: case PowerCommand.PowerStatus.WARMUP: this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen); this.btnMute.IsEnabled = true; try { AVMuteCommand qcmd = new AVMuteCommand(AVMuteCommand.Action.QUERYSTATE); if (await c.sendCommand(qcmd) == Command.Response.SUCCESS) { if (qcmd.Status == AVMuteCommand.Action.MUTE) { _timerMuteBlink.Start(); } else { _timerMuteBlink.Stop(); } } } catch (Exception) { } break; } }