   alias Nerves.UART
 
   @uart_pid UART
+
   @default_log_path Path.join([".", "log", "temperature_logger.log"])
+
   # 10 seconds
-  @default_sample_rate 10
+  @default_period 10
+
   # Texas Instruments
   @vendor_id 1105
+
   # MSP430G2 Rev.1.4
   @product_id 62514
+
   @baud 9600
-  # 5 seconds
-  @period 5
+
+  # 1 seconds
+  @min_period 1
+
   @on "O"
+
   @off "F"
+
   @open_options [
     speed: @baud,
     active: true,

    end
  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
  end

  defp set_up(port, log_path, period) do
    with {:ok, settings} <- generate_settings(log_path, period),
         :ok <- UART.open(uart_pid(), port, @open_options),
         :ok <- UART.flush(uart_pid()),
         :ok <- UART.write(uart_pid(), @on),
         :ok <- UART.drain(uart_pid()),
         :ok <- add_backend(log_path),
         do: {:ok, settings}
  end

  defp teardown(settings) do
    with :ok <- UART.write(uart_pid(), @off),
         :ok <- UART.drain(uart_pid()),
         :ok <- UART.close(uart_pid()),
         do: remove_backend(settings.log_path)
  end

  defp add_backend(path) do
    Logger.add_backend({LoggerFileBackend, path})

