   defp remove_backend(path) do
     Logger.remove_backend({LoggerFileBackend, path})
   end
+
+  defp calculate_upper_limit(sample_rate) when sample_rate < @period do
+    {:error, :sample_rate_less_than_period}
+  end
+
+  defp calculate_upper_limit(sample_rate) when rem(sample_rate, @period) != 0 do
+    {:error, :sample_rate_not_multiple_of_period}
+  end
+
+  defp calculate_upper_limit(sample_rate) do
+    upper_limit = div(sample_rate, @period)
+    {:ok, upper_limit}
+  end
 end

  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}


  @uart_pid UART
  @default_log_path Path.join([".", "log", "temperature_logger.log"])
  # 10 seconds
  @default_sample_rate 10
  # Texas Instruments
  @vendor_id 1105
  # MSP430G2 Rev.1.4
  @product_id 62514
  @baud 9600
  # 5 seconds
  @period 5
  @on "O"
  @off "F"
  @debug false
