Skip to content

Commit 7da4d63

Browse files
authored
Update README.md
1 parent 997d48f commit 7da4d63

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

README.md

+66-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,72 @@ The microcontroller firmware of the `Raspberry Pi Pico` was created in micropyth
116116
The source code files are located in the folder `src/firmware_rp2040` and the Python source code files in the folder `src/firmware_rp2040/src`.
117117
The program `Thonny` can be used to adapt the software directly on the scale.
118118

119-
## BUILD FIRMWARE IMAGE
119+
### STRUCTURE
120+
121+
The entry point of the software is in the `main.py`, which is called by the custom pre-boot script `boot.py`. The general configuration of the hardware (e.g. which pins the buttons are connected to) is done in the `config.py` file.
122+
123+
The control of the hardware components is done in the files:
124+
125+
* `ui.py` - UI system + display control
126+
* `ledring.py` - LED effects for the LED ring
127+
* `Scales.py` - readout of the HX711
128+
* `settings.py`- filesystem access for writing/reading recipe files and settings
129+
130+
All these classes can be easily called from all other scripts using the singleton pattern. This makes integration very simple and uniform:
131+
132+
```python
133+
import ledring
134+
import ui
135+
import Scale
136+
# CLEAR DISPLAY
137+
ui().clear()
138+
# SET LED RING
139+
ledring().set_neopixel_full_hsv(ledring().COLOR_PRESET_HSV_H__BLUE)
140+
# GET CURRENT SCALE MEASUREMENT
141+
ScaleInterface().get_current_weight()
142+
```
143+
144+
The individual menus are designed as a plug-in system. This allows you to quickly create your own extensions.
145+
The plugins are designated in the system with the prefix `menu_entry_*.py` and the functions are derived from the base class `menu_entry.py`.
146+
This consists of an `activate`, `teardown` and `update` function, which are called accordingly when the corresponding menu entry is called.
147+
148+
```python
149+
class menu_entry_MyPlugin(menu_entry.menu_entry):
150+
151+
def __init__(self):
152+
super().__init__("INFO", "Have a nice day :)")
153+
154+
def preview(self):
155+
print("preview {}".format(self.name))
156+
ui().show_recipe_information(self.name, self.description)
157+
158+
159+
def activate(self):
160+
print("activate {}".format(self.name))
161+
ui().show_titlescreen()
162+
163+
164+
def teardown(self):
165+
print("teardown {}".format(self.name))
166+
167+
168+
def update(self, _system_command: system_command.system_command):
169+
# REACT TO SYSTEM EVENTS, SEE system_commands.py
170+
if _system_command.type == system_command.system_command.COMMAND_TYPE_NAVIGATION:
171+
menu_manager().exit_current_menu()
172+
173+
```
174+
175+
176+
To add the plugin, import the module in `main.py` and add the class into the menu tree:
177+
178+
```python
179+
from menu_entry_MyPlugin import menu_entry_MyPlugin
180+
menu_manager.menu_manager().add_subentries(menu_entry_MyPlugin.menu_entry_MyPlugin())
181+
```
182+
183+
184+
### BUILD FIRMWARE IMAGE
120185

121186
To create a finished and complete firmware image, the folder `src/firmware_rp2040` contains a bash script which creates the images using `Docker` for the `Raspberry Pi Pico` and `Raspberry Pi Pico W` and the required boot configurations.
122187

0 commit comments

Comments
 (0)