micrOSDevToolKit 2.9.7__py3-none-any.whl → 2.9.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of micrOSDevToolKit might be problematic. Click here for more details.
- micrOS/release_info/micrOS_ReleaseInfo/system_analysis_sum.json +11 -11
- micrOS/source/Espnow.py +89 -56
- micrOS/source/LM_L298N_DCmotor.py +4 -4
- micrOS/source/LM_L9110_DCmotor.py +3 -3
- micrOS/source/LM_VL53L0X.py +2 -2
- micrOS/source/LM_aht10.py +2 -2
- micrOS/source/LM_bme280.py +2 -2
- micrOS/source/LM_buzzer.py +12 -15
- micrOS/source/LM_cct.py +10 -13
- micrOS/source/LM_co2.py +3 -3
- micrOS/source/LM_dht11.py +2 -2
- micrOS/source/LM_dht22.py +2 -2
- micrOS/source/LM_dimmer.py +2 -2
- micrOS/source/LM_distance.py +3 -3
- micrOS/source/LM_ds18.py +2 -2
- micrOS/source/LM_genIO.py +52 -37
- micrOS/source/LM_haptic.py +2 -2
- micrOS/source/LM_i2c.py +2 -2
- micrOS/source/LM_i2s_mic.py +5 -5
- micrOS/source/LM_keychain.py +2 -2
- micrOS/source/LM_ld2410.py +2 -2
- micrOS/source/LM_light_sensor.py +2 -2
- micrOS/source/LM_neopixel.py +9 -12
- micrOS/source/LM_oled.py +2 -2
- micrOS/source/LM_oled_sh1106.py +3 -3
- micrOS/source/LM_oled_ui.py +2 -2
- micrOS/source/LM_ph_sensor.py +3 -3
- micrOS/source/LM_presence.py +2 -2
- micrOS/source/LM_rencoder.py +2 -2
- micrOS/source/LM_rgb.py +15 -22
- micrOS/source/LM_servo.py +3 -3
- micrOS/source/LM_stepper.py +5 -5
- micrOS/source/LM_switch.py +5 -5
- micrOS/source/LM_trackball.py +3 -3
- micrOS/source/LM_veml7700.py +2 -2
- micrOS/source/Shell.py +1 -1
- micrOS/source/microIO.py +27 -9
- {micrOSDevToolKit-2.9.7.dist-info → micrOSDevToolKit-2.9.8.dist-info}/METADATA +1 -1
- {micrOSDevToolKit-2.9.7.dist-info → micrOSDevToolKit-2.9.8.dist-info}/RECORD +81 -82
- toolkit/dashboard_apps/SystemTest.py +1 -1
- toolkit/dashboard_apps/uLightDemo.py +1 -1
- toolkit/workspace/precompiled/Espnow.mpy +0 -0
- toolkit/workspace/precompiled/LM_L298N_DCmotor.mpy +0 -0
- toolkit/workspace/precompiled/LM_L9110_DCmotor.py +3 -3
- toolkit/workspace/precompiled/LM_VL53L0X.py +2 -2
- toolkit/workspace/precompiled/LM_aht10.mpy +0 -0
- toolkit/workspace/precompiled/LM_bme280.mpy +0 -0
- toolkit/workspace/precompiled/LM_buzzer.mpy +0 -0
- toolkit/workspace/precompiled/LM_cct.mpy +0 -0
- toolkit/workspace/precompiled/LM_co2.mpy +0 -0
- toolkit/workspace/precompiled/LM_dht11.mpy +0 -0
- toolkit/workspace/precompiled/LM_dht22.mpy +0 -0
- toolkit/workspace/precompiled/LM_dimmer.mpy +0 -0
- toolkit/workspace/precompiled/LM_distance.mpy +0 -0
- toolkit/workspace/precompiled/LM_ds18.mpy +0 -0
- toolkit/workspace/precompiled/LM_genIO.mpy +0 -0
- toolkit/workspace/precompiled/LM_haptic.mpy +0 -0
- toolkit/workspace/precompiled/LM_i2c.py +2 -2
- toolkit/workspace/precompiled/LM_i2s_mic.mpy +0 -0
- toolkit/workspace/precompiled/LM_keychain.mpy +0 -0
- toolkit/workspace/precompiled/LM_ld2410.mpy +0 -0
- toolkit/workspace/precompiled/LM_light_sensor.mpy +0 -0
- toolkit/workspace/precompiled/LM_neopixel.mpy +0 -0
- toolkit/workspace/precompiled/LM_oled.mpy +0 -0
- toolkit/workspace/precompiled/LM_oled_sh1106.mpy +0 -0
- toolkit/workspace/precompiled/LM_oled_ui.mpy +0 -0
- toolkit/workspace/precompiled/LM_ph_sensor.py +3 -3
- toolkit/workspace/precompiled/LM_presence.mpy +0 -0
- toolkit/workspace/precompiled/LM_rencoder.py +2 -2
- toolkit/workspace/precompiled/LM_rgb.mpy +0 -0
- toolkit/workspace/precompiled/LM_servo.mpy +0 -0
- toolkit/workspace/precompiled/LM_stepper.mpy +0 -0
- toolkit/workspace/precompiled/LM_switch.mpy +0 -0
- toolkit/workspace/precompiled/LM_trackball.mpy +0 -0
- toolkit/workspace/precompiled/LM_veml7700.mpy +0 -0
- toolkit/workspace/precompiled/Shell.mpy +0 -0
- toolkit/workspace/precompiled/microIO.mpy +0 -0
- toolkit/workspace/precompiled/node_config.json +0 -1
- {micrOSDevToolKit-2.9.7.data → micrOSDevToolKit-2.9.8.data}/scripts/devToolKit.py +0 -0
- {micrOSDevToolKit-2.9.7.dist-info → micrOSDevToolKit-2.9.8.dist-info}/LICENSE +0 -0
- {micrOSDevToolKit-2.9.7.dist-info → micrOSDevToolKit-2.9.8.dist-info}/WHEEL +0 -0
- {micrOSDevToolKit-2.9.7.dist-info → micrOSDevToolKit-2.9.8.dist-info}/top_level.txt +0 -0
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
],
|
|
59
59
|
"Debug.py": [
|
|
60
60
|
8.4,
|
|
61
|
-
|
|
61
|
+
18
|
|
62
62
|
],
|
|
63
63
|
"Network.py": [
|
|
64
64
|
9.71,
|
|
65
65
|
8
|
|
66
66
|
],
|
|
67
67
|
"Espnow.py": [
|
|
68
|
-
|
|
68
|
+
8.86,
|
|
69
69
|
1
|
|
70
70
|
],
|
|
71
71
|
"Scheduler.py": [
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
1
|
|
74
74
|
],
|
|
75
75
|
"microIO.py": [
|
|
76
|
-
9.
|
|
76
|
+
9.42,
|
|
77
77
|
42
|
|
78
78
|
],
|
|
79
79
|
"micrOS.py": [
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
0
|
|
106
106
|
],
|
|
107
107
|
"LM_genIO.py": [
|
|
108
|
-
9.
|
|
108
|
+
9.12,
|
|
109
109
|
0
|
|
110
110
|
],
|
|
111
111
|
"LM_oled_ui.py": [
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
0
|
|
150
150
|
],
|
|
151
151
|
"LM_buzzer.py": [
|
|
152
|
-
8.
|
|
152
|
+
8.8,
|
|
153
153
|
0
|
|
154
154
|
],
|
|
155
155
|
"LM_switch.py": [
|
|
@@ -177,11 +177,11 @@
|
|
|
177
177
|
0
|
|
178
178
|
],
|
|
179
179
|
"LM_neopixel.py": [
|
|
180
|
-
7.
|
|
180
|
+
7.54,
|
|
181
181
|
2
|
|
182
182
|
],
|
|
183
183
|
"LM_cct.py": [
|
|
184
|
-
|
|
184
|
+
9.03,
|
|
185
185
|
1
|
|
186
186
|
],
|
|
187
187
|
"LM_L9110_DCmotor.py": [
|
|
@@ -249,7 +249,7 @@
|
|
|
249
249
|
0
|
|
250
250
|
],
|
|
251
251
|
"LM_rgb.py": [
|
|
252
|
-
8.
|
|
252
|
+
8.82,
|
|
253
253
|
1
|
|
254
254
|
],
|
|
255
255
|
"LM_distance.py": [
|
|
@@ -315,11 +315,11 @@
|
|
|
315
315
|
},
|
|
316
316
|
"summary": {
|
|
317
317
|
"core": [
|
|
318
|
-
|
|
318
|
+
3358,
|
|
319
319
|
23
|
|
320
320
|
],
|
|
321
321
|
"load": [
|
|
322
|
-
|
|
322
|
+
9061,
|
|
323
323
|
55
|
|
324
324
|
],
|
|
325
325
|
"core_dep": [
|
|
@@ -332,6 +332,6 @@
|
|
|
332
332
|
],
|
|
333
333
|
"core_score": 9.13,
|
|
334
334
|
"load_score": 8.23,
|
|
335
|
-
"version": "2.9.
|
|
335
|
+
"version": "2.9.8-0"
|
|
336
336
|
}
|
|
337
337
|
}
|
micrOS/source/Espnow.py
CHANGED
|
@@ -1,112 +1,146 @@
|
|
|
1
|
-
import uasyncio as asyncio
|
|
2
1
|
from aioespnow import AIOESPNow
|
|
3
2
|
from binascii import hexlify
|
|
4
|
-
from Tasks import NativeTask, TaskBase
|
|
3
|
+
from Tasks import NativeTask, TaskBase, lm_exec, lm_is_loaded
|
|
5
4
|
from Network import get_mac
|
|
6
5
|
from Config import cfgget
|
|
6
|
+
from Debug import errlog_add
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# Configuration values and globals
|
|
9
9
|
_INSTANCE = None
|
|
10
|
-
_DEVFID = cfgget('devfid')
|
|
11
|
-
|
|
10
|
+
_DEVFID = cfgget('devfid') # for example, "node01"
|
|
12
11
|
|
|
13
12
|
async def asend(now, mac, msg):
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
"""
|
|
14
|
+
Send a message over ESPNow. The sent message will be extended with the server prompt.
|
|
15
|
+
The prompt indicates the end-of-message with a '$' marker.
|
|
16
|
+
"""
|
|
17
|
+
prompt = f"{_DEVFID}$" # '$' symbol is the ACK (end of message)!
|
|
18
|
+
# Append a newline and the server prompt to the message.
|
|
19
|
+
full_msg = f"{msg}\n{prompt}".encode("utf-8")
|
|
20
|
+
return await now.asend(mac, full_msg)
|
|
18
21
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
my_task.out = f"MSG-IN: {msg_in}"
|
|
23
|
-
data = msg_in.split("\n")
|
|
24
|
-
prompt, command = data[0], data[1]
|
|
25
|
-
msg_out = f"RUN CMD: {command} ON {prompt.replace('$', '')}"
|
|
26
|
-
# TODO: execute command
|
|
27
|
-
return True, msg_out
|
|
28
|
-
return False, ""
|
|
22
|
+
def _serv_execute(msg, my_task):
|
|
23
|
+
"""
|
|
24
|
+
Process an incoming command and return a tuple (ready, response).
|
|
29
25
|
|
|
26
|
+
The function decodes the message, strips any trailing '$' (which marks the prompt),
|
|
27
|
+
and then interprets the message as a command. The command is split into tokens where
|
|
28
|
+
the first token is considered the module/command. If the module is allowed (lm_is_loaded),
|
|
29
|
+
the command is executed with lm_exec; otherwise, "NotAllowed" is returned.
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
command_line = msg.decode('utf-8').strip()
|
|
33
|
+
except UnicodeError:
|
|
34
|
+
my_task.out = "[NOW SERVE] Invalid encoding"
|
|
35
|
+
return False, "Invalid encoding"
|
|
36
|
+
|
|
37
|
+
# Split the command into tokens.
|
|
38
|
+
tokens = command_line.split()
|
|
39
|
+
if not tokens:
|
|
40
|
+
return False, "[NOW SERVE] Empty command"
|
|
41
|
+
# Remove trailing prompt marker if present.
|
|
42
|
+
client_token = "?$"
|
|
43
|
+
if tokens[-1].endswith("$"):
|
|
44
|
+
client_token = tokens[-1]
|
|
45
|
+
tokens = tokens[:-1]
|
|
46
|
+
my_task.out = f"[NOW SERVE] {' '.join(tokens)} (from {client_token})"
|
|
47
|
+
# Check if the module/command is allowed.
|
|
48
|
+
module = tokens[0]
|
|
49
|
+
if lm_is_loaded(module):
|
|
50
|
+
try:
|
|
51
|
+
state, out = lm_exec(tokens)
|
|
52
|
+
except Exception as e:
|
|
53
|
+
# Optionally log the exception here.
|
|
54
|
+
state, out = False, f"[ERR][NOW SERVE] {tokens}: {e}"
|
|
55
|
+
else:
|
|
56
|
+
state, out = False, f"[WARN][NOW SERVE] NotAllowed {tokens[0]}"
|
|
57
|
+
return state, out
|
|
30
58
|
|
|
31
|
-
# Echo any received messages back to the sender
|
|
32
59
|
async def _server(now):
|
|
60
|
+
"""
|
|
61
|
+
ESPNow server task that continuously waits for incoming messages and processes commands.
|
|
62
|
+
"""
|
|
33
63
|
with TaskBase.TASKS.get('espnow.server', None) as my_task:
|
|
34
64
|
async for mac, msg in now:
|
|
35
65
|
try:
|
|
36
|
-
|
|
37
|
-
if
|
|
38
|
-
await asend(now, mac,
|
|
66
|
+
state, response = _serv_execute(msg, my_task)
|
|
67
|
+
if state:
|
|
68
|
+
await asend(now, mac, response)
|
|
69
|
+
else:
|
|
70
|
+
errlog_add(response)
|
|
39
71
|
except OSError as err:
|
|
72
|
+
# If the peer is not yet added, add it and retry.
|
|
40
73
|
if len(err.args) > 1 and err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND':
|
|
41
74
|
now.add_peer(mac)
|
|
42
|
-
|
|
43
|
-
if
|
|
44
|
-
await asend(now, mac,
|
|
75
|
+
state, response = _serv_execute(msg, my_task)
|
|
76
|
+
if state:
|
|
77
|
+
await asend(now, mac, response)
|
|
78
|
+
else:
|
|
79
|
+
errlog_add(response)
|
|
80
|
+
else:
|
|
81
|
+
# Optionally handle or log other OSErrors here.
|
|
82
|
+
errlog_add(f"[ERR][NOW SERVER] {err}")
|
|
45
83
|
|
|
46
|
-
|
|
47
|
-
# Send a periodic ping to a peer
|
|
48
84
|
async def _send(now, peer, tag, msg):
|
|
49
|
-
|
|
85
|
+
"""
|
|
86
|
+
ESPNow client task: send a command to a peer and update task status.
|
|
87
|
+
"""
|
|
88
|
+
with TaskBase.TASKS.get(tag, None) as my_task:
|
|
50
89
|
if not await asend(now, peer, msg):
|
|
51
|
-
my_task.out = "Peer not responding"
|
|
90
|
+
my_task.out = "[NOW SEND] Peer not responding"
|
|
52
91
|
else:
|
|
53
|
-
my_task.out = f"
|
|
54
|
-
|
|
92
|
+
my_task.out = f"[NOW SEND] {msg}"
|
|
55
93
|
|
|
56
94
|
###################################################
|
|
57
95
|
# Control functions #
|
|
58
96
|
###################################################
|
|
59
97
|
def initialize():
|
|
60
98
|
"""
|
|
61
|
-
Initialize ESPNow protocol
|
|
99
|
+
Initialize the ESPNow protocol. (WLAN must be active.)
|
|
62
100
|
"""
|
|
63
|
-
# Network module: WLAN interface must be active to send()/recv()
|
|
64
101
|
global _INSTANCE
|
|
65
102
|
if _INSTANCE is None:
|
|
66
|
-
now = AIOESPNow() #
|
|
103
|
+
now = AIOESPNow() # Instance with async support
|
|
67
104
|
now.active(True)
|
|
68
105
|
_INSTANCE = now
|
|
69
106
|
return _INSTANCE
|
|
70
107
|
|
|
71
|
-
|
|
72
108
|
def add_peer(now, peer):
|
|
73
109
|
"""
|
|
74
|
-
Add peer
|
|
75
|
-
:param now:
|
|
76
|
-
:param peer:
|
|
110
|
+
Add a peer given its MAC address.
|
|
111
|
+
:param now: ESPNow instance.
|
|
112
|
+
:param peer: Binary MAC address of a peer (e.g. b'\xbb\xbb\xbb\xbb\xbb\xbb').
|
|
77
113
|
"""
|
|
78
|
-
|
|
79
|
-
|
|
114
|
+
now.add_peer(peer)
|
|
115
|
+
return "Peer register done"
|
|
80
116
|
|
|
81
117
|
def espnow_server():
|
|
82
118
|
"""
|
|
83
|
-
Start async ESPNow receiver server
|
|
119
|
+
Start the async ESPNow receiver server.
|
|
84
120
|
"""
|
|
85
121
|
now = initialize()
|
|
86
|
-
#
|
|
122
|
+
# Create an asynchronous task with tag 'espnow.server'
|
|
87
123
|
state = NativeTask().create(callback=_server(now), tag='espnow.server')
|
|
88
124
|
return "Starting" if state else "Already running"
|
|
89
125
|
|
|
90
|
-
|
|
91
126
|
def espnow_send(peer, msg):
|
|
92
127
|
"""
|
|
93
|
-
Send
|
|
94
|
-
:param peer:
|
|
95
|
-
:param msg:
|
|
128
|
+
Send a command over ESPNow.
|
|
129
|
+
:param peer: Binary MAC address of another device.
|
|
130
|
+
:param msg: String command message to send.
|
|
96
131
|
"""
|
|
97
132
|
now = initialize()
|
|
98
|
-
|
|
99
|
-
task_id = f"espnow.cli.{
|
|
100
|
-
#
|
|
133
|
+
mac_str = hexlify(peer, ':').decode()
|
|
134
|
+
task_id = f"espnow.cli.{mac_str}"
|
|
135
|
+
# Create an asynchronous sending task.
|
|
101
136
|
state = NativeTask().create(callback=_send(now, peer, task_id, msg), tag=task_id)
|
|
102
137
|
return "Starting" if state else "Already running"
|
|
103
138
|
|
|
104
|
-
|
|
105
139
|
def stats():
|
|
106
140
|
"""
|
|
107
|
-
Return stats for ESPNow peers
|
|
108
|
-
stats: tx_pkts, tx_responses, tx_failures, rx_packets, rx_dropped_packets
|
|
109
|
-
peers: peer, rssi, time_ms
|
|
141
|
+
Return stats for ESPNow peers.
|
|
142
|
+
stats: tx_pkts, tx_responses, tx_failures, rx_packets, rx_dropped_packets.
|
|
143
|
+
peers: peer, rssi, time_ms.
|
|
110
144
|
"""
|
|
111
145
|
now = initialize()
|
|
112
146
|
try:
|
|
@@ -119,9 +153,8 @@ def stats():
|
|
|
119
153
|
_peers = str(e)
|
|
120
154
|
return {"stats": _stats, "peers": _peers}
|
|
121
155
|
|
|
122
|
-
|
|
123
156
|
def mac_address():
|
|
124
157
|
"""
|
|
125
|
-
Get binary
|
|
158
|
+
Get the binary MAC address.
|
|
126
159
|
"""
|
|
127
160
|
return get_mac()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from machine import Pin, PWM
|
|
2
|
-
from microIO import
|
|
2
|
+
from microIO import bind_pin, pinmap_search
|
|
3
3
|
|
|
4
4
|
#########################################
|
|
5
5
|
# ANALOG DIMMER CONTROLLER PARAMS #
|
|
@@ -15,9 +15,9 @@ __L298N_OBJS = []
|
|
|
15
15
|
def __l298n_init():
|
|
16
16
|
global __L298N_OBJS
|
|
17
17
|
if len(__L298N_OBJS) == 0:
|
|
18
|
-
__L298N_OBJS.append(PWM(Pin(
|
|
19
|
-
__L298N_OBJS.append(Pin(
|
|
20
|
-
__L298N_OBJS.append(Pin(
|
|
18
|
+
__L298N_OBJS.append(PWM(Pin(bind_pin('l298speed')), freq=50))
|
|
19
|
+
__L298N_OBJS.append(Pin(bind_pin('l298dir_1'), Pin.OUT))
|
|
20
|
+
__L298N_OBJS.append(Pin(bind_pin('l298dir_2'), Pin.OUT))
|
|
21
21
|
__L298N_OBJS[0].duty(0) # Set default speed (PWM)
|
|
22
22
|
__L298N_OBJS[1].value(0) # Set default direction for dc motor1
|
|
23
23
|
__L298N_OBJS[2].value(1) # Set default direction for dc motor1
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from microIO import
|
|
1
|
+
from microIO import bind_pin, pinmap_search
|
|
2
2
|
|
|
3
3
|
#########################################
|
|
4
4
|
# ANALOG DIMMER CONTROLLER PARAMS #
|
|
@@ -15,8 +15,8 @@ def __l9110_init():
|
|
|
15
15
|
global __L9110_OBJS
|
|
16
16
|
if len(__L9110_OBJS) == 0:
|
|
17
17
|
from machine import Pin, PWM
|
|
18
|
-
__L9110_OBJS.append(PWM(Pin(
|
|
19
|
-
__L9110_OBJS.append(PWM(Pin(
|
|
18
|
+
__L9110_OBJS.append(PWM(Pin(bind_pin('l9110dir_1')), freq=1024))
|
|
19
|
+
__L9110_OBJS.append(PWM(Pin(bind_pin('l9110dir_2')), freq=1024))
|
|
20
20
|
__L9110_OBJS[0].duty(0) # Set default speed (PWM)
|
|
21
21
|
__L9110_OBJS[1].duty(0) # Set default speed (PWM)
|
|
22
22
|
return __L9110_OBJS
|
micrOS/source/LM_VL53L0X.py
CHANGED
|
@@ -2,7 +2,7 @@ from micropython import const
|
|
|
2
2
|
import ustruct
|
|
3
3
|
import utime
|
|
4
4
|
from machine import I2C, Pin
|
|
5
|
-
from microIO import
|
|
5
|
+
from microIO import bind_pin, pinmap_search
|
|
6
6
|
|
|
7
7
|
__TOF_OBJ = None
|
|
8
8
|
|
|
@@ -31,7 +31,7 @@ class TimeoutError(RuntimeError):
|
|
|
31
31
|
|
|
32
32
|
class VL53L0X:
|
|
33
33
|
def __init__(self, address=57):
|
|
34
|
-
self.i2c = I2C(-1, Pin(
|
|
34
|
+
self.i2c = I2C(-1, Pin(bind_pin('i2c_scl')), Pin(bind_pin('i2c_sda')), freq=9600)
|
|
35
35
|
self.address = address
|
|
36
36
|
self.init()
|
|
37
37
|
self._started = False
|
micrOS/source/LM_aht10.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from machine import I2C, Pin
|
|
2
|
-
from microIO import
|
|
2
|
+
from microIO import bind_pin, pinmap_search
|
|
3
3
|
from Common import syslog
|
|
4
4
|
from time import sleep
|
|
5
5
|
from binascii import hexlify
|
|
@@ -24,7 +24,7 @@ def _handle_connection_error(f):
|
|
|
24
24
|
|
|
25
25
|
class AHT10:
|
|
26
26
|
def __init__(self, address = 0x38):
|
|
27
|
-
self.i2c = I2C(-1, Pin(
|
|
27
|
+
self.i2c = I2C(-1, Pin(bind_pin('i2c_scl')), Pin(bind_pin('i2c_sda')), freq = 9600)
|
|
28
28
|
self.address = address
|
|
29
29
|
if not self.init_sensor():
|
|
30
30
|
raise Exception("Could not initialize the sensor!")
|
micrOS/source/LM_bme280.py
CHANGED
|
@@ -6,7 +6,7 @@ https://randomnerdtutorials.com/micropython-bme280-esp32-esp8266/
|
|
|
6
6
|
|
|
7
7
|
import utime as time
|
|
8
8
|
from machine import Pin, I2C
|
|
9
|
-
from microIO import
|
|
9
|
+
from microIO import bind_pin, pinmap_search
|
|
10
10
|
from Common import notify
|
|
11
11
|
from Types import resolve
|
|
12
12
|
|
|
@@ -299,7 +299,7 @@ class BME280:
|
|
|
299
299
|
def __init_bme280_i2c():
|
|
300
300
|
global BME280_OBJ
|
|
301
301
|
if BME280_OBJ is None:
|
|
302
|
-
i2c = I2C(scl=Pin(
|
|
302
|
+
i2c = I2C(scl=Pin(bind_pin('i2c_scl')), sda=Pin(bind_pin('i2c_sda')), freq=10000)
|
|
303
303
|
BME280_OBJ = BME280(i2c=i2c)
|
|
304
304
|
return BME280_OBJ
|
|
305
305
|
|
micrOS/source/LM_buzzer.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from sys import platform
|
|
2
2
|
from utime import sleep
|
|
3
|
-
from microIO import
|
|
3
|
+
from microIO import bind_pin, pinmap_search
|
|
4
4
|
from Common import micro_task, notify
|
|
5
5
|
from Types import resolve
|
|
6
6
|
|
|
@@ -175,15 +175,15 @@ def _builtin_tones(tone=None):
|
|
|
175
175
|
#########################################
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
def __buzzer_init():
|
|
178
|
+
def __buzzer_init(pin=None):
|
|
179
|
+
"""
|
|
180
|
+
:param pin: optional number to overwrite default pin
|
|
181
|
+
"""
|
|
179
182
|
global __BUZZER_OBJ
|
|
180
183
|
if __BUZZER_OBJ is None:
|
|
181
184
|
from machine import Pin, PWM
|
|
182
|
-
dimmer_pin = Pin(
|
|
183
|
-
|
|
184
|
-
__BUZZER_OBJ = PWM(dimmer_pin, freq=600)
|
|
185
|
-
else:
|
|
186
|
-
__BUZZER_OBJ = PWM(dimmer_pin, freq=600)
|
|
185
|
+
dimmer_pin = Pin(bind_pin('buzzer', number=pin))
|
|
186
|
+
__BUZZER_OBJ = PWM(dimmer_pin, freq=600)
|
|
187
187
|
__BUZZER_OBJ.duty(512) # 50%
|
|
188
188
|
return __BUZZER_OBJ
|
|
189
189
|
|
|
@@ -283,23 +283,20 @@ def list_tones():
|
|
|
283
283
|
return '\n'.join(list(_builtin_tones()))
|
|
284
284
|
|
|
285
285
|
|
|
286
|
-
def load(
|
|
286
|
+
def load(check_notify=False, pin=None, cache=True):
|
|
287
287
|
"""
|
|
288
288
|
Initialize buzzer module
|
|
289
|
-
:param cache bool: file state machine cache: True/False/None(default: automatic True)
|
|
290
|
-
- Load .pds (state machine cache) for this load module
|
|
291
|
-
- Apply loaded states to gpio pins (boot function)
|
|
292
289
|
:param check_notify: check notify enabled/disabled - make noise if enabled only
|
|
290
|
+
:param pin: optional number to overwrite default pin
|
|
291
|
+
:param cache: default True, store stages on disk (.pds)
|
|
293
292
|
:return str: Verdict
|
|
294
293
|
"""
|
|
295
294
|
from sys import platform
|
|
296
295
|
global __PERSISTENT_CACHE, CHECK_NOTIFY
|
|
297
|
-
|
|
298
|
-
__PERSISTENT_CACHE = False if platform == 'esp8266' else True
|
|
299
|
-
else:
|
|
300
|
-
__PERSISTENT_CACHE = cache
|
|
296
|
+
__PERSISTENT_CACHE = cache
|
|
301
297
|
__persistent_cache_manager('r')
|
|
302
298
|
CHECK_NOTIFY = check_notify
|
|
299
|
+
__buzzer_init(pin=pin)
|
|
303
300
|
return f"CACHE: {__PERSISTENT_CACHE}, check notify: {CHECK_NOTIFY}"
|
|
304
301
|
|
|
305
302
|
|
micrOS/source/LM_cct.py
CHANGED
|
@@ -5,7 +5,7 @@ from machine import Pin, PWM
|
|
|
5
5
|
from sys import platform
|
|
6
6
|
from utime import sleep_ms
|
|
7
7
|
from Common import transition_gen, micro_task
|
|
8
|
-
from microIO import
|
|
8
|
+
from microIO import bind_pin, pinmap_search
|
|
9
9
|
from random import randint
|
|
10
10
|
from Types import resolve
|
|
11
11
|
|
|
@@ -24,10 +24,10 @@ class Data:
|
|
|
24
24
|
# ANALOG CCT WITH 2 channel PWM #
|
|
25
25
|
#########################################
|
|
26
26
|
|
|
27
|
-
def __cwww_init():
|
|
27
|
+
def __cwww_init(pin_warm=None, pin_cold=None):
|
|
28
28
|
if Data.CWWW_OBJS[0] is None or Data.CWWW_OBJS[1] is None:
|
|
29
|
-
cw = Pin(
|
|
30
|
-
ww = Pin(
|
|
29
|
+
cw = Pin(bind_pin('cwhite', pin_cold))
|
|
30
|
+
ww = Pin(bind_pin('wwhite', pin_warm))
|
|
31
31
|
if platform == 'esp8266':
|
|
32
32
|
Data.CWWW_OBJS = (PWM(cw, freq=1024),
|
|
33
33
|
PWM(ww, freq=1024))
|
|
@@ -72,19 +72,16 @@ def __state_machine(c, w):
|
|
|
72
72
|
# Application functions #
|
|
73
73
|
#########################
|
|
74
74
|
|
|
75
|
-
def load(cache=
|
|
75
|
+
def load(pin_warm=None, pin_cold=None, cache=True):
|
|
76
76
|
"""
|
|
77
77
|
Initialize Cold white / Warm white LED module
|
|
78
|
-
:param
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
:param pin_warm: optional number to overwrite default pin
|
|
79
|
+
:param pin_cold: optional number to overwrite default pin
|
|
80
|
+
:param cache: save/load state machine to disk (.pds)
|
|
81
81
|
:return str: Cache state
|
|
82
82
|
"""
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Data.PERSISTENT_CACHE = False if platform == 'esp8266' else True
|
|
86
|
-
else:
|
|
87
|
-
Data.PERSISTENT_CACHE = cache
|
|
83
|
+
__cwww_init(pin_warm, pin_cold)
|
|
84
|
+
Data.PERSISTENT_CACHE = cache
|
|
88
85
|
__persistent_cache_manager('r') # recover data cache
|
|
89
86
|
if Data.CWWW_CACHE[2] == 1:
|
|
90
87
|
Data.CWWW_CACHE[2] = 0 # Force ON at boot
|
micrOS/source/LM_co2.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from math import pow
|
|
2
2
|
from sys import platform
|
|
3
3
|
from machine import ADC, Pin
|
|
4
|
-
from microIO import
|
|
4
|
+
from microIO import bind_pin, pinmap_search
|
|
5
5
|
from Types import resolve
|
|
6
6
|
|
|
7
7
|
#########################################
|
|
@@ -20,10 +20,10 @@ def __get_resistance():
|
|
|
20
20
|
global __ADC, __ADC_PROP
|
|
21
21
|
if __ADC is None:
|
|
22
22
|
if 'esp8266' in platform:
|
|
23
|
-
__ADC = ADC(
|
|
23
|
+
__ADC = ADC(bind_pin('co2')) # 1V measure range
|
|
24
24
|
__ADC_PROP = (1023, 1.0)
|
|
25
25
|
else:
|
|
26
|
-
__ADC = ADC(Pin(
|
|
26
|
+
__ADC = ADC(Pin(bind_pin('co2')))
|
|
27
27
|
__ADC.atten(ADC.ATTN_11DB) # 3.6V measure range
|
|
28
28
|
__ADC.width(ADC.WIDTH_10BIT) # Default 10 bit ADC
|
|
29
29
|
__ADC_PROP = (1023, 3.6)
|
micrOS/source/LM_dht11.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from microIO import
|
|
1
|
+
from microIO import bind_pin, pinmap_search
|
|
2
2
|
from Common import data_logger
|
|
3
3
|
from Types import resolve
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ def __init_DHT11():
|
|
|
14
14
|
if __DHT_OBJ is None:
|
|
15
15
|
from dht import DHT11
|
|
16
16
|
from machine import Pin
|
|
17
|
-
__DHT_OBJ = DHT11(Pin(
|
|
17
|
+
__DHT_OBJ = DHT11(Pin(bind_pin('dhtpin')))
|
|
18
18
|
return __DHT_OBJ
|
|
19
19
|
|
|
20
20
|
|
micrOS/source/LM_dht22.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from microIO import
|
|
1
|
+
from microIO import bind_pin, pinmap_search
|
|
2
2
|
from Common import data_logger
|
|
3
3
|
from Types import resolve
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ def __init_DHT22():
|
|
|
14
14
|
if __DHT_OBJ is None:
|
|
15
15
|
from dht import DHT22
|
|
16
16
|
from machine import Pin
|
|
17
|
-
__DHT_OBJ = DHT22(Pin(
|
|
17
|
+
__DHT_OBJ = DHT22(Pin(bind_pin('dhtpin')))
|
|
18
18
|
return __DHT_OBJ
|
|
19
19
|
|
|
20
20
|
|
micrOS/source/LM_dimmer.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from sys import platform
|
|
2
|
-
from microIO import
|
|
2
|
+
from microIO import bind_pin, pinmap_search
|
|
3
3
|
from Common import transition_gen, micro_task
|
|
4
4
|
from utime import sleep_ms
|
|
5
5
|
from Types import resolve
|
|
@@ -24,7 +24,7 @@ class Data:
|
|
|
24
24
|
def __dimmer_init():
|
|
25
25
|
if Data.DIMMER_OBJ is None:
|
|
26
26
|
from machine import Pin, PWM
|
|
27
|
-
dimmer_pin = Pin(
|
|
27
|
+
dimmer_pin = Pin(bind_pin('dim_1'))
|
|
28
28
|
if platform == 'esp8266':
|
|
29
29
|
Data.DIMMER_OBJ = PWM(dimmer_pin, freq=1024)
|
|
30
30
|
else:
|
micrOS/source/LM_distance.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from machine import Pin, time_pulse_us
|
|
2
2
|
from utime import sleep_us
|
|
3
|
-
from microIO import
|
|
3
|
+
from microIO import bind_pin, pinmap_search
|
|
4
4
|
from Common import micro_task
|
|
5
5
|
from Types import resolve
|
|
6
6
|
|
|
@@ -14,8 +14,8 @@ def __init_HCSR04():
|
|
|
14
14
|
"""
|
|
15
15
|
global __TRIGGER_OBJ, __ECHO_OBJ
|
|
16
16
|
if __TRIGGER_OBJ is None or __ECHO_OBJ is None:
|
|
17
|
-
trigger_pin =
|
|
18
|
-
echo_pin =
|
|
17
|
+
trigger_pin = bind_pin('hcsrtrig')
|
|
18
|
+
echo_pin = bind_pin('hcsrecho')
|
|
19
19
|
# Init trigger pin (out)
|
|
20
20
|
__TRIGGER_OBJ = Pin(trigger_pin, mode=Pin.OUT, pull=None)
|
|
21
21
|
__TRIGGER_OBJ.value(0)
|
micrOS/source/LM_ds18.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import machine, onewire, ds18x20, time
|
|
2
|
-
from microIO import
|
|
2
|
+
from microIO import bind_pin, pinmap_search
|
|
3
3
|
from Types import resolve
|
|
4
4
|
|
|
5
5
|
DS_OBJ = None
|
|
@@ -8,7 +8,7 @@ DS_OBJ = None
|
|
|
8
8
|
def __init_DS18():
|
|
9
9
|
global DS_OBJ
|
|
10
10
|
if DS_OBJ is None:
|
|
11
|
-
ds_pin = machine.Pin(
|
|
11
|
+
ds_pin = machine.Pin(bind_pin('ds18'))
|
|
12
12
|
DS_OBJ = ds18x20.DS18X20(onewire.OneWire(ds_pin))
|
|
13
13
|
return DS_OBJ
|
|
14
14
|
|