Skip to content

Commit da92a9a

Browse files
committed
update to MH 0.7
1 parent e1eb658 commit da92a9a

File tree

4 files changed

+1332
-13
lines changed

4 files changed

+1332
-13
lines changed

ports/esp32/boards/MICROHYDRA/launcher/launcher.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414

1515
"""
1616
17-
VERSION: 0.6
17+
VERSION: 0.7
1818
1919
CHANGES:
20-
Improved Settings app UI
20+
Adjusted battery level detection, improved launcher sort method,
21+
added apps folders to import path,
22+
added ability to jump to alphabetical location in apps list,
23+
added new fbuf-based display driver to lib
2124
2225
This program is designed to be used in conjunction with the "apploader.py" program, to select and launch MPy apps for the Cardputer.
2326
@@ -168,8 +171,8 @@ def scan_apps(sd):
168171
app_names.append( this_name )
169172
app_paths[f"{this_name}"] = f"/sd/apps/{entry}"
170173

171-
172-
app_names.sort()
174+
#sort alphabetically without uppercase/lowercase discrimination:
175+
app_names.sort(key=lambda element: element.lower())
173176

174177
#add an appname to refresh the app list
175178
app_names.append("Reload Apps")
@@ -246,19 +249,27 @@ def read_battery_level(adc):
246249
read approx battery level on the adc and return as int range 0 (low) to 3 (high)
247250
"""
248251
raw_value = adc.read_uv() # vbat has a voltage divider of 1/2
249-
250-
if raw_value < 525000: # 1.05v
252+
253+
# more real-world data is needed to dial in battery level.
254+
# the original values were low, so they will be adjusted based on feedback.
255+
256+
#originally 525000 (1.05v)
257+
if raw_value < 1575000: #3.15v
251258
return 0
252-
if raw_value < 1050000: # 2.1v
259+
#originally 1050000 (2.1v)
260+
if raw_value < 1750000: #3.5v
253261
return 1
254-
if raw_value < 1575000: # 3.15v
262+
#originally 1575000 (3.15v)
263+
if raw_value < 1925000: #3.85v
255264
return 2
265+
# 2100000 (4.2v)
256266
return 3 # 4.2v or higher
257267

258268

259269

260270

261271

272+
262273
#--------------------------------------------------------------------------------------------------
263274
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
264275
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Main Loop: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -492,8 +503,27 @@ def main_loop():
492503
beep.play(('C4','B4','C5','C5'),100,volume)
493504

494505
launch_app(app_paths[app_names[app_selector_index]])
495-
496-
506+
507+
else: # keyboard shortcuts!
508+
for key in pressed_keys:
509+
# jump to letter:
510+
if key not in prev_pressed_keys and len(key) == 1: # filter special keys and repeated presses
511+
if key in 'abcdefghijklmnopqrstuvwxyz1234567890':
512+
#search for that letter in the app list
513+
for idx, name in enumerate(app_names):
514+
if name.lower().startswith(key):
515+
#animation:
516+
if app_selector_index > idx:
517+
scroll_direction = -1
518+
elif app_selector_index < idx:
519+
scroll_direction = 1
520+
current_vscsad = target_vscsad
521+
# go there!
522+
app_selector_index = idx
523+
if ui_sound:
524+
beep.play(("G3"), 100, volume)
525+
found_key = True
526+
break
497527

498528
# once we parse the keypresses for this loop, we need to store them for next loop
499529
prev_pressed_keys = pressed_keys
@@ -676,3 +706,4 @@ def main_loop():
676706

677707

678708

709+

ports/esp32/boards/MICROHYDRA/lib/microhydra.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,58 @@ def mix_color565(color1, color2, mix_factor=0.5):
178178
blue = math.floor(blue * 31)
179179

180180
return combine_color565(red,green,blue)
181+
182+
183+
184+
def darker_color565(color,mix_factor=0.5):
185+
"""
186+
Get the darker version of a 565 color.
187+
"""
188+
#separate to components
189+
r,g,b = separate_color565(color)
190+
#convert to float 0.0 to 1.0
191+
r /= 31; g /= 63; b /= 31
192+
#convert to hsv 0.0 to 1.0
193+
h,s,v = rgb_to_hsv(r,g,b)
194+
195+
#higher sat value is percieved as darker
196+
s *= 1 + mix_factor
197+
v *= 1 - mix_factor
181198

199+
#convert back to rgb floats
200+
r,g,b = hsv_to_rgb(h,s,v)
201+
#convert back to 565 range
202+
r = math.floor(r * 31)
203+
g = math.floor(g * 63)
204+
b = math.floor(b * 31)
205+
206+
return combine_color565(r,g,b)
207+
208+
209+
def lighter_color565(color,mix_factor=0.5):
210+
"""
211+
Get the lighter version of a 565 color.
212+
"""
213+
#separate to components
214+
r,g,b = separate_color565(color)
215+
#convert to float 0.0 to 1.0
216+
r /= 31; g /= 63; b /= 31
217+
#convert to hsv 0.0 to 1.0
218+
h,s,v = rgb_to_hsv(r,g,b)
219+
220+
#higher sat value is percieved as darker
221+
s *= 1 - mix_factor
222+
v *= 1 + mix_factor
223+
224+
#convert back to rgb floats
225+
r,g,b = hsv_to_rgb(h,s,v)
226+
#convert back to 565 range
227+
r = math.floor(r * 31)
228+
g = math.floor(g * 63)
229+
b = math.floor(b * 31)
230+
231+
return combine_color565(r,g,b)
232+
182233

183234
def color565_shiftred(color, mix_factor=0.5):
184235
"""
@@ -202,4 +253,4 @@ def color565_shiftgreen(color, mix_factor=0.5):
202253
if __name__ == "__main__":
203254
# just for testing
204255

205-
print('output:', mix_color565(4421, 53243, 0.5))
256+
print('output:', mix_color565(4421, 53243, 0.5))

0 commit comments

Comments
 (0)