Ejemplo n.º 1
0
 public void PowerOn()
 {
     if (_connection.turnOn()) {
         _powerStatus = PowerCommand.PowerStatus.ON;
     }
     else {
         _powerStatus = PowerCommand.PowerStatus.UNKNOWN;
     }
 }
        private async void btnPwr_Click(object sender, RoutedEventArgs e)
        {
            await Task.Run(async() =>
            {
                try
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        this.btnPwr.Background = new SolidColorBrush(Colors.LawnGreen);
                        this.btnMute.IsEnabled = false;
                        _timerPowerBlink.Start();
                    });

                    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 c.turnOn();
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            _timerPowerCheck.Interval = new TimeSpan(0, 0, 5);     //10 sec;
                        });

                        break;

                    case PowerCommand.PowerStatus.ON:
                    case PowerCommand.PowerStatus.WARMUP:
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            this.btnPwr.Background = btndefBack;
                            this.btnMute.IsEnabled = false;
                            _timerMuteBlink.Stop();
                            _timerPowerBlink.Stop();
                            btnMute.Background = btndefBack;
                        });
                        await c.turnOff();
                        break;
                    }
                }
                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;
            }
        }
Ejemplo n.º 5
0
 public void PowerOn()
 {
     _powerStatus = Network.WakeOnLan.WakeUp(MAC) ? PowerCommand.PowerStatus.ON : PowerCommand.PowerStatus.UNKNOWN;
 }
Ejemplo n.º 6
0
 public void PowerOff()
 {
     _powerStatus = Wmi.Util.ShutdownHost(IP) == Wmi.Util.ShutdownResult.SUCCESS ? PowerCommand.PowerStatus.OFF : PowerCommand.PowerStatus.UNKNOWN;
 }