imunano33  0.1.1
climate.hpp
Go to the documentation of this file.
1 
6 #ifndef INCLUDE_IMUNANO33_CLIMATE_HPP_
7 #define INCLUDE_IMUNANO33_CLIMATE_HPP_
8 
9 #include "imunano33/unit.hpp"
10 
11 namespace imunano33 {
25 class Climate {
26 public:
32  Climate() = default;
33 
37  Climate(const Climate &other) = default;
38 
42  Climate &operator=(const Climate &other) = default;
43 
47  ~Climate() = default;
48 
52  Climate(Climate &&) = default;
53 
57  Climate &operator=(Climate &&) = default;
58 
67  bool dataExists() const { return m_dataExists; }
68 
78  template <TempUnit U> num_t getTemp() const {
79  num_t res = 0;
80 
81  switch (U) {
82  case FAHRENHEIT:
83 #ifdef IMUNANO33_EMBED
84  res = m_temp * (9.0F / 5.0F) + 32.0F;
85 #else
86  res = m_temp * (9.0 / 5.0) + 32.0;
87 #endif
88  break;
89  case CELSIUS:
90  res = m_temp;
91  break;
92  case KELVIN:
93 #ifdef IMUNANO33_EMBED
94  res = m_temp + 273.15F;
95 #else
96  res = m_temp + 273.15;
97 #endif
98  break;
99  default:
100  res = m_temp;
101  }
102 
103  return res;
104  }
105 
115  template <PressureUnit U> num_t getPressure() const {
116  num_t res = 0;
117 
118  switch (U) {
119  case KPA:
120  res = m_pressure;
121  break;
122  case ATM:
123 #ifdef IMUNANO33_EMBED
124  res = m_pressure * 0.00986923266716F;
125 #else
126  res = m_pressure * 0.00986923266716;
127 #endif
128  break;
129  case MMHG:
130 #ifdef IMUNANO33_EMBED
131  res = m_pressure * 7.500617F;
132 #else
133  res = m_pressure * 7.500617;
134 #endif
135  break;
136  case PSI:
137 #ifdef IMUNANO33_EMBED
138  res = m_pressure * 0.1450377377F;
139 #else
140  res = m_pressure * 0.1450377377;
141 #endif
142  break;
143  }
144 
145  return res;
146  }
147 
157  num_t getHumidity() const { return m_humid; }
158 
166  void update(const num_t temp, const num_t humid, const num_t pressure) {
167  m_dataExists = true;
168  m_temp = temp;
169  m_humid = humid;
170  m_pressure = pressure;
171  }
172 
178  void reset() { m_dataExists = false; }
179 
180 private:
181  bool m_dataExists{false};
182 
183  num_t m_temp = 0.0;
184  num_t m_humid = 0.0;
185  num_t m_pressure = 0.0;
186 };
187 } // namespace imunano33
188 
189 #endif
Contains imunano33::TempUnit and imunano33::PressureUnit enums, in addition to number type.
double num_t
Alias to number type depending on embed.
Definition: unit.hpp:34
@ MMHG
Converts pressure to millimeters of mercury.
Definition: unit.hpp:27
@ ATM
Definition: unit.hpp:25
@ KPA
Converts pressure to kilopascal.
Definition: unit.hpp:24
@ PSI
Converts pressure to pounds per square inch.
Definition: unit.hpp:28
@ CELSIUS
Converts temperature to Celsius.
Definition: unit.hpp:16
@ KELVIN
Converts temperature to Kelvin.
Definition: unit.hpp:17
@ FAHRENHEIT
Converts temperature to Fahrenheit.
Definition: unit.hpp:15
Handles climate data from Nano 33 (or other) sensors.
Definition: climate.hpp:25
Climate(const Climate &other)=default
Copy constructor.
bool dataExists() const
Determines if climate data exists.
Definition: climate.hpp:67
num_t getPressure() const
Gets pressure.
Definition: climate.hpp:115
~Climate()=default
Destructor.
num_t getTemp() const
Gets temperature.
Definition: climate.hpp:78
Climate & operator=(const Climate &other)=default
Assignment operator.
Climate(Climate &&)=default
Move constructor.
void update(const num_t temp, const num_t humid, const num_t pressure)
Updates climate data.
Definition: climate.hpp:166
Climate()=default
Default constructor.
Climate & operator=(Climate &&)=default
Move assignment.
num_t getHumidity() const
Gets relative humidity.
Definition: climate.hpp:157
void reset()
Resets climate data.
Definition: climate.hpp:178