Skip to content

Commit f4e68f7

Browse files
committed
Added value typing logic/methodology - add a value *type* to an output parameter
1 parent fa64bba commit f4e68f7

File tree

28 files changed

+307
-68
lines changed

28 files changed

+307
-68
lines changed

src/core/flux_base/flxCoreParam.h

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,43 @@
2525
#include "flxCoreTypes.h"
2626
#include "flxUtils.h"
2727

28+
// Define a type used to enumerate parameter value types (not data types, but values, like temp, accel)
29+
30+
typedef uint16_t flxParamValueType_t;
31+
32+
const flxParamValueType_t kParamValueNone = 0;
33+
2834
//----------------------------------------------------------------------------------------
2935
// flxParameter
3036
//
3137
// Base/Core Parameter Class
3238
//
3339
// From an abstract sense, a basic parameter - nothing more
34-
40+
//
3541
class flxParameter : public flxDescriptor
3642
{
3743
bool _isEnabled;
44+
flxParamValueType_t _valueType;
3845

3946
public:
40-
flxParameter() : _isEnabled{true} {};
47+
flxParameter() : _isEnabled{true}, _valueType{kParamValueNone}
48+
{
49+
}
4150

4251
bool enabled(void)
4352
{
4453
return _isEnabled;
4554
}
4655

56+
flxParamValueType_t valueType(void)
57+
{
58+
return _valueType;
59+
}
60+
void setValueType(flxParamValueType_t type)
61+
{
62+
_valueType = type;
63+
}
64+
4765
virtual void setEnabled(bool enabled)
4866
{
4967
_isEnabled = enabled;
@@ -292,6 +310,14 @@ class _flxParameterOut : public _flxDataOut<T>, public flxParameterOutScalar
292310
(*this)(obj, name);
293311
}
294312

313+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
314+
{
315+
// Value type
316+
setValueType(vtype);
317+
318+
// cascade to other version of method
319+
(*this)(obj, name, desc);
320+
}
295321
// override to deal with dirty status of object.
296322
void setEnabled(bool bEnabled)
297323
{
@@ -488,6 +514,14 @@ class flxParameterOutString : public flxParameterOutScalar, public _flxDataOutSt
488514
(*this)(obj, name);
489515
}
490516

517+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
518+
{
519+
// Value type
520+
setValueType(vtype);
521+
522+
// cascade to other version of method
523+
(*this)(obj, name, desc);
524+
}
491525
// override to deal with dirty status of object.
492526
void setEnabled(bool bEnabled)
493527
{
@@ -641,6 +675,14 @@ class flxParameterOutArrayType : public flxParameterOutArray
641675
(*this)(obj, name);
642676
}
643677

678+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
679+
{
680+
// Value type
681+
setValueType(vtype);
682+
683+
// cascade to other version of method
684+
(*this)(obj, name, desc);
685+
}
644686
// override to deal with dirty status of object.
645687
void setEnabled(bool bEnabled)
646688
{
@@ -805,7 +847,14 @@ class flxParameterOutArrayString : public flxParameterOutArray
805847
// cascade to other version of method
806848
(*this)(obj, name);
807849
}
850+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
851+
{
852+
// Value type
853+
setValueType(vtype);
808854

855+
// cascade to other version of method
856+
(*this)(obj, name, desc);
857+
}
809858
// override to deal with dirty status of object.
810859
void setEnabled(bool bEnabled)
811860
{
@@ -913,6 +962,14 @@ class _flxParameterIn : public flxParameterIn, public _flxDataIn<T>
913962
(*this)(obj, name);
914963
}
915964

965+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
966+
{
967+
// Value type
968+
setValueType(vtype);
969+
970+
// cascade to other version of method
971+
(*this)(obj, name, desc);
972+
}
916973
//---------------------------------------------------------------------------------
917974
void set(T const &value)
918975
{
@@ -1063,6 +1120,14 @@ class flxParameterInString : public flxParameterIn, _flxDataInString
10631120
(*this)(obj, name);
10641121
}
10651122

1123+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
1124+
{
1125+
// Value type
1126+
setValueType(vtype);
1127+
1128+
// cascade to other version of method
1129+
(*this)(obj, name, desc);
1130+
}
10661131
//---------------------------------------------------------------------------------
10671132
void set(std::string const &value)
10681133
{
@@ -1188,6 +1253,15 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu
11881253
(*this)(obj, name);
11891254
}
11901255

1256+
void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype)
1257+
{
1258+
// Value type
1259+
setValueType(vtype);
1260+
1261+
// cascade to other version of method
1262+
(*this)(obj, name, desc);
1263+
}
1264+
11911265
//---------------------------------------------------------------------------------
11921266
void set()
11931267
{
@@ -1229,9 +1303,10 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu
12291303

12301304
// Use some macro magic to determine which actual call to make based on the number of passed in
12311305
// parameters..
1232-
#define _spGetRegAttributeMacro(_1, _2, _3, _NAME_, ...) _NAME_
1306+
#define _spGetRegAttributeMacro(_1, _2, _3, _4, _NAME_, ...) _NAME_
12331307
#define flxRegister(...) \
1234-
_spGetRegAttributeMacro(__VA_ARGS__, flxRegisterDesc, flxRegisterName, flxRegisterObj)(__VA_ARGS__)
1308+
_spGetRegAttributeMacro(__VA_ARGS__, flxRegisterValueType, flxRegisterDesc, flxRegisterName, \
1309+
flxRegisterObj)(__VA_ARGS__)
12351310

12361311
#define flxRegisterObj(_obj_name_) _obj_name_(this, #_obj_name_)
12371312

@@ -1241,6 +1316,9 @@ template <class Object, void (Object::*_setter)()> class flxParameterInVoid : pu
12411316
// User provided Name and description
12421317
#define flxRegisterDesc(_obj_name_, _name_, _desc_) _obj_name_(this, _name_, _desc_)
12431318

1319+
// For parameters - user provided value type
1320+
#define flxRegisterValueType(_obj_name_, _name_, _desc_, _type_) _obj_name_(this, _name_, _desc_, _type_)
1321+
12441322
// Define a object type that supports parameter lists (input and output)
12451323
class flxOperation : public flxObject, public _flxParameterContainer
12461324
{
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2022-2024, SparkFun Electronics Inc. All rights reserved.
5+
* This software includes information which is proprietary to and a
6+
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7+
* to anyone outside of this organization. Reproduction by any means
8+
* whatsoever is prohibited without express written permission.
9+
*
10+
*---------------------------------------------------------------------------------
11+
*/
12+
13+
#pragma once
14+
15+
#include "flxCoreParam.h"
16+
17+
// Define value types for our devices. These value types provide a broad parameter value type classification
18+
// to parameter values.
19+
//
20+
// A Value type is set on a parameter using a below code and using the setValueType() method. The
21+
// value type is retrieved using the valueType() method.
22+
//
23+
// Note - by default parameters have a value type of kParamValueNone - which is zero. Our types
24+
// are numbered starting at 1.
25+
26+
const flxParamValueType_t kParamValueTemperature = 1;
27+
const flxParamValueType_t kParamValueHumidity = 2;
28+
const flxParamValueType_t kParamValuePressure = 3;
29+
30+
// VOC - Volatile Organic Compounds concentration in ppb - uint16_t value
31+
const flxParamValueType_t kParamValueVOC = 4;
32+
33+
// AQI - Air Quality Index - uint16_t value
34+
const flxParamValueType_t kParamValueAQI = 5;
35+
36+
// CO2 - Carbon Dioxide concentration in ppb- uint16_t value
37+
const flxParamValueType_t kParamValueCO2 = 6;
38+
39+
// ETOH - Ethanol concentration in ppb - uint16_t value
40+
const flxParamValueType_t kParamValueETOH = 7;
41+
42+
// Humidity - Relative Humidity in percent - float value
43+
const flxParamValueType_t kParamValueHumidity_F = 8;
44+
45+
// Pressure - Pressure in Pascals - float value
46+
const flxParamValueType_t kParamValuePressure_F = 9;
47+
48+
// Temperature - Temperature in Celsius - float value
49+
const flxParamValueType_t kParamValueTempC = 10;
50+
51+
// Temperature - Temperature in Fahrenheit - float value
52+
const flxParamValueType_t kParamValueTempF = 11;
53+
54+
// TVOC - Total Volatile Organic Compounds concentration in ppb - float value
55+
const flxParamValueType_t kParamValueTVOC = 12;
56+
57+
// CO2 - Carbon Dioxide concentration in ppb- float value
58+
const flxParamValueType_t kParamValueCO2_F = 13;
59+
60+
// Meters Per Second - float value
61+
const flxParamValueType_t kParamValueMPS = 14;
62+
63+
// Miles Per Hour - float value
64+
const flxParamValueType_t kParamValueMPH = 15;
65+
66+
// Latitude - in degrees - float value
67+
const flxParamValueType_t kParamValueLatitude = 16;
68+
69+
// Longitude in degrees - float value
70+
const flxParamValueType_t kParamValueLongitude = 17;
71+
72+
// Altitude in meters - float value
73+
const flxParamValueType_t kParamValueAltitude = 18;
74+
75+
// Acceleration X in milli-g - float value
76+
const flxParamValueType_t kParamValueAccelX = 19;
77+
78+
// Acceleration Y in milli-g - float value
79+
const flxParamValueType_t kParamValueAccelY = 20;
80+
81+
// Acceleration Z in milli-g - float value
82+
const flxParamValueType_t kParamValueAccelZ = 21;
83+
84+
// Gyro X in milli-dps - float value
85+
const flxParamValueType_t kParamValueGyroX = 22;
86+
87+
// Gyro Y in milli-dps - float value
88+
const flxParamValueType_t kParamValueGyroY = 23;
89+
90+
// Gyro Z in milli-dps - float value
91+
const flxParamValueType_t kParamValueGyroZ = 24;
92+
93+
// Pressure in milli-bar - float value
94+
const flxParamValueType_t kParamValuePressure_mBar = 25;
95+
96+
// Weight in "user" units - float value
97+
const flxParamValueType_t kParamValueWeightUserUnits = 26;
98+
99+
// X Coordinate - CIE 1931 Color Space - float value
100+
const flxParamValueType_t kParamValueCIE_X = 27;
101+
102+
// Y Coordinate - CIE 1931 Color Space - float value
103+
const flxParamValueType_t kParamValueCIE_Y = 28;
104+
105+
// CCT - Correlated Color Temperature in Kelvin - uint16_t value
106+
const flxParamValueType_t kParamValueCCT = 29;
107+
108+
// LUX - Light intensity in Lux - uint32_t value
109+
const flxParamValueType_t kParamValueLUX = 30;
110+
111+
// Time - Epoch time in seconds - uint32_t value
112+
const flxParamValueType_t kParamValueEpoch = 31;
113+
114+
// CO2 - Carbon Dioxide concentration in ppm - uint32_t value
115+
const flxParamValueType_t kParamValueCO2_U32 = 32;
116+
117+
// TVOC - Total Volatile Organic Compounds concentration in ppb - uint32_t value
118+
const flxParamValueType_t kParamValueTVOC_U32 = 33;
119+
120+
// H2 - Hydrogen concentration in ppm - uint32_t value
121+
const flxParamValueType_t kParamValueH2 = 34;
122+
123+
// ETOH - Ethanol concentration in ppb - uint32_t value
124+
const flxParamValueType_t kParamValueETOH_U32 = 35;
125+
126+
// Presence - Presence detection 1/cm - int16_t value
127+
const flxParamValueType_t kParamValuePresence = 36;
128+
129+
// Motion - Motion detection value - int16_t value
130+
const flxParamValueType_t kParamValueMotion = 37;
131+
132+
// Proximity - Proximity detection value - uint16_t value
133+
const flxParamValueType_t kParamValueProximity = 38;
134+
135+
// Lux - Light intensity in Lux - uint16_t value
136+
const flxParamValueType_t kParamValueLUX_U16 = 39;
137+
138+
// UVA Index - float value
139+
const flxParamValueType_t kParamValueUVAIndex = 40;
140+
141+
// UVB Index - float value
142+
const flxParamValueType_t kParamValueUVBIndex = 41;
143+
144+
// UV Index - float value
145+
const flxParamValueType_t kParamValueUVIndex = 42;
146+
147+
// Lux - Light intensity in Lux - float value
148+
const flxParamValueType_t kParamValueLUX_F = 43;
149+
150+
// Ambient Light - Ambient light level - uint32_t value
151+
const flxParamValueType_t kParamValueAmbientLight = 44;
152+
153+
// White Light - White light level - uint32_t value
154+
const flxParamValueType_t kParamValueWhiteLight = 45;
155+
156+
// Distance - Distance in meters - uint32_t value
157+
const flxParamValueType_t kParamValueDistance = 46;

src/device/device_bme280/flxDevBME280.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ flxDevBME280::flxDevBME280()
5252
setDescription("The Bosch BME280 Atmospheric Sensor");
5353

5454
// Register parameters
55-
flxRegister(humidity, "Humidity", "The sensed humidity value");
56-
flxRegister(temperatureF, "TemperatureF", "The sensed Temperature in degrees Fahrenheit");
57-
flxRegister(temperatureC, "TemperatureC", "The sensed Temperature in degrees Celsius");
58-
flxRegister(pressure, "Pressure", "The sensed pressure");
55+
flxRegister(humidity, "Humidity", "The sensed humidity value", kParamValueHumidity_F);
56+
flxRegister(temperatureF, "TemperatureF", "The sensed Temperature in degrees Fahrenheit", kParamValueTempF);
57+
flxRegister(temperatureC, "TemperatureC", "The sensed Temperature in degrees Celsius", kParamValueTempC);
58+
flxRegister(pressure, "Pressure", "The sensed pressure", kParamValuePressure_F);
5959
flxRegister(altitudeM, "AltitudeM", "The sensed altitude in meters");
6060
flxRegister(altitudeF, "AltitudeF", "The sensed altitude in feet");
6161
}

src/device/device_bme68x/flxDevBME68x.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ flxDevBME68x::flxDevBME68x()
5353
setDescription("The Bosch BME68x Atmospheric Sensor");
5454

5555
// Register parameters
56-
flxRegister(humidity, "Humidity", "The sensed humidity value");
57-
flxRegister(temperatureC, "TemperatureC", "The sensed temperature in degrees C");
58-
flxRegister(pressure, "Pressure", "The sensed pressure");
56+
flxRegister(humidity, "Humidity", "The sensed humidity value", kParamValueHumidity_F);
57+
flxRegister(temperatureC, "TemperatureC", "The sensed temperature in degrees C", kParamValueTempC);
58+
flxRegister(pressure, "Pressure", "The sensed pressure", kParamValuePressure_F);
5959
flxRegister(gasResistance, "Gas Resistance", "The sensed gas resistance");
6060
flxRegister(status, "Sensor Status", "The sensor status");
6161
}

src/device/device_bmp384/flxDevBMP384.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ flxDevBMP384::flxDevBMP384()
5252
setDescription("The Bosch BMP384 Pressure and Temperature Sensor");
5353

5454
// Register parameters
55-
flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius");
56-
flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals");
55+
flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius", kParamValueTempC);
56+
flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals", kParamValueHumidity_F);
5757
}
5858

5959
//----------------------------------------------------------------------------------------------------------

src/device/device_bmp581/flxDevBMP581.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ flxDevBMP581::flxDevBMP581()
5252
setDescription("The Bosch BMP581 Pressure and Temperature Sensor.");
5353

5454
// Register parameters
55-
flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius");
56-
flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals");
55+
flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius", kParamValueTempC);
56+
flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals", kParamValuePressure_F);
5757
}
5858

5959
//----------------------------------------------------------------------------------------------------------

src/device/device_ccs811/flxDevCCS811.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ flxDevCCS811::flxDevCCS811() //: CCS811(kCCS811AddressDefault)
4242
setDescription("An air quality sensor from AMS");
4343

4444
// Register output params
45-
flxRegister(co2, "CO2", "CO2 reading");
46-
flxRegister(tvoc, "VOC", "Volatile Organic Compound reading");
45+
flxRegister(co2, "CO2", "CO2 reading", kParamValueCO2_F);
46+
flxRegister(tvoc, "VOC", "Volatile Organic Compound reading", kParamValueTVOC);
4747
}
4848

4949
// Function to encapsulate the ops needed to get values from the sensor.

0 commit comments

Comments
 (0)