/// <summary> /// Load external channel configurations. /// </summary> internal static void LoadExternalConfigs() { IList <Card> cards = Card.ListAll(); if (cards.Count == 0) { Log.Info("Cannot load external channel configurations, there are no TV cards registered"); Card dummyCard = new Card(0, "device path", "Dummy TV Card", 0, false, DateTime.Now, "recording folder", 0, false, 0, "timeshifting folder", 0, 0, false, false, false, 0); cards.Add(dummyCard); } _externalChannelConfigs = new ExternalChannelConfig[cards.Count]; int index = 0; foreach (Card card in cards) { string fileName = Path.Combine(ExtCfgFolder, String.Format("ExternalChannelConfig{0}.xml", card.IdCard)); try { _externalChannelConfigs[index] = ExternalChannelConfig.Load(fileName); } catch (Exception ex) { _externalChannelConfigs[index] = new ExternalChannelConfig(fileName); Log.Error(ex.ToString()); } _externalChannelConfigs[index].CardId = card.IdCard; index++; } }
public void SetToConfig(int cardId) { ExternalChannelConfig config = TV3BlasterPlugin.GetExternalChannelConfig(cardId); config.CardId = cardId; config.PauseTime = Decimal.ToInt32(numericUpDownPauseTime.Value); config.SendSelect = checkBoxSendSelect.Checked; config.DoubleChannelSelect = checkBoxDoubleSelect.Checked; config.RepeatChannelCommands = Decimal.ToInt32(numericUpDownRepeat.Value); int chDigits = comboBoxChDigits.SelectedIndex; if (chDigits > 0) { chDigits++; } config.ChannelDigits = chDigits; config.RepeatPauseTime = Decimal.ToInt32(numericUpDownRepeatDelay.Value); config.UsePreChangeCommand = checkBoxUsePreChange.Checked; config.SelectCommand = listViewExternalCommands.Items[10].SubItems[1].Text; config.PreChangeCommand = listViewExternalCommands.Items[11].SubItems[1].Text; for (int i = 0; i < 10; i++) { config.Digits[i] = listViewExternalCommands.Items[i].SubItems[1].Text; } }
public void SetToCard(int cardId) { ExternalChannelConfig config = TV3BlasterPlugin.GetExternalChannelConfig(cardId); if (config == null) { MessageBox.Show(this, "You must save your card configurations before copying between card setups", "No saved configration to copy from", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Setup command list. for (int i = 0; i < 10; i++) { listViewExternalCommands.Items[i].SubItems[1].Text = config.Digits[i]; } listViewExternalCommands.Items[10].SubItems[1].Text = config.SelectCommand; listViewExternalCommands.Items[11].SubItems[1].Text = config.PreChangeCommand; // Setup options. numericUpDownPauseTime.Value = config.PauseTime; checkBoxSendSelect.Checked = config.SendSelect; checkBoxDoubleSelect.Checked = config.DoubleChannelSelect; numericUpDownRepeat.Value = config.RepeatChannelCommands; checkBoxDoubleSelect.Enabled = checkBoxSendSelect.Checked; int channelDigitsSelect = config.ChannelDigits; if (channelDigitsSelect > 0) { channelDigitsSelect--; } comboBoxChDigits.SelectedIndex = channelDigitsSelect; checkBoxUsePreChange.Checked = config.UsePreChangeCommand; numericUpDownRepeatDelay.Value = new Decimal(config.RepeatPauseTime); }
/// <summary> /// Load external channel configurations. /// </summary> private static void LoadExternalConfigs() { ArrayList cards = new ArrayList(); TVDatabase.GetCards(ref cards); if (cards.Count == 0) { Log.Warn("TV2BlasterPlugin: Cannot load external channel configurations, there are no TV cards registered"); cards.Add(0); } _externalChannelConfigs = new ExternalChannelConfig[cards.Count]; int index = 0; foreach (int cardId in cards) { string fileName = Path.Combine(ExtCfgFolder, String.Format("ExternalChannelConfig{0}.xml", cardId)); try { _externalChannelConfigs[index] = ExternalChannelConfig.Load(fileName); } catch (Exception ex) { Log.Error(ex); _externalChannelConfigs[index] = new ExternalChannelConfig(fileName); } _externalChannelConfigs[index].CardId = cardId; index++; } }
/// <summary> /// Processes the external channel. /// </summary> /// <param name="args">Integer array of parameters.</param> private static void ProcessExternalChannel(object args) { try { int[] data = args as int[]; if (data == null) { throw new ArgumentException("Parameter is not of type int[]", "args"); } ExternalChannelConfig config = GetExternalChannelConfig(data[1]); if (config == null) { throw new InvalidOperationException(String.Format("External channel config for card \"{0}\" not found", data[1])); } // Clean up the "data[0]" string into "channel". StringBuilder channel = new StringBuilder(); foreach (char digit in data[0].ToString()) { if (char.IsDigit(digit)) { channel.Append(digit); } } // Pad the channel number with leading 0's to meet ChannelDigits length. while (channel.ToString().Length < config.ChannelDigits) { channel.Insert(0, '0'); } // Process the channel and blast the relevant IR Commands. string channelString = channel.ToString(); for (int repeatCount = 0; repeatCount <= config.RepeatChannelCommands; repeatCount++) { string command; if (repeatCount > 0 && config.RepeatPauseTime > 0) { Thread.Sleep(config.RepeatPauseTime); } if (config.UsePreChangeCommand) { command = config.PreChangeCommand; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, -1, channelString); if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } } } foreach (char digit in channelString) { int charVal = digit - 48; command = config.Digits[charVal]; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, charVal, channelString); if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } } } if (config.SendSelect) { command = config.SelectCommand; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, -1, channelString); if (config.DoubleChannelSelect) { if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } ProcessExternalCommand(command, -1, channelString); } } } } } catch (Exception ex) { Log.Error(ex.ToString()); } }
/// <summary> /// Processes the external channel. /// </summary> /// <param name="args">String array of parameters.</param> private static void ProcessExternalChannel(object args) { try { string[] data = args as string[]; if (data == null) { throw new ArgumentException("Parameter is not of type string[]", "args"); } int card = int.Parse(data[1]); // To work around a known problem in MediaPortal scheduled recording if (card < 0) { card = _externalChannelConfigs[0].CardId; Log.Warn( "TV2BlasterPlugin: MediaPortal reports invalid TV Card ID ({0}), using STB settings for first TV Card ({1})", data[1], card); } else { card++; } ExternalChannelConfig config = GetExternalChannelConfig(card); // Clean up the "data[0]" string into "channel". StringBuilder channel = new StringBuilder(); foreach (char digit in data[0]) { if (char.IsDigit(digit)) { channel.Append(digit); } } // Pad the channel number with leading 0's to meet ChannelDigits length. while (channel.Length < config.ChannelDigits) { channel.Insert(0, '0'); } // Process the channel and blast the relevant IR Commands. string channelString = channel.ToString(); for (int repeatCount = 0; repeatCount <= config.RepeatChannelCommands; repeatCount++) { string command; if (repeatCount > 0 && config.RepeatPauseTime > 0) { Thread.Sleep(config.RepeatPauseTime); } if (config.UsePreChangeCommand) { command = config.PreChangeCommand; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, -1, channelString); if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } } } foreach (char digit in channelString) { int charVal = digit - 48; command = config.Digits[charVal]; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, charVal, channelString); if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } } } if (config.SendSelect) { command = config.SelectCommand; if (!String.IsNullOrEmpty(command)) { ProcessExternalCommand(command, -1, channelString); if (config.DoubleChannelSelect) { if (config.PauseTime > 0) { Thread.Sleep(config.PauseTime); } ProcessExternalCommand(command, -1, channelString); } } } } } catch (Exception ex) { Log.Error(ex); } }