![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
Gas data (its response curve and danger level) used by the MQ gas sensors. More...
#include <GasData.h>
Public Member Functions | |
| GasData () | |
| Builds an empty GasData with all curve values sentinel-initialized to INT_MIN. More... | |
| 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) | |
| Builds a GasData from an explicit slope and y-intercept plus its three graph points. More... | |
| 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) | |
| Builds a GasData from its three graph points, computing the slope and y-intercept from them. More... | |
| GasData (const EGasType &gasType, const double &gasSlope, const double &gasYIntercept, const double &dangerLevel, const bool &isUsingDataCache) | |
| Builds a GasData from an explicit slope and y-intercept, leaving the graph points sentinel-initialized. More... | |
| virtual | ~GasData () |
| Destroys the GasData. More... | |
| double | CalculateSlope () |
| Computes the response curve's slope (m) from the first and last graph points, using base-10 logs. More... | |
| double | CalculateYIntercept () |
| Computes the response curve's y-intercept (b) from the middle graph point, calculating the slope first if needed. More... | |
| std::string | ToString () const |
| Serializes the gas name, slope, and y-intercept to a string. More... | |
| const char * | GetGasName () const |
| Gets the human-readable name of this data's gas type. More... | |
| EGasType | GetGasType () const |
| Gets the gas type this data describes. More... | |
| double | GetGasSlope () |
| Gets the response curve's slope (m), calculating it first if it has not been computed yet. More... | |
| double | GetGasYIntercept () const |
| Gets the response curve's y-intercept (b). More... | |
| double | GetFirstX () const |
| Gets the x of the first graph point. More... | |
| double | GetFirstY () const |
| Gets the y of the first graph point. More... | |
| double | GetMiddleX () const |
| Gets the x of the middle graph point. More... | |
| double | GetMiddleY () const |
| Gets the y of the middle graph point. More... | |
| double | GetLastX () const |
| Gets the x of the last graph point. More... | |
| double | GetLastY () const |
| Gets the y of the last graph point. More... | |
| double | GetDangerLevel () const |
| Gets the concentration (ppm) considered dangerous for this gas. More... | |
| 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. More... | |
| bool | GetIsUsingDataCache () const |
| Gets whether this gas sensor uses the data cache for its calculations. More... | |
| void | SetGasSlope (const double &slope) |
| Sets the response curve's slope (m). More... | |
| void | SetGasYIntercept (const double &yIntercept) |
| Sets the response curve's y-intercept (b). More... | |
| void | SetFirstX (const double &firstX) |
| Sets the x of the first graph point. More... | |
| void | SetFirstY (const double &firstY) |
| Sets the y of the first graph point. More... | |
| void | SetMiddleX (const double &middleX) |
| Sets the x of the middle graph point. More... | |
| void | SetMiddleY (const double &middleY) |
| Sets the y of the middle graph point. More... | |
| void | SetLastX (const double &lastX) |
| Sets the x of the last graph point. More... | |
| void | SetLastY (const double &lastY) |
| Sets the y of the last graph point. More... | |
| void | SetDangerLevel (const double &dangerLevel) |
| Sets the concentration (ppm) considered dangerous for this gas. More... | |
| void | SetDataCacheValueAtIndex (const int &index, const double &value) |
| Sets a cached value at the given raw-analog index, ignoring out-of-range indices. More... | |
| void | SetIsUsingDataCache (const bool &isUsingDataCache) |
| Sets whether this gas sensor uses the data cache for its calculations. More... | |
Static Public Member Functions | |
| static const char * | GetGasName (const EGasType &gasType) |
| Gets the human-readable name for a given gas type. More... | |
Static Public Attributes | |
| static const int | MAX_ANALOG_VALUE = 1023 |
| The maximum 10-bit raw analog reading. More... | |
Private Attributes | |
| EGasType | myGasType |
| The type of gas this data corresponds to. More... | |
| double | myGasSlope |
| The m in "y = mx + b". More... | |
| double | myGasYIntercept |
| The b in "y = mx + b". More... | |
| double | myFirstX |
| The x in the first point on the graph. More... | |
| double | myFirstY |
| The y in the first point on the graph. More... | |
| double | myMiddleX |
| The x in-between the start and last. More... | |
| double | myMiddleY |
| The y in-between the start and last. More... | |
| double | myLastX |
| The x for the last point on the graph. More... | |
| double | myLastY |
| The y for the last point on the graph. More... | |
| double | myDangerLevel |
| The amount considered dangerous for this gas in ppm. More... | |
| double | myDataCache [MAX_ANALOG_VALUE+1] = {} |
| Cache of expensive calculations (e.g. BAC in the MQ-3). Zero-initialized; filled by cache-using sensors. More... | |
| bool | myIsUsingDataCache |
| True if this gas sensor uses the data cache for calculations instead of slope and intercept. More... | |
Gas data (its response curve and danger level) used by the MQ gas sensors.
| RumPi::GasData::GasData | ( | ) |
| RumPi::GasData::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 | ||
| ) |
Builds a GasData from an explicit slope and y-intercept plus its three graph points.
| [in] | gasType | The type of gas this data describes. |
| [in] | gasSlope | The slope (m) of the response curve. |
| [in] | gasYIntercept | The y-intercept (b) of the response curve. |
| [in] | startX | The x of the first graph point. |
| [in] | startY | The y of the first graph point. |
| [in] | middleX | The x of the middle graph point. |
| [in] | middleY | The y of the middle graph point. |
| [in] | lastX | The x of the last graph point. |
| [in] | lastY | The y of the last graph point. |
| [in] | dangerLevel | The concentration (ppm) considered dangerous for this gas. |
| [in] | isUsingDataCache | True if the sensor uses a cache instead of slope/intercept. |
| RumPi::GasData::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 | ||
| ) |
Builds a GasData from its three graph points, computing the slope and y-intercept from them.
| [in] | gasType | The type of gas this data describes. |
| [in] | startX | The x of the first graph point. |
| [in] | startY | The y of the first graph point. |
| [in] | middleX | The x of the middle graph point. |
| [in] | middleY | The y of the middle graph point. |
| [in] | lastX | The x of the last graph point. |
| [in] | lastY | The y of the last graph point. |
| [in] | dangerLevel | The concentration (ppm) considered dangerous for this gas. |
| [in] | isUsingDataCache | True if the sensor uses a cache instead of slope/intercept. |
| RumPi::GasData::GasData | ( | const EGasType & | gasType, |
| const double & | gasSlope, | ||
| const double & | gasYIntercept, | ||
| const double & | dangerLevel, | ||
| const bool & | isUsingDataCache | ||
| ) |
Builds a GasData from an explicit slope and y-intercept, leaving the graph points sentinel-initialized.
| [in] | gasType | The type of gas this data describes. |
| [in] | gasSlope | The slope (m) of the response curve. |
| [in] | gasYIntercept | The y-intercept (b) of the response curve. |
| [in] | dangerLevel | The concentration (ppm) considered dangerous for this gas. |
| [in] | isUsingDataCache | True if the sensor uses a cache instead of slope/intercept. |
|
virtual |
| double RumPi::GasData::CalculateSlope | ( | ) |
Computes the response curve's slope (m) from the first and last graph points, using base-10 logs.
| double RumPi::GasData::CalculateYIntercept | ( | ) |
Computes the response curve's y-intercept (b) from the middle graph point, calculating the slope first if needed.
| double RumPi::GasData::GetDangerLevel | ( | ) | const |
Gets the concentration (ppm) considered dangerous for this gas.
| double RumPi::GasData::GetDataCacheValueAtIndex | ( | const int & | index | ) | const |
Gets a cached value at the given raw-analog index, or 0 if the index is out of range.
| [in] | index | The raw analog value (0 to MAX_ANALOG_VALUE) to look up. |
| double RumPi::GasData::GetFirstX | ( | ) | const |
Gets the x of the first graph point.
| double RumPi::GasData::GetFirstY | ( | ) | const |
Gets the y of the first graph point.
| const char * RumPi::GasData::GetGasName | ( | ) | const |
Gets the human-readable name of this data's gas type.
|
static |
Gets the human-readable name for a given gas type.
Output: Propane (C3H8)
| [in] | gasType | The gas type to name. |
| double RumPi::GasData::GetGasSlope | ( | ) |
Gets the response curve's slope (m), calculating it first if it has not been computed yet.
| EGasType RumPi::GasData::GetGasType | ( | ) | const |
Gets the gas type this data describes.
| double RumPi::GasData::GetGasYIntercept | ( | ) | const |
Gets the response curve's y-intercept (b).
| bool RumPi::GasData::GetIsUsingDataCache | ( | ) | const |
Gets whether this gas sensor uses the data cache for its calculations.
| double RumPi::GasData::GetLastX | ( | ) | const |
Gets the x of the last graph point.
| double RumPi::GasData::GetLastY | ( | ) | const |
Gets the y of the last graph point.
| double RumPi::GasData::GetMiddleX | ( | ) | const |
Gets the x of the middle graph point.
| double RumPi::GasData::GetMiddleY | ( | ) | const |
Gets the y of the middle graph point.
| void RumPi::GasData::SetDangerLevel | ( | const double & | dangerLevel | ) |
Sets the concentration (ppm) considered dangerous for this gas.
| [in] | dangerLevel | The danger level, in ppm. |
| void RumPi::GasData::SetDataCacheValueAtIndex | ( | const int & | index, |
| const double & | value | ||
| ) |
Sets a cached value at the given raw-analog index, ignoring out-of-range indices.
| [in] | index | The raw analog value (0 to MAX_ANALOG_VALUE) to write. |
| [in] | value | The value to cache at that index. |
| void RumPi::GasData::SetFirstX | ( | const double & | firstX | ) |
Sets the x of the first graph point.
| [in] | firstX | The x of the first graph point. |
| void RumPi::GasData::SetFirstY | ( | const double & | firstY | ) |
Sets the y of the first graph point.
| [in] | firstY | The y of the first graph point. |
| void RumPi::GasData::SetGasSlope | ( | const double & | slope | ) |
Sets the response curve's slope (m).
| [in] | slope | The slope (m) to set. |
| void RumPi::GasData::SetGasYIntercept | ( | const double & | yIntercept | ) |
Sets the response curve's y-intercept (b).
| [in] | yIntercept | The y-intercept (b) to set. |
| void RumPi::GasData::SetIsUsingDataCache | ( | const bool & | isUsingDataCache | ) |
Sets whether this gas sensor uses the data cache for its calculations.
| [in] | isUsingDataCache | True to use the data cache instead of slope/intercept. |
| void RumPi::GasData::SetLastX | ( | const double & | lastX | ) |
Sets the x of the last graph point.
| [in] | lastX | The x of the last graph point. |
| void RumPi::GasData::SetLastY | ( | const double & | lastY | ) |
Sets the y of the last graph point.
| [in] | lastY | The y of the last graph point. |
| void RumPi::GasData::SetMiddleX | ( | const double & | middleX | ) |
Sets the x of the middle graph point.
| [in] | middleX | The x of the middle graph point. |
| void RumPi::GasData::SetMiddleY | ( | const double & | middleY | ) |
Sets the y of the middle graph point.
| [in] | middleY | The y of the middle graph point. |
| std::string RumPi::GasData::ToString | ( | ) | const |
Serializes the gas name, slope, and y-intercept to a string.
|
static |
The maximum 10-bit raw analog reading.
|
private |
The amount considered dangerous for this gas in ppm.
|
private |
Cache of expensive calculations (e.g. BAC in the MQ-3). Zero-initialized; filled by cache-using sensors.
|
private |
The x in the first point on the graph.
|
private |
The y in the first point on the graph.
|
private |
The m in "y = mx + b".
|
private |
The type of gas this data corresponds to.
|
private |
The b in "y = mx + b".
|
private |
True if this gas sensor uses the data cache for calculations instead of slope and intercept.
|
private |
The x for the last point on the graph.
|
private |
The y for the last point on the graph.
|
private |
The x in-between the start and last.
|
private |
The y in-between the start and last.