Skip to content

Commit 045801c

Browse files
luoweiyuanlbuque
authored andcommitted
libs/chain: Add support for chain angle and chain encoder.
Signed-off-by: luoweiyuan <[email protected]>
1 parent 3dfb8f2 commit 045801c

File tree

20 files changed

+1349
-109
lines changed

20 files changed

+1349
-109
lines changed

docs/en/chain/angle.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Chain Angle
2+
===========
3+
4+
.. include:: ../refs/chain.angle.ref
5+
6+
AngleChain is the helper class for angle sensor devices on the Chain bus. It provides methods to read angle values in different resolutions (12-bit and 8-bit ADC) and configure the clockwise rotation direction.
7+
8+
Support the following products:
9+
10+
|Chain Angle|
11+
12+
UiFlow2 Example
13+
---------------
14+
15+
Angle reading with RGB brightness control
16+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
Open the |m5core_chain_angle_basic_example.m5f2| project in UiFlow2.
19+
20+
This example demonstrates how to read angle values from the Chain Angle sensor and control RGB brightness based on the angle value.
21+
The example reads 8-bit ADC values (0-255) and maps them to brightness values (0-100) for visual feedback.
22+
23+
UiFlow2 Code Block:
24+
25+
|m5core_chain_angle_basic_example.png|
26+
27+
Example output:
28+
29+
None
30+
31+
MicroPython Example
32+
-------------------
33+
34+
Angle reading with RGB brightness control
35+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
37+
This example demonstrates how to read angle values from the Chain Angle sensor and control RGB brightness based on the angle value.
38+
The example reads 8-bit ADC values (0-255) and maps them to brightness values (0-100) for visual feedback.
39+
40+
MicroPython Code Block:
41+
42+
.. literalinclude:: ../../../examples/chain/angle/m5core_chain_angle_basic_example.py
43+
:language: python
44+
:linenos:
45+
46+
Example output:
47+
48+
None
49+
50+
51+
**API**
52+
-------
53+
54+
AngleChain
55+
^^^^^^^^^^
56+
57+
.. autoclass:: chain.angle.AngleChain
58+
:members:
59+
:member-order: bysource
60+
:exclude-members:
61+
62+
For other button and some general methods, please refer to the :class:`ChainKey <chain.key.KeyChain>` class.
63+

docs/en/chain/encoder.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Chain Encoder
2+
=============
3+
4+
.. include:: ../refs/chain.encoder.ref
5+
6+
EncoderChain is the helper class for encoder devices on the Chain bus. It provides methods to read encoder values and increments, reset the encoder, configure the clockwise rotation direction, and handle button events with RGB LED feedback.
7+
8+
Support the following products:
9+
10+
|Chain Encoder|
11+
12+
UiFlow2 Example
13+
---------------
14+
15+
Encoder reading with brightness control
16+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
Open the |m5core_chain_encoder_basic_example.m5f2| project in UiFlow2.
19+
20+
This example demonstrates how to read encoder values and increments, handle button click events, and control RGB LED brightness based on encoder rotation. The encoder value is displayed on screen and updated in real-time.
21+
22+
UiFlow2 Code Block:
23+
24+
|m5core_chain_encoder_basic_example.png|
25+
26+
Example output:
27+
28+
None
29+
30+
MicroPython Example
31+
-------------------
32+
33+
Encoder reading with brightness control
34+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
36+
This example demonstrates how to read encoder values and increments, handle button click events, and control RGB LED brightness based on encoder rotation. The encoder value is displayed on screen and updated in real-time.
37+
38+
MicroPython Code Block:
39+
40+
.. literalinclude:: ../../../examples/chain/encoder/m5core_chain_encoder_basic_example.py
41+
:language: python
42+
:linenos:
43+
44+
Example output:
45+
46+
None
47+
48+
49+
**API**
50+
-------
51+
52+
EncoderChain
53+
^^^^^^^^^^^^
54+
55+
.. autoclass:: chain.encoder.EncoderChain
56+
:members:
57+
:member-order: bysource
58+
:exclude-members:
59+
60+
For other button and some general methods, please refer to the :class:`ChainKey <chain.key.KeyChain>` class.
61+

docs/en/chain/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Chain
44
.. toctree::
55
:maxdepth: 1
66

7+
angle.rst
8+
encoder.rst
79
chainbus.rst
810
joystick.rst
911
key.rst

docs/en/refs/chain.angle.ref

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
.. |Chain Angle| image:: https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1192/U208-Chain-angle-main-pictures-01.webp
3+
:target: https://docs.m5stack.com/en/products/sku/U208
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/init.png
8+
.. |get_adc12.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/get_adc12.png
9+
.. |get_adc8.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/get_adc8.png
10+
.. |get_cw_increase.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/get_cw_increase.png
11+
.. |set_cw_increase.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/set_cw_increase.png
12+
.. |m5core_chain_angle_basic_example.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/angle/example.png
13+
14+
.. |m5core_chain_angle_basic_example.m5f2| raw:: html
15+
16+
<a
17+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/chain/angle/m5core_chain_angle_basic_example.m5f2"
18+
target="_blank"
19+
>
20+
m5core_chain_angle_basic_example.m5f2
21+
</a>

docs/en/refs/chain.encoder.ref

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
.. |Chain Encoder| image:: https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/1192/U207-Chain-encoder-main-pictures-01.webp
3+
:target: https://docs.m5stack.com/en/products/sku/U207
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/init.png
8+
.. |get_encoder_value.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_encoder_value.png
9+
.. |reset_encoder_value.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/reset_encoder_value.png
10+
.. |get_cw_increase.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_cw_increase.png
11+
.. |set_cw_increase.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_cw_increase.png
12+
.. |get_encoder_increment.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_encoder_increment.png
13+
.. |reset_encoder_increment.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/reset_encoder_increment.png
14+
.. |get_button_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_button_state.png
15+
.. |get_button_mode.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_button_mode.png
16+
.. |set_button_mode.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_button_mode.png
17+
.. |get_button_double_click_trigger_interval.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_button_double_click_trigger_interval.png
18+
.. |set_button_double_click_trigger_interval.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_button_double_click_trigger_interval.png
19+
.. |get_button_long_press_trigger_interval.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_button_long_press_trigger_interval.png
20+
.. |set_button_long_press_trigger_interval.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_button_long_press_trigger_interval.png
21+
.. |click_event.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/click_event.png
22+
.. |double_click_event.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/double_click_event.png
23+
.. |long_press_event.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/long_press_event.png
24+
.. |get_rgb_color.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_rgb_color.png
25+
.. |set_rgb_color.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_rgb_color.png
26+
.. |get_rgb_brightness.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_rgb_brightness.png
27+
.. |set_rgb_brightness.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/set_rgb_brightness.png
28+
.. |get_device_uid.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_device_uid.png
29+
.. |get_bootloader_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_bootloader_version.png
30+
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/get_firmware_version.png
31+
.. |m5core_chain_encoder_basic_example.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/encoder/example.png
32+
33+
.. |m5core_chain_encoder_basic_example.m5f2| raw:: html
34+
35+
<a
36+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/chain/encoder/m5core_chain_encoder_basic_example.m5f2"
37+
target="_blank"
38+
>
39+
m5core_chain_encoder_basic_example.m5f2
40+
</a>

docs/en/refs/chain.key.ref

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/get_firmware_version.png
99
.. |get_rgb_brightness.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/get_rgb_brightness.png
1010
.. |get_rgb_color.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/get_rgb_color.png
11+
.. |get_device_uid.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/get_device_uid.png
1112
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/init.png
1213
.. |key_click_callback.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/key_click_callback.png
1314
.. |long_press_callback.png| image:: https://static-cdn.m5stack.com/mpy_docs/chain/key/long_press_callback.png

0 commit comments

Comments
 (0)