public void OnReceivePairConfirm(TCPConnection connection, string pairedId, string lockedId)
    {
        ConnectionsDisplayer.DisplayedConnectionHandle handle = null;
        if (ConnectionsDisplayer.Instance)
        {
            handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
        }

        bool paired = pairedId != "0";        //string "0" means the device is unpaired now

        if (pairedId == SystemInfo.deviceUniqueIdentifier)
        {
            Haze.Logger.Log("Paired to " + connection);
            connection.paired = true;
            if (handle != null)
            {
                handle.display.Available = true;
            }
            //Give an update to the VideosDisplayer
            if (VideosDisplayer.Instance)
            {
                VideosDisplayer.Instance.OnPairConnection(connection);
            }
            if (VideosDisplayer0ld.Instance)
            {
                VideosDisplayer0ld.Instance.OnPairConnection(connection);
            }
        }
        else
        {
            if (connection.paired)
            {
                connection.paired = false;
                Haze.Logger.Log("Unpaired from " + connection);
            }
            Haze.Logger.LogWarning("Setting available to " + !paired + " for connection " + connection);
            if (handle != null)
            {
                handle.display.Available = !paired;
            }
        }

        connection.lockedId = lockedId;

        //Update all device displays
        if (ConnectionsDisplayer.Instance)
        {
            foreach (ConnectionsDisplayer.DisplayedConnectionHandle h in ConnectionsDisplayer.Instance.Handles)
            {
                h.display.UpdateDisplay();
            }
        }

        lastConnectedDevice = connection;
        onConnected.Invoke(connection);
    }
 public void OnConnectionResponsivenessChanged(TCPConnection connection, bool isResponsive)
 {
     ConnectionsDisplayer.DisplayedConnectionHandle handle = null;
     if (ConnectionsDisplayer.Instance)
     {
         handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
         if (handle != null)
         {
             handle.display.UpdateDisplay();
         }
     }
 }
 public void OnReceiveHasVideoResponse(TCPConnection connection, string videoName)
 {
     Haze.Logger.Log(connection + " has video " + videoName);
     ConnectionsDisplayer.DisplayedConnectionHandle handle = null;
     if (ConnectionsDisplayer.Instance)
     {
         handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
         if (handle != null)
         {
             handle.display.AddAvailableVideo(videoName);
         }
     }
 }
 public void OnReceiveAutocalibrationResult(TCPConnection connection, byte command, float drift)
 {
     if (ConnectionsDisplayer.Instance)
     {
         ConnectionsDisplayer.DisplayedConnectionHandle handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
         if (handle != null)
         {
             //Treat the response as necessary
             handle.display.OnReceiveAutocalibrationResult(command, drift);
         }
         else
         {
             Haze.Logger.LogWarning("Received autocalibration result from a non-existent connection apparently :(");
         }
     }
 }
 public void OnReceiveLoadVideoResponse(TCPConnection connection, bool ok, string errorMessage)
 {
     if (ok)
     {
         Haze.Logger.Log(connection + " has successfully loaded video.");
         ConnectionsDisplayer.DisplayedConnectionHandle handle = null;
         if (ConnectionsDisplayer.Instance)
         {
             handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
             if (handle != null)
             {
                 handle.display.IsVideoReady = true;
             }
         }
     }
     else
     {
         Haze.Logger.LogWarning("Error: " + connection + " could not load video: " + errorMessage);
         //TODO: display error message
     }
 }
    public void OnReceiveStatus(TCPConnection connection, byte b_battery, short s_fps, byte b_temp)
    {
        int   battery     = (int)b_battery;
        float fps         = ((float)s_fps) * 0.1f;
        int   temperature = (int)b_temp;

        LastFPSReceived     = fps;
        LastBatteryReceived = battery;

        if (ConnectionsDisplayer.Instance)
        {
            ConnectionsDisplayer.DisplayedConnectionHandle handle = ConnectionsDisplayer.Instance.GetConnectionHandle(connection);
            if (handle != null)
            {
                handle.display.Battery     = battery;
                handle.display.FPS         = fps;
                handle.display.Temperature = temperature;
            }
            else
            {
                Haze.Logger.LogWarning("Received status from a non-existent connection, apparently...");
            }
        }
    }