From d2dd65da2465b0f76dfb4d22b5755c58f768bf9c Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Tue, 23 Jul 2024 15:46:13 -0600 Subject: [PATCH 1/9] Added a warning message if the device isnt' in the channel setting. --- src/iot/iot_thingspeak/flxIoTThingSpeak.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/iot/iot_thingspeak/flxIoTThingSpeak.h b/src/iot/iot_thingspeak/flxIoTThingSpeak.h index 3d7bf22..798b0f3 100644 --- a/src/iot/iot_thingspeak/flxIoTThingSpeak.h +++ b/src/iot/iot_thingspeak/flxIoTThingSpeak.h @@ -92,7 +92,10 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore, public { jObj = jsonDoc[it->first]; if (jObj.isNull()) + { + flxLog_W(F("ThingSpeak - no channel id found for device: %s. Check the Channel setting"), it->first); continue; + } // Thingspeak channel values are sent as "field=&field=..." buffer = ""; From 56b803992a9012bd2b2d2236bf43052d66059267 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 24 Jul 2024 10:09:37 -0600 Subject: [PATCH 2/9] added check for dup thingstream channel ids --- src/iot/iot_thingspeak/flxIoTThingSpeak.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/iot/iot_thingspeak/flxIoTThingSpeak.h b/src/iot/iot_thingspeak/flxIoTThingSpeak.h index 798b0f3..e303b27 100644 --- a/src/iot/iot_thingspeak/flxIoTThingSpeak.h +++ b/src/iot/iot_thingspeak/flxIoTThingSpeak.h @@ -51,6 +51,7 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore, public std::stringstream s_stream(theList); // create string stream from the string std::string keyvalue; std::string::size_type sz; + std::string newValue; while (s_stream.good()) { @@ -65,7 +66,18 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore, public flxLogM_W(kMsgErrValueError, name(), "Device=Channel ID"); continue; } - _deviceToChannel[flx_utils::strtrim(keyvalue.substr(0, sz))] = flx_utils::strtrim(keyvalue.substr(sz + 1)); + newValue = flx_utils::strtrim(keyvalue.substr(sz + 1)); + // no dups for values (channel ids) + for (auto it = _deviceToChannel.begin(); it != _deviceToChannel.end(); it++) + { + if (it->second == newValue) + { + flxLogM_W(kMsgErrValueError, name(), "Duplicate ThingStream channel ID [%s], skipping", + keyvalue.c_str()); + continue; + } + } + _deviceToChannel[flx_utils::strtrim(keyvalue.substr(0, sz))] = newValue; } } From 614a0144b05e798bdce93c252eb7960513065b49 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Thu, 1 Aug 2024 11:59:27 -0600 Subject: [PATCH 3/9] the mqtt topic is automatically set, so no need to expose the property the user - now hiding property in class constructor --- src/iot/iot_thingspeak/flxIoTThingSpeak.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/iot/iot_thingspeak/flxIoTThingSpeak.h b/src/iot/iot_thingspeak/flxIoTThingSpeak.h index e303b27..36b9670 100644 --- a/src/iot/iot_thingspeak/flxIoTThingSpeak.h +++ b/src/iot/iot_thingspeak/flxIoTThingSpeak.h @@ -88,6 +88,10 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore, public flxRegister(deviceList, "Channels", "Comma separated list of ="); + // The topic is auto-generated -- it needs/uses the channel ID. So, let's hide the topic property it from the + // user + topic.setHidden(true); + flux.add(this); } From 6530c62fb81e63a89b38dd0f8af3ebc40e238fad Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Thu, 1 Aug 2024 13:01:24 -0600 Subject: [PATCH 4/9] added method to hide a property at runtime --- src/core/flux_base/flxCoreProps.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/flux_base/flxCoreProps.h b/src/core/flux_base/flxCoreProps.h index fc38c29..641c4a6 100644 --- a/src/core/flux_base/flxCoreProps.h +++ b/src/core/flux_base/flxCoreProps.h @@ -63,6 +63,7 @@ class flxProperty : public flxDescriptor virtual flxDataVariable getValue(void) = 0; virtual bool hidden(void) = 0; + virtual void setHidden(void) = 0; virtual bool secure(void) = 0; //--------------------------------------------------------------------------------- virtual size_t size(void) @@ -209,6 +210,16 @@ class _flxPropertyContainer return totalSize; }; + //--------------------------------------------------------------------------------- + // method to hide a property. + void hideProperty(flxProperty &theProp) + { + theProp.setHidden(); + // deal with hidden property optimization.. + removeProperty(theProp); + addProperty(theProp); + } + private: flxPropertyList _properties; @@ -247,6 +258,11 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn, public _flxDa { return _isHidden; } + // Add a method that allows the property to be hidden if public + void setHidden(void) + { + _isHidden = true; + } bool secure() { return _isSecure; @@ -394,6 +410,11 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut { return _isHidden; } + // Add a method that allows the property to be hidden if public + void setHidden(void) + { + _isHidden = true; + } bool secure() { return _isSecure; From 901e83dd1a92cf67362c435ca762618002eacaf3 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Thu, 1 Aug 2024 13:01:55 -0600 Subject: [PATCH 5/9] hides the topic property correctly now --- src/iot/iot_thingspeak/flxIoTThingSpeak.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iot/iot_thingspeak/flxIoTThingSpeak.h b/src/iot/iot_thingspeak/flxIoTThingSpeak.h index 36b9670..2bb88c7 100644 --- a/src/iot/iot_thingspeak/flxIoTThingSpeak.h +++ b/src/iot/iot_thingspeak/flxIoTThingSpeak.h @@ -89,8 +89,8 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore, public flxRegister(deviceList, "Channels", "Comma separated list of ="); // The topic is auto-generated -- it needs/uses the channel ID. So, let's hide the topic property it from the - // user - topic.setHidden(true); + // user. + hideProperty(topic); flux.add(this); } From 46f9e23c822de6f0eabad9b4cfa7b7bad3154f62 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Tue, 24 Sep 2024 07:29:19 -0600 Subject: [PATCH 6/9] Tweaks as a result of RP2350 porting of the framework --- src/core/flux_base/flxCoreLog.h | 2 +- src/core/flux_base/flxCoreTypes.h | 1 + src/core/flux_base/flxSerial.h | 12 ++++++------ src/core/flux_base/flxUtils.cpp | 2 +- src/core/flux_logging/flxLogger.cpp | 2 +- src/device/device_gnss/flxDevGNSS.h | 2 +- src/device/device_nau7802/flxDevNAU7802.h | 6 +++--- src/device/device_pasco2v01/flxDevPASCO2V01.h | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/core/flux_base/flxCoreLog.h b/src/core/flux_base/flxCoreLog.h index eb9a3e1..2181fb7 100644 --- a/src/core/flux_base/flxCoreLog.h +++ b/src/core/flux_base/flxCoreLog.h @@ -143,7 +143,7 @@ class flxLogging //------------------------------------------------------------------------- // generic log interface - for flash strings - int logPrintf(const flxLogLevel_t level, bool newline, const __FlashStringHelper *fmt, ...); + int logPrintf(const flxLogLevel_t level, bool newline, const arduino::__FlashStringHelper *fmt, ...); //------------------------------------------------------------------------- // generic log interface diff --git a/src/core/flux_base/flxCoreTypes.h b/src/core/flux_base/flxCoreTypes.h index b3d7eae..0b247a7 100644 --- a/src/core/flux_base/flxCoreTypes.h +++ b/src/core/flux_base/flxCoreTypes.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "flxCoreLog.h" #include "flxUtils.h" diff --git a/src/core/flux_base/flxSerial.h b/src/core/flux_base/flxSerial.h index e87ae77..a46037e 100644 --- a/src/core/flux_base/flxSerial.h +++ b/src/core/flux_base/flxSerial.h @@ -97,12 +97,12 @@ class flxSerial_ : public flxWriter flxSerial_() : _headerWritten{false}, _colorEnabled{false} {}; // Color strings for serial consoles - static constexpr char *kClrNormal = "\033[0;39m"; - static constexpr char *kClrGreen = "\033[1;32m"; - static constexpr char *kClrYellow = "\033[1;33m"; - static constexpr char *kClrRed = "\033[1;31m"; - static constexpr char *kClrBlue = "\033[1;34m"; - static constexpr char *kClrWhite = "\033[1;37m"; + static constexpr const char *kClrNormal = "\033[0;39m"; + static constexpr const char *kClrGreen = "\033[1;32m"; + static constexpr const char *kClrYellow = "\033[1;33m"; + static constexpr const char *kClrRed = "\033[1;31m"; + static constexpr const char *kClrBlue = "\033[1;34m"; + static constexpr const char *kClrWhite = "\033[1;37m"; bool _headerWritten; diff --git a/src/core/flux_base/flxUtils.cpp b/src/core/flux_base/flxUtils.cpp index 1ebb4f9..e3261c3 100644 --- a/src/core/flux_base/flxUtils.cpp +++ b/src/core/flux_base/flxUtils.cpp @@ -403,7 +403,7 @@ void flx_utils::timestampISO8601(time_t &t_time, char *buffer, size_t length, bo void flx_utils::formatByteString(uint64_t nBytes, uint prec, char *szBuffer, size_t len) { - char *sizeNames[] = {"B", "KB", "MB", "GB", "TB"}; + const char *sizeNames[] = {"B", "KB", "MB", "GB", "TB"}; if (nBytes < 0) nBytes = 0; diff --git a/src/core/flux_logging/flxLogger.cpp b/src/core/flux_logging/flxLogger.cpp index d777dca..bd83948 100644 --- a/src/core/flux_logging/flxLogger.cpp +++ b/src/core/flux_logging/flxLogger.cpp @@ -362,7 +362,7 @@ void flxLogger::logMessage(char *header, char *message) void flxLogger::updateTimeParameterName(void) { - char *timeTitle = "Time"; + const char *timeTitle = "Time"; switch (_timestampType) { case TimeStampMillis: diff --git a/src/device/device_gnss/flxDevGNSS.h b/src/device/device_gnss/flxDevGNSS.h index 0e05afe..d54b854 100644 --- a/src/device/device_gnss/flxDevGNSS.h +++ b/src/device/device_gnss/flxDevGNSS.h @@ -83,7 +83,7 @@ class flxDevGNSS : public flxDeviceI2CType, public flxIClock, public float read_pdop(); float read_horiz_acc(); float read_vert_acc(); - uint read_tow(); + uint32_t read_tow(); std::string read_iso8601(); std::string read_yyyy_mm_dd(); std::string read_yyyy_dd_mm(); diff --git a/src/device/device_nau7802/flxDevNAU7802.h b/src/device/device_nau7802/flxDevNAU7802.h index 9918a71..1628eda 100644 --- a/src/device/device_nau7802/flxDevNAU7802.h +++ b/src/device/device_nau7802/flxDevNAU7802.h @@ -70,17 +70,17 @@ class flxDevNAU7802 : public flxDeviceI2CType, public NAU7802 // methods used to get values for our RW properties int32_t get_zero_offset(); - void set_zero_offset(int); + void set_zero_offset(int32_t); float get_calibration_factor(); void set_calibration_factor(float); // methods for the external calibration offset and gain hidden properties int32_t get_ext_offset(void); - void set_ext_offset(int); + void set_ext_offset(int32_t); uint32_t get_ext_gain(void); - void set_ext_gain(uint); + void set_ext_gain(uint32_t); // methods used to set our input parameters void calculate_zero_offset(); diff --git a/src/device/device_pasco2v01/flxDevPASCO2V01.h b/src/device/device_pasco2v01/flxDevPASCO2V01.h index 856b755..cedb90f 100644 --- a/src/device/device_pasco2v01/flxDevPASCO2V01.h +++ b/src/device/device_pasco2v01/flxDevPASCO2V01.h @@ -66,7 +66,7 @@ class flxDevPASCO2V01 : public flxDeviceI2CType PASCO2Ino *_theSensor; // methods used to get values for our output parameters - uint read_CO2(); + uint32_t read_CO2(); // methods used to get values for our RW properties bool get_auto_calibrate(); From fa64bbae7799796273226e6a23dfa03c8a3e3023 Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Tue, 24 Sep 2024 08:59:10 -0600 Subject: [PATCH 7/9] tweak for platform diffs of flash string def --- src/core/flux_base/flxCoreLog.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/flux_base/flxCoreLog.h b/src/core/flux_base/flxCoreLog.h index 2181fb7..9b4fefc 100644 --- a/src/core/flux_base/flxCoreLog.h +++ b/src/core/flux_base/flxCoreLog.h @@ -13,7 +13,7 @@ #pragma once // Messaging/logging system for the framework -//#include "flxCoreEvent.h" +// #include "flxCoreEvent.h" #include #include #include @@ -143,7 +143,13 @@ class flxLogging //------------------------------------------------------------------------- // generic log interface - for flash strings - int logPrintf(const flxLogLevel_t level, bool newline, const arduino::__FlashStringHelper *fmt, ...); + int logPrintf(const flxLogLevel_t level, bool newline, +#if defined(ESP32) || defined(ESP8266) + const __FlashStringHelper *fmt, +#else + const arduino::__FlashStringHelper *fmt, +#endif + ...); //------------------------------------------------------------------------- // generic log interface From f4e68f7da0011a9dc8a1d281bf99b433d923acef Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 13 Nov 2024 13:23:28 -0700 Subject: [PATCH 8/9] Added value typing logic/methodology - add a value *type* to an output parameter --- src/core/flux_base/flxCoreParam.h | 86 +++++++++- src/core/flux_base/flxDeviceValueTypes.h | 157 ++++++++++++++++++ src/device/device_bme280/flxDevBME280.cpp | 8 +- src/device/device_bme68x/flxDevBME68x.cpp | 6 +- src/device/device_bmp384/flxDevBMP384.cpp | 4 +- src/device/device_bmp581/flxDevBMP581.cpp | 4 +- src/device/device_ccs811/flxDevCCS811.cpp | 4 +- src/device/device_ens160/flxDevENS160.cpp | 12 +- src/device/device_fs3000/flxDevFS3000.cpp | 4 +- src/device/device_gnss/flxDevGNSS.cpp | 6 +- src/device/device_ism330/flxDevISM330.cpp | 12 +- src/device/device_lps25hb/flxDevLPS25HB.cpp | 4 +- .../flxDevMicroPressure.cpp | 2 +- src/device/device_ms5637/flxDevMS5637.cpp | 4 +- src/device/device_nau7802/flxDevNAU7802.cpp | 2 +- src/device/device_opt4048/flxDevOPT4048.cpp | 8 +- src/device/device_rv8803/flxDevRV8803.cpp | 2 +- src/device/device_scd40/flxDevSCD40.cpp | 6 +- src/device/device_sgp30/flxDevSGP30.cpp | 8 +- src/device/device_sgp40/flxDevSGP40.cpp | 2 +- src/device/device_shtc3/flxDevSHTC3.cpp | 6 +- src/device/device_stc31/flxDevSTC31.cpp | 4 +- .../device_sths34pf80/flxDevSTHS34PF80.cpp | 4 +- src/device/device_tmp117/flxDevTMP117.cpp | 2 +- src/device/device_vcnl4040/flxDevVCNL4040.cpp | 4 +- src/device/device_veml6075/flxDevVEML6075.cpp | 6 +- src/device/device_veml7700/flxDevVEML7700.cpp | 6 +- src/device/device_vl53l1x/flxDevVL53L1X.cpp | 2 +- 28 files changed, 307 insertions(+), 68 deletions(-) create mode 100644 src/core/flux_base/flxDeviceValueTypes.h diff --git a/src/core/flux_base/flxCoreParam.h b/src/core/flux_base/flxCoreParam.h index 877c639..4f6d191 100644 --- a/src/core/flux_base/flxCoreParam.h +++ b/src/core/flux_base/flxCoreParam.h @@ -25,25 +25,43 @@ #include "flxCoreTypes.h" #include "flxUtils.h" +// Define a type used to enumerate parameter value types (not data types, but values, like temp, accel) + +typedef uint16_t flxParamValueType_t; + +const flxParamValueType_t kParamValueNone = 0; + //---------------------------------------------------------------------------------------- // flxParameter // // Base/Core Parameter Class // // From an abstract sense, a basic parameter - nothing more - +// class flxParameter : public flxDescriptor { bool _isEnabled; + flxParamValueType_t _valueType; public: - flxParameter() : _isEnabled{true} {}; + flxParameter() : _isEnabled{true}, _valueType{kParamValueNone} + { + } bool enabled(void) { return _isEnabled; } + flxParamValueType_t valueType(void) + { + return _valueType; + } + void setValueType(flxParamValueType_t type) + { + _valueType = type; + } + virtual void setEnabled(bool enabled) { _isEnabled = enabled; @@ -292,6 +310,14 @@ class _flxParameterOut : public _flxDataOut, public flxParameterOutScalar (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } // override to deal with dirty status of object. void setEnabled(bool bEnabled) { @@ -488,6 +514,14 @@ class flxParameterOutString : public flxParameterOutScalar, public _flxDataOutSt (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } // override to deal with dirty status of object. void setEnabled(bool bEnabled) { @@ -641,6 +675,14 @@ class flxParameterOutArrayType : public flxParameterOutArray (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } // override to deal with dirty status of object. void setEnabled(bool bEnabled) { @@ -805,7 +847,14 @@ class flxParameterOutArrayString : public flxParameterOutArray // cascade to other version of method (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + // cascade to other version of method + (*this)(obj, name, desc); + } // override to deal with dirty status of object. void setEnabled(bool bEnabled) { @@ -913,6 +962,14 @@ class _flxParameterIn : public flxParameterIn, public _flxDataIn (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } //--------------------------------------------------------------------------------- void set(T const &value) { @@ -1063,6 +1120,14 @@ class flxParameterInString : public flxParameterIn, _flxDataInString (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } //--------------------------------------------------------------------------------- void set(std::string const &value) { @@ -1188,6 +1253,15 @@ template class flxParameterInVoid : pu (*this)(obj, name); } + void operator()(Object *obj, const char *name, const char *desc, flxParamValueType_t vtype) + { + // Value type + setValueType(vtype); + + // cascade to other version of method + (*this)(obj, name, desc); + } + //--------------------------------------------------------------------------------- void set() { @@ -1229,9 +1303,10 @@ template class flxParameterInVoid : pu // Use some macro magic to determine which actual call to make based on the number of passed in // parameters.. -#define _spGetRegAttributeMacro(_1, _2, _3, _NAME_, ...) _NAME_ +#define _spGetRegAttributeMacro(_1, _2, _3, _4, _NAME_, ...) _NAME_ #define flxRegister(...) \ - _spGetRegAttributeMacro(__VA_ARGS__, flxRegisterDesc, flxRegisterName, flxRegisterObj)(__VA_ARGS__) + _spGetRegAttributeMacro(__VA_ARGS__, flxRegisterValueType, flxRegisterDesc, flxRegisterName, \ + flxRegisterObj)(__VA_ARGS__) #define flxRegisterObj(_obj_name_) _obj_name_(this, #_obj_name_) @@ -1241,6 +1316,9 @@ template class flxParameterInVoid : pu // User provided Name and description #define flxRegisterDesc(_obj_name_, _name_, _desc_) _obj_name_(this, _name_, _desc_) +// For parameters - user provided value type +#define flxRegisterValueType(_obj_name_, _name_, _desc_, _type_) _obj_name_(this, _name_, _desc_, _type_) + // Define a object type that supports parameter lists (input and output) class flxOperation : public flxObject, public _flxParameterContainer { diff --git a/src/core/flux_base/flxDeviceValueTypes.h b/src/core/flux_base/flxDeviceValueTypes.h new file mode 100644 index 0000000..c903056 --- /dev/null +++ b/src/core/flux_base/flxDeviceValueTypes.h @@ -0,0 +1,157 @@ +/* + *--------------------------------------------------------------------------------- + * + * Copyright (c) 2022-2024, SparkFun Electronics Inc. All rights reserved. + * This software includes information which is proprietary to and a + * trade secret of SparkFun Electronics Inc. It is not to be disclosed + * to anyone outside of this organization. Reproduction by any means + * whatsoever is prohibited without express written permission. + * + *--------------------------------------------------------------------------------- + */ + +#pragma once + +#include "flxCoreParam.h" + +// Define value types for our devices. These value types provide a broad parameter value type classification +// to parameter values. +// +// A Value type is set on a parameter using a below code and using the setValueType() method. The +// value type is retrieved using the valueType() method. +// +// Note - by default parameters have a value type of kParamValueNone - which is zero. Our types +// are numbered starting at 1. + +const flxParamValueType_t kParamValueTemperature = 1; +const flxParamValueType_t kParamValueHumidity = 2; +const flxParamValueType_t kParamValuePressure = 3; + +// VOC - Volatile Organic Compounds concentration in ppb - uint16_t value +const flxParamValueType_t kParamValueVOC = 4; + +// AQI - Air Quality Index - uint16_t value +const flxParamValueType_t kParamValueAQI = 5; + +// CO2 - Carbon Dioxide concentration in ppb- uint16_t value +const flxParamValueType_t kParamValueCO2 = 6; + +// ETOH - Ethanol concentration in ppb - uint16_t value +const flxParamValueType_t kParamValueETOH = 7; + +// Humidity - Relative Humidity in percent - float value +const flxParamValueType_t kParamValueHumidity_F = 8; + +// Pressure - Pressure in Pascals - float value +const flxParamValueType_t kParamValuePressure_F = 9; + +// Temperature - Temperature in Celsius - float value +const flxParamValueType_t kParamValueTempC = 10; + +// Temperature - Temperature in Fahrenheit - float value +const flxParamValueType_t kParamValueTempF = 11; + +// TVOC - Total Volatile Organic Compounds concentration in ppb - float value +const flxParamValueType_t kParamValueTVOC = 12; + +// CO2 - Carbon Dioxide concentration in ppb- float value +const flxParamValueType_t kParamValueCO2_F = 13; + +// Meters Per Second - float value +const flxParamValueType_t kParamValueMPS = 14; + +// Miles Per Hour - float value +const flxParamValueType_t kParamValueMPH = 15; + +// Latitude - in degrees - float value +const flxParamValueType_t kParamValueLatitude = 16; + +// Longitude in degrees - float value +const flxParamValueType_t kParamValueLongitude = 17; + +// Altitude in meters - float value +const flxParamValueType_t kParamValueAltitude = 18; + +// Acceleration X in milli-g - float value +const flxParamValueType_t kParamValueAccelX = 19; + +// Acceleration Y in milli-g - float value +const flxParamValueType_t kParamValueAccelY = 20; + +// Acceleration Z in milli-g - float value +const flxParamValueType_t kParamValueAccelZ = 21; + +// Gyro X in milli-dps - float value +const flxParamValueType_t kParamValueGyroX = 22; + +// Gyro Y in milli-dps - float value +const flxParamValueType_t kParamValueGyroY = 23; + +// Gyro Z in milli-dps - float value +const flxParamValueType_t kParamValueGyroZ = 24; + +// Pressure in milli-bar - float value +const flxParamValueType_t kParamValuePressure_mBar = 25; + +// Weight in "user" units - float value +const flxParamValueType_t kParamValueWeightUserUnits = 26; + +// X Coordinate - CIE 1931 Color Space - float value +const flxParamValueType_t kParamValueCIE_X = 27; + +// Y Coordinate - CIE 1931 Color Space - float value +const flxParamValueType_t kParamValueCIE_Y = 28; + +// CCT - Correlated Color Temperature in Kelvin - uint16_t value +const flxParamValueType_t kParamValueCCT = 29; + +// LUX - Light intensity in Lux - uint32_t value +const flxParamValueType_t kParamValueLUX = 30; + +// Time - Epoch time in seconds - uint32_t value +const flxParamValueType_t kParamValueEpoch = 31; + +// CO2 - Carbon Dioxide concentration in ppm - uint32_t value +const flxParamValueType_t kParamValueCO2_U32 = 32; + +// TVOC - Total Volatile Organic Compounds concentration in ppb - uint32_t value +const flxParamValueType_t kParamValueTVOC_U32 = 33; + +// H2 - Hydrogen concentration in ppm - uint32_t value +const flxParamValueType_t kParamValueH2 = 34; + +// ETOH - Ethanol concentration in ppb - uint32_t value +const flxParamValueType_t kParamValueETOH_U32 = 35; + +// Presence - Presence detection 1/cm - int16_t value +const flxParamValueType_t kParamValuePresence = 36; + +// Motion - Motion detection value - int16_t value +const flxParamValueType_t kParamValueMotion = 37; + +// Proximity - Proximity detection value - uint16_t value +const flxParamValueType_t kParamValueProximity = 38; + +// Lux - Light intensity in Lux - uint16_t value +const flxParamValueType_t kParamValueLUX_U16 = 39; + +// UVA Index - float value +const flxParamValueType_t kParamValueUVAIndex = 40; + +// UVB Index - float value +const flxParamValueType_t kParamValueUVBIndex = 41; + +// UV Index - float value +const flxParamValueType_t kParamValueUVIndex = 42; + +// Lux - Light intensity in Lux - float value +const flxParamValueType_t kParamValueLUX_F = 43; + +// Ambient Light - Ambient light level - uint32_t value +const flxParamValueType_t kParamValueAmbientLight = 44; + +// White Light - White light level - uint32_t value +const flxParamValueType_t kParamValueWhiteLight = 45; + +// Distance - Distance in meters - uint32_t value +const flxParamValueType_t kParamValueDistance = 46; \ No newline at end of file diff --git a/src/device/device_bme280/flxDevBME280.cpp b/src/device/device_bme280/flxDevBME280.cpp index e93347b..b58567f 100644 --- a/src/device/device_bme280/flxDevBME280.cpp +++ b/src/device/device_bme280/flxDevBME280.cpp @@ -52,10 +52,10 @@ flxDevBME280::flxDevBME280() setDescription("The Bosch BME280 Atmospheric Sensor"); // Register parameters - flxRegister(humidity, "Humidity", "The sensed humidity value"); - flxRegister(temperatureF, "TemperatureF", "The sensed Temperature in degrees Fahrenheit"); - flxRegister(temperatureC, "TemperatureC", "The sensed Temperature in degrees Celsius"); - flxRegister(pressure, "Pressure", "The sensed pressure"); + flxRegister(humidity, "Humidity", "The sensed humidity value", kParamValueHumidity_F); + flxRegister(temperatureF, "TemperatureF", "The sensed Temperature in degrees Fahrenheit", kParamValueTempF); + flxRegister(temperatureC, "TemperatureC", "The sensed Temperature in degrees Celsius", kParamValueTempC); + flxRegister(pressure, "Pressure", "The sensed pressure", kParamValuePressure_F); flxRegister(altitudeM, "AltitudeM", "The sensed altitude in meters"); flxRegister(altitudeF, "AltitudeF", "The sensed altitude in feet"); } diff --git a/src/device/device_bme68x/flxDevBME68x.cpp b/src/device/device_bme68x/flxDevBME68x.cpp index 2558885..32c1060 100644 --- a/src/device/device_bme68x/flxDevBME68x.cpp +++ b/src/device/device_bme68x/flxDevBME68x.cpp @@ -53,9 +53,9 @@ flxDevBME68x::flxDevBME68x() setDescription("The Bosch BME68x Atmospheric Sensor"); // Register parameters - flxRegister(humidity, "Humidity", "The sensed humidity value"); - flxRegister(temperatureC, "TemperatureC", "The sensed temperature in degrees C"); - flxRegister(pressure, "Pressure", "The sensed pressure"); + flxRegister(humidity, "Humidity", "The sensed humidity value", kParamValueHumidity_F); + flxRegister(temperatureC, "TemperatureC", "The sensed temperature in degrees C", kParamValueTempC); + flxRegister(pressure, "Pressure", "The sensed pressure", kParamValuePressure_F); flxRegister(gasResistance, "Gas Resistance", "The sensed gas resistance"); flxRegister(status, "Sensor Status", "The sensor status"); } diff --git a/src/device/device_bmp384/flxDevBMP384.cpp b/src/device/device_bmp384/flxDevBMP384.cpp index 070364b..5f0d824 100644 --- a/src/device/device_bmp384/flxDevBMP384.cpp +++ b/src/device/device_bmp384/flxDevBMP384.cpp @@ -52,8 +52,8 @@ flxDevBMP384::flxDevBMP384() setDescription("The Bosch BMP384 Pressure and Temperature Sensor"); // Register parameters - flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius"); - flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals"); + flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius", kParamValueTempC); + flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals", kParamValueHumidity_F); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_bmp581/flxDevBMP581.cpp b/src/device/device_bmp581/flxDevBMP581.cpp index 4c23262..83b267f 100644 --- a/src/device/device_bmp581/flxDevBMP581.cpp +++ b/src/device/device_bmp581/flxDevBMP581.cpp @@ -52,8 +52,8 @@ flxDevBMP581::flxDevBMP581() setDescription("The Bosch BMP581 Pressure and Temperature Sensor."); // Register parameters - flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius"); - flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals"); + flxRegister(temperatureC, "Temperature (C)", "The sensed temperature in degrees Celsius", kParamValueTempC); + flxRegister(pressure, "Pressure (Pa)", "The sensed pressure in Pascals", kParamValuePressure_F); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_ccs811/flxDevCCS811.cpp b/src/device/device_ccs811/flxDevCCS811.cpp index 6f03e40..0fd0a7a 100644 --- a/src/device/device_ccs811/flxDevCCS811.cpp +++ b/src/device/device_ccs811/flxDevCCS811.cpp @@ -42,8 +42,8 @@ flxDevCCS811::flxDevCCS811() //: CCS811(kCCS811AddressDefault) setDescription("An air quality sensor from AMS"); // Register output params - flxRegister(co2, "CO2", "CO2 reading"); - flxRegister(tvoc, "VOC", "Volatile Organic Compound reading"); + flxRegister(co2, "CO2", "CO2 reading", kParamValueCO2_F); + flxRegister(tvoc, "VOC", "Volatile Organic Compound reading", kParamValueTVOC); } // Function to encapsulate the ops needed to get values from the sensor. diff --git a/src/device/device_ens160/flxDevENS160.cpp b/src/device/device_ens160/flxDevENS160.cpp index 524b149..615223e 100644 --- a/src/device/device_ens160/flxDevENS160.cpp +++ b/src/device/device_ens160/flxDevENS160.cpp @@ -45,10 +45,14 @@ flxDevENS160::flxDevENS160() : _opMode{SFE_ENS160_STANDARD}, _tempCComp{nullptr} flxRegister(updatePeriodSecs, "Update Period", "Compensation from input device update period (secs)"); // Register output params - flxRegister(val_AQI, "AQI", "Air Quality Index"); - flxRegister(val_TVOC, "TVOC", "Total Volatile Organic Compound"); - flxRegister(val_ETOH, "ETOH", "Ethanol Concentration"); - flxRegister(val_ECO2, "eCO2", "Equivalent CO2"); + flxRegister(val_AQI, "AQI", "Air Quality Index", kParamValueAQI); + + flxRegister(val_TVOC, "TVOC", "Total Volatile Organic Compound", kParamValueVOC); + + flxRegister(val_ETOH, "ETOH", "Ethanol Concentration", kParamValueETOH); + + flxRegister(val_ECO2, "eCO2", "Equivalent CO2", kParamValueCO2); + flxRegister(val_TempC, "Temp Comp", "The current temperature compensation value (C)"); flxRegister(val_RH, "Humidity Comp", "The current relative humidity compensation value"); diff --git a/src/device/device_fs3000/flxDevFS3000.cpp b/src/device/device_fs3000/flxDevFS3000.cpp index 8c23916..69c43f4 100644 --- a/src/device/device_fs3000/flxDevFS3000.cpp +++ b/src/device/device_fs3000/flxDevFS3000.cpp @@ -35,8 +35,8 @@ flxDevFS3000::flxDevFS3000() setDescription("FS3000 air velocity sensor"); // Register output params - flxRegister(flow_mps, "Flow (MPS)", "Flow (Metres Per Second)"); - flxRegister(flow_mph, "Flow (MPH)", "Flow (Miles Per Hour)"); + flxRegister(flow_mps, "Flow (MPS)", "Flow (Metres Per Second)", kParamValueMPS); + flxRegister(flow_mph, "Flow (MPH)", "Flow (Miles Per Hour)", kParamValueMPH); // Register property flxRegister(fs3000version, "FS3000 Version", "FS3000 Sensor Version"); diff --git a/src/device/device_gnss/flxDevGNSS.cpp b/src/device/device_gnss/flxDevGNSS.cpp index f6ae1e7..663d6ea 100644 --- a/src/device/device_gnss/flxDevGNSS.cpp +++ b/src/device/device_gnss/flxDevGNSS.cpp @@ -61,11 +61,11 @@ flxDevGNSS::flxDevGNSS() flxRegister(hour, "Hour", "Hour"); flxRegister(min, "Minute", "Minute"); flxRegister(sec, "Second", "Second"); - flxRegister(latitude, "Latitude (deg)", "Latitude in degrees"); + flxRegister(latitude, "Latitude (deg)", "Latitude in degrees", kParamValueLatitude); latitude.setPrecision(7); - flxRegister(longitude, "Longitude (deg)", "Longitude in degrees"); + flxRegister(longitude, "Longitude (deg)", "Longitude in degrees", kParamValueLongitude); longitude.setPrecision(7); - flxRegister(altitude, "Altitude (m)", "Altitude above geoid in meters"); + flxRegister(altitude, "Altitude (m)", "Altitude above geoid in meters", kParamValueAltitude); flxRegister(altitudeMSL, "Altitude MSL (m)", "Altitude above Mean Sea Level in meters"); flxRegister(SIV, "SIV", "Satellites In View"); flxRegister(fixType, "Fix Type", "Fix Type"); diff --git a/src/device/device_ism330/flxDevISM330.cpp b/src/device/device_ism330/flxDevISM330.cpp index 695cfa5..4866917 100644 --- a/src/device/device_ism330/flxDevISM330.cpp +++ b/src/device/device_ism330/flxDevISM330.cpp @@ -52,12 +52,12 @@ flxDevISM330Base::flxDevISM330Base() // to support managed properties/public properties // Register parameters - flxRegister(accelX, "Accel X (milli-g)", "Accelerometer X (milli-g)"); - flxRegister(accelY, "Accel Y (milli-g)", "Accelerometer Y (milli-g)"); - flxRegister(accelZ, "Accel Z (milli-g)", "Accelerometer Z (milli-g)"); - flxRegister(gyroX, "Gyro X (milli-dps)", "Gyro X (milli-dps)"); - flxRegister(gyroY, "Gyro Y (milli-dps)", "Gyro Y (milli-dps)"); - flxRegister(gyroZ, "Gyro Z (milli-dps)", "Gyro Z (milli-dps)"); + flxRegister(accelX, "Accel X (milli-g)", "Accelerometer X (milli-g)", kParamValueAccelX); + flxRegister(accelY, "Accel Y (milli-g)", "Accelerometer Y (milli-g)", kParamValueAccelY); + flxRegister(accelZ, "Accel Z (milli-g)", "Accelerometer Z (milli-g)", kParamValueAccelZ); + flxRegister(gyroX, "Gyro X (milli-dps)", "Gyro X (milli-dps)", kParamValueGyroX); + flxRegister(gyroY, "Gyro Y (milli-dps)", "Gyro Y (milli-dps)", kParamValueGyroY); + flxRegister(gyroZ, "Gyro Z (milli-dps)", "Gyro Z (milli-dps)", kParamValueGyroZ); flxRegister(temperature, "Temperature (C)", "The ambient temperature in degrees C"); // Register properties diff --git a/src/device/device_lps25hb/flxDevLPS25HB.cpp b/src/device/device_lps25hb/flxDevLPS25HB.cpp index 0194c54..357bc22 100644 --- a/src/device/device_lps25hb/flxDevLPS25HB.cpp +++ b/src/device/device_lps25hb/flxDevLPS25HB.cpp @@ -35,8 +35,8 @@ flxDevLPS25HB::flxDevLPS25HB() setDescription("LPS25HB Temperature and Pressure sensor"); // Register output params - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); - flxRegister(pressurehPa, "Pressure (hPa)", "The atmospheric pressure in hPa"); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); + flxRegister(pressurehPa, "Pressure (hPa)", "The atmospheric pressure in hPa", kParamValuePressure_F); } // Function to encapsulate the ops needed to get values from the sensor. diff --git a/src/device/device_micropressure/flxDevMicroPressure.cpp b/src/device/device_micropressure/flxDevMicroPressure.cpp index 435ad35..8652af8 100644 --- a/src/device/device_micropressure/flxDevMicroPressure.cpp +++ b/src/device/device_micropressure/flxDevMicroPressure.cpp @@ -37,7 +37,7 @@ flxDevMicroPressure::flxDevMicroPressure() // Register output params flxRegister(pressure_PSI, "Pressure (PSI)", "Atmospheric pressure in Pounds per Square Inch"); - flxRegister(pressure_Pa, "Pressure (Pa)", "Atmospheric pressure in Pascals"); + flxRegister(pressure_Pa, "Pressure (Pa)", "Atmospheric pressure in Pascals", kParamValuePressure_F); flxRegister(pressure_kPa, "Pressure (kPa)", "Atmospheric pressure in kilo-Pascals"); flxRegister(pressure_torr, "Pressure (torr)", "Atmospheric pressure in torr"); flxRegister(pressure_inHg, "Pressure (inHg)", "Atmospheric pressure in inches of mercury"); diff --git a/src/device/device_ms5637/flxDevMS5637.cpp b/src/device/device_ms5637/flxDevMS5637.cpp index 4647169..6f74247 100644 --- a/src/device/device_ms5637/flxDevMS5637.cpp +++ b/src/device/device_ms5637/flxDevMS5637.cpp @@ -35,8 +35,8 @@ flxDevMS5637::flxDevMS5637() setDescription("MS5637 Pressure and Temperature sensor"); // Register output params - flxRegister(pressure_mbar, "Pressure (mbar)", "Atmospheric pressure in milli-bar"); - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); + flxRegister(pressure_mbar, "Pressure (mbar)", "Atmospheric pressure in milli-bar", kParamValuePressure_mBar); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); } // Function to encapsulate the ops needed to get values from the sensor. diff --git a/src/device/device_nau7802/flxDevNAU7802.cpp b/src/device/device_nau7802/flxDevNAU7802.cpp index 62b36cf..635d70b 100644 --- a/src/device/device_nau7802/flxDevNAU7802.cpp +++ b/src/device/device_nau7802/flxDevNAU7802.cpp @@ -75,7 +75,7 @@ flxDevNAU7802::flxDevNAU7802() flxRegister(_externalCalGain, "ExternalGain"); // Register parameters - flxRegister(weight, "Weight", "Weight in units - as set by the calibrationFactor"); + flxRegister(weight, "Weight", "Weight in units - as set by the calibrationFactor", kParamValueWeightUserUnits); flxRegister(calculateZeroOffset, "Calculate Zero Offset", "Perform a zero offset calibration. Sets the scale weight to zero"); flxRegister(calculateCalibrationFactor, "Calculate Calibration Factor", diff --git a/src/device/device_opt4048/flxDevOPT4048.cpp b/src/device/device_opt4048/flxDevOPT4048.cpp index aadb889..74eefab 100644 --- a/src/device/device_opt4048/flxDevOPT4048.cpp +++ b/src/device/device_opt4048/flxDevOPT4048.cpp @@ -49,10 +49,10 @@ flxDevOPT4048::flxDevOPT4048() setName(getDeviceName(), "OPT4048 Tristimulus Color Sensor"); // Register parameters - flxRegister(CIEx, "CIEx", "The X coordinate on the CIE 1931 Color Space Graph"); - flxRegister(CIEy, "CIEy", "The Y coordinate on the CIE 1931 Color Space Graph"); - flxRegister(CCT, "CCT", "The Correlated Color Temperature (CCT) of the sensor (K)"); - flxRegister(Lux, "Lux", "The Lux value, or 'brightness'."); + flxRegister(CIEx, "CIEx", "The X coordinate on the CIE 1931 Color Space Graph", kParamValueCIE_X); + flxRegister(CIEy, "CIEy", "The Y coordinate on the CIE 1931 Color Space Graph", kParamValueCIE_Y); + flxRegister(CCT, "CCT", "The Correlated Color Temperature (CCT) of the sensor (K)", kParamValueCCT); + flxRegister(Lux, "Lux", "The Lux value, or 'brightness'.", kParamValueLUX); flxRegister(mode, "mode", "The Operation Mode: Power Down, Auto One Shot, One Shot, Continuous"); flxRegister(time, "time", "Time spent converting analog values from internal sensors"); diff --git a/src/device/device_rv8803/flxDevRV8803.cpp b/src/device/device_rv8803/flxDevRV8803.cpp index 8fe1510..365e8c7 100644 --- a/src/device/device_rv8803/flxDevRV8803.cpp +++ b/src/device/device_rv8803/flxDevRV8803.cpp @@ -47,7 +47,7 @@ flxDevRV8803::flxDevRV8803() flxRegister(readMonth, "Read the month", "Read the name of the month (January, February etc)"); flxRegister(readMonthShort, "Read the month (short)", "Read the name of the month (Jan, Feb etc)"); flxRegister(readYear, "Read the year", "Read the year (2022 etc)"); - flxRegister(getEpoch, "Get Epoch", "Get the time in seconds since the Epoch"); + flxRegister(getEpoch, "Get Epoch", "Get the time in seconds since the Epoch", kParamValueEpoch); // Register input params flxRegister(setEpoch, "Set Epoch", "Set the time since the Epoch"); diff --git a/src/device/device_scd40/flxDevSCD40.cpp b/src/device/device_scd40/flxDevSCD40.cpp index 1feb25f..4b79d42 100644 --- a/src/device/device_scd40/flxDevSCD40.cpp +++ b/src/device/device_scd40/flxDevSCD40.cpp @@ -57,9 +57,9 @@ flxDevSCD40::flxDevSCD40() flxRegister(temperatureOffset, "Temperature Offset", "Define how warm the sensor is compared to ambient"); // Register parameters - flxRegister(co2PPM, "CO2 (PPM)", "The CO2 concentration in Parts Per Million"); - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); - flxRegister(humidity, "Humidity (%RH)", "The releative humidity in %"); + flxRegister(co2PPM, "CO2 (PPM)", "The CO2 concentration in Parts Per Million", kParamValueCO2_U32); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); + flxRegister(humidity, "Humidity (%RH)", "The releative humidity in %", kParamValueHumidity_F); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_sgp30/flxDevSGP30.cpp b/src/device/device_sgp30/flxDevSGP30.cpp index 33423ec..87a5a37 100644 --- a/src/device/device_sgp30/flxDevSGP30.cpp +++ b/src/device/device_sgp30/flxDevSGP30.cpp @@ -49,10 +49,10 @@ flxDevSGP30::flxDevSGP30() setDescription("SGP30 Air Quality Sensor"); // Register parameters - flxRegister(tvoc, "TVOC (PPB)", "Total Volatile Organic Compounds in Parts Per Billion"); - flxRegister(co2, "CO2 (PPM)", "CO2 concentration in Parts Per Million"); - flxRegister(h2, "H2 (PPM)", "Hydrogen concentration in Parts Per Million"); - flxRegister(ethanol, "Ethanol (PPM)", "Ethanol concentration in Parts Per Million"); + flxRegister(tvoc, "TVOC (PPB)", "Total Volatile Organic Compounds in Parts Per Billion", kParamValueTVOC_U32); + flxRegister(co2, "CO2 (PPM)", "CO2 concentration in Parts Per Million", kParamValueCO2_U32); + flxRegister(h2, "H2 (PPM)", "Hydrogen concentration in Parts Per Million", kParamValueH2); + flxRegister(ethanol, "Ethanol (PPM)", "Ethanol concentration in Parts Per Million", kParamValueETOH_U32); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_sgp40/flxDevSGP40.cpp b/src/device/device_sgp40/flxDevSGP40.cpp index 1d0221f..8259676 100644 --- a/src/device/device_sgp40/flxDevSGP40.cpp +++ b/src/device/device_sgp40/flxDevSGP40.cpp @@ -49,7 +49,7 @@ flxDevSGP40::flxDevSGP40() setDescription("SGP40 Air Quality Sensor"); // Register parameters - flxRegister(vocIndex, "VOC Index", "Volatile Organic Compounds Index"); + flxRegister(vocIndex, "VOC Index", "Volatile Organic Compounds Index", kParamValueTVOC_U32); flxRegister(rh, "Humidity (%RH)", "The relative humidity in %"); flxRegister(temperature, "Temperature (C)", "The temperature in degrees C"); diff --git a/src/device/device_shtc3/flxDevSHTC3.cpp b/src/device/device_shtc3/flxDevSHTC3.cpp index c5bc462..d3efa6d 100644 --- a/src/device/device_shtc3/flxDevSHTC3.cpp +++ b/src/device/device_shtc3/flxDevSHTC3.cpp @@ -49,9 +49,9 @@ flxDevSHTC3::flxDevSHTC3() setDescription("SHTC3 Humidity and Temperature Sensor"); // Register parameters - flxRegister(humidity, "Humidity (%RH)", "The relative humidity in %"); - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); - flxRegister(temperatureF, "Temperature (F)", "The temperature in degrees F"); + flxRegister(humidity, "Humidity (%RH)", "The relative humidity in %", kParamValueHumidity_F); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); + flxRegister(temperatureF, "Temperature (F)", "The temperature in degrees F", kParamValueTempF); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_stc31/flxDevSTC31.cpp b/src/device/device_stc31/flxDevSTC31.cpp index 85f143f..5e2c535 100644 --- a/src/device/device_stc31/flxDevSTC31.cpp +++ b/src/device/device_stc31/flxDevSTC31.cpp @@ -47,8 +47,8 @@ flxDevSTC31::flxDevSTC31() setDescription("STC31 CO2 Sensor"); // Register parameters - flxRegister(co2, "CO2 (%)", "The CO2 concentration in %"); - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); + flxRegister(co2, "CO2 (%)", "The CO2 concentration in %", kParamValueCO2_F); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); flxRegister(rh, "Humidity (%RH)", "Adjust the CO2 measurement using this humidity (%RH)"); flxRegister(temperatureC_In, "Temperature (C)", "Adjust the CO2 measurement using this temperature (C)"); diff --git a/src/device/device_sths34pf80/flxDevSTHS34PF80.cpp b/src/device/device_sths34pf80/flxDevSTHS34PF80.cpp index 6ef1134..bcd64d9 100644 --- a/src/device/device_sths34pf80/flxDevSTHS34PF80.cpp +++ b/src/device/device_sths34pf80/flxDevSTHS34PF80.cpp @@ -47,8 +47,8 @@ flxDevSTHS34PF80::flxDevSTHS34PF80() // needed to support managed properties/public properties and parameters // Register Properties - flxRegister(presence, "Presence (cm^-1)", "Presence Value (1/cm)"); - flxRegister(motion, "Motion (LSB)", "Motion Value"); + flxRegister(presence, "Presence (cm^-1)", "Presence Value (1/cm)", kParamValuePresence); + flxRegister(motion, "Motion (LSB)", "Motion Value", kParamValueMotion); flxRegister(temperature, "Temperature (C)", "Temperature Value (C)"); // Register Parameters diff --git a/src/device/device_tmp117/flxDevTMP117.cpp b/src/device/device_tmp117/flxDevTMP117.cpp index 33e4d39..6accd23 100644 --- a/src/device/device_tmp117/flxDevTMP117.cpp +++ b/src/device/device_tmp117/flxDevTMP117.cpp @@ -47,7 +47,7 @@ flxDevTMP117::flxDevTMP117() setDescription("TMP117 Precision Temperature Sensor"); // Register parameters - flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C"); + flxRegister(temperatureC, "Temperature (C)", "The temperature in degrees C", kParamValueTempC); } //---------------------------------------------------------------------------------------------------------- diff --git a/src/device/device_vcnl4040/flxDevVCNL4040.cpp b/src/device/device_vcnl4040/flxDevVCNL4040.cpp index 90075d7..09a5748 100644 --- a/src/device/device_vcnl4040/flxDevVCNL4040.cpp +++ b/src/device/device_vcnl4040/flxDevVCNL4040.cpp @@ -49,8 +49,8 @@ flxDevVCNL4040::flxDevVCNL4040() setDescription("VCNL4040 Proximity Sensor"); // Register parameters - flxRegister(proximity, "Proximity", "Proximity : high values indicate close proximity"); - flxRegister(lux, "Lux", "The light level in lux"); + flxRegister(proximity, "Proximity", "Proximity : high values indicate close proximity", kParamValueProximity); + flxRegister(lux, "Lux", "The light level in lux", kParamValueLUX_U16); // Register read-write properties flxRegister(ledCurrent, "LED Current (mA)", "The LED current in milliamps)"); diff --git a/src/device/device_veml6075/flxDevVEML6075.cpp b/src/device/device_veml6075/flxDevVEML6075.cpp index 14583fd..9462503 100644 --- a/src/device/device_veml6075/flxDevVEML6075.cpp +++ b/src/device/device_veml6075/flxDevVEML6075.cpp @@ -49,9 +49,9 @@ flxDevVEML6075::flxDevVEML6075() setDescription("VEML6075 UV Sensor"); // Register parameters - flxRegister(uva, "UVA Level", "The UVA light level"); - flxRegister(uvb, "UVB Level", "The UVB light level"); - flxRegister(uvIndex, "UV Index", "The combined UV index"); + flxRegister(uva, "UVA Level", "The UVA light level", kParamValueUVAIndex); + flxRegister(uvb, "UVB Level", "The UVB light level", kParamValueUVBIndex); + flxRegister(uvIndex, "UV Index", "The combined UV index", kParamValueUVIndex); // Register read-write properties flxRegister(integrationTime, "Integration Time (ms)", "The measurement integration time in milliseconds"); diff --git a/src/device/device_veml7700/flxDevVEML7700.cpp b/src/device/device_veml7700/flxDevVEML7700.cpp index bbc84a2..3327f05 100644 --- a/src/device/device_veml7700/flxDevVEML7700.cpp +++ b/src/device/device_veml7700/flxDevVEML7700.cpp @@ -49,9 +49,9 @@ flxDevVEML7700::flxDevVEML7700() setDescription("VEML7700 Ambient Light Sensor"); // Register parameters - flxRegister(ambientLight, "Ambient Light Level", "The ambient light level"); - flxRegister(whiteLevel, "White Level", "The measured light white level"); - flxRegister(lux, "Lux", "The light level in lux"); + flxRegister(ambientLight, "Ambient Light Level", "The ambient light level", kParamValueAmbientLight); + flxRegister(whiteLevel, "White Level", "The measured light white level", kParamValueWhiteLight); + flxRegister(lux, "Lux", "The light level in lux", kParamValueLUX_F); // Register read-write properties flxRegister(integrationTime, "Integration Time (ms)", "The measurement integration time in milliseconds"); diff --git a/src/device/device_vl53l1x/flxDevVL53L1X.cpp b/src/device/device_vl53l1x/flxDevVL53L1X.cpp index b225481..fd2b205 100644 --- a/src/device/device_vl53l1x/flxDevVL53L1X.cpp +++ b/src/device/device_vl53l1x/flxDevVL53L1X.cpp @@ -49,7 +49,7 @@ flxDevVL53L1X::flxDevVL53L1X() setDescription("VL53L1X Distance Sensor"); // Register parameters - flxRegister(distance, "Distance (mm)", "The measured distance in mm"); + flxRegister(distance, "Distance (mm)", "The measured distance in mm", kParamValueDistance); flxRegister(rangeStatus, "Range Status", "The measurement range status : 0 = good"); flxRegister(signalRate, "Signal Rate", "The measurement signal rate"); From ba90f485a5033fbd6d5fe21ad6fa28cf31b909fc Mon Sep 17 00:00:00 2001 From: Kirk Benell Date: Wed, 13 Nov 2024 13:25:52 -0700 Subject: [PATCH 9/9] tweaks and adjustments that resulted in the port to an arm/non esp platform. Mostly around global/static object creation timelines - which are undefined by c++ and vary between systems --- src/core/flux_base/CMakeLists.txt | 1 + src/core/flux_base/flxCoreLog.h | 1 + src/core/flux_base/flxCoreProps.h | 63 ++++++++++----- src/core/flux_base/flxCoreTypes.h | 4 +- src/core/flux_base/flxDevice.h | 1 + src/core/flux_base/flxFlux.h | 27 +++++-- src/core/flux_base/flxSerial.cpp | 12 +++ src/core/flux_base/flxSerial.h | 5 ++ src/core/flux_base/flxTimer.h | 20 +++-- src/core/flux_base/flxUtils.cpp | 53 +++++++++++++ src/core/flux_base/flxUtils.h | 4 + src/core/flux_base/spSpark.cpp | 79 +++++++++++++++---- src/core/flux_logging/flxFmtJSON.h | 25 +++--- src/core/flux_logging/flxLogger.cpp | 2 +- src/core/flux_logging/flxLogger.h | 2 +- src/core/flux_prefs/flxSettings.h | 2 +- .../flux_prefs_serial/flxSettingsSerial.h | 1 + 17 files changed, 232 insertions(+), 70 deletions(-) diff --git a/src/core/flux_base/CMakeLists.txt b/src/core/flux_base/CMakeLists.txt index 48baebb..3385d29 100644 --- a/src/core/flux_base/CMakeLists.txt +++ b/src/core/flux_base/CMakeLists.txt @@ -8,6 +8,7 @@ flux_sdk_add_source_files( flxCore.h flxCoreDevice.cpp flxCoreDevice.h + flxDeviceValueTypes.h flxCoreEvent.h flxCoreEvent.cpp flxCoreEventID.h diff --git a/src/core/flux_base/flxCoreLog.h b/src/core/flux_base/flxCoreLog.h index 9b4fefc..758ddbb 100644 --- a/src/core/flux_base/flxCoreLog.h +++ b/src/core/flux_base/flxCoreLog.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "flxCoreEventID.h" diff --git a/src/core/flux_base/flxCoreProps.h b/src/core/flux_base/flxCoreProps.h index 641c4a6..432fc9d 100644 --- a/src/core/flux_base/flxCoreProps.h +++ b/src/core/flux_base/flxCoreProps.h @@ -250,22 +250,26 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn, public _flxDa { public: - _flxPropertyBase() : _isHidden{HIDDEN}, _isSecure{SECURE} + _flxPropertyBase() : _flags{0} { + if (HIDDEN) + setHidden(); + if (SECURE) + _flags |= kIsSecure; } bool hidden() { - return _isHidden; + return (_flags & kIsHidden == kIsHidden); } // Add a method that allows the property to be hidden if public void setHidden(void) { - _isHidden = true; + _flags |= kIsHidden; } bool secure() { - return _isSecure; + return (_flags & kIsSecure == kIsSecure); } //--------------------------------------------------------------------------------- flxDataType_t type() @@ -299,7 +303,7 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn, public _flxDa bool status = true; // We don't save hidden or secure properties if this is an external source - if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!_isHidden && !_isSecure)) + if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!hidden() && !secure())) { T c = get(); bool status = stBlk->write(name(), c); @@ -382,8 +386,10 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn, public _flxDa } private: - bool _isHidden; - bool _isSecure; + static constexpr const uint8_t kIsHidden = 0x1; + static constexpr const uint8_t kIsSecure = 0x2; + + uint8_t _flags; }; //---------------------------------------------------------------------------------------- @@ -402,22 +408,26 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut flxDataLimitType *_dataLimit; public: - _flxPropertyBaseString() : _dataLimit{nullptr}, _isHidden{HIDDEN}, _isSecure{SECURE} + _flxPropertyBaseString() : _dataLimit{nullptr}, _flags{0} { + if (HIDDEN) + setHidden(); + if (SECURE) + _flags |= kIsSecure; } bool hidden() { - return _isHidden; + return (_flags & kIsHidden == kIsHidden); } // Add a method that allows the property to be hidden if public void setHidden(void) { - _isHidden = true; + _flags |= kIsHidden; } bool secure() { - return _isSecure; + return (_flags & kIsSecure == kIsSecure); } flxDataType_t type() @@ -466,17 +476,17 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut // If this is a secure string and storage is internal, the strings are stored // encrypted - if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure) + if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure()) return stBlk->saveSecureString(name(), get().c_str()); // If we are saving to an external source, we don't save hidden values or secure values. // But, for secure props, we to write the key and a blank string (makes it easier to enter values) // We don't save hidden or secure properties if this is an external source - if (stBlk->kind() == flxStorage::flxStorageKindInternal || !_isHidden) + if (stBlk->kind() == flxStorage::flxStorageKindInternal || !hidden()) { // if a secure property and external storage, set value to an empty string - std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && _isSecure) ? "" : get(); + std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && secure()) ? "" : get(); status = stBlk->writeString(name(), c.c_str()); if (!status) @@ -491,7 +501,7 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut size_t len; // Secure string? - if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure) + if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure()) { // get buffer length. Note, add one to make sure we have room for line termination len = stBlk->getBytesLength(name()) + 1; @@ -565,8 +575,10 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut }; private: - bool _isHidden; - bool _isSecure; + static constexpr const uint8_t kIsHidden = 0x1; + static constexpr const uint8_t kIsSecure = 0x2; + + uint8_t _flags; }; //---------------------------------------------------------------------------------------------------- @@ -636,7 +648,7 @@ class _flxPropertyTypedRW : public _flxPropertyBase void operator()(Object *obj, bool skipAdd = false) { // my_object must be derived from _flxPropertyContainer - static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object"); + // static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object"); my_object = obj; assert(my_object); @@ -676,6 +688,9 @@ class _flxPropertyTypedRW : public _flxPropertyBase { if (!my_object) // would normally throw an exception, but not very Arduino like! { + if (_hasInitial) + return _initialValue; + flxLogM_E(kMsgParentObjNotSet, "property"); return (T)0; } @@ -687,8 +702,10 @@ class _flxPropertyTypedRW : public _flxPropertyBase { if (!my_object) { - flxLogM_E(kMsgParentObjNotSet, "property"); - return; // would normally throw an exception, but not very Arduino like! + // cache the value until we are connected to the containing object + _hasInitial = true; + _initialValue = value; + return; } (my_object->*_setter)(value); @@ -1291,6 +1308,8 @@ class flxPropertyRWString : public _flxPropertyBaseString { if (!my_object) { + if (_hasInitial) + return _initialValue; flxLogM_E(kMsgParentObjNotSet, "property"); return ""; } @@ -1303,7 +1322,9 @@ class flxPropertyRWString : public _flxPropertyBaseString { if (!my_object) { - flxLogM_E(kMsgParentObjNotSet, "property"); + _hasInitial = true; + _initialValue = value; + return; } diff --git a/src/core/flux_base/flxCoreTypes.h b/src/core/flux_base/flxCoreTypes.h index 0b247a7..b1c5754 100644 --- a/src/core/flux_base/flxCoreTypes.h +++ b/src/core/flux_base/flxCoreTypes.h @@ -21,7 +21,6 @@ #include #include #include -#include #include "flxCoreLog.h" #include "flxUtils.h" @@ -283,6 +282,9 @@ enum flxDataType_t : std::uint8_t flxTypeDouble = 0x28, flxTypeString = 0x21 }; +const flxDataType_t flxDataTypeArray[] = {flxTypeNone, flxTypeBool, flxTypeInt8, flxTypeUInt8, + flxTypeInt16, flxTypeUInt16, flxTypeInt32, flxTypeUInt32, + flxTypeFloat, flxTypeDouble, flxTypeString}; /******************************************************************************* * @brief A constexpr function that returns the flxDataType_t value for a given type. diff --git a/src/core/flux_base/flxDevice.h b/src/core/flux_base/flxDevice.h index 4884406..adedadf 100644 --- a/src/core/flux_base/flxDevice.h +++ b/src/core/flux_base/flxDevice.h @@ -33,6 +33,7 @@ #include #include "flxCoreDevice.h" +#include "flxDeviceValueTypes.h" #include "flxFlux.h" //---------------------------------------------------------------------------------- diff --git a/src/core/flux_base/flxFlux.h b/src/core/flux_base/flxFlux.h index bfbab12..2ad7ccc 100644 --- a/src/core/flux_base/flxFlux.h +++ b/src/core/flux_base/flxFlux.h @@ -16,10 +16,13 @@ #include "flxCoreDevice.h" #include "flxSerial.h" #include +#include +#include +#include class flxApplication; -// // happy functions for happy users. +// happy functions for happy users. // bool spark_start(bool bAutoLoad = true); // bool spark_loop(); @@ -203,7 +206,6 @@ class flxFlux : public flxObjectContainer uint32_t version() { return _v_major * 10000 + _v_minor * 100 + _v_point; - ; } void version(uint32_t &major, uint32_t &minor, uint32_t &point) { @@ -262,7 +264,9 @@ class flxFlux : public flxObjectContainer { _theApplication = theApp; // set the app as the first entry of our actions list - Actions.insert(Actions.begin(), (flxAction *)theApp); + // KDB - This is causing a crash on startup on rp2350 <<<<<<<<<<<<<<<<<<<<<<< + if (initialized()) + Actions.insert(Actions.begin(), (flxAction *)theApp); } } @@ -317,6 +321,7 @@ class flxFlux : public flxObjectContainer bool _deviceAutoload; bool _loadSettings; + // Note private constructor... flxFlux() : _v_major{0}, _v_minor{0}, _v_point{0}, _v_build{0}, _v_desc{""}, _v_idprefix{"0000"}, @@ -338,6 +343,9 @@ class flxFlux : public flxObjectContainer this->push_back(pTmp); } + bool initialized(); + void setInitialized(bool bInit); + flxOperation *_getByType(flxTypeID type) { @@ -360,6 +368,8 @@ class flxFlux : public flxObjectContainer extern flxFlux &flux; +flxFlux &flux_get(void); + // Define our application class interface. class flxApplication : public flxActionType { @@ -451,6 +461,13 @@ class flxApplication : public flxActionType return false; } - private: + // private: flxDescriptor appDesc; -}; \ No newline at end of file +}; + +void flux_add(flxAction &theAction); +void flux_add(flxAction *theAction); +void flux_add(flxDevice &theDevice); +void flux_add(flxDevice *theDevice); +void flux_add(flxApplication &theApp); +void flux_add(flxApplication *theApp); \ No newline at end of file diff --git a/src/core/flux_base/flxSerial.cpp b/src/core/flux_base/flxSerial.cpp index 8422e39..a2c79fe 100644 --- a/src/core/flux_base/flxSerial.cpp +++ b/src/core/flux_base/flxSerial.cpp @@ -78,4 +78,16 @@ void flxSerial_::textToNormal(void) { if (_colorEnabled) Serial.print(kClrNormal); +} + +void flxSerial_::textToCyan(void) +{ + if (_colorEnabled) + Serial.print(kClrCyan); +} + +void flxSerial_::textToMagenta(void) +{ + if (_colorEnabled) + Serial.print(kClrMagenta); } \ No newline at end of file diff --git a/src/core/flux_base/flxSerial.h b/src/core/flux_base/flxSerial.h index a46037e..dd4eb7d 100644 --- a/src/core/flux_base/flxSerial.h +++ b/src/core/flux_base/flxSerial.h @@ -17,6 +17,7 @@ #pragma once #include "flxCoreEvent.h" +#include "flxCoreInterface.h" #include "flxOutput.h" #include @@ -92,6 +93,8 @@ class flxSerial_ : public flxWriter void textToBlue(void); void textToWhite(void); void textToNormal(void); + void textToCyan(void); + void textToMagenta(void); private: flxSerial_() : _headerWritten{false}, _colorEnabled{false} {}; @@ -103,6 +106,8 @@ class flxSerial_ : public flxWriter static constexpr const char *kClrRed = "\033[1;31m"; static constexpr const char *kClrBlue = "\033[1;34m"; static constexpr const char *kClrWhite = "\033[1;37m"; + static constexpr const char *kClrCyan = "\033[1;36m"; + static constexpr const char *kClrMagenta = "\033[1;35m"; bool _headerWritten; diff --git a/src/core/flux_base/flxTimer.h b/src/core/flux_base/flxTimer.h index e7eed32..c2033ce 100644 --- a/src/core/flux_base/flxTimer.h +++ b/src/core/flux_base/flxTimer.h @@ -42,27 +42,25 @@ class flxTimer : public flxActionType // for our timing unsigned long _lastLogTime = 0; + uint32_t _initialInterval = 0; flxJob _timerJob; public: - flxTimer(int start = 500) : _lastLogTime(0) + flxTimer(uint32_t start = 15000) : _lastLogTime(0), _initialInterval(start) { - - flxRegister(interval, "Interval", "Timer interval in milliseconds"); - - // interval = start; - - flux.add(this); - + // Add this to the list of actions in the framework + flux_add(this); setName("Timer", "A reoccurring timer"); - - // setup the job used to trigger the timer (note - we enable "job compression" for this ) - _timerJob.setup(name(), start, this, &flxTimer::onTimer, false); }; bool initialize(void) { + // Register the interval property - do here not in ctor due to uncertainty of global object creation order + + flxRegister(interval, "Interval", "Timer interval in milliseconds"); + // setup the job used to trigger the timer (note - we enable "job compression" for this ) + _timerJob.setup(name(), _initialInterval, this, &flxTimer::onTimer, false); // Add the job to the job queue flxAddJobToQueue(_timerJob); diff --git a/src/core/flux_base/flxUtils.cpp b/src/core/flux_base/flxUtils.cpp index e3261c3..eceedac 100644 --- a/src/core/flux_base/flxUtils.cpp +++ b/src/core/flux_base/flxUtils.cpp @@ -455,4 +455,57 @@ bool flx_utils::createVariableName(const char *szInVariable, char *szOutVariable szOutVariable[idst] = '\0'; return (strlen(szOutVariable) > 1); +} +//--------------------------------------------------------------------------------------- +// CRC32 Calculation +// Implementation of CRC32 from https://web.mit.edu/freebsd/head/sys/libkern/crc32.c + +static const uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, + 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, + 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, + 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, + 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, + 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, + 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, + 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, + 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, + 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, + 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, + 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, + 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, + 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, + 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + +//--------------------------------------------------------------------------------------- +/// calc_crc32() +/// +/// @brief Calculate a CRC32 value for a buffer +/// @param[in] crc input CRC value +/// @param[in] buf buffer to calculate CRC on +/// @param[in] size size of buffer +/// +/// @return The calculated CRC32 value +/// +uint32_t flx_utils::calc_crc32(uint32_t crc, const uint8_t *buf, uint32_t size) +{ + + crc = ~crc; + while (size--) + crc = crc32_tab[(crc ^ *buf++) & 0xFF] ^ (crc >> 8); + return ~crc; } \ No newline at end of file diff --git a/src/core/flux_base/flxUtils.h b/src/core/flux_base/flxUtils.h index c94f9ae..318906f 100644 --- a/src/core/flux_base/flxUtils.h +++ b/src/core/flux_base/flxUtils.h @@ -16,6 +16,7 @@ #include #include #include +#include // use a utils namespace @@ -61,4 +62,7 @@ void formatByteString(uint64_t nBytes, uint prec, char *szBuffer, size_t len); bool createVariableName(const char *szInVariable, char *szOutVariable); +// CRC32 Calculation +uint32_t calc_crc32(uint32_t crc, const uint8_t *buf, uint32_t size); + } // namespace flx_utils diff --git a/src/core/flux_base/spSpark.cpp b/src/core/flux_base/spSpark.cpp index cc106e2..8d4c6a7 100644 --- a/src/core/flux_base/spSpark.cpp +++ b/src/core/flux_base/spSpark.cpp @@ -25,23 +25,45 @@ static flxLoggingDrvDefault _logDriver; +static bool _isInitalized = false; + const char *kApplicationHashIDTag = "Application ID"; // Global object - for quick access to Spark. flxFlux &flux = flxFlux::get(); + +bool flxFlux::initialized() +{ + return _isInitalized; +} + +void flxFlux::setInitialized(bool bInit) +{ + _isInitalized = bInit; +} //------------------------------------------------------- // // Note: Auto-load is true by default bool flxFlux::start() { + // settings - add to our system now that we are up and running. + add(&flxSettings); + // if we have an application, call the init method. // The intent is to give the app time to setup anything before // the system sets up if (_theApplication) - _theApplication->onInit(); + { + + // if the app was set during startup (before main - when globals are instantiated), it + // wasn't added to the system. So do that now. + if (Actions.size() == 0 || Actions.at(0) != (flxAction *)_theApplication) + Actions.insert(Actions.begin(), (flxAction *)_theApplication); + _theApplication->onInit(); + } // setup our logging system. _logDriver.setOutput(flxSerial); flxLog.setLogDriver(_logDriver); @@ -62,6 +84,8 @@ bool flxFlux::start() if (strlen(_theApplication->description()) > 0) this->setDescription(_theApplication->description()); } + else + flxLog_W(F("No application object set.")); writeBanner(); @@ -77,6 +101,12 @@ bool flxFlux::start() if (_theApplication) _theApplication->onDeviceLoad(); + // initialize actions + for (auto pAction : Actions) + { + if (!pAction->initialize()) + flxLog_W(F("[Startup] %s failed to initialize."), pAction->name()); + } // Everything should be loaded -- restore settings from storage if (_loadSettings && flxSettings.isAvailable()) { @@ -91,13 +121,6 @@ bool flxFlux::start() else flxLog_I(F("Restore of System Settings unavailable.")); - // initialize actions - for (auto pAction : Actions) - { - if (!pAction->initialize()) - flxLog_W(F("[Startup] %s failed to initialize."), pAction->name()); - } - // Call start on the application // Loop in the application if (_theApplication) @@ -116,11 +139,12 @@ bool flxFlux::start() // start the job queue if (!flxJobQueue.start()) flxLog_E("Job queue failed to start - unrecoverable error. "); - // else - // { - // flxLog_I(F("Job queue initialized")); - // flxJobQueue.dump(); - // } + // // else + // // { + // // flxLog_I(F("Job queue initialized")); + // // flxJobQueue.dump(); + // // } + setInitialized(true); return true; } @@ -349,7 +373,6 @@ const char *flxFlux::deviceId(void) snprintf(szDeviceID, sizeof(szDeviceID), "%4s%012llX", _v_idprefix, ESP.getEfuseMac()); bInitialized = true; } - #endif return (const char *)szDeviceID; } @@ -406,3 +429,31 @@ bool flxFlux::verboseDevNames(void) { return _verboseDevNames; } +flxFlux &flux_get() +{ + return flxFlux::get(); +} +void flux_add(flxAction &theAction) +{ + flxFlux::get().add(&theAction); +} +void flux_add(flxAction *theAction) +{ + flxFlux::get().add(theAction); +} +void flux_add(flxDevice &theDevice) +{ + flxFlux::get().add(&theDevice); +} +void flux_add(flxDevice *theDevice) +{ + flxFlux::get().add(theDevice); +} +void flux_add(flxApplication &theApp) +{ + flxFlux::get().setApplication(&theApp); +} +void flux_add(flxApplication *theApp) +{ + flxFlux::get().setApplication(theApp); +} \ No newline at end of file diff --git a/src/core/flux_logging/flxFmtJSON.h b/src/core/flux_logging/flxFmtJSON.h index 98f4d0a..a84672c 100644 --- a/src/core/flux_logging/flxFmtJSON.h +++ b/src/core/flux_logging/flxFmtJSON.h @@ -181,7 +181,9 @@ template class flxFormatJSON : public flxOutputFormat { if (_spDoc) { - _jSection = _spDoc->createNestedObject(szName); + // _jSection = _spDoc->createNestedObject(szName); + + _jSection = (*_spDoc)[szName].to(); _pSectionName = szName; } } @@ -276,6 +278,7 @@ template class flxFormatJSON : public flxOutputFormat } //----------------------------------------------------------------- + // TODO: Rethink the buffer settings -- appears to not be needed with latest ArduinoJson version. void setBufferSize(size_t new_size) { // Same? @@ -286,17 +289,7 @@ template class flxFormatJSON : public flxOutputFormat if (_spDoc) _spDoc.reset(); - // create a smart pointer to hold the JSON document - try - { - _spDoc = std::make_shared(new_size); - } - catch (const std::exception &e) - { - _buffer_size = 0; - flxLogM_E(kMsgErrAllocError, "JSON Buffer"); - return; - } + _spDoc = std::make_shared(); _buffer_size = new_size; } @@ -331,7 +324,8 @@ template class flxFormatJSON : public flxOutputFormat // Need to recurse for (int i = 0; i < theArray->dimensions()[currentDim]; i++) { - JsonArray jsonNext = jsonArray.createNestedArray(); + // JsonArray jsonNext = jsonArray.createNestedArray(); + JsonArray jsonNext = jsonArray.add(); // recurse writeOutArrayDimension(jsonNext, pData, theArray, currentDim + 1); } @@ -342,7 +336,8 @@ template class flxFormatJSON : public flxOutputFormat { // create an array in this section - JsonArray jsonArray = _jSection.createNestedArray(tag); + // JsonArray jsonArray = _jSection.createNestedArray(tag); + JsonArray jsonArray = _jSection[tag].to(); T *pData = theArray->get(); @@ -357,7 +352,7 @@ template class flxFormatJSON : public flxOutputFormat size_t _buffer_size; // Shared pointer to the JSON document - std::shared_ptr _spDoc; + std::shared_ptr _spDoc; private: std::vector _jsonWriters; diff --git a/src/core/flux_logging/flxLogger.cpp b/src/core/flux_logging/flxLogger.cpp index bd83948..eb754b0 100644 --- a/src/core/flux_logging/flxLogger.cpp +++ b/src/core/flux_logging/flxLogger.cpp @@ -139,7 +139,7 @@ flxLogger::flxLogger() flxRegister(logRateMetric, "Rate Metric", "Enabled to record the logging rate data"); - flux.add(this); + flux_add(this); } //---------------------------------------------------------------------------- // logScalar() diff --git a/src/core/flux_logging/flxLogger.h b/src/core/flux_logging/flxLogger.h index 0518b81..f6e6fe3 100644 --- a/src/core/flux_logging/flxLogger.h +++ b/src/core/flux_logging/flxLogger.h @@ -23,7 +23,7 @@ #pragma once -#include +// #include #include #include diff --git a/src/core/flux_prefs/flxSettings.h b/src/core/flux_prefs/flxSettings.h index 49bb4e4..bb997b8 100644 --- a/src/core/flux_prefs/flxSettings.h +++ b/src/core/flux_prefs/flxSettings.h @@ -146,7 +146,7 @@ class flxSettingsSave : public flxActionType flxRegister(saveFallback, "Save to Fallback", "Save system settings to the fallback storage"); flxRegister(restoreFallback, "Restore from Fallback", "Restore system settings from the fallback storage"); - flux.add(this); + } flxStorage *_primaryStorage; diff --git a/src/core/flux_prefs_serial/flxSettingsSerial.h b/src/core/flux_prefs_serial/flxSettingsSerial.h index 363633c..1555629 100644 --- a/src/core/flux_prefs_serial/flxSettingsSerial.h +++ b/src/core/flux_prefs_serial/flxSettingsSerial.h @@ -41,6 +41,7 @@ class flxSettingsSerial : public flxActionType setHidden(); // don't cross the streams and don't show this object ... in the menu system it creates :) // Default root is our system + // TODO - move this to the application level setSystemRoot(&flux); // Our menu timeout value