micrOSDevToolKit 2.10.5__py3-none-any.whl → 2.11.0__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.
- env/driver_cp210x/macOS_VCP_Driver/SiLabsUSBDriverDisk.dmg +0 -0
- env/driver_cp210x/macOS_VCP_Driver/macOS_VCP_Driver_Release_Notes.txt +17 -1
- micrOS/micropython/esp32c6-GENERIC-20250415-v1.25.0.bin +0 -0
- micrOS/micropython/esp32s3-4MBflash-20241129-v1.24.1.bin +0 -0
- micrOS/release_info/micrOS_ReleaseInfo/system_analysis_sum.json +47 -51
- micrOS/source/Common.py +262 -87
- micrOS/source/Debug.py +44 -88
- micrOS/source/Espnow.py +1 -1
- micrOS/source/Files.py +21 -2
- micrOS/source/Hooks.py +60 -17
- micrOS/source/IO_esp32c6.py +16 -0
- micrOS/source/IO_esp32s3.py +37 -1
- micrOS/source/IO_m5stamp.py +35 -1
- micrOS/source/IO_qtpy.py +22 -17
- micrOS/source/IO_s3matrix.py +21 -0
- micrOS/source/IO_tinypico.py +38 -0
- micrOS/source/LM_VL53L0X.py +1 -1
- micrOS/source/LM_buzzer.py +6 -7
- micrOS/source/LM_cct.py +6 -5
- micrOS/source/LM_dimmer.py +6 -5
- micrOS/source/LM_espnow.py +15 -10
- micrOS/source/LM_i2c.py +3 -2
- micrOS/source/LM_neoeffects.py +173 -230
- micrOS/source/LM_neomatrix.py +305 -0
- micrOS/source/LM_neopixel.py +10 -10
- micrOS/source/LM_oled_ui.py +18 -5
- micrOS/source/LM_pacman.py +25 -21
- micrOS/source/LM_qmi8658.py +204 -0
- micrOS/source/LM_rest.py +3 -3
- micrOS/source/LM_rgb.py +6 -6
- micrOS/source/LM_roboarm.py +5 -4
- micrOS/source/LM_switch.py +6 -4
- micrOS/source/LM_tcs3472.py +75 -0
- micrOS/source/LM_telegram.py +5 -4
- micrOS/source/Logger.py +46 -32
- micrOS/source/Shell.py +11 -10
- micrOS/source/Tasks.py +7 -4
- micrOS/source/Time.py +5 -3
- micrOS/source/__pycache__/Common.cpython-312.pyc +0 -0
- micrOS/source/__pycache__/Logger.cpython-312.pyc +0 -0
- micrOS/source/micrOS.py +5 -2
- micrOS/source/microIO.py +8 -6
- {microsdevtoolkit-2.10.5.dist-info → microsdevtoolkit-2.11.0.dist-info}/METADATA +2 -1
- {microsdevtoolkit-2.10.5.dist-info → microsdevtoolkit-2.11.0.dist-info}/RECORD +101 -96
- toolkit/DevEnvUSB.py +5 -0
- toolkit/Gateway.py +3 -3
- toolkit/LM_to_compile.dat +1 -0
- toolkit/dashboard_apps/NeoEffectsDemo.py +8 -15
- toolkit/dashboard_apps/QMI8685_GYRO.py +68 -0
- toolkit/dashboard_apps/_app_base.py +2 -2
- toolkit/dashboard_apps/_gyro_visualizer.py +78 -0
- toolkit/simulator_lib/__pycache__/IO_darwin.cpython-312.pyc +0 -0
- toolkit/simulator_lib/__pycache__/machine.cpython-312.pyc +0 -0
- toolkit/simulator_lib/__pycache__/neopixel.cpython-312.pyc +0 -0
- toolkit/simulator_lib/__pycache__/sim_console.cpython-312.pyc +0 -0
- toolkit/simulator_lib/machine.py +0 -1
- toolkit/simulator_lib/neopixel.py +3 -2
- toolkit/socketClient.py +3 -2
- toolkit/user_data/webhooks/generic.py +1 -1
- toolkit/user_data/webhooks/macro.py +1 -1
- toolkit/user_data/webhooks/template.py +1 -1
- toolkit/workspace/precompiled/Common.mpy +0 -0
- toolkit/workspace/precompiled/Debug.mpy +0 -0
- toolkit/workspace/precompiled/Espnow.mpy +0 -0
- toolkit/workspace/precompiled/Files.mpy +0 -0
- toolkit/workspace/precompiled/Hooks.mpy +0 -0
- toolkit/workspace/precompiled/IO_esp32c6.mpy +0 -0
- toolkit/workspace/precompiled/IO_esp32s3.mpy +0 -0
- toolkit/workspace/precompiled/IO_m5stamp.mpy +0 -0
- toolkit/workspace/precompiled/IO_qtpy.mpy +0 -0
- toolkit/workspace/precompiled/IO_s3matrix.mpy +0 -0
- toolkit/workspace/precompiled/IO_tinypico.mpy +0 -0
- toolkit/workspace/precompiled/LM_VL53L0X.py +1 -1
- toolkit/workspace/precompiled/LM_buzzer.mpy +0 -0
- toolkit/workspace/precompiled/LM_cct.mpy +0 -0
- toolkit/workspace/precompiled/LM_dimmer.mpy +0 -0
- toolkit/workspace/precompiled/LM_espnow.py +15 -10
- toolkit/workspace/precompiled/LM_i2c.py +3 -2
- toolkit/workspace/precompiled/LM_neoeffects.mpy +0 -0
- toolkit/workspace/precompiled/LM_neomatrix.mpy +0 -0
- toolkit/workspace/precompiled/LM_neopixel.mpy +0 -0
- toolkit/workspace/precompiled/LM_oled_ui.mpy +0 -0
- toolkit/workspace/precompiled/LM_pacman.mpy +0 -0
- toolkit/workspace/precompiled/LM_qmi8658.py +204 -0
- toolkit/workspace/precompiled/LM_rest.mpy +0 -0
- toolkit/workspace/precompiled/LM_rgb.mpy +0 -0
- toolkit/workspace/precompiled/LM_roboarm.mpy +0 -0
- toolkit/workspace/precompiled/LM_switch.mpy +0 -0
- toolkit/workspace/precompiled/LM_tcs3472.py +75 -0
- toolkit/workspace/precompiled/LM_telegram.mpy +0 -0
- toolkit/workspace/precompiled/Logger.mpy +0 -0
- toolkit/workspace/precompiled/Shell.mpy +0 -0
- toolkit/workspace/precompiled/Tasks.mpy +0 -0
- toolkit/workspace/precompiled/Time.mpy +0 -0
- toolkit/workspace/precompiled/micrOS.mpy +0 -0
- toolkit/workspace/precompiled/microIO.mpy +0 -0
- micrOS/micropython/esp32s3-20240105-v1.22.1.bin +0 -0
- micrOS/source/LM_catgame.py +0 -75
- micrOS/source/LM_demo.py +0 -97
- micrOS/source/LM_intercon.py +0 -60
- micrOS/source/LM_ph_sensor.py +0 -51
- toolkit/workspace/precompiled/LM_catgame.py +0 -75
- toolkit/workspace/precompiled/LM_demo.py +0 -97
- toolkit/workspace/precompiled/LM_intercon.mpy +0 -0
- toolkit/workspace/precompiled/LM_ph_sensor.py +0 -51
- /micrOS/micropython/{esp32s3-20241129-v1.24.1.bin → esp32s3-8MBflash-20241129-v1.24.1.bin} +0 -0
- {microsdevtoolkit-2.10.5.data → microsdevtoolkit-2.11.0.data}/scripts/devToolKit.py +0 -0
- {microsdevtoolkit-2.10.5.dist-info → microsdevtoolkit-2.11.0.dist-info}/WHEEL +0 -0
- {microsdevtoolkit-2.10.5.dist-info → microsdevtoolkit-2.11.0.dist-info}/licenses/LICENSE +0 -0
- {microsdevtoolkit-2.10.5.dist-info → microsdevtoolkit-2.11.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
from neopixel import NeoPixel
|
|
2
|
+
from machine import Pin
|
|
3
|
+
from utime import sleep_ms
|
|
4
|
+
|
|
5
|
+
from microIO import bind_pin
|
|
6
|
+
from Types import resolve
|
|
7
|
+
from Common import manage_task, AnimationPlayer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NeoPixelMatrix(AnimationPlayer):
|
|
11
|
+
INSTANCE = None
|
|
12
|
+
DEFAULT_COLOR = (100, 23, 0) # Default color for the matrix
|
|
13
|
+
|
|
14
|
+
def __init__(self, width: int = 8, height: int = 8, pin: int = 0):
|
|
15
|
+
super().__init__(tag="neomatrix")
|
|
16
|
+
self.width = width
|
|
17
|
+
self.height = height
|
|
18
|
+
self.num_pixels = width * height
|
|
19
|
+
self.pixels = NeoPixel(Pin(pin, Pin.OUT), self.num_pixels)
|
|
20
|
+
self._color_buffer = [(0, 0, 0)] * self.num_pixels # Store original RGB values
|
|
21
|
+
self._brightness = 0.25 # Brightness level, default 25%
|
|
22
|
+
NeoPixelMatrix.INSTANCE = self
|
|
23
|
+
|
|
24
|
+
def update(self, x:int, y:int, color:tuple[int, int, int]):
|
|
25
|
+
# Animation player will call this method to update pixels.
|
|
26
|
+
self.set_pixel(x, y, color)
|
|
27
|
+
|
|
28
|
+
def draw(self):
|
|
29
|
+
# Animation player will call this method to update the display.
|
|
30
|
+
self.pixels.write()
|
|
31
|
+
|
|
32
|
+
def clear(self):
|
|
33
|
+
# Animation player will call this method to clear the display.
|
|
34
|
+
for i in range(self.num_pixels):
|
|
35
|
+
# Write pixel buffer before write to ws2812
|
|
36
|
+
self.pixels[i] = (0, 0, 0)
|
|
37
|
+
# Send buffer to device
|
|
38
|
+
self.draw()
|
|
39
|
+
|
|
40
|
+
def _coord_to_index(self, x: int, y: int, zigzag:bool=True):
|
|
41
|
+
"""
|
|
42
|
+
Zigzag layout: even rows left-to-right, odd rows right-to-left
|
|
43
|
+
"""
|
|
44
|
+
if (zigzag is None or zigzag) and y % 2 == 0:
|
|
45
|
+
return y * self.width + x
|
|
46
|
+
return y * self.width + (self.width - 1 - x)
|
|
47
|
+
|
|
48
|
+
def _rgb_to_grb_with_br(self, color: tuple[int, int, int]):
|
|
49
|
+
"""
|
|
50
|
+
Converts RGB to GRB with brightness adjustment.
|
|
51
|
+
"""
|
|
52
|
+
def scale(val):
|
|
53
|
+
return max(0, min(255, int(val * self._brightness)))
|
|
54
|
+
|
|
55
|
+
return scale(color[1]), scale(color[0]), scale(color[2])
|
|
56
|
+
|
|
57
|
+
def set_pixel(self, x: int, y: int, color: tuple[int, int, int], zigzag:bool=True):
|
|
58
|
+
"""
|
|
59
|
+
Set pixel at (x, y) with RGB
|
|
60
|
+
"""
|
|
61
|
+
if 0 <= x < self.width and 0 <= y < self.height:
|
|
62
|
+
index = self._coord_to_index(x, y, zigzag=zigzag)
|
|
63
|
+
self._color_buffer[index] = color # store original RGB for brightness control
|
|
64
|
+
self.pixels[index] = self._rgb_to_grb_with_br(color)
|
|
65
|
+
|
|
66
|
+
def color(self, color: tuple[int, int, int]):
|
|
67
|
+
"""
|
|
68
|
+
Fill color OR Animation color change.
|
|
69
|
+
:param color: tuple[int, int, int] range: 0-255
|
|
70
|
+
:return: str
|
|
71
|
+
"""
|
|
72
|
+
r, g, b = max(0, min(color[0], 255)), max(0, min(color[1], 255)), max(0, min(color[2], 255))
|
|
73
|
+
color = (r, g, b)
|
|
74
|
+
NeoPixelMatrix.DEFAULT_COLOR = color
|
|
75
|
+
if manage_task(self._task_tag, "isbusy"):
|
|
76
|
+
return f"Set animation color to {color}"
|
|
77
|
+
for i in range(self.num_pixels):
|
|
78
|
+
self._color_buffer[i] = color
|
|
79
|
+
# Write pixel buffer before write to ws2812
|
|
80
|
+
self.pixels[i] = self._rgb_to_grb_with_br(color)
|
|
81
|
+
# Send buffer to device
|
|
82
|
+
self.draw()
|
|
83
|
+
return f"Set all pixels to {color}"
|
|
84
|
+
|
|
85
|
+
def brightness(self, br: int):
|
|
86
|
+
"""
|
|
87
|
+
Change the brightness of all pixels.
|
|
88
|
+
"""
|
|
89
|
+
br = max(0, min(br, 100)) # clamp brightness to 0–100%
|
|
90
|
+
self._brightness = br / 100.0
|
|
91
|
+
# Set color matrix brightness
|
|
92
|
+
for i, color in enumerate(self._color_buffer):
|
|
93
|
+
# Write pixel buffer before write to ws2812
|
|
94
|
+
self.pixels[i] = self._rgb_to_grb_with_br(color)
|
|
95
|
+
self.draw()
|
|
96
|
+
return f"Set brightness to {br}%"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def draw_colormap(self, bitmap:list):
|
|
100
|
+
"""
|
|
101
|
+
Draw a bitmap on the Neopixel
|
|
102
|
+
bitmap: [(x, y, (r, g, b)),
|
|
103
|
+
(x, y, (r, g, b)), ...]
|
|
104
|
+
"""
|
|
105
|
+
if len(bitmap) == 0:
|
|
106
|
+
self.clear()
|
|
107
|
+
return
|
|
108
|
+
for bm in bitmap:
|
|
109
|
+
x, y, color = bm
|
|
110
|
+
self.set_pixel(x, y, color, zigzag=False)
|
|
111
|
+
self.draw()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
##########################################################################################################
|
|
115
|
+
##########################################################################################################
|
|
116
|
+
# --- Example usage with micrOS framework ---
|
|
117
|
+
|
|
118
|
+
def load(width=8, height=8):
|
|
119
|
+
"""
|
|
120
|
+
Load NeoPixelMatrix instance. If not already loaded
|
|
121
|
+
"""
|
|
122
|
+
if NeoPixelMatrix.INSTANCE is None:
|
|
123
|
+
NeoPixelMatrix(width=width, height=height, pin=bind_pin('neop'))
|
|
124
|
+
return NeoPixelMatrix.INSTANCE
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def pixel(x, y, color=None, show=True):
|
|
128
|
+
"""
|
|
129
|
+
Set pixel at (x,y) to RGB color.
|
|
130
|
+
"""
|
|
131
|
+
color = NeoPixelMatrix.DEFAULT_COLOR if color is None else color
|
|
132
|
+
matrix = load()
|
|
133
|
+
matrix.set_pixel(x, y, color)
|
|
134
|
+
if show:
|
|
135
|
+
matrix.draw()
|
|
136
|
+
return "Set and draw color"
|
|
137
|
+
return "Set color"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def draw():
|
|
141
|
+
"""
|
|
142
|
+
Draw the current frame manually on the screen.
|
|
143
|
+
"""
|
|
144
|
+
load().draw()
|
|
145
|
+
return "Draw screen"
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def clear():
|
|
149
|
+
"""
|
|
150
|
+
Clear the screen.
|
|
151
|
+
"""
|
|
152
|
+
load().clear()
|
|
153
|
+
return "Clear screen"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def color_fill(r: int, g: int, b: int):
|
|
157
|
+
"""
|
|
158
|
+
Fill the screen with a solid color.
|
|
159
|
+
OR
|
|
160
|
+
Change animation color (when possible)
|
|
161
|
+
"""
|
|
162
|
+
return load().color((r, g, b))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def brightness(br: int):
|
|
166
|
+
"""
|
|
167
|
+
Change the brightness of the display. (0-100)
|
|
168
|
+
"""
|
|
169
|
+
return load().brightness(br)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def control(speed_ms=None, bt_draw:bool=None):
|
|
173
|
+
"""
|
|
174
|
+
Change the speed of frame generation for animations.
|
|
175
|
+
"""
|
|
176
|
+
data = load().control(play_speed_ms=speed_ms, bt_draw=bt_draw)
|
|
177
|
+
_speed_ms = data.get("player_speed", None)
|
|
178
|
+
return f"Control state: {data} (speed: {_speed_ms}ms)"
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def stop():
|
|
182
|
+
"""
|
|
183
|
+
Stop the current animation
|
|
184
|
+
"""
|
|
185
|
+
return load().stop()
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def draw_colormap(bitmap):
|
|
189
|
+
try:
|
|
190
|
+
load().draw_colormap(bitmap)
|
|
191
|
+
except Exception as e:
|
|
192
|
+
return str(e)
|
|
193
|
+
return "Done."
|
|
194
|
+
# -----------------------------------------------------------------------------
|
|
195
|
+
# -----------------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def rainbow(speed_ms=0):
|
|
199
|
+
def effect_rainbow():
|
|
200
|
+
def hsv_to_rgb(h, s, v):
|
|
201
|
+
max_color = 150 #255
|
|
202
|
+
h = float(h)
|
|
203
|
+
s = float(s)
|
|
204
|
+
v = float(v)
|
|
205
|
+
i = int(h * 6.0)
|
|
206
|
+
f = (h * 6.0) - i
|
|
207
|
+
p = v * (1.0 - s)
|
|
208
|
+
q = v * (1.0 - s * f)
|
|
209
|
+
t = v * (1.0 - s * (1.0 - f))
|
|
210
|
+
i = i % 6
|
|
211
|
+
if i == 0:
|
|
212
|
+
r, g, b = v, t, p
|
|
213
|
+
elif i == 1:
|
|
214
|
+
r, g, b = q, v, p
|
|
215
|
+
elif i == 2:
|
|
216
|
+
r, g, b = p, v, t
|
|
217
|
+
elif i == 3:
|
|
218
|
+
r, g, b = p, q, v
|
|
219
|
+
elif i == 4:
|
|
220
|
+
r, g, b = t, p, v
|
|
221
|
+
elif i == 5:
|
|
222
|
+
r, g, b = v, p, q
|
|
223
|
+
return int(r * max_color), int(g * max_color), int(b * max_color)
|
|
224
|
+
|
|
225
|
+
width = 8
|
|
226
|
+
height = 8
|
|
227
|
+
total_frames = 64
|
|
228
|
+
|
|
229
|
+
for frame in range(total_frames):
|
|
230
|
+
for y in range(height):
|
|
231
|
+
for x in range(width):
|
|
232
|
+
index = y * width + x
|
|
233
|
+
hue = ((index + frame) % 64) / 64.0
|
|
234
|
+
r, g, b = hsv_to_rgb(hue, 1.0, 0.7)
|
|
235
|
+
yield x, y, (r, g, b)
|
|
236
|
+
|
|
237
|
+
return load().play(effect_rainbow, speed_ms=speed_ms, bt_draw=True, bt_size=8)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def snake(speed_ms:int=50, length:int=5):
|
|
241
|
+
def effect_snake():
|
|
242
|
+
clear_color = (0, 0, 0)
|
|
243
|
+
total_steps = 8 * 8 + length # run just past the end to clear tail
|
|
244
|
+
|
|
245
|
+
for step in range(total_steps):
|
|
246
|
+
# 1) clear the tail pixel once the snake is longer than `length`
|
|
247
|
+
if step >= length:
|
|
248
|
+
tail_idx = step - length
|
|
249
|
+
tx, ty = tail_idx % 8, tail_idx // 8
|
|
250
|
+
yield tx, ty, clear_color
|
|
251
|
+
|
|
252
|
+
# 2) move the head (only while head index < 64)
|
|
253
|
+
if step < 8 * 8:
|
|
254
|
+
hx, hy = step % 8, step // 8
|
|
255
|
+
yield hx, hy, NeoPixelMatrix.DEFAULT_COLOR
|
|
256
|
+
|
|
257
|
+
return load().play(effect_snake, speed_ms=speed_ms)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def cube(speed_ms=10):
|
|
261
|
+
def effect_cube(max_radius:int = 3):
|
|
262
|
+
"""
|
|
263
|
+
Generator yielding (x, y, color) for a centered 2×2 square ("cube")
|
|
264
|
+
that expands outward to `max_radius` then collapses back.
|
|
265
|
+
"""
|
|
266
|
+
width, height = 8, 8
|
|
267
|
+
# Center the 2×2 core in an 8×8 grid
|
|
268
|
+
cx, cy = width // 2 - 1, height // 2 - 1
|
|
269
|
+
|
|
270
|
+
# Expansion phase: radius 0 (2×2) up to max_radius
|
|
271
|
+
for r in range(0, max_radius + 1):
|
|
272
|
+
for dx in range(-r, r + 2):
|
|
273
|
+
for dy in range(-r, r + 2):
|
|
274
|
+
x, y = cx + dx, cy + dy
|
|
275
|
+
if 0 <= x < width and 0 <= y < height:
|
|
276
|
+
yield x, y, NeoPixelMatrix.DEFAULT_COLOR
|
|
277
|
+
# Clear matrix
|
|
278
|
+
try:
|
|
279
|
+
NeoPixelMatrix.INSTANCE.clear()
|
|
280
|
+
except:
|
|
281
|
+
pass
|
|
282
|
+
# Collapse phase: back down, skipping the largest to avoid duplicate
|
|
283
|
+
for r in range(max_radius - 1, -1, -1):
|
|
284
|
+
for dx in range(-r, r + 2):
|
|
285
|
+
for dy in range(-r, r + 2):
|
|
286
|
+
x, y = cx + dx, cy + dy
|
|
287
|
+
if 0 <= x < width and 0 <= y < height:
|
|
288
|
+
yield x, y, NeoPixelMatrix.DEFAULT_COLOR
|
|
289
|
+
|
|
290
|
+
return load().play(effect_cube, speed_ms=speed_ms)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def help(widgets=False):
|
|
294
|
+
return resolve(('load width=8 height=8',
|
|
295
|
+
'pixel x y color=(10, 3, 0) show=True',
|
|
296
|
+
'BUTTON clear',
|
|
297
|
+
'COLOR color_fill r=<0-255-5> g=<0-255-5> b=<0-255-5>',
|
|
298
|
+
'SLIDER brightness br=<0-60-2>',
|
|
299
|
+
'BUTTON stop',
|
|
300
|
+
'BUTTON snake speed_ms=50 length=5',
|
|
301
|
+
'BUTTON rainbow',
|
|
302
|
+
'BUTTON cube speed_ms=10',
|
|
303
|
+
'SLIDER control speed_ms=<2-200-2> bt_draw=None',
|
|
304
|
+
'draw_colormap bitmap=[(0,0,(10,2,0)),(x,y,color),...]'
|
|
305
|
+
), widgets=widgets)
|
micrOS/source/LM_neopixel.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from neopixel import NeoPixel
|
|
2
2
|
from machine import Pin
|
|
3
|
-
from sys import platform
|
|
4
3
|
from utime import sleep_ms
|
|
5
|
-
from Common import transition_gen, micro_task
|
|
4
|
+
from Common import transition_gen, micro_task, data_dir
|
|
6
5
|
from microIO import bind_pin, pinmap_search
|
|
7
6
|
from random import randint
|
|
8
7
|
from Types import resolve
|
|
@@ -19,6 +18,7 @@ class Data:
|
|
|
19
18
|
PERSISTENT_CACHE = False
|
|
20
19
|
RGB_TASK_TAG = "neopixel._tran"
|
|
21
20
|
TASK_STATE = False
|
|
21
|
+
FILE_CACHE = data_dir('neopixel.cache')
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
#########################################
|
|
@@ -40,7 +40,7 @@ def __init_NEOPIXEL(pin=None, n=24):
|
|
|
40
40
|
|
|
41
41
|
def __persistent_cache_manager(mode):
|
|
42
42
|
"""
|
|
43
|
-
|
|
43
|
+
File cache
|
|
44
44
|
modes:
|
|
45
45
|
r - recover, s - save
|
|
46
46
|
"""
|
|
@@ -48,12 +48,12 @@ def __persistent_cache_manager(mode):
|
|
|
48
48
|
return
|
|
49
49
|
if mode == 's':
|
|
50
50
|
# SAVE CACHE
|
|
51
|
-
with open(
|
|
51
|
+
with open(Data.FILE_CACHE, 'w') as f:
|
|
52
52
|
f.write(','.join([str(k) for k in Data.DCACHE]))
|
|
53
53
|
return
|
|
54
54
|
try:
|
|
55
55
|
# RESTORE CACHE
|
|
56
|
-
with open(
|
|
56
|
+
with open(Data.FILE_CACHE, 'r') as f:
|
|
57
57
|
Data.DCACHE = [float(data) for data in f.read().strip().split(',')]
|
|
58
58
|
except:
|
|
59
59
|
pass
|
|
@@ -77,7 +77,7 @@ def load(ledcnt=24, pin=None, cache=True):
|
|
|
77
77
|
Initiate NeoPixel RGB module
|
|
78
78
|
:param ledcnt: number of led segments
|
|
79
79
|
:param pin: optional number to overwrite default pin
|
|
80
|
-
:param cache: default True, store stages on disk + Load (.
|
|
80
|
+
:param cache: default True, store stages on disk + Load (.cache)
|
|
81
81
|
:return str: Cache state
|
|
82
82
|
"""
|
|
83
83
|
Data.PERSISTENT_CACHE = cache
|
|
@@ -182,13 +182,13 @@ def segment(r=None, g=None, b=None, s=0, cache=False, write=True):
|
|
|
182
182
|
:param g: green value 0-255
|
|
183
183
|
:param b: blue value 0-255
|
|
184
184
|
:param s: segment - index 0-ledcnt
|
|
185
|
-
:param cache: cache color (update .
|
|
185
|
+
:param cache: cache color (update .cache file)
|
|
186
186
|
:param write: send color buffer to neopixel (update LEDs)
|
|
187
187
|
:return dict: rgb status - states: R, G, B, S
|
|
188
188
|
"""
|
|
189
|
-
r = Data.DCACHE[0] if r is None else r
|
|
190
|
-
g = Data.DCACHE[1] if g is None else g
|
|
191
|
-
b = Data.DCACHE[2] if b is None else b
|
|
189
|
+
r = int(Data.DCACHE[0]) if r is None else r
|
|
190
|
+
g = int(Data.DCACHE[1]) if g is None else g
|
|
191
|
+
b = int(Data.DCACHE[2]) if b is None else b
|
|
192
192
|
neo_n = __init_NEOPIXEL().n
|
|
193
193
|
if s <= neo_n:
|
|
194
194
|
Data.NEOPIXEL_OBJ[s] = (r, g, b)
|
micrOS/source/LM_oled_ui.py
CHANGED
|
@@ -15,6 +15,7 @@ try:
|
|
|
15
15
|
except:
|
|
16
16
|
gol_nextgen = None # Optional function handling
|
|
17
17
|
|
|
18
|
+
from utime import ticks_ms, ticks_diff # For IRQ joystick handling
|
|
18
19
|
|
|
19
20
|
#################################
|
|
20
21
|
# PAGE MANAGER CLASS DEFINITION #
|
|
@@ -157,11 +158,23 @@ class PageUI:
|
|
|
157
158
|
# [IRQ] - event type setup
|
|
158
159
|
pin_obj.irq(trigger=Pin.IRQ_FALLING, handler=callback)
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
def _event_handler(control_command, prell_ms=150):
|
|
162
|
+
nonlocal _p_last
|
|
163
|
+
_last = _p_last.get(control_command)
|
|
164
|
+
last = 0 if _last is None else _last
|
|
165
|
+
# Calculate time difference between last trigger action and now tick.
|
|
166
|
+
diff = ticks_diff(ticks_ms(), last)
|
|
167
|
+
if abs(diff) > prell_ms:
|
|
168
|
+
# Save now tick - last trigger action
|
|
169
|
+
_p_last[control_command] = ticks_ms()
|
|
170
|
+
self.control(control_command)
|
|
171
|
+
|
|
172
|
+
_p_last = {}
|
|
173
|
+
_set("js_right", lambda pin: _event_handler('next'))
|
|
174
|
+
_set("js_left", lambda pin: _event_handler('prev'))
|
|
175
|
+
_set("js_up", lambda pin: _event_handler('on'))
|
|
176
|
+
_set("js_down", lambda pin: _event_handler('off'))
|
|
177
|
+
_set("js_press", lambda pin: _event_handler('press'))
|
|
165
178
|
self.irq_ok = True
|
|
166
179
|
|
|
167
180
|
def __power_save(self):
|
micrOS/source/LM_pacman.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from sys import modules
|
|
2
2
|
from Common import socket_stream
|
|
3
3
|
from Files import _is_module, list_fs, ilist_fs, remove_fs
|
|
4
|
+
from Files import OSPath, path_join
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
#############################################
|
|
@@ -42,7 +43,7 @@ def rm(path, allow_dir=False):
|
|
|
42
43
|
def dirtree(path="/", raw=False):
|
|
43
44
|
"""Return only directories from a given path."""
|
|
44
45
|
path = path if path.endswith('/') else f"{path}/"
|
|
45
|
-
folders = [
|
|
46
|
+
folders = [path_join(path, item) for item in ilist_fs(path, type_filter='d')]
|
|
46
47
|
folder_contents = {folder:list_fs(folder) for folder in folders}
|
|
47
48
|
if raw:
|
|
48
49
|
return folder_contents
|
|
@@ -124,39 +125,42 @@ def moduls(unload=None):
|
|
|
124
125
|
|
|
125
126
|
|
|
126
127
|
@socket_stream
|
|
127
|
-
def cachedump(
|
|
128
|
+
def cachedump(delete=None, msgobj=None):
|
|
128
129
|
"""
|
|
129
|
-
Cache system persistent data storage files (.
|
|
130
|
-
:param
|
|
130
|
+
Cache system persistent data storage files (.cache)
|
|
131
|
+
:param delete: cache name to delete
|
|
131
132
|
"""
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
data_dir = OSPath.DATA
|
|
134
|
+
if delete is None:
|
|
135
|
+
# List cache files aka application cache
|
|
134
136
|
msg_buf = []
|
|
135
|
-
for
|
|
136
|
-
|
|
137
|
+
for cache in (c for c in ilist_fs(data_dir, type_filter='f') if c.endswith('.cache')):
|
|
138
|
+
_path = path_join(data_dir, cache)
|
|
139
|
+
with open(_path, 'r') as f:
|
|
137
140
|
if msgobj is None:
|
|
138
|
-
msg_buf.append(f'{
|
|
141
|
+
msg_buf.append(f'{_path}: {f.read()}')
|
|
139
142
|
else:
|
|
140
|
-
msgobj(f'{
|
|
143
|
+
msgobj(f'{_path}: {f.read()}')
|
|
141
144
|
return msg_buf if len(msg_buf) > 0 else ''
|
|
142
|
-
# Remove given
|
|
145
|
+
# Remove given cache file
|
|
143
146
|
try:
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
delete_cache = path_join(data_dir, f"{delete}.cache")
|
|
148
|
+
verdict = remove_fs(delete_cache)
|
|
149
|
+
return f'{delete_cache} delete done.: {verdict}'
|
|
146
150
|
except:
|
|
147
|
-
return f'{
|
|
151
|
+
return f'{delete}.cache not exists'
|
|
148
152
|
|
|
149
153
|
|
|
150
|
-
def
|
|
154
|
+
def datdump():
|
|
151
155
|
"""
|
|
152
156
|
Generic .dat file dump
|
|
153
|
-
- logged data from LMs, sensor
|
|
157
|
+
- logged data from LMs, sensor data, etc...
|
|
154
158
|
"""
|
|
155
|
-
|
|
156
|
-
dats = (f for f in ilist_fs(type_filter='f') if f.endswith('.dat'))
|
|
159
|
+
data_dir = OSPath.DATA
|
|
160
|
+
dats = (f for f in ilist_fs(data_dir, type_filter='f') if f.endswith('.dat'))
|
|
157
161
|
out = {}
|
|
158
162
|
for dat in dats:
|
|
159
|
-
with open(
|
|
163
|
+
with open(path_join(data_dir, dat), 'r') as f:
|
|
160
164
|
out[dat] = f.read()
|
|
161
165
|
return out
|
|
162
166
|
|
|
@@ -220,8 +224,8 @@ def help(widgets=False):
|
|
|
220
224
|
"""
|
|
221
225
|
return ('listmods', 'delmod mod=<module>.py/.mpy or .js/.html/.css', 'del_duplicates',
|
|
222
226
|
'moduls unload="LM_rgb/None"',
|
|
223
|
-
'cachedump
|
|
224
|
-
'
|
|
227
|
+
'cachedump delete=None',
|
|
228
|
+
'datdump',
|
|
225
229
|
'download url="BxNxM/micrOS/master/toolkit/workspace/precompiled/LM_robustness.py"',
|
|
226
230
|
'micros_checksum',
|
|
227
231
|
'ls path="/" content="*/f/d" select="*/LM/IO"',
|