RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
GasData.h
Go to the documentation of this file.
1#pragma once
2#include "../Common.h"
3
4namespace RumPi
5{
13 {
31 };
32
39 class GasData
40 {
41 public:
42 static const int MAX_ANALOG_VALUE = 1023;
43
44 private:
46 double myGasSlope;
48 double myFirstX;
49 double myFirstY;
50 double myMiddleX;
51 double myMiddleY;
52 double myLastX;
53 double myLastY;
55 double myDataCache[MAX_ANALOG_VALUE + 1] = {};
57
58 public:
69 GasData();
70
93 GasData(const EGasType& gasType, const double& gasSlope, const double& gasYIntercept, const double& startX, const double& startY, const double& middleX, const double& middleY, const double& lastX, const double& lastY, const double& dangerLevel, const bool& isUsingDataCache);
94
115 GasData(const EGasType& gasType, const double& startX, const double& startY, const double& middleX, const double& middleY, const double& lastX, const double& lastY, const double& dangerLevel, const bool& isUsingDataCache);
116
133 GasData(const EGasType& gasType, const double& gasSlope, const double& gasYIntercept, const double& dangerLevel, const bool& isUsingDataCache);
134
146 virtual ~GasData();
147
160 double CalculateSlope();
161
174 double CalculateYIntercept();
175
188 std::string ToString() const;
189
202 const char* GetGasName() const;
203
219 static const char* GetGasName(const EGasType& gasType);
220
233 EGasType GetGasType() const;
234
247 double GetGasSlope();
248
261 double GetGasYIntercept() const;
262
275 double GetFirstX() const;
276
289 double GetFirstY() const;
290
303 double GetMiddleX() const;
304
317 double GetMiddleY() const;
318
331 double GetLastX() const;
332
345 double GetLastY() const;
346
359 double GetDangerLevel() const;
360
375 double GetDataCacheValueAtIndex(const int& index) const;
376
389 bool GetIsUsingDataCache() const;
390
403 void SetGasSlope(const double& slope);
404
417 void SetGasYIntercept(const double& yIntercept);
418
431 void SetFirstX(const double& firstX);
432
445 void SetFirstY(const double& firstY);
446
459 void SetMiddleX(const double& middleX);
460
473 void SetMiddleY(const double& middleY);
474
487 void SetLastX(const double& lastX);
488
501 void SetLastY(const double& lastY);
502
515 void SetDangerLevel(const double& dangerLevel);
516
530 void SetDataCacheValueAtIndex(const int& index, const double& value);
531
544 void SetIsUsingDataCache(const bool& isUsingDataCache);
545 };
546} // namespace RumPi
Gas data (its response curve and danger level) used by the MQ gas sensors.
Definition: GasData.h:40
static const int MAX_ANALOG_VALUE
The maximum 10-bit raw analog reading.
Definition: GasData.h:42
double GetLastY() const
Gets the y of the last graph point.
Definition: GasData.cpp:463
void SetFirstX(const double &firstX)
Sets the x of the first graph point.
Definition: GasData.cpp:576
void SetMiddleY(const double &middleY)
Sets the y of the middle graph point.
Definition: GasData.cpp:627
std::string ToString() const
Serializes the gas name, slope, and y-intercept to a string.
Definition: GasData.cpp:733
double GetFirstY() const
Gets the y of the first graph point.
Definition: GasData.cpp:395
double GetLastX() const
Gets the x of the last graph point.
Definition: GasData.cpp:446
double myDangerLevel
The amount considered dangerous for this gas in ppm.
Definition: GasData.h:54
double myMiddleY
The y in-between the start and last.
Definition: GasData.h:51
void SetLastY(const double &lastY)
Sets the y of the last graph point.
Definition: GasData.cpp:661
double myGasSlope
The m in "y = mx + b".
Definition: GasData.h:46
GasData()
Builds an empty GasData with all curve values sentinel-initialized to INT_MIN.
Definition: GasData.cpp:15
double myDataCache[MAX_ANALOG_VALUE+1]
Cache of expensive calculations (e.g. BAC in the MQ-3). Zero-initialized; filled by cache-using senso...
Definition: GasData.h:55
double myLastY
The y for the last point on the graph.
Definition: GasData.h:53
double GetGasYIntercept() const
Gets the response curve's y-intercept (b).
Definition: GasData.cpp:361
double myMiddleX
The x in-between the start and last.
Definition: GasData.h:50
double myFirstY
The y in the first point on the graph.
Definition: GasData.h:49
void SetDataCacheValueAtIndex(const int &index, const double &value)
Sets a cached value at the given raw-analog index, ignoring out-of-range indices.
Definition: GasData.cpp:696
double GetDataCacheValueAtIndex(const int &index) const
Gets a cached value at the given raw-analog index, or 0 if the index is out of range.
Definition: GasData.cpp:499
void SetGasYIntercept(const double &yIntercept)
Sets the response curve's y-intercept (b).
Definition: GasData.cpp:559
double GetFirstX() const
Gets the x of the first graph point.
Definition: GasData.cpp:378
EGasType GetGasType() const
Gets the gas type this data describes.
Definition: GasData.cpp:322
double GetGasSlope()
Gets the response curve's slope (m), calculating it first if it has not been computed yet.
Definition: GasData.cpp:339
double GetMiddleX() const
Gets the x of the middle graph point.
Definition: GasData.cpp:412
void SetIsUsingDataCache(const bool &isUsingDataCache)
Sets whether this gas sensor uses the data cache for its calculations.
Definition: GasData.cpp:716
void SetLastX(const double &lastX)
Sets the x of the last graph point.
Definition: GasData.cpp:644
double GetMiddleY() const
Gets the y of the middle graph point.
Definition: GasData.cpp:429
double GetDangerLevel() const
Gets the concentration (ppm) considered dangerous for this gas.
Definition: GasData.cpp:480
void SetDangerLevel(const double &dangerLevel)
Sets the concentration (ppm) considered dangerous for this gas.
Definition: GasData.cpp:678
double CalculateSlope()
Computes the response curve's slope (m) from the first and last graph points, using base-10 logs.
Definition: GasData.cpp:164
const char * GetGasName() const
Gets the human-readable name of this data's gas type.
Definition: GasData.cpp:216
double myGasYIntercept
The b in "y = mx + b".
Definition: GasData.h:47
void SetFirstY(const double &firstY)
Sets the y of the first graph point.
Definition: GasData.cpp:593
double myLastX
The x for the last point on the graph.
Definition: GasData.h:52
double CalculateYIntercept()
Computes the response curve's y-intercept (b) from the middle graph point, calculating the slope firs...
Definition: GasData.cpp:187
double myFirstX
The x in the first point on the graph.
Definition: GasData.h:48
virtual ~GasData()
Destroys the GasData.
Definition: GasData.cpp:147
bool GetIsUsingDataCache() const
Gets whether this gas sensor uses the data cache for its calculations.
Definition: GasData.cpp:525
void SetGasSlope(const double &slope)
Sets the response curve's slope (m).
Definition: GasData.cpp:542
EGasType myGasType
The type of gas this data corresponds to.
Definition: GasData.h:45
void SetMiddleX(const double &middleX)
Sets the x of the middle graph point.
Definition: GasData.cpp:610
bool myIsUsingDataCache
True if this gas sensor uses the data cache for calculations instead of slope and intercept.
Definition: GasData.h:56
RumPi is the library's top-level facade.
Definition: AlertManager.h:6
EGasType
The types of gas the MQ sensor family can detect.
Definition: GasData.h:13
@ E_Benzene
Definition: GasData.h:17
@ E_CarbonMonoxide
Definition: GasData.h:21
@ E_Ammonium
Definition: GasData.h:16
@ E_Hydrogen
Definition: GasData.h:24
@ E_Hexane
Definition: GasData.h:23
@ E_Acetone
Definition: GasData.h:14
@ E_Benzine
Definition: GasData.h:18
@ E_Methane
Definition: GasData.h:26
@ E_Butane
Definition: GasData.h:19
@ E_NaturalGas
Definition: GasData.h:27
@ E_LPG
Definition: GasData.h:25
@ E_Alcohol
Definition: GasData.h:15
@ E_Toluene
Definition: GasData.h:30
@ E_Propane
Definition: GasData.h:28
@ E_CarbonDioxide
Definition: GasData.h:20
@ E_Smoke
Definition: GasData.h:29
@ E_CNG
Definition: GasData.h:22