Skip to content

Commit 5f20268

Browse files
authored
Merge pull request #173 from sparkfun/feature/arm-port-part1
Feature/arm port part1
2 parents fa64bba + ba90f48 commit 5f20268

File tree

45 files changed

+539
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+539
-138
lines changed

src/core/flux_base/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ flux_sdk_add_source_files(
88
flxCore.h
99
flxCoreDevice.cpp
1010
flxCoreDevice.h
11+
flxDeviceValueTypes.h
1112
flxCoreEvent.h
1213
flxCoreEvent.cpp
1314
flxCoreEventID.h

src/core/flux_base/flxCoreLog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <WString.h>
1818
#include <map>
1919
#include <stdarg.h>
20+
#include <stdexcept>
2021
#include <vector>
2122

2223
#include "flxCoreEventID.h"

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
{

src/core/flux_base/flxCoreProps.h

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,26 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
250250
{
251251

252252
public:
253-
_flxPropertyBase() : _isHidden{HIDDEN}, _isSecure{SECURE}
253+
_flxPropertyBase() : _flags{0}
254254
{
255+
if (HIDDEN)
256+
setHidden();
257+
if (SECURE)
258+
_flags |= kIsSecure;
255259
}
256260

257261
bool hidden()
258262
{
259-
return _isHidden;
263+
return (_flags & kIsHidden == kIsHidden);
260264
}
261265
// Add a method that allows the property to be hidden if public
262266
void setHidden(void)
263267
{
264-
_isHidden = true;
268+
_flags |= kIsHidden;
265269
}
266270
bool secure()
267271
{
268-
return _isSecure;
272+
return (_flags & kIsSecure == kIsSecure);
269273
}
270274
//---------------------------------------------------------------------------------
271275
flxDataType_t type()
@@ -299,7 +303,7 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
299303
bool status = true;
300304

301305
// We don't save hidden or secure properties if this is an external source
302-
if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!_isHidden && !_isSecure))
306+
if (stBlk->kind() == flxStorage::flxStorageKindInternal || (!hidden() && !secure()))
303307
{
304308
T c = get();
305309
bool status = stBlk->write(name(), c);
@@ -382,8 +386,10 @@ class _flxPropertyBase : public flxProperty, public _flxDataIn<T>, public _flxDa
382386
}
383387

384388
private:
385-
bool _isHidden;
386-
bool _isSecure;
389+
static constexpr const uint8_t kIsHidden = 0x1;
390+
static constexpr const uint8_t kIsSecure = 0x2;
391+
392+
uint8_t _flags;
387393
};
388394

389395
//----------------------------------------------------------------------------------------
@@ -402,22 +408,26 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
402408
flxDataLimitType<std::string> *_dataLimit;
403409

404410
public:
405-
_flxPropertyBaseString() : _dataLimit{nullptr}, _isHidden{HIDDEN}, _isSecure{SECURE}
411+
_flxPropertyBaseString() : _dataLimit{nullptr}, _flags{0}
406412
{
413+
if (HIDDEN)
414+
setHidden();
415+
if (SECURE)
416+
_flags |= kIsSecure;
407417
}
408418

409419
bool hidden()
410420
{
411-
return _isHidden;
421+
return (_flags & kIsHidden == kIsHidden);
412422
}
413423
// Add a method that allows the property to be hidden if public
414424
void setHidden(void)
415425
{
416-
_isHidden = true;
426+
_flags |= kIsHidden;
417427
}
418428
bool secure()
419429
{
420-
return _isSecure;
430+
return (_flags & kIsSecure == kIsSecure);
421431
}
422432

423433
flxDataType_t type()
@@ -466,17 +476,17 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
466476

467477
// If this is a secure string and storage is internal, the strings are stored
468478
// encrypted
469-
if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure)
479+
if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure())
470480
return stBlk->saveSecureString(name(), get().c_str());
471481

472482
// If we are saving to an external source, we don't save hidden values or secure values.
473483
// But, for secure props, we to write the key and a blank string (makes it easier to enter values)
474484

475485
// We don't save hidden or secure properties if this is an external source
476-
if (stBlk->kind() == flxStorage::flxStorageKindInternal || !_isHidden)
486+
if (stBlk->kind() == flxStorage::flxStorageKindInternal || !hidden())
477487
{
478488
// if a secure property and external storage, set value to an empty string
479-
std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && _isSecure) ? "" : get();
489+
std::string c = (stBlk->kind() == flxStorage::flxStorageKindExternal && secure()) ? "" : get();
480490

481491
status = stBlk->writeString(name(), c.c_str());
482492
if (!status)
@@ -491,7 +501,7 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
491501
size_t len;
492502

493503
// Secure string?
494-
if (stBlk->kind() == flxStorage::flxStorageKindInternal && _isSecure)
504+
if (stBlk->kind() == flxStorage::flxStorageKindInternal && secure())
495505
{
496506
// get buffer length. Note, add one to make sure we have room for line termination
497507
len = stBlk->getBytesLength(name()) + 1;
@@ -565,8 +575,10 @@ class _flxPropertyBaseString : public flxProperty, _flxDataInString, _flxDataOut
565575
};
566576

567577
private:
568-
bool _isHidden;
569-
bool _isSecure;
578+
static constexpr const uint8_t kIsHidden = 0x1;
579+
static constexpr const uint8_t kIsSecure = 0x2;
580+
581+
uint8_t _flags;
570582
};
571583

572584
//----------------------------------------------------------------------------------------------------
@@ -636,7 +648,7 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
636648
void operator()(Object *obj, bool skipAdd = false)
637649
{
638650
// my_object must be derived from _flxPropertyContainer
639-
static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object");
651+
// static_assert(std::is_base_of<_flxPropertyContainer, Object>::value, "TypedRW: invalid object");
640652

641653
my_object = obj;
642654
assert(my_object);
@@ -676,6 +688,9 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
676688
{
677689
if (!my_object) // would normally throw an exception, but not very Arduino like!
678690
{
691+
if (_hasInitial)
692+
return _initialValue;
693+
679694
flxLogM_E(kMsgParentObjNotSet, "property");
680695
return (T)0;
681696
}
@@ -687,8 +702,10 @@ class _flxPropertyTypedRW : public _flxPropertyBase<T, HIDDEN, SECURE>
687702
{
688703
if (!my_object)
689704
{
690-
flxLogM_E(kMsgParentObjNotSet, "property");
691-
return; // would normally throw an exception, but not very Arduino like!
705+
// cache the value until we are connected to the containing object
706+
_hasInitial = true;
707+
_initialValue = value;
708+
return;
692709
}
693710

694711
(my_object->*_setter)(value);
@@ -1291,6 +1308,8 @@ class flxPropertyRWString : public _flxPropertyBaseString<HIDDEN, SECURE>
12911308
{
12921309
if (!my_object)
12931310
{
1311+
if (_hasInitial)
1312+
return _initialValue;
12941313
flxLogM_E(kMsgParentObjNotSet, "property");
12951314
return "";
12961315
}
@@ -1303,7 +1322,9 @@ class flxPropertyRWString : public _flxPropertyBaseString<HIDDEN, SECURE>
13031322
{
13041323
if (!my_object)
13051324
{
1306-
flxLogM_E(kMsgParentObjNotSet, "property");
1325+
_hasInitial = true;
1326+
_initialValue = value;
1327+
13071328
return;
13081329
}
13091330

src/core/flux_base/flxCoreTypes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <string>
2222
#include <type_traits>
2323
#include <vector>
24-
#include <stdexcept>
2524

2625
#include "flxCoreLog.h"
2726
#include "flxUtils.h"
@@ -283,6 +282,9 @@ enum flxDataType_t : std::uint8_t
283282
flxTypeDouble = 0x28,
284283
flxTypeString = 0x21
285284
};
285+
const flxDataType_t flxDataTypeArray[] = {flxTypeNone, flxTypeBool, flxTypeInt8, flxTypeUInt8,
286+
flxTypeInt16, flxTypeUInt16, flxTypeInt32, flxTypeUInt32,
287+
flxTypeFloat, flxTypeDouble, flxTypeString};
286288

287289
/*******************************************************************************
288290
* @brief A constexpr function that returns the flxDataType_t value for a given type.

src/core/flux_base/flxDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <vector>
3434

3535
#include "flxCoreDevice.h"
36+
#include "flxDeviceValueTypes.h"
3637
#include "flxFlux.h"
3738

3839
//----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)