RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::GasData Class Reference

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...
 

Detailed Description

Gas data (its response curve and danger level) used by the MQ gas sensors.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ GasData() [1/4]

RumPi::GasData::GasData ( )

Builds an empty GasData with all curve values sentinel-initialized to INT_MIN.

Author
Eddie O'Hagan
Date
8/13/2026
GasData data;
GasData()
Builds an empty GasData with all curve values sentinel-initialized to INT_MIN.
Definition: GasData.cpp:15

◆ GasData() [2/4]

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.

Author
Eddie O'Hagan
Date
8/13/2026
GasData data(EGasType::E_Smoke, 1.5, 2.0, 200.0, 1.75, 1000.0, 0.99, 10000.0, 0.44, 1000.0, true);
@ E_Smoke
Definition: GasData.h:29
Parameters
[in]gasTypeThe type of gas this data describes.
[in]gasSlopeThe slope (m) of the response curve.
[in]gasYInterceptThe y-intercept (b) of the response curve.
[in]startXThe x of the first graph point.
[in]startYThe y of the first graph point.
[in]middleXThe x of the middle graph point.
[in]middleYThe y of the middle graph point.
[in]lastXThe x of the last graph point.
[in]lastYThe y of the last graph point.
[in]dangerLevelThe concentration (ppm) considered dangerous for this gas.
[in]isUsingDataCacheTrue if the sensor uses a cache instead of slope/intercept.

◆ GasData() [3/4]

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.

Author
Eddie O'Hagan
Date
8/13/2026
GasData data(EGasType::E_Smoke, 200.0, 1.75, 1000.0, 0.99, 10000.0, 0.44, 1000.0, true);
Parameters
[in]gasTypeThe type of gas this data describes.
[in]startXThe x of the first graph point.
[in]startYThe y of the first graph point.
[in]middleXThe x of the middle graph point.
[in]middleYThe y of the middle graph point.
[in]lastXThe x of the last graph point.
[in]lastYThe y of the last graph point.
[in]dangerLevelThe concentration (ppm) considered dangerous for this gas.
[in]isUsingDataCacheTrue if the sensor uses a cache instead of slope/intercept.

◆ GasData() [4/4]

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.

Author
Eddie O'Hagan
Date
8/13/2026
GasData data(EGasType::E_Alcohol, 2.2984, 0.5302, 1000.0, true);
@ E_Alcohol
Definition: GasData.h:15
Parameters
[in]gasTypeThe type of gas this data describes.
[in]gasSlopeThe slope (m) of the response curve.
[in]gasYInterceptThe y-intercept (b) of the response curve.
[in]dangerLevelThe concentration (ppm) considered dangerous for this gas.
[in]isUsingDataCacheTrue if the sensor uses a cache instead of slope/intercept.

◆ ~GasData()

RumPi::GasData::~GasData ( )
virtual

Destroys the GasData.

Author
Eddie O'Hagan
Date
8/13/2026
GasData* data = new GasData();
delete data;

Member Function Documentation

◆ CalculateSlope()

double RumPi::GasData::CalculateSlope ( )

Computes the response curve's slope (m) from the first and last graph points, using base-10 logs.

Author
Eddie O'Hagan
Date
8/13/2026
double slope = data.CalculateSlope();
Returns
The computed slope (m), which is also cached in the object.

◆ CalculateYIntercept()

double RumPi::GasData::CalculateYIntercept ( )

Computes the response curve's y-intercept (b) from the middle graph point, calculating the slope first if needed.

Author
Eddie O'Hagan
Date
8/13/2026
double yIntercept = data.CalculateYIntercept();
Returns
The computed y-intercept (b), which is also cached in the object.

◆ GetDangerLevel()

double RumPi::GasData::GetDangerLevel ( ) const

Gets the concentration (ppm) considered dangerous for this gas.

Author
Eddie O'Hagan
Date
8/13/2026
double dangerLevel = data.GetDangerLevel();
Returns
The danger level, in ppm.

◆ GetDataCacheValueAtIndex()

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.

Author
Eddie O'Hagan
Date
8/13/2026
double ppm = data.GetDataCacheValueAtIndex(512);
Parameters
[in]indexThe raw analog value (0 to MAX_ANALOG_VALUE) to look up.
Returns
The cached value, or 0 if the index is out of range.

◆ GetFirstX()

double RumPi::GasData::GetFirstX ( ) const

Gets the x of the first graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double firstX = data.GetFirstX();
Returns
The x of the first graph point.

◆ GetFirstY()

double RumPi::GasData::GetFirstY ( ) const

Gets the y of the first graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double firstY = data.GetFirstY();
Returns
The y of the first graph point.

◆ GetGasName() [1/2]

const char * RumPi::GasData::GetGasName ( ) const

Gets the human-readable name of this data's gas type.

Author
Eddie O'Hagan
Date
8/13/2026
const char* name = data.GetGasName();
Returns
The gas name (e.g. "Propane (C3H8)").

◆ GetGasName() [2/2]

const char * RumPi::GasData::GetGasName ( const EGasType gasType)
static

Gets the human-readable name for a given gas type.

Author
Eddie O'Hagan
Date
8/13/2026
const char * GetGasName() const
Gets the human-readable name of this data's gas type.
Definition: GasData.cpp:216
@ E_Propane
Definition: GasData.h:28

Output: Propane (C3H8)

Parameters
[in]gasTypeThe gas type to name.
Returns
The gas name, or "UNKNOWN" if the type is unrecognized.

◆ GetGasSlope()

double RumPi::GasData::GetGasSlope ( )

Gets the response curve's slope (m), calculating it first if it has not been computed yet.

Author
Eddie O'Hagan
Date
8/13/2026
double slope = data.GetGasSlope();
Returns
The slope (m) of the response curve.

◆ GetGasType()

EGasType RumPi::GasData::GetGasType ( ) const

Gets the gas type this data describes.

Author
Eddie O'Hagan
Date
8/13/2026
EGasType type = data.GetGasType();
EGasType
The types of gas the MQ sensor family can detect.
Definition: GasData.h:13
Returns
The gas type.

◆ GetGasYIntercept()

double RumPi::GasData::GetGasYIntercept ( ) const

Gets the response curve's y-intercept (b).

Author
Eddie O'Hagan
Date
8/13/2026
double yIntercept = data.GetGasYIntercept();
Returns
The y-intercept (b) of the response curve.

◆ GetIsUsingDataCache()

bool RumPi::GasData::GetIsUsingDataCache ( ) const

Gets whether this gas sensor uses the data cache for its calculations.

Author
Eddie O'Hagan
Date
8/13/2026
bool usingCache = data.GetIsUsingDataCache();
Returns
True if the data cache is used instead of slope/intercept.

◆ GetLastX()

double RumPi::GasData::GetLastX ( ) const

Gets the x of the last graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double lastX = data.GetLastX();
Returns
The x of the last graph point.

◆ GetLastY()

double RumPi::GasData::GetLastY ( ) const

Gets the y of the last graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double lastY = data.GetLastY();
Returns
The y of the last graph point.

◆ GetMiddleX()

double RumPi::GasData::GetMiddleX ( ) const

Gets the x of the middle graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double middleX = data.GetMiddleX();
Returns
The x of the middle graph point.

◆ GetMiddleY()

double RumPi::GasData::GetMiddleY ( ) const

Gets the y of the middle graph point.

Author
Eddie O'Hagan
Date
8/13/2026
double middleY = data.GetMiddleY();
Returns
The y of the middle graph point.

◆ SetDangerLevel()

void RumPi::GasData::SetDangerLevel ( const double &  dangerLevel)

Sets the concentration (ppm) considered dangerous for this gas.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetDangerLevel(1000.0);
Parameters
[in]dangerLevelThe danger level, in ppm.

◆ SetDataCacheValueAtIndex()

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.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetDataCacheValueAtIndex(512, 42.0);
Parameters
[in]indexThe raw analog value (0 to MAX_ANALOG_VALUE) to write.
[in]valueThe value to cache at that index.

◆ SetFirstX()

void RumPi::GasData::SetFirstX ( const double &  firstX)

Sets the x of the first graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetFirstX(200.0);
Parameters
[in]firstXThe x of the first graph point.

◆ SetFirstY()

void RumPi::GasData::SetFirstY ( const double &  firstY)

Sets the y of the first graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetFirstY(1.75);
Parameters
[in]firstYThe y of the first graph point.

◆ SetGasSlope()

void RumPi::GasData::SetGasSlope ( const double &  slope)

Sets the response curve's slope (m).

Author
Eddie O'Hagan
Date
8/13/2026
data.SetGasSlope(1.5);
Parameters
[in]slopeThe slope (m) to set.

◆ SetGasYIntercept()

void RumPi::GasData::SetGasYIntercept ( const double &  yIntercept)

Sets the response curve's y-intercept (b).

Author
Eddie O'Hagan
Date
8/13/2026
data.SetGasYIntercept(2.0);
Parameters
[in]yInterceptThe y-intercept (b) to set.

◆ SetIsUsingDataCache()

void RumPi::GasData::SetIsUsingDataCache ( const bool &  isUsingDataCache)

Sets whether this gas sensor uses the data cache for its calculations.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetIsUsingDataCache(true);
Parameters
[in]isUsingDataCacheTrue to use the data cache instead of slope/intercept.

◆ SetLastX()

void RumPi::GasData::SetLastX ( const double &  lastX)

Sets the x of the last graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetLastX(10000.0);
Parameters
[in]lastXThe x of the last graph point.

◆ SetLastY()

void RumPi::GasData::SetLastY ( const double &  lastY)

Sets the y of the last graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetLastY(0.44);
Parameters
[in]lastYThe y of the last graph point.

◆ SetMiddleX()

void RumPi::GasData::SetMiddleX ( const double &  middleX)

Sets the x of the middle graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetMiddleX(1000.0);
Parameters
[in]middleXThe x of the middle graph point.

◆ SetMiddleY()

void RumPi::GasData::SetMiddleY ( const double &  middleY)

Sets the y of the middle graph point.

Author
Eddie O'Hagan
Date
8/13/2026
data.SetMiddleY(0.99);
Parameters
[in]middleYThe y of the middle graph point.

◆ ToString()

std::string RumPi::GasData::ToString ( ) const

Serializes the gas name, slope, and y-intercept to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = gasData.ToString();
Returns
A string describing the gas data.

Member Data Documentation

◆ MAX_ANALOG_VALUE

const int RumPi::GasData::MAX_ANALOG_VALUE = 1023
static

The maximum 10-bit raw analog reading.

◆ myDangerLevel

double RumPi::GasData::myDangerLevel
private

The amount considered dangerous for this gas in ppm.

◆ myDataCache

double RumPi::GasData::myDataCache[MAX_ANALOG_VALUE+1] = {}
private

Cache of expensive calculations (e.g. BAC in the MQ-3). Zero-initialized; filled by cache-using sensors.

◆ myFirstX

double RumPi::GasData::myFirstX
private

The x in the first point on the graph.

◆ myFirstY

double RumPi::GasData::myFirstY
private

The y in the first point on the graph.

◆ myGasSlope

double RumPi::GasData::myGasSlope
private

The m in "y = mx + b".

◆ myGasType

EGasType RumPi::GasData::myGasType
private

The type of gas this data corresponds to.

◆ myGasYIntercept

double RumPi::GasData::myGasYIntercept
private

The b in "y = mx + b".

◆ myIsUsingDataCache

bool RumPi::GasData::myIsUsingDataCache
private

True if this gas sensor uses the data cache for calculations instead of slope and intercept.

◆ myLastX

double RumPi::GasData::myLastX
private

The x for the last point on the graph.

◆ myLastY

double RumPi::GasData::myLastY
private

The y for the last point on the graph.

◆ myMiddleX

double RumPi::GasData::myMiddleX
private

The x in-between the start and last.

◆ myMiddleY

double RumPi::GasData::myMiddleY
private

The y in-between the start and last.


The documentation for this class was generated from the following files: