From aa3110d5644379dcdb8d0d7e0803fdb68887ac7c Mon Sep 17 00:00:00 2001 From: BlueFox Date: Fri, 15 Nov 2024 18:24:22 +0100 Subject: [PATCH] Added small instructions on the setting of configuration changes --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70db708..3fab1c7 100644 --- a/README.md +++ b/README.md @@ -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().` 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