Skip to content

Commit ba90f48

Browse files
committed
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
1 parent f4e68f7 commit ba90f48

File tree

17 files changed

+232
-70
lines changed

17 files changed

+232
-70
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/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
//----------------------------------------------------------------------------------

src/core/flux_base/flxFlux.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
#include "flxCoreDevice.h"
1717
#include "flxSerial.h"
1818
#include <memory>
19+
#include <string.h>
20+
#include <string>
21+
#include <vector>
1922

2023
class flxApplication;
2124

22-
// // happy functions for happy users.
25+
// happy functions for happy users.
2326
// bool spark_start(bool bAutoLoad = true);
2427
// bool spark_loop();
2528

@@ -203,7 +206,6 @@ class flxFlux : public flxObjectContainer
203206
uint32_t version()
204207
{
205208
return _v_major * 10000 + _v_minor * 100 + _v_point;
206-
;
207209
}
208210
void version(uint32_t &major, uint32_t &minor, uint32_t &point)
209211
{
@@ -262,7 +264,9 @@ class flxFlux : public flxObjectContainer
262264
{
263265
_theApplication = theApp;
264266
// set the app as the first entry of our actions list
265-
Actions.insert(Actions.begin(), (flxAction *)theApp);
267+
// KDB - This is causing a crash on startup on rp2350 <<<<<<<<<<<<<<<<<<<<<<<
268+
if (initialized())
269+
Actions.insert(Actions.begin(), (flxAction *)theApp);
266270
}
267271
}
268272

@@ -317,6 +321,7 @@ class flxFlux : public flxObjectContainer
317321

318322
bool _deviceAutoload;
319323
bool _loadSettings;
324+
320325
// Note private constructor...
321326
flxFlux()
322327
: _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
338343
this->push_back(pTmp);
339344
}
340345

346+
bool initialized();
347+
void setInitialized(bool bInit);
348+
341349
flxOperation *_getByType(flxTypeID type)
342350
{
343351

@@ -360,6 +368,8 @@ class flxFlux : public flxObjectContainer
360368

361369
extern flxFlux &flux;
362370

371+
flxFlux &flux_get(void);
372+
363373
// Define our application class interface.
364374
class flxApplication : public flxActionType<flxApplication>
365375
{
@@ -451,6 +461,13 @@ class flxApplication : public flxActionType<flxApplication>
451461
return false;
452462
}
453463

454-
private:
464+
// private:
455465
flxDescriptor appDesc;
456-
};
466+
};
467+
468+
void flux_add(flxAction &theAction);
469+
void flux_add(flxAction *theAction);
470+
void flux_add(flxDevice &theDevice);
471+
void flux_add(flxDevice *theDevice);
472+
void flux_add(flxApplication &theApp);
473+
void flux_add(flxApplication *theApp);

src/core/flux_base/flxSerial.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,16 @@ void flxSerial_::textToNormal(void)
7878
{
7979
if (_colorEnabled)
8080
Serial.print(kClrNormal);
81+
}
82+
83+
void flxSerial_::textToCyan(void)
84+
{
85+
if (_colorEnabled)
86+
Serial.print(kClrCyan);
87+
}
88+
89+
void flxSerial_::textToMagenta(void)
90+
{
91+
if (_colorEnabled)
92+
Serial.print(kClrMagenta);
8193
}

src/core/flux_base/flxSerial.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include "flxCoreEvent.h"
20+
#include "flxCoreInterface.h"
2021
#include "flxOutput.h"
2122
#include <Arduino.h>
2223

@@ -92,6 +93,8 @@ class flxSerial_ : public flxWriter
9293
void textToBlue(void);
9394
void textToWhite(void);
9495
void textToNormal(void);
96+
void textToCyan(void);
97+
void textToMagenta(void);
9598

9699
private:
97100
flxSerial_() : _headerWritten{false}, _colorEnabled{false} {};
@@ -103,6 +106,8 @@ class flxSerial_ : public flxWriter
103106
static constexpr const char *kClrRed = "\033[1;31m";
104107
static constexpr const char *kClrBlue = "\033[1;34m";
105108
static constexpr const char *kClrWhite = "\033[1;37m";
109+
static constexpr const char *kClrCyan = "\033[1;36m";
110+
static constexpr const char *kClrMagenta = "\033[1;35m";
106111

107112
bool _headerWritten;
108113

src/core/flux_base/flxTimer.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,25 @@ class flxTimer : public flxActionType<flxTimer>
4242

4343
// for our timing
4444
unsigned long _lastLogTime = 0;
45+
uint32_t _initialInterval = 0;
4546

4647
flxJob _timerJob;
4748

4849
public:
49-
flxTimer(int start = 500) : _lastLogTime(0)
50+
flxTimer(uint32_t start = 15000) : _lastLogTime(0), _initialInterval(start)
5051
{
51-
52-
flxRegister(interval, "Interval", "Timer interval in milliseconds");
53-
54-
// interval = start;
55-
56-
flux.add(this);
57-
52+
// Add this to the list of actions in the framework
53+
flux_add(this);
5854
setName("Timer", "A reoccurring timer");
59-
60-
// setup the job used to trigger the timer (note - we enable "job compression" for this )
61-
_timerJob.setup(name(), start, this, &flxTimer::onTimer, false);
6255
};
6356

6457
bool initialize(void)
6558
{
59+
// Register the interval property - do here not in ctor due to uncertainty of global object creation order
60+
61+
flxRegister(interval, "Interval", "Timer interval in milliseconds");
62+
// setup the job used to trigger the timer (note - we enable "job compression" for this )
63+
_timerJob.setup(name(), _initialInterval, this, &flxTimer::onTimer, false);
6664
// Add the job to the job queue
6765
flxAddJobToQueue(_timerJob);
6866

0 commit comments

Comments
 (0)