6
6
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7
7
* to anyone outside of this organization. Reproduction by any means
8
8
* whatsoever is prohibited without express written permission.
9
- *
9
+ *
10
10
*---------------------------------------------------------------------------------
11
11
*/
12
-
13
12
14
13
#pragma once
15
14
16
15
#include " flxCore.h"
17
16
#include " flxCoreDevice.h"
18
17
#include < memory>
19
18
20
-
21
-
22
-
23
19
class flxApplication ;
24
20
25
21
// // happy functions for happy users.
@@ -68,7 +64,6 @@ class flxFlux : public flxObjectContainer
68
64
flxDeviceContainer Devices;
69
65
flxActionContainer Actions;
70
66
71
-
72
67
// ---------------------------------------------------------------------------------
73
68
bool save (flxStorage *pStorage);
74
69
@@ -165,15 +160,15 @@ class flxFlux : public flxObjectContainer
165
160
return Devices;
166
161
}
167
162
168
- flxBusSPI & spiDriver ()
163
+ flxBusSPI &spiDriver ()
169
164
{
170
165
// has the driver been initialized?
171
166
if (!_spiDriver.initialized ())
172
167
_spiDriver.begin (true );
173
168
174
169
return _spiDriver;
175
170
}
176
- flxBusI2C & i2cDriver ()
171
+ flxBusI2C &i2cDriver ()
177
172
{
178
173
// has the driver been initialized?
179
174
if (!_i2cDriver.initialized ())
@@ -183,27 +178,28 @@ class flxFlux : public flxObjectContainer
183
178
}
184
179
185
180
// Version Things
186
- void setVersion (uint32_t major, uint32_t minor, uint32_t point, const char * desc, uint32_t build )
181
+ void setVersion (uint32_t major, uint32_t minor, uint32_t point, const char *desc, uint32_t build)
187
182
{
188
183
_v_major = major;
189
184
_v_minor = minor;
190
185
_v_point = point;
191
186
_v_build = build;
192
187
_v_desc = desc;
193
188
}
194
-
195
- void versionString (char *buffer, size_t nbuffer, bool bFull= false )
189
+
190
+ void versionString (char *buffer, size_t nbuffer, bool bFull = false )
196
191
{
197
192
if (bFull)
198
- snprintf (buffer, nbuffer, " %02u.%02u.%02u %s - build %06x" ,
199
- _v_major, _v_minor, _v_point, _v_desc. c_str (), _v_build);
193
+ snprintf (buffer, nbuffer, " %02u.%02u.%02u %s - build %06x" , _v_major, _v_minor, _v_point, _v_desc. c_str (),
194
+ _v_build);
200
195
else
201
- snprintf (buffer, nbuffer, " %02u.%02u.%02u" , _v_major, _v_minor, _v_point);
196
+ snprintf (buffer, nbuffer, " %02u.%02u.%02u" , _v_major, _v_minor, _v_point);
202
197
}
203
198
204
199
uint32_t version ()
205
200
{
206
- return _v_major * 10000 + _v_minor * 100 + _v_point;;
201
+ return _v_major * 10000 + _v_minor * 100 + _v_point;
202
+ ;
207
203
}
208
204
void version (uint32_t &major, uint32_t &minor, uint32_t &point)
209
205
{
@@ -217,11 +213,12 @@ class flxFlux : public flxObjectContainer
217
213
return _v_build;
218
214
}
219
215
220
- void setAppClassID (const char * ID )
216
+ void setAppClassID (const char *ID, char prefix[ 5 ] )
221
217
{
222
218
_appClassID = ID;
219
+ memcpy (_v_idprefix, prefix, 5 );
223
220
}
224
- const char * appClassID (void )
221
+ const char *appClassID (void )
225
222
{
226
223
return _appClassID;
227
224
}
@@ -236,24 +233,7 @@ class flxFlux : public flxObjectContainer
236
233
flxLog_N (F (" Version: %s\n\r " ), szBuffer);
237
234
}
238
235
239
- const char * deviceId (void )
240
- {
241
- // ID is 16 in length, use a C string
242
- static char szDeviceID[17 ]={0 };
243
- static bool bInitialized=false ;
244
- #ifdef ESP32
245
-
246
- if (!bInitialized)
247
- {
248
- memset (szDeviceID, ' \0 ' , sizeof (szDeviceID));
249
- snprintf (szDeviceID, sizeof (szDeviceID), " %016llX" , ESP.getEfuseMac ());
250
-
251
- bInitialized=true ;
252
- }
253
-
254
- #endif
255
- return (const char *)szDeviceID;
256
- }
236
+ const char *deviceId (void );
257
237
258
238
void setApplication (flxApplication &theApp)
259
239
{
@@ -266,11 +246,11 @@ class flxFlux : public flxObjectContainer
266
246
{
267
247
_theApplication = theApp;
268
248
// set the app as the first entry of our actions list
269
- Actions.insert (Actions.begin (), (flxAction*)theApp);
249
+ Actions.insert (Actions.begin (), (flxAction *)theApp);
270
250
}
271
251
}
272
252
273
- flxApplication * application (void )
253
+ flxApplication *application (void )
274
254
{
275
255
return _theApplication;
276
256
}
@@ -280,42 +260,41 @@ class flxFlux : public flxObjectContainer
280
260
bool getAppToken (uint8_t token[32 ]);
281
261
282
262
private:
283
-
284
- flxBusI2C _i2cDriver;
285
- flxBusSPI _spiDriver;
263
+ flxBusI2C _i2cDriver;
264
+ flxBusSPI _spiDriver;
286
265
287
266
uint32_t _v_major;
288
267
uint32_t _v_minor;
289
268
uint32_t _v_point;
290
269
uint32_t _v_build;
291
270
std::string _v_desc;
271
+ char _v_idprefix[5 ];
292
272
293
273
const char *_appClassID;
294
274
295
- flxApplication * _theApplication;
275
+ flxApplication *_theApplication;
296
276
297
277
uint8_t _token[32 ];
298
278
bool _hasToken;
299
279
300
280
// Note private constructor...
301
- flxFlux () : _v_major{0 }, _v_minor{0 }, _v_point{0 }, _v_build{0 }, _v_desc{" " },
302
- _appClassID{nullptr }, _theApplication{nullptr }, _token{0 }, _hasToken{false }
281
+ flxFlux ()
282
+ : _v_major{0 }, _v_minor{0 }, _v_point{0 }, _v_build{0 }, _v_desc{" " }, _v_idprefix{" 0000" }, _appClassID{nullptr },
283
+ _theApplication{nullptr }, _token{0 }, _hasToken{false }
303
284
{
304
285
305
286
// setup some default heirarchy things ...
306
287
this ->setName (" Flux" , " The SparkFun Flux Framework" );
307
288
Actions.setName (" Settings" , " System settings and operations" );
308
289
Devices.setName (" Devices Settings" , " Settings for connected devices" );
309
290
310
-
311
291
// Our container has two children, the device and the actions container
312
292
// Cast the devices and actions to objects to add. And had to use
313
293
// a temp var to get the references to take.
314
- flxObject * pTmp = &Actions;
294
+ flxObject *pTmp = &Actions;
315
295
this ->push_back (pTmp);
316
296
pTmp = &Devices;
317
297
this ->push_back (pTmp);
318
-
319
298
}
320
299
321
300
flxOperation *_getByType (flxTypeID type)
@@ -344,24 +323,24 @@ extern flxFlux &flux;
344
323
class flxApplication : public flxActionType <flxApplication>
345
324
{
346
325
347
- public:
326
+ public:
348
327
flxApplication ()
349
328
{
350
329
flux.setApplication (this );
351
330
352
331
// Set a name/descriptor that shows up in the menu system.
353
- ((flxObject*)this )->setName (" Application Settings" , " Main Application Settings" );
332
+ ((flxObject *)this )->setName (" Application Settings" , " Main Application Settings" );
354
333
}
355
-
334
+
356
335
// Name things - the overall base object of the system has a descriptor - we want this
357
336
// method signature to name the app, but also allow this app object (which is an action)
358
337
// to be used in the menuing system ... so
359
338
// - override the flxDescriptor methods on the app object
360
339
// -- use a descriptor instance variable to store the data
361
340
// - Methods called on the application will get these name/desc values
362
341
// - Methods called on sub-class objects get the base object name/desc
363
- // So we can use the same methods is both cases, but leverage the fact that
364
- // the base descriptor class methods are not virtual.
342
+ // So we can use the same methods is both cases, but leverage the fact that
343
+ // the base descriptor class methods are not virtual.
365
344
366
345
void setName (const char *name)
367
346
{
@@ -375,7 +354,7 @@ class flxApplication : public flxActionType<flxApplication>
375
354
{
376
355
this ->setName (name);
377
356
this ->setDescription (desc);
378
- }
357
+ }
379
358
const char *name (void )
380
359
{
381
360
return appDesc.name ();
@@ -405,16 +384,22 @@ class flxApplication : public flxActionType<flxApplication>
405
384
return ;
406
385
}
407
386
408
- void setVersion (uint major, uint minor, uint point, const char * desc, uint32_t build )
387
+ // called just prior to system restore on startup
388
+ virtual void onRestore (void )
389
+ {
390
+ return ;
391
+ }
392
+
393
+ void setVersion (uint major, uint minor, uint point, const char *desc, uint32_t build)
409
394
{
410
395
flux.setVersion (major, minor, point, desc, build);
411
396
}
412
397
413
- void setAppClassID (const char * ID )
398
+ void setAppClassID (const char *ID, char prefix[ 5 ] )
414
399
{
415
- flux.setAppClassID (ID);
400
+ flux.setAppClassID (ID, prefix );
416
401
}
417
- private:
418
- flxDescriptor appDesc;
419
402
403
+ private:
404
+ flxDescriptor appDesc;
420
405
};
0 commit comments