Skip to content

Commit c061f5a

Browse files
committed
docs: Add Rotary API docs.
Signed-off-by: lbuque <1102390310@qq.com>
1 parent fd39ba0 commit c061f5a

File tree

7 files changed

+304
-0
lines changed

7 files changed

+304
-0
lines changed

docs/_static/hardware/rotary/example.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/en/hardware/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Hardware
55
:maxdepth: 1
66

77
power.rst
8+
rotary.rst

docs/en/hardware/rotary.rst

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
Rotary
2+
======
3+
4+
.. include:: ../refs/hardware.rotary.ref
5+
6+
7+
Rotary is used to control the rotary encoder integrated inside the host. Below
8+
is the detailed Rotary support for the host:
9+
10+
.. table::
11+
:widths: auto
12+
:align: center
13+
14+
+-----------------+--------+
15+
| Controller | Rotary |
16+
+=================+========+
17+
| Dial | |S| |
18+
+-----------------+--------+
19+
| DinMeter | |S| |
20+
+-----------------+--------+
21+
22+
.. |S| unicode:: U+2714
23+
24+
25+
Micropython Example::
26+
27+
import os, sys, io
28+
import M5
29+
from M5 import *
30+
from hardware import *
31+
32+
label0 = None
33+
rotary = None
34+
35+
def btnA_wasClicked_event(state):
36+
global label0, rotary
37+
rotary.reset_rotary_value()
38+
label0.setText(str(rotary.get_rotary_value()))
39+
40+
def setup():
41+
global label0, rotary
42+
43+
M5.begin()
44+
Widgets.fillScreen(0x222222)
45+
label0 = Widgets.Label("0", 96, 80, 1.0, 0xffa000, 0x222222, Widgets.FONTS.DejaVu72)
46+
47+
BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
48+
49+
rotary = Rotary()
50+
51+
def loop():
52+
global label0, rotary
53+
M5.update()
54+
if rotary.get_rotary_status():
55+
label0.setText(str(rotary.get_rotary_value()))
56+
57+
if __name__ == '__main__':
58+
try:
59+
setup()
60+
while True:
61+
loop()
62+
except (Exception, KeyboardInterrupt) as e:
63+
try:
64+
from utility import print_error_msg
65+
print_error_msg(e)
66+
except ImportError:
67+
print("please update to latest firmware")
68+
69+
70+
UIFLOW2 Example:
71+
72+
|example.svg|
73+
74+
75+
class Rotary
76+
------------
77+
78+
Constructors
79+
------------
80+
81+
.. class:: Rotary()
82+
83+
Creates a Rotary object.
84+
85+
UIFLOW2:
86+
87+
|init.svg|
88+
89+
Methods
90+
-------
91+
92+
.. method:: Rotary.get_rotary_status() -> bool
93+
94+
Gets the rotation status of the Rotary object.
95+
96+
UIFLOW2:
97+
98+
|get_rotary_status.svg|
99+
100+
101+
.. method:: Rotary.get_rotary_value() -> int
102+
103+
.. note:: Cannot be used simultaneously with :meth:`Rotary.get_rotary_increments()`.
104+
105+
Gets the rotation value of the Rotary object.
106+
107+
UIFLOW2:
108+
109+
|get_rotary_value.svg|
110+
111+
112+
.. method:: Rotary.get_rotary_increments() -> int
113+
114+
.. note:: Cannot be used simultaneously with :meth:`Rotary.get_rotary_increments()`.
115+
116+
Gets the rotation value of the Rotary object.
117+
118+
UIFLOW2:
119+
120+
|get_rotary_increments.svg|
121+
122+
123+
.. method:: Rotary.reset_rotary_value() -> None
124+
125+
Resets the rotation value of the Rotary object.
126+
127+
UIFLOW2:
128+
129+
|reset_rotary_value.svg|
130+
131+
132+
.. method:: Rotary.set_rotary_value() -> None
133+
134+
Sets the rotation value of the Rotary object.
135+
136+
UIFLOW2:
137+
138+
|set_rotary_value.svg|

docs/en/refs/hardware.rotary.ref

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. |example.svg| image:: ../../_static/hardware/rotary/example.svg
2+
3+
.. |init.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/init.svg
4+
5+
.. |get_rotary_status.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_status.svg
6+
7+
.. |get_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_value.svg
8+
9+
.. |reset_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/reset_rotary_value.svg
10+
11+
.. |set_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/set_rotary_value.svg
12+
13+
.. |get_rotary_increments.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_increments.svg

docs/zh_CN/hardware/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Hardware
99
speaker.rst
1010
imu.rst
1111
power.rst
12+
rotary.rst

docs/zh_CN/hardware/rotary.rst

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
Rotary
2+
======
3+
4+
.. include:: ../refs/hardware.rotary.ref
5+
6+
7+
Rotary 用于控制主机内部集成的旋转编码器。以下是主机的 Rotary 支持详细:
8+
9+
.. table::
10+
:widths: auto
11+
:align: center
12+
13+
+-----------------+--------+
14+
| Controller | Rotary |
15+
+=================+========+
16+
| Dial | |S| |
17+
+-----------------+--------+
18+
| DinMeter | |S| |
19+
+-----------------+--------+
20+
21+
.. |S| unicode:: U+2714
22+
23+
24+
Micropython Example::
25+
26+
import os, sys, io
27+
import M5
28+
from M5 import *
29+
from hardware import *
30+
31+
label0 = None
32+
rotary = None
33+
34+
def btnA_wasClicked_event(state):
35+
global label0, rotary
36+
rotary.reset_rotary_value()
37+
label0.setText(str(rotary.get_rotary_value()))
38+
39+
def setup():
40+
global label0, rotary
41+
42+
M5.begin()
43+
Widgets.fillScreen(0x222222)
44+
label0 = Widgets.Label("0", 96, 80, 1.0, 0xffa000, 0x222222, Widgets.FONTS.DejaVu72)
45+
46+
BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
47+
48+
rotary = Rotary()
49+
50+
def loop():
51+
global label0, rotary
52+
M5.update()
53+
if rotary.get_rotary_status():
54+
label0.setText(str(rotary.get_rotary_value()))
55+
56+
if __name__ == '__main__':
57+
try:
58+
setup()
59+
while True:
60+
loop()
61+
except (Exception, KeyboardInterrupt) as e:
62+
try:
63+
from utility import print_error_msg
64+
print_error_msg(e)
65+
except ImportError:
66+
print("please update to latest firmware")
67+
68+
69+
UIFLOW2 Example:
70+
71+
|example.svg|
72+
73+
74+
class Rotary
75+
------------
76+
77+
Constructors
78+
------------
79+
80+
.. class:: Rotary()
81+
82+
创建一个 Rotary 对象.
83+
84+
UIFLOW2:
85+
86+
|init.svg|
87+
88+
Methods
89+
-------
90+
91+
.. method:: Rotary.get_rotary_status() -> bool
92+
93+
获取 Rotary 对象的旋转状态。
94+
95+
UIFLOW2:
96+
97+
|get_rotary_status.svg|
98+
99+
100+
.. method:: Rotary.get_rotary_value() -> int
101+
102+
.. note:: 不能和 :meth:`Rotary.get_rotary_increments()` 同时使用
103+
104+
获取 Rotary 对象的旋转值。
105+
106+
UIFLOW2:
107+
108+
|get_rotary_value.svg|
109+
110+
111+
.. method:: Rotary.get_rotary_increments() -> int
112+
113+
.. note:: 不能和 :meth:`Rotary.get_rotary_status()` 同时使用
114+
115+
获取 Rotary 对象的旋转增量。可用于判断旋转方向。
116+
117+
UIFLOW2:
118+
119+
|get_rotary_increments.svg|
120+
121+
122+
.. method:: Rotary.reset_rotary_value() -> None
123+
124+
重置 Rotary 对象的旋转值。
125+
126+
UIFLOW2:
127+
128+
|reset_rotary_value.svg|
129+
130+
131+
.. method:: Rotary.set_rotary_value() -> None
132+
133+
设置 Rotary 对象的旋转值。
134+
135+
UIFLOW2:
136+
137+
|set_rotary_value.svg|

docs/zh_CN/refs/hardware.rotary.ref

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. |example.svg| image:: ../../_static/hardware/rotary/example.svg
2+
3+
.. |init.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/init.svg
4+
5+
.. |get_rotary_status.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_status.svg
6+
7+
.. |get_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_value.svg
8+
9+
.. |reset_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/reset_rotary_value.svg
10+
11+
.. |set_rotary_value.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/set_rotary_value.svg
12+
13+
.. |get_rotary_increments.svg| image:: https://m5stack.oss-cn-shenzhen.aliyuncs.com/mpy_docs/hardware/rotary/get_rotary_increments.svg

0 commit comments

Comments
 (0)