Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Remove individual temp and rh compensation functions, use a single on…
Browse files Browse the repository at this point in the history
…e that takes in the struct
  • Loading branch information
doawoo committed Feb 24, 2023
1 parent 215dcd6 commit 0cb17b0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/sht4x/measurement.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@ defmodule SHT4X.Measurement do

@spec from_raw(<<_::48>>, Keyword.t()) :: t()
def from_raw(<<raw_t::16, _crc1, raw_rh::16, _crc2>>, opts) do
temperature_compensation_func =
Keyword.get(opts, :temperature_compensation_func, fn v -> v end)

humidity_compensation_func = Keyword.get(opts, :humidity_compensation_func, fn v -> v end)

corrected_raw_t = temperature_compensation_func.(raw_t)
corrected_raw_rh = humidity_compensation_func.(raw_rh)
compensation_func = Keyword.get(opts, :compensation_func, &Function.identity/1)

__struct__(
humidity_rh: humidity_rh_from_raw(corrected_raw_rh),
temperature_c: temperature_c_from_raw(corrected_raw_t),
humidity_rh: humidity_rh_from_raw(raw_rh),
temperature_c: temperature_c_from_raw(raw_t),
raw_reading_temperature: raw_t,
raw_reading_humidity: raw_rh,
timestamp_ms: System.monotonic_time(:millisecond)
)
|> compensation_func.()
|> put_dew_point_c()
end

Expand Down

0 comments on commit 0cb17b0

Please sign in to comment.