Esempio n. 1
0
        private void channelScanWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int numChannels = this.MaxChannel.PhysicalChannel - this.MinChannel.PhysicalChannel;
            IVirtualChannelProvider _virtualChannelTuner = this as IVirtualChannelProvider;

            for (int i = this.MinChannel.PhysicalChannel; i <= this.MaxChannel.PhysicalChannel; i++)
            {
                if (CheckScanCanceled(e))
                {
                    return;
                }

                this.SetChannel(new Channel(i));
                Thread.Sleep(500);

                if (CheckScanCanceled(e))
                {
                    return;
                }

                int str = this.GetSignalStrength();
                AppLogger.Message("Try channel : " + i + " str=" + str);
                if (str != 0)
                {
                    Channel actual = this.GetChannel();
                    if (actual.MajorChannel != -1)
                    {
                        if (_virtualChannelTuner != null)
                        {
                            List <Channel> virtualChannels = _virtualChannelTuner.GetVirtualChannels();
                            foreach (Channel ch in virtualChannels)
                            {
                                if ((ch.MajorChannel == actual.MajorChannel) && (ch.MinorChannel > 0))
                                {
                                    ch.CarrierFrequency = actual.CarrierFrequency;
                                    _foundChannels.Add(ch);
                                }
                            }
                        }
                        else
                        {
                            _foundChannels.Add(actual);
                        }
                    }
                }

                if (CheckScanCanceled(e))
                {
                    return;
                }
                channelScanWorker.ReportProgress((int)(((double)(i - this.MinChannel.PhysicalChannel) / (double)numChannels) * 100));
            }
        }
Esempio n. 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            _timer.Enabled = false;
            int str = _baseTuner.GetSignalStrength();

            Debug.WriteLine("Channel " + _current.ToString() + " Str: " + str.ToString());
            if (str != 0)
            {
                Channel actual = _baseTuner.TryChannel;
                if (actual != null)
                {
                    Debug.WriteLine("actually found channel: " + actual.ToDebugString());
                    if (_virtualChannelTuner != null)
                    {
                        List <Channel> virtualChannels = _virtualChannelTuner.GetVirtualChannels();
                        foreach (Channel ch in virtualChannels)
                        {
                            _channelList.Add(ch);
                        }
                    }
                    else
                    {
                        _channelList.Add(actual);
                    }
                    _channelList.DumpToDebug();
                }
            }

            if (Current.Equals(_max))
            {
                Stop();

                _baseTuner.KnownChannels = this.FoundChannels;

                if (_baseTuner.KnownChannels.Count > 0)
                {
                    _baseTuner.Channel = _baseTuner.KnownChannels.Items[0];
                }

                if (ChannelScanComplete != null)
                {
                    ChannelScanComplete.Invoke(this, new ChannelScanCompleteEventArgs(_channelList.Count));
                }
            }
            else
            {
                Current = new Channel(Current.PhysicalChannel + 1);
                _baseTuner.TryChannel = Current;
                curChannelCount++;
                if (ChannelScanProgressUpdate != null)
                {
                    this.ChannelScanProgress = (int)(((double)curChannelCount / (double)totalChannels) * 100.0);
                    ChannelScanProgressUpdate.Invoke(this, new EventArgs());
                }

                if (!_channelScanCancelled)
                {
                    _timer.Enabled = true;
                }
            }
        }