Skip to content

Commit 40ac7fc

Browse files
committed
libs/unit/acssr.py: Add ACSSR Unit and DCSSR Unit.
Signed-off-by: lbuque <[email protected]>
1 parent 0642773 commit 40ac7fc

File tree

13 files changed

+631
-0
lines changed

13 files changed

+631
-0
lines changed

docs/en/refs/unit.acssr.ref

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. |ACSSR Unit| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/acssr/acssr_01.webp
2+
:target: https://docs.m5stack.com/en/unit/acssr
3+
:height: 200px
4+
:width: 200 px
5+
6+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/init.png
7+
.. |on.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/on.png
8+
.. |call.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_relay.png
9+
.. |value.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/value.png
10+
.. |off.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/off.png
11+
.. |fill_color.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/fill_color.png
12+
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/get_firmware_version.png
13+
.. |set_address.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_address.png
14+
.. |set_address1.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/set_address1.png
15+
.. |i2c_example.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/i2c_example.png
16+
.. |modbus_example.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/acssr/modbus_example.png
17+
18+
.. |cores3_acssr_i2c_example.m5f2| raw:: html
19+
20+
<a
21+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/acssr/cores3_acssr_i2c_example.m5f2"
22+
target="_blank"
23+
>
24+
cores3_acssr_i2c_example.m5f2
25+
</a>
26+
27+
.. |cores3_acssr_modbus_example.m5f2| raw:: html
28+
29+
<a
30+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/acssr/cores3_acssr_modbus_example.m5f2"
31+
target="_blank"
32+
>
33+
cores3_acssr_modbus_example.m5f2
34+
</a>

docs/en/refs/unit.dcssr.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. |DCSSR Unit| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/DCSSR%20Unit/img-5e00db88-b5c7-4dd9-9061-b4700dc60c6e.webp
2+
:target: https://docs.m5stack.com/en/unit/DCSSR%20Unit
3+
:height: 200px
4+
:width: 200 px
5+
6+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/dcssr/init.png

docs/en/units/acssr.rst

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
ACSSR Unit
2+
==========
3+
4+
.. include:: ../refs/unit.acssr.ref
5+
6+
Support the following products:
7+
8+
|ACSSR Unit|
9+
10+
11+
Micropython I2C Example:
12+
13+
.. literalinclude:: ../../../examples/unit/acssr/cores3_acssr_i2c_example.py
14+
:language: python
15+
:linenos:
16+
17+
18+
Micropython Modbus Example:
19+
20+
.. literalinclude:: ../../../examples/unit/acssr/cores3_acssr_modbus_example.py
21+
:language: python
22+
:linenos:
23+
24+
25+
UIFLOW2 I2C Example:
26+
27+
|i2c_example.png|
28+
29+
30+
UIFLOW2 Modbus Example:
31+
32+
|modbus_example.png|
33+
34+
35+
.. only:: builder_html
36+
37+
|cores3_acssr_i2c_example.m5f2|
38+
39+
|cores3_acssr_modbus_example.m5f2|
40+
41+
42+
class ACSSRUnit
43+
---------------
44+
45+
Constructors
46+
------------
47+
48+
.. class:: ACSSRUnit(bus, address=None)
49+
50+
Create an ACSSRUnit object.
51+
52+
:param bus: I2C bus or Modbus.
53+
:param address: Slave address. Default is 0x50 in I2C mode. Default is 0x04 in Modbus mode.
54+
55+
UIFLOW2:
56+
57+
|init.png|
58+
59+
60+
.. _unit.ACSSRUnit.Methods:
61+
62+
Methods
63+
-------
64+
65+
.. method:: ACSSRUnit.on() -> None
66+
67+
Turn on the relay.
68+
69+
UIFLOW2:
70+
71+
|on.png|
72+
73+
74+
.. method:: ACSSRUnit.off() -> None
75+
76+
Turn off the relay.
77+
78+
UIFLOW2:
79+
80+
|off.png|
81+
82+
83+
.. method:: ACSSRUnit.__call__([x])
84+
85+
Turn on the relay if x is True, otherwise turn off the relay.
86+
87+
:param x: True or False.
88+
89+
UIFLOW2:
90+
91+
|call.png|
92+
93+
94+
.. method:: ACSSRUnit.value([x])
95+
96+
Turn on the relay if x is True, otherwise turn off the relay.
97+
98+
:param x: True or False.
99+
100+
UIFLOW2:
101+
102+
|value.png|
103+
104+
105+
.. method:: ACSSRUnit.fill_color(rgb: int = 0) -> None
106+
107+
Set the color of the LED.
108+
109+
:param rgb: RGB color value. Default is 0.
110+
111+
UIFLOW2:
112+
113+
|fill_color.png|
114+
115+
116+
.. method:: ACSSRUnit.get_firmware_version() -> int
117+
118+
Get the firmware version of the unit.
119+
120+
:return: Firmware version.
121+
122+
UIFLOW2:
123+
124+
|get_firmware_version.png|
125+
126+
127+
.. method:: ACSSRUnit.set_address(new_address: int) -> None
128+
129+
Set the I2C address of the unit.
130+
131+
:param new_address: New I2C address. The range is 0x01-0x7f.
132+
133+
UIFLOW2:
134+
135+
|set_address.png|
136+
137+
|set_address1.png|

docs/en/units/dcssr.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
DCSSR Unit
2+
==========
3+
4+
.. include:: ../refs/unit.dcssr.ref
5+
6+
Support the following products:
7+
8+
|DCSSR Unit|
9+
10+
11+
class DCSSRUnit
12+
---------------
13+
14+
Constructors
15+
------------
16+
17+
.. class:: DCSSRUnit(bus, address=0x50)
18+
19+
Create an DCSSRUnit object.
20+
21+
:param i2c: I2C bus or Modbus.
22+
:param address: Slave address. Default is 0x50 in I2C mode. Default is 0x04 in Modbus mode.
23+
24+
UIFLOW2:
25+
26+
|init.png|
27+
28+
29+
DCSSRUnit class inherits ACSSRUnit class, See :ref:`unit.ACSSRUnit.Methods <unit.ACSSRUnit.Methods>` for more details.

docs/en/units/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Unit
55
:maxdepth: 1
66

77
accel.rst
8+
acssr.rst
89
adc.rst
910
ain4.rst
1011
angle.rst
@@ -15,6 +16,7 @@ Unit
1516
catch.rst
1617
dac.rst
1718
dac2.rst
19+
dcssr.rst
1820
dds.rst
1921
digi_clock.rst
2022
dlight.rst

examples/unit/acssr/cores3_acssr_i2c_example.m5f2

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os, sys, io
6+
import M5
7+
from M5 import *
8+
from hardware import *
9+
from unit import ACSSRUnit
10+
11+
12+
label0 = None
13+
rect0 = None
14+
label1 = None
15+
title0 = None
16+
label3 = None
17+
i2c0 = None
18+
acssr_0 = None
19+
20+
21+
touch_x = None
22+
touch_y = None
23+
x = None
24+
y = None
25+
w = None
26+
h = None
27+
state = None
28+
ret = None
29+
30+
31+
# Describe this function...
32+
def is_touch(touch_x, touch_y, x, y, w, h):
33+
global state, ret, label0, rect0, label1, title0, label3, i2c0, acssr_0
34+
ret = False
35+
if touch_x >= x and touch_x <= x + w:
36+
if touch_y >= y and touch_y <= y + h:
37+
ret = True
38+
return ret
39+
40+
41+
# Describe this function...
42+
def display_ui(state):
43+
global touch_x, touch_y, x, y, w, h, ret, label0, rect0, label1, title0, label3, i2c0, acssr_0
44+
if state:
45+
rect0.setColor(color=0x00FF00, fill_c=0x00FF00)
46+
label3.setColor(0xFFFFFF, 0x00FF00)
47+
label3.setText(str("On"))
48+
acssr_0.fill_color(0x00FF00)
49+
else:
50+
rect0.setColor(color=0xFF0000, fill_c=0xFF0000)
51+
label3.setColor(0xFFFFFF, 0xFF0000)
52+
label3.setText(str("Off"))
53+
acssr_0.fill_color(0xFF0000)
54+
55+
56+
def setup():
57+
global \
58+
label0, \
59+
rect0, \
60+
label1, \
61+
title0, \
62+
label3, \
63+
i2c0, \
64+
acssr_0, \
65+
ret, \
66+
state, \
67+
touch_x, \
68+
x, \
69+
w, \
70+
touch_y, \
71+
y, \
72+
h
73+
74+
M5.begin()
75+
Widgets.fillScreen(0x222222)
76+
label0 = Widgets.Label("label0", 188, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
77+
rect0 = Widgets.Rectangle(130, 105, 60, 30, 0x00FF00, 0x00FF00)
78+
label1 = Widgets.Label(
79+
"Firmware Version:", 8, 30, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
80+
)
81+
title0 = Widgets.Title("ACSSR Unit", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
82+
label3 = Widgets.Label("On", 147, 111, 1.0, 0xFFFFFF, 0x00FF00, Widgets.FONTS.DejaVu18)
83+
84+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
85+
print(i2c0.scan())
86+
acssr_0 = ACSSRUnit(i2c0, 0x50)
87+
label0.setText(str(acssr_0.get_firmware_version()))
88+
state = acssr_0.value()
89+
display_ui(state)
90+
91+
92+
def loop():
93+
global \
94+
label0, \
95+
rect0, \
96+
label1, \
97+
title0, \
98+
label3, \
99+
i2c0, \
100+
acssr_0, \
101+
ret, \
102+
state, \
103+
touch_x, \
104+
x, \
105+
w, \
106+
touch_y, \
107+
y, \
108+
h
109+
M5.update()
110+
if M5.Touch.getCount():
111+
if is_touch(
112+
(M5.Touch.getTouchPointRaw())[0], (M5.Touch.getTouchPointRaw())[1], 130, 105, 60, 30
113+
):
114+
state = not state
115+
acssr_0(state)
116+
display_ui(state)
117+
118+
119+
if __name__ == "__main__":
120+
try:
121+
setup()
122+
while True:
123+
loop()
124+
except (Exception, KeyboardInterrupt) as e:
125+
try:
126+
from utility import print_error_msg
127+
128+
print_error_msg(e)
129+
except ImportError:
130+
print("please update to latest firmware")

examples/unit/acssr/cores3_acssr_modbus_example.m5f2

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)