Skip to content

Commit 6056fdf

Browse files
authored
[mapping] Update docs (#5194)
1 parent bcb4069 commit 6056fdf

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

content/components/mapping.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ description: "Mapping Component"
33
title: "Mapping Component"
44
---
55

6-
The `mapping` component allows you to create a map or dictionary that allows a one-to-one translation from keys to values. This enables e.g. mapping a string to a number or vice versa, or mapping a string such as a weather condition to an image.
6+
The `mapping` component allows you to create a map or dictionary that allows a one-to-one translation from keys to
7+
values. This enables e.g. mapping a string to a number or vice versa, or mapping a string such as a weather condition to an image.
78

89
```yaml
910
# Example configuration entry
@@ -45,7 +46,11 @@ You can also map to a class. This is useful when you want to map to a more compl
4546

4647
## Using a mapping
4748

48-
A mapping defined in this component can be used in lambdas in other components. The mapping can be accessed using the `id` function, and the value can be looked up using the `[]` operator as per the above example.
49+
A mapping defined in this component can be used in lambdas in other components. The mapping can be accessed using
50+
the ``id`` function, and the value can be looked up using the ``[]`` operator as per the above example, or the ``get`` function.
51+
A map may be updated at run time using a lambda call, e.g. ``map.set("key", value)``.
52+
53+
Maps are stored in RAM, but will use PSRAM if available.
4954

5055
A more complex example follows:
5156

@@ -84,8 +89,14 @@ display:
8489
- platform: ...
8590
# update the display drawing random text in random colors
8691
lambda: |-
87-
auto color = color_map[random_uint32() % 3];
92+
auto color = color_map.get(random_uint32() % 3]); # Uses get() to index the color_map
8893
it.printf(100, 100, id(roboto20), color, id(string_map)[random_uint32() % 3].c_str(), Color(0));
94+
95+
on_...:
96+
then:
97+
- lambda: |-
98+
id(color_map).set(2, Color::random_color());
99+
89100
```
90101

91102
## See Also

0 commit comments

Comments
 (0)