     GenServer.call(__MODULE__, {:cmd, cmd})
   end
 
-  defstruct [port: nil, verbose: true, recording: true, log: nil]
+  def attach(_ctl, ble) do
+    GenServer.call(__MODULE__, {:attach, ble})
+  end
+
+  defstruct [port: nil, verbose: true, recording: true, log: nil, ble: nil]
 
   def init([]) do
     path = System.find_executable("bluetoothctl")

    Regex.replace(regexp, s, "")
  end

  # def parse("[bluetooth]# \r" <> event), do: parse_event(event)
  def parse("[NEW] " <> new_event), do: {:new, parse_device(new_event)}
  def parse("[CHG] " <> chg_event), do: {:change, parse_device(chg_event)}
  def parse(output), do: {output}

  def parse_device(<<"Device ", uuid :: binary-size(17), " ", rest::binary>>) do
    {:device, uuid, rest}
  end
  def parse_device(<<"Controller ", uuid :: binary-size(17), " ", rest::binary>>) do
    {:controller, uuid, rest}
  end
end

    Port.command(port, data)
    |> reply(state)
  end
  def handle_call({:attach, ble}, _from, state) do
    new_state = %__MODULE__{state | ble: ble}
    reply(:ok, new_state)
  end


  defp reply(ret_value, state) do
    {:reply, ret_value, state}
