@Override
    public synchronized void connect(BluetoothDevice device, boolean secure, long timeout) {
        if (D) Log.d(TAG, "connect to: " + device);

        // no connection attempt already made
        if (!connectionAttempts.containsKey(device)) {
            // no active connection already set up
            if (!remoteConnections.containsKey(device)) {
                // then we create a new connection
                ConnectThread ct = new ConnectThread(this, device, secure, timeout);
                ct.addListener(this);
                ct.start();
                connectionAttempts.put(device, ct);
            } else {
                if (D) Log.d(TAG, "Connection already made with "+device+", abort double connection");
            }
        } else {
            if (D) Log.d(TAG, "Connection attempt to "+device+" already initiated, abort double connection");
        }
        // TODO change the state implementation
        // setState(STATE_CONNECTING);
    }