From e6660e2c28a206823a7cdf3fdd6eb380a6321585 Mon Sep 17 00:00:00 2001 From: John Lienau Date: Mon, 17 Mar 2025 06:09:09 +0100 Subject: [PATCH 1/2] Use constexpressions instead of #defines in MQ131.h Using constant expressions (`constexpr`) instead of `#define` to get type-safety. --- src/MQ131.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MQ131.h b/src/MQ131.h index 40ed46a..2121993 100644 --- a/src/MQ131.h +++ b/src/MQ131.h @@ -34,15 +34,15 @@ #include // Default values -#define MQ131_DEFAULT_RL 1000000 // Default load resistance of 1MOhms -#define MQ131_DEFAULT_STABLE_CYCLE 15 // Number of cycles with low deviation to consider - // the calibration as stable and reliable -#define MQ131_DEFAULT_TEMPERATURE_CELSIUS 20 // Default temperature to correct environmental drift -#define MQ131_DEFAULT_HUMIDITY_PERCENT 65 // Default humidity to correct environmental drift -#define MQ131_DEFAULT_LO_CONCENTRATION_R0 1917.22 // Default R0 for low concentration MQ131 -#define MQ131_DEFAULT_LO_CONCENTRATION_TIME2READ 80 // Default time to read before stable signal for low concentration MQ131 -#define MQ131_DEFAULT_HI_CONCENTRATION_R0 235.00 // Default R0 for high concentration MQ131 -#define MQ131_DEFAULT_HI_CONCENTRATION_TIME2READ 80 // Default time to read before stable signal for high concentration MQ131 +constexpr int MQ131_DEFAULT_RL 1000000 // Default load resistance of 1MOhms +constexpr int MQ131_DEFAULT_STABLE_CYCLE 15 // Number of cycles with low deviation to consider + // the calibration as stable and reliable +constexpr int MQ131_DEFAULT_TEMPERATURE_CELSIUS 20 // Default temperature to correct environmental drift +constexpr int MQ131_DEFAULT_HUMIDITY_PERCENT 65 // Default humidity to correct environmental drift +constexpr float MQ131_DEFAULT_LO_CONCENTRATION_R0 1917.22 // Default R0 for low concentration MQ131 +constexpr int MQ131_DEFAULT_LO_CONCENTRATION_TIME2READ 80 // Default time to read before stable signal for low concentration MQ131 +constexpr float MQ131_DEFAULT_HI_CONCENTRATION_R0 235.00 // Default R0 for high concentration MQ131 +constexpr int MQ131_DEFAULT_HI_CONCENTRATION_TIME2READ 80 // Default time to read before stable signal for high concentration MQ131 enum MQ131Model {LOW_CONCENTRATION, HIGH_CONCENTRATION,SN_O2_LOW_CONCENTRATION}; enum MQ131Unit {PPM, PPB, MG_M3, UG_M3}; From 32cd9e15c985e4ea565ed45aaa5d2a81900b6678 Mon Sep 17 00:00:00 2001 From: John Lienau Date: Mon, 17 Mar 2025 05:15:08 +0000 Subject: [PATCH 2/2] Use pragma once instead of #define --- src/MQ131.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/MQ131.h b/src/MQ131.h index 2121993..0d95908 100644 --- a/src/MQ131.h +++ b/src/MQ131.h @@ -28,8 +28,7 @@ * SOFTWARE. *******************************************************************************/ -#ifndef _MQ131_H_ -#define _MQ131_H_ +#pragma once #include @@ -133,5 +132,3 @@ class MQ131Class { }; extern MQ131Class MQ131; - -#endif // _MQ131_H_