     Logger.remove_backend({LoggerFileBackend, path})
   end
 
+  defp generate_settings(log_path, sample_rate) do
+    case calculate_upper_limit(sample_rate) do
+      {:ok, upper_limit} ->
+        settings = %{
+          log_path: log_path,
+          sample_rate: sample_rate,
+          lower_limit: 0,
+          upper_limit: upper_limit,
+          count: 0,
+          direction: -1
+        }
+        {:ok, settings}
+
+      {:error, error} ->
+        {:error, error}
+    end
+  end
+
   defp calculate_upper_limit(sample_rate) when sample_rate < @period do
     {:error, :sample_rate_less_than_period}
   end

  ## Server Callbacks

  def init(:ok) do
    {:ok, _pid} = UART.start_link(name: @uart_pid)
    state = %{}
    {:ok, state}
  end


  def handle_call({:start_logging, opts}, _from, state) do
    port = Keyword.get(opts, :port, default_port())

    if Map.has_key?(state, port) do
      {:reply, {:error, :eagain}, state} # @todo return custom error atom
    else
      log_path = Path.expand(Keyword.get(opts, :log_path, @default_log_path))
      sample_rate = Keyword.get(opts, :sample_rate, @default_sample_rate)

      case set_up(port, log_path, sample_rate) do
        {:ok, settings} ->
          new_state = Map.put(state, port, settings)
          {:reply, :ok, new_state}

        {:error, error} ->
          {:reply, {:error, error}, state}
      end
    end
  end
