Skip to content

Commit 6a3e8ce

Browse files
author
funnygeeker
committed
update 2.0
1 parent 1b8e0de commit 6a3e8ce

35 files changed

+3827
-579
lines changed

README.ZH-CN.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
[English (英语)](./README.md)
2+
# micropython-easymenu
3+
micropython 的简易菜单库,可以通过简单的配置,构造一个菜单
4+
5+
### 已测试的开发板
6+
- esp32c3
7+
8+
#### 已测试的屏幕
9+
- st7789
10+
11+
### 软件依赖
12+
13+
#### 必须
14+
- [micropython-easydisplay](https://github.com/funnygeeker/micropython-easydisplay)
15+
16+
#### 可选
17+
- [micropython-easybutton](https://github.com/funnygeeker/micropython-easybutton)
18+
19+
### 使用示例
20+
```python
21+
# This is an example of usage
22+
import time
23+
import framebuf
24+
from machine import SPI, Pin
25+
from drivers import st7789_spi
26+
from libs.easydisplay import EasyDisplay
27+
from libs.easymenu import EasyMenu
28+
29+
# ESP32C3 & ST7789
30+
spi = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(19), mosi=Pin(18))
31+
dp = st7789_spi.ST7789(width=240, height=240, spi=spi, cs=0, dc=1, rst=11, rotation=1)
32+
ed = EasyDisplay(display=dp, font="/font/text_lite_16px_2311.v3.bmf", show=True, color=0xFFFF, clear=True,
33+
color_type=framebuf.RGB565)
34+
menu = {
35+
'offset':(16,16),
36+
'title': ('Test Menu', 'center', 0),
37+
'start': (0, 22),
38+
'layout': (2, 2),
39+
'spacing': (60, 20),
40+
0: {'text': 'TEXT0'},
41+
1: {'text': 'TEXT1',
42+
0: {'text': ('TEXT1-0', 0, 0)},
43+
1: {'text': ('TEXT1-1', 0, 0)}
44+
},
45+
2: {'text': ('TEXT2', 0, 0)},
46+
3: {'text': ('TEXT3', 0, 0)},
47+
4: {'text': ('TEXT4', 0, 0)},
48+
5: {'text': ('TEXT5', 0, 0)}
49+
}
50+
em = EasyMenu(ed, menu)
51+
time.sleep(3)
52+
em.previous() # 上一个选项
53+
time.sleep(3)
54+
em.next() # 下一个选项
55+
print(em.select()) # 输出当前选项的内容
56+
```
57+
有关 EasyDisplay 的示例和说明,请前往:[micropython-easydisplay](https://github.com/funnygeeker/micropython-easydisplay)
58+
59+
### 配置说明
60+
- 提示:您可以在标准的菜单规范中增加额外的数据,配合 `enter()``select()` 函数,读取里面的扩展数据,从而实现一些功能
61+
- `menu` 参数配置详细说明及示例如下:
62+
```python
63+
menu = {'_len': 1,
64+
# 当前页菜单长度(由程序自动管理,非必要请勿填写)
65+
'image': ('/img/text.pbm', 0, 0),
66+
# 菜单页图像:不填则不显示,元组 ('图像文件路径', x, y),支持 dat, pbm, bmp 图片,这里的元组也可以替换为列表,图片需要包含后缀名,详细的图片说明详见 micropython-easydisplay
67+
'title': ('Main Menu', 'center', 0), # 举例: 'Title' , ('Title', 0, 0)
68+
# 菜单页标题:不填则不显示,有两种填写格式 元组 ('标题', x, y) 或者 字符串 '标题'(默认居中文字,y坐标为 0),这里的元组也可以替换为列表,标题的 x坐标 支持使用 'center', 'left', 'right' 代替, y坐标 支持使用 'center', 'top', 'bottom' 代替
69+
'start': (0, 0),
70+
# 选项的起始点:不填则由程序自动计算,从 (x, y) 开始,每间隔 spacing 的长度显示一个选项
71+
'clear': (0, 0, 239, 239),
72+
# 清屏的区域:(x_start, y_start, x_end, y_end) 不填则默认全屏,该选项可以用于实现:同屏幕多个菜单同时存在
73+
'style': {'border': 0, 'title_line': 1, 'img_reversion': 0},
74+
# 样式:不填则使用默认值,请填入字典:
75+
# border: 外边框的样式,目前版本中,0 为不启用外边框(被选中的选项会反色),1 为启用外边框(被选中的选项会反色)
76+
# title_line: 在标题下方增加一条线,0 为不启用,1 为启用
77+
# img_reversion: 图像显示时会被反色,仅适用于 bmp 和 pbm 图像
78+
'layout': (4, 1),
79+
# 布局:不填则自动计算,但是建议填写,(x, y),每页 x * y 个选项
80+
'offset': (0, 0),
81+
# 偏移:不填默认 (0, 0),为选项中所有未指定偏移的图像和文字增加偏移
82+
'spacing': (100, 20),
83+
# 间隔:不填则自动计算,但是建议填写,每个选项的起始点间隔 (x, y) 坐标显示
84+
0: {'text': ('option-1', 0, 0),
85+
# 不填则不显示,有两种填写格式 元组 ('文本', x, y) 或者 字符串 '文本'(默认偏移为(0, 0)),这里的元组也可以替换为列表,text 的偏移暂时只能用数字表示
86+
'img': ('/img/text.dat', 0, 0),
87+
# 选项图像:不填则不显示,元组 ('图像文件路径', x, y) 或者 字符串 '图像文件路径'(默认偏移为(0, 0))支持 dat, pbm, bmp 图片,这里的元组也可以替换为列表,图片需要包含后缀名,详细的图片说明详见 micropython-easydisplay
88+
'select': True,
89+
# 是否可被选中:不填默认 False,当 select 为 True 时,该选项或菜单会被显示,但是光标会自动跳过该选项,无法被选中
90+
},
91+
# 这是一个普通选项的示例,【只需要选项中包含数字 0 的键,该选项就会被识别为菜单,使用 enter() 函数时,会进入下一级菜单】
92+
1: {'title': 'Sub Menu',
93+
'text': 'option-2',
94+
'img': '/img/text.dat',
95+
'image': ('/img/text.pbm', 0, 0),
96+
0: {
97+
'text': 'option-2-1'
98+
},
99+
1: {
100+
'text': 'option-2-2'
101+
}
102+
},
103+
# 这是一个包含菜单选项的示例
104+
}
105+
```
106+
107+
- 典型示例如下:
108+
```python
109+
menu = {
110+
'offset':(16,16),
111+
'title': ('Test Menu', 'center', 0),
112+
'start': (0, 22),
113+
'layout': (2, 2),
114+
'spacing': (60, 20),
115+
0: {'text': 'TEXT0'},
116+
1: {'text': 'TEXT1',
117+
0: {'text': ('TEXT1-0', 0, 0)},
118+
1: {'text': ('TEXT1-1', 0, 0)}
119+
},
120+
2: {'text': ('TEXT2', 0, 0)},
121+
3: {'text': ('TEXT3', 0, 0)},
122+
4: {'text': ('TEXT4', 0, 0)},
123+
5: {'text': ('TEXT5', 0, 0)}
124+
}
125+
```

README.md

Lines changed: 150 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,151 @@
1+
[简体中文 (Chinese)](./README.ZH-CN.md)
12
# micropython-easymenu
2-
这是一个测试版本:适用于 micropython 的菜单库,可以在屏幕上显示菜单
3-
4-
3月再来看这个仓库吧,还在写
5-
6-
### 支持的芯片
7-
#### 已测试
8-
- st7735
9-
#### 待测试
10-
- st1306
11-
- 其他的待定
12-
13-
### 软件依赖
14-
#### 必须
15-
- https://github.com/funnygeeker/micropython-easydisplay
16-
#### 推荐
17-
- https://github.com/funnygeeker/micropython-easybutton
3+
4+
A simple menu library for Micropython that allows you to construct a menu through simple configuration.
5+
6+
### Tested Development Boards
7+
- esp32c3
8+
9+
#### Tested Screens
10+
- st7789
11+
12+
### Software Dependencies
13+
14+
#### Mandatory
15+
- [micropython-easydisplay](https://github.com/funnygeeker/micropython-easydisplay)
16+
17+
#### Optional
18+
- [micropython-easybutton](https://github.com/funnygeeker/micropython-easybutton)
19+
20+
### Usage Example
21+
```python
22+
# This is an example of usage
23+
import time
24+
import framebuf
25+
from machine import SPI, Pin
26+
from drivers import st7789_spi
27+
from libs.easydisplay import EasyDisplay
28+
from libs.easymenu import EasyMenu
29+
30+
# ESP32C3 & ST7789
31+
spi = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(19), mosi=Pin(18))
32+
dp = st7789_spi.ST7789(width=240, height=240, spi=spi, cs=0, dc=1, rst=11, rotation=1)
33+
ed = EasyDisplay(display=dp, font="/font/text_lite_16px_2311.v3.bmf", show=True, color=0xFFFF, clear=True,
34+
color_type=framebuf.RGB565)
35+
menu = {
36+
'offset':(16,16),
37+
'title': ('Test Menu', 'center', 0),
38+
'start': (0, 22),
39+
'layout': (2, 2),
40+
'spacing': (60, 20),
41+
0: {'text': 'TEXT0'},
42+
1: {'text': 'TEXT1',
43+
0: {'text': ('TEXT1-0', 0, 0)},
44+
1: {'text': ('TEXT1-1', 0, 0)}
45+
},
46+
2: {'text': ('TEXT2', 0, 0)},
47+
3: {'text': ('TEXT3', 0, 0)},
48+
4: {'text': ('TEXT4', 0, 0)},
49+
5: {'text': ('TEXT5', 0, 0)}
50+
}
51+
em = EasyMenu(ed, menu)
52+
time.sleep(3)
53+
em.previous() # Previous option
54+
time.sleep(3)
55+
em.next() # Next option
56+
print(em.select()) # Outputs the content of the current option
57+
```
58+
59+
For examples and explanations about EasyDisplay, please visit: [micropython-easydisplay](https://github.com/funnygeeker/micropython-easydisplay)
60+
61+
### Configuration Explanation
62+
- Note: You can add extra data in the standard menu specification and use the `enter()` and `select()` functions to read the extended data to achieve certain functionalities.
63+
- The detailed explanation and an example of the `menu` parameter configuration are as follows:
64+
```python
65+
menu = {'_len': 1,
66+
# Current page menu length (automatically managed by the program, please do not fill in if unnecessary)
67+
'image': ('/img/text.pbm', 0, 0),
68+
# Menu page image: If not filled in, it will not be displayed. Tuple ('image file path', x, y)
69+
# is supported, either as a tuple or as a list. Images can be dat, pbm, or bmp format.
70+
# The tuple can also be replaced with a list. Images need to include the file extension.
71+
# For detailed image instructions, please refer to micropython-easydisplay.
72+
'title': ('Main Menu', 'center', 0),
73+
# Menu page title: If not filled in, it will not be displayed. There are two formats:
74+
# Tuple ('title', x, y) or a string 'title' (default centered text, y-coordinate is 0).
75+
# The tuple can also be replaced with a list. The x-coordinate of the title supports using
76+
# 'center', 'left', 'right' instead, and the y-coordinate supports using 'center', 'top',
77+
# 'bottom' instead.
78+
'start': (0, 0),
79+
# Starting point of options: If not filled in, it will be automatically calculated. Starting
80+
# from (x, y), each option is displayed at a length equal to the spacing.
81+
'clear': (0, 0, 239, 239),
82+
# Clearing the screen area: (x_start, y_start, x_end, y_end) If not filled in, default to full screen.
83+
# This option can be used to implement multiple menus on the same screen simultaneously.
84+
'style': {'border': 0, 'title_line': 1, 'img_reversion': 0},
85+
# Style: If not filled in, default values will be used. Please fill in a dictionary:
86+
# border: Style of the outer border. In the current version, 0 means no outer border
87+
# (the selected option will be highlighted), and 1 means having an outer border
88+
# (the selected option will be highlighted).
89+
# title_line: Add a line below the title, 0 for disable and 1 for enable.
90+
# img_reversion: Images will be displayed with reversed colors. Only applicable to bmp and pbm images.
91+
'layout': (4, 1),
92+
# Layout: If not filled in, it will be automatically calculated, but it is recommended to fill in.
93+
# (x, y), x * y options per page.
94+
'offset': (0, 0),
95+
# Offset: Default is (0, 0). Adds an offset to all images and texts in the options that have not
96+
# specified an offset.
97+
'spacing': (100, 20),
98+
# Spacing: If not filled in, it will be automatically calculated, but it is recommended to fill in.
99+
# Coordinates (x, y) for the starting point interval of each option.
100+
0: {'text': ('option-1', 0, 0),
101+
# If not filled in, it will not be displayed. There are two formats:
102+
# Tuple ('text', x, y) or a string 'text' (default offset is (0, 0)).
103+
# The tuple can also be replaced with a list. The offset of text can only be expressed as a number.
104+
'img': ('/img/text.dat', 0, 0),
105+
# Option image: If not filled in, it will not be displayed. Tuple ('image file path', x, y)
106+
# or a string 'image file path' (default offset is (0, 0)) is supported.
107+
# Images can be dat, pbm, or bmp format. The tuple can also be replaced with a list.
108+
# Images need to include the file extension. For detailed image instructions, please refer
109+
# to micropython-easydisplay.
110+
'select': True,
111+
# Whether it can be selected: If not filled in, default to False. When select is True,
112+
# the option or menu will be displayed, but the cursor will automatically skip this option and
113+
# cannot be selected.
114+
},
115+
# This is an example of a regular option. If an option contains a key with the number 0,
116+
# the option will be recognized as a menu, and when the enter() function is used,
117+
# it will enter the next level menu.
118+
1: {'title': 'Sub Menu',
119+
'text': 'option-2',
120+
'img': '/img/text.dat',
121+
'image': ('/img/text.pbm', 0, 0),
122+
0: {
123+
'text': 'option-2-1'
124+
},
125+
1: {
126+
'text': 'option-2-2'
127+
}
128+
},
129+
# This is an example of a menu containing menu options.
130+
}
131+
```
132+
133+
- A typical example is as follows:
134+
```python
135+
menu = {
136+
'offset':(16,16),
137+
'title': ('Test Menu', 'center', 0),
138+
'start': (0, 22),
139+
'layout': (2, 2),
140+
'spacing': (60, 20),
141+
0: {'text': 'TEXT0'},
142+
1: {'text': 'TEXT1',
143+
0: {'text': ('TEXT1-0', 0, 0)},
144+
1: {'text': ('TEXT1-1', 0, 0)}
145+
},
146+
2: {'text': ('TEXT2', 0, 0)},
147+
3: {'text': ('TEXT3', 0, 0)},
148+
4: {'text': ('TEXT4', 0, 0)},
149+
5: {'text': ('TEXT5', 0, 0)}
150+
}
151+
```

drivers/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## 屏幕驱动(Chinese)
2+
3+
### 说明
4+
- 文件名含有 `buf` 的驱动是使用 `Framebuffer` 的帧缓冲区驱动,具有较高的效率和丰富的功能,
5+
在开发板内存充足的情况下请尽量选择该驱动
6+
7+
8+
- 文件名含有 `spi` 的驱动是使用 `SPI` 对屏幕进行直接驱动,配合 `micropython-easydisplay` 使用时效率略低,
9+
但是对内存不足以使用 `Framebuffer` 的开发板非常友好
10+
11+
12+
- 部分驱动可能存在一些错误,如果您遇到了错误并修复了 `BUG`,别忘记提交 `Pull Request` 来向项目提交您的更改建议。
13+
14+
15+
## Screen Drivers
16+
17+
### Description
18+
- Drivers with filenames containing `buf` are `Framebuffer` drivers, which have higher efficiency and richer features. Please choose these drivers when there is sufficient memory available on the development board.
19+
20+
21+
- Drivers with filenames containing `spi` are SPI drivers used for direct driving of the screen. When used with `micropython-easydisplay`, they have slightly lower efficiency but are very friendly for development boards with insufficient memory to use `Framebuffer`.
22+
23+
24+
- Some drivers may have some errors. If you encounter an error and fix a bug, don't forget to submit a pull request to contribute your suggested changes to the project.

drivers/ssd1306_buf.mpy

2.47 KB
Binary file not shown.

0 commit comments

Comments
 (0)