text: let address = document.getElementById('connect-address'),
    connect = document.getElementById('connect'),
    buttonConnect = document.getElementById('connect-button');
  
  let loginShown = true;
  
  // Set function to be called on NetworkTables connect. Not implemented.
  //NetworkTables.addWsConnectionListener(onNetworkTablesConnection, true);
  
  // Sets function to be called when any NetworkTables key/value changes
  //NetworkTables.addGlobalListener(onValueChanged, true);
  
  // Function for hiding the connect box
  onkeydown = key => {
    if (key.key === 'Escape') {
      document.body.classList.toggle('login', false);
      loginShown = false;
    }
  };
  
  
  app.controller('doConnection', ['$scope', function($scope) {
    $scope.count = 0;
    $scope.openModal = function() {
        document.body.classList.toggle('login', true);
        loginShown = true;
        setLogin();
    };
  }]);
  
  /**
   * Function to be called when robot connects
   * @param {boolean} connected
   */
  function onRobotConnection(connected) {
    
    scp = scp;
  
    var state = connected ? 'Robot connected!' : 'Robot disconnected';
    console.log(state);
  
    scp.data.communication.robotState = state;
    scp.data.communication.robot = connected;
    
    if (connected) {
      // On connect hide the connect popup
      document.body.classList.toggle('login', false);
      loginShown = false;
    }
    if(!connected){
      if (loginShown) {
        setLogin();
      }
  
      scp.data.sensors.isGyroCalibrated = false;
    }
    scp.$apply();
  }
  
  function setLogin() {
    // Add Enter key handler
    // Enable the input and the button
    address.disabled = connect.disabled = false;
    connect.textContent = 'Connect';
    // Add the default address and select xxxx
    address.value = '10.57.5.2';
    address.focus();
    address.setSelectionRange(8, 12);
  }
  // On click try to connect and disable the input and the button
  connect.onclick = () => {
    ipc.send('connect', address.value,1735);
    address.disabled = connect.disabled = true;
    connect.textContent = 'Connecting...';
  };
  address.onkeydown = ev => {
    if (ev.key === 'Enter') {
      connect.click();
      ev.preventDefault();
      ev.stopPropagation();
    }
  };
  
  // Set function to be called when robot dis/connects
  NetworkTables.addRobotConnectionListener(onRobotConnection, false);
  
  // Show login when starting
  
  document.body.classList.toggle('login', true);
  setLogin();