Added small instructions on the setting of configuration changes

This commit is contained in:
BlueFox 2024-11-15 18:24:22 +01:00
parent f03cc4a44c
commit aa3110d564
Signed by: BlueFox
GPG Key ID: 327233DA85435270

View File

@ -62,7 +62,37 @@ All the configuration can be done in the [config.json](config.json) file in JSON
| "LCD\_I2C\_NUM\_ROWS" | int | how many rows for character display has the display? | 2 |
| "LCD\_I2C\_NUM\_COLS" | int | and how many characters can it display per row? | 16 |
Note that this software has it's own small wrapper for the config file, e.g. to have instant access to an LCD object generated on the fly. These are all documented in the [utils.py](utils.py) file!
Note that this software has it's own small wrapper for the config file, e.g. to have instant access to an LCD object generated on the fly. These are all documented in the [utils.py](utils.py) file! When setting configuration options from your custom code, keep in mind that doing this via the `Config().<ATTR_NAME>` way just means writing the value directly to the file, while getting it goes through the wrapper to make e.g. the pin a machine.Pin object. But you just can't write a pin back into an attribute.
This wont work:
```python
from utils import Config
from machine import Pin
cfg = Config()
btn1 = cfg.PIN_IN_BTN_1
# Now we don't like this setting anymore
new_btn1 = Pin(10, Pin.IN, Pin.PULL_DOWN)
cfg.PIN_IN_BTN_1 = new_btn1
```
Instead, you have to do it that way:
```python
from utils import Config
from machine import Pin
cfg = Config
btn1 = cfg.PIN_IN_BTN_1
# Now we don't like it so we write the new pin in our json format
cfg.PIN_IN_BTN_1 = {"pin": 10, "pull": "down"}
```
So, as the `Config` class uses python's magic function for getting and setting attributes, the process of changing some config is not completely intuitive, but when keeping that in mind, it's very handy!
## Used libraries