ads1115  0.2.0
threshold.cpp
Go to the documentation of this file.
1 // ADS1115
2 #include "ads1115/threshold.hpp"
3 
4 // stl
5 #include <bit>
6 #include <cstdint>
7 #include <stdexcept>
8 
9 namespace ADS1115
10 {
11  Threshold::Threshold(const std::int16_t low, const std::int16_t high)
12  {
13  set(low, high);
14  }
15 
16  void Threshold::set(const std::int16_t low, const std::int16_t high)
17  {
18  if ((std::bit_cast<std::uint16_t>(high) & 0x8000)
19  and !(std::bit_cast<std::uint16_t>(low) & 0x8000)) {
20  m_high = high;
21  m_low = low;
22  return;
23  }
24  if (high < low) {
25  throw std::runtime_error("The high threshold has to be bigger than the low threshold.");
26  }
27  m_high = high;
28  m_low = low;
29  }
30 
31  std::int16_t Threshold::getHigh() const
32  {
33  return m_high;
34  }
35  std::int16_t Threshold::getLow() const
36  {
37  return m_low;
38  }
39 } // namespace ADS1115
ADS1115
Definition: ads1115.hpp:16
ADS1115::Threshold::getLow
std::int16_t getLow() const
Definition: threshold.cpp:35
threshold.hpp
ADS1115::Threshold::getHigh
std::int16_t getHigh() const
Definition: threshold.cpp:31
ADS1115::Threshold::set
void set(const std::int16_t low, const std::int16_t high)
Definition: threshold.cpp:16
ADS1115::Threshold::m_high
std::int16_t m_high
Definition: threshold.hpp:14
ADS1115::Threshold::m_low
std::int16_t m_low
Definition: threshold.hpp:15
ADS1115::Threshold::Threshold
Threshold()=default