 
       case msg do
         :ok ->
-          new_state = Map.put(state, port, log_path)
+          {:ok, upper_limit} = calculate_upper_limit(sample_rate)
+          settings = %{
+            log_path: log_path,
+            sample_rate: sample_rate,
+            lower_limit: 0,
+            upper_limit: upper_limit,
+            counter: 0,
+            direction: -1
+          }
+
+          new_state = Map.put(state, port, settings)
           {:reply, msg, new_state}
 
         _ ->

  def handle_call({:start_logging, opts}, _from, state) do
    port = Keyword.get(opts, :port, default_port())
    log_path = Keyword.get(opts, :log_path, @default_log_path) |> Path.expand()

    if Map.has_key?(state, port) do
      {:reply, {:error, :eagain}, state}

        with :ok <- UART.write(uart_pid(), @off),
             :ok <- UART.drain(uart_pid()),
             :ok <- UART.close(uart_pid()),
             do: remove_backend(Map.get(state, port).log_path)

      case msg do
        :ok ->
