CecTray: display a warning if we can't poll the TV
[deb_libcec.git] / src / LibCecTray / controller / CECController.cs
index f7a3a04fb37dec7777e6c2ce78cbc6d58247817c..6db226790f1ff7adb0036c1c97708b122bd23b00 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the libCEC(R) library.
  *
- * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited.  All rights reserved.
  * libCEC(R) is an original work, containing original code.
  *
  * libCEC(R) is a trademark of Pulse-Eight Limited.
@@ -203,6 +203,11 @@ namespace LibCECTray.controller
     /// </summary>
     public void Initialise()
     {
+      // only load once
+      if (_initialised)
+        return;
+      _initialised = true;
+
       CECActions.ConnectToDevice(Config);
       Applications.Initialise(this);
     }
@@ -215,6 +220,7 @@ namespace LibCECTray.controller
       Lib.DisableCallbacks();
       Lib.StandbyDevices(CecLogicalAddress.Broadcast);
       Lib.Close();
+      _initialised = false;
     }
 
     /// <summary>
@@ -361,6 +367,32 @@ namespace LibCECTray.controller
       return 1;
     }
 
+    public override int ReceiveAlert(CecAlert alert, CecParameter data)
+    {
+      switch (alert)
+      {
+        case CecAlert.ServiceDevice:
+          MessageBox.Show(Resources.alert_service_device, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+        case CecAlert.ConnectionLost:
+          MessageBox.Show(Resources.alert_connection_lost, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+        case CecAlert.PermissionError:
+          MessageBox.Show(Resources.alert_permission_error, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+        case CecAlert.PortBusy:
+          MessageBox.Show(Resources.alert_port_busy, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+        case CecAlert.PhysicalAddressError:
+          MessageBox.Show(Resources.alert_physical_address_error, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+        case CecAlert.TVPollFailed:
+          MessageBox.Show(Resources.alert_tv_poll_failed, Resources.cec_alert, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+          break;
+      }
+      return 1;
+    }
+
     public override int ConfigurationChanged(LibCECConfiguration config)
     {
       Settings.PhysicalAddress.Value = Config.PhysicalAddress;
@@ -438,7 +470,7 @@ namespace LibCECTray.controller
       {
         if (_config == null)
         {
-          _config = new LibCECConfiguration { DeviceName = "CEC Tray", ClientVersion = CecClientVersion.Version2_0_0 };
+          _config = new LibCECConfiguration { DeviceName = "CEC Tray", ClientVersion = CecClientVersion.Version2_1_0 };
           _config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice;
           _config.SetCallbacks(this);
 
@@ -490,6 +522,23 @@ namespace LibCECTray.controller
       get { return Lib.ToString(Config.ClientVersion); }
     }
 
+    /// <summary>
+    /// Get the usb vendor id
+    /// </summary>
+    public ushort AdapterVendorId
+    {
+      get { return Lib.GetAdapterVendorId(); }
+    }
+
+    /// <summary>
+    /// Get the usb product id
+    /// </summary>
+    public ushort AdapterProductId
+    {
+      get { return Lib.GetAdapterProductId(); }
+    }
+
+
     /// <summary>
     /// libCEC
     /// </summary>
@@ -502,6 +551,7 @@ namespace LibCECTray.controller
     private readonly CECTray _gui;
     public Actions CECActions;
     private bool _deviceChangeWarningDisplayed;
+    private bool _initialised;
 
     #endregion
   }