Skip to content

Commit f239588

Browse files
committed
Update README
1 parent 1503f19 commit f239588

1 file changed

Lines changed: 48 additions & 13 deletions

File tree

README.rst

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,19 @@ This example generates a `uint8_t` property value. A different type may be speci
297297
Calculated Values
298298
-----------------
299299

300-
With ConfigDB, if an attribute name is prefixed with ``@`` then it will be evaluated as a simple expression.
301-
Variable names correspond to environment variables.
302-
See https://github.com/SmingHub/Sming/blob/develop/Tools/Python/evaluator/README.md for details.
300+
Within a ConfigDB schema, if an attribute name is prefixed with @ then the attribute value will be evaluated and the result used as the actual value.
301+
The expression must be given as a string, with variable names corresponding to environment variables.
302+
See :doc:`/_inc/Tools/Python/evaluator/README` for details.
303303

304304
The ``.cfgdb`` schema are pre-processed on every build and the source files regenerated automatically if there is a change.
305-
The pre-processed schema can be found in ``out/ConfigDB/schema/``.
305+
The pre-processed schema can be found in ``out/ConfigDB/schema/``, together with a *summary.txt* file.
306306

307307
An example is included in the test application:
308308

309309
.. code-block:: json
310310
311-
"properties": {
311+
"simple-string": {
312+
"type": "string",
312313
"@default": "SIMPLE_STRING"
313314
}
314315
@@ -335,21 +336,28 @@ JSON does not support extended number formats, such as `0x12`, so this mechanism
335336

336337
.. code-block:: json
337338
338-
"properties": {
339+
"simple-int": {
340+
"type": "integer",
339341
"@default": "8 + 27",
340342
"minimum": 0,
341343
"@maximum": "0xffff"
342344
}
343345
344346
345-
Array defaults
346-
~~~~~~~~~~~~~~
347+
Array values
348+
~~~~~~~~~~~~
349+
350+
If a calculated attribute value is an array, then each element is evaluated separately.
351+
Arrays may contain a mixture of types, but only string values will be evalulated: others will be passed through unchanged.
347352

348-
Array defaults may contain a mixture of types:
349353

350354
.. code-block:: json
351355
352-
"properties": {
356+
"simple-array": {
357+
"type": "array",
358+
"items": {
359+
"type": "integer"
360+
},
353361
"@default": [
354362
"0x12",
355363
5,
@@ -358,7 +366,34 @@ Array defaults may contain a mixture of types:
358366
]
359367
}
360368
361-
Only string values will be evalulated, the others will be passed through unchanged.
369+
370+
Dictionary values
371+
~~~~~~~~~~~~~~~~~
372+
373+
To conditionally select from one of a number of options, provide a dictionary as the calculated attribute value.
374+
The first key which evaluates as *True* is matched, and the corresponding value becomes the value for the property.
375+
If none of the entries matches, an error is raised.
376+
377+
In this example, the default contents of the *pin-list* array is determined by the targetted SOC.
378+
The final *"True": []* ensures a value is provided if nothing else is matched.
379+
380+
.. code-block:: json
381+
382+
"pin-list": {
383+
"type": "array",
384+
"items": {
385+
"type": "integer",
386+
"minimum": 0,
387+
"maximum": 255
388+
},
389+
"@default": {
390+
"SMING_SOC == 'esp8266'": [ 1, 2, 3, 4 ],
391+
"SMING_SOC == 'esp32c3'": [ 5, 6, 7, 8 ],
392+
"SMING_SOC == 'esp32s2'": [ 9, 10, 11, 12 ],
393+
"SMING_SOC in ['rp2040', 'rp2350']": [ 13, 14, 15, 16 ],
394+
"True": []
395+
}
396+
}
362397
363398
364399
Store loading / saving
@@ -372,11 +407,11 @@ This can be overridden to customise loading/saving behaviour.
372407
The :cpp:func:`ConfigDB::Database::getFormat` method is called to get the storage format for a given Store.
373408
A :cpp:class:`ConfigDB::Format` implementation provides various methods for serializing and de-serializing database and object content.
374409

375-
Currently only **json** is implemented - see :cpp:class:`ConfigDB::Json::format`.
410+
Currently only **json** is implemented - see :cpp:member:`ConfigDB::Json::format`.
376411
Each store is contained in a separate file.
377412
The name of the store forms the JSONPath prefix for any contained objects and values.
378413

379-
The :sample:`BasicConfig` sample demonstrates using the stream classes to read and write data from a web client.
414+
The :sample:`Basic_Config` sample demonstrates using the stream classes to read and write data from a web client.
380415

381416
.. important::
382417

0 commit comments

Comments
 (0)