@@ -159,16 +159,29 @@ def install_expander_firmware(filename):
159159 except Exception as e :
160160 print ("Could not check CH32 firmware version after install, many things, including LCD RESET, won't work!" )
161161
162- '''
162+
163163# Quick and dirty patch of BatteryManager to use the CH32 battery level:
164- # mpos.io_expander.analog causes keypresses
165164def get_voltage (force_refresh = False , raw_adc_value = None ):
166- return (0.001651 * mpos.io_expander.analog[2] + 0.08709) # copied from fri3d_2024.py
165+ # First workaround Fri3dCamp/badge_2026_fw/issues/2 by disabling input polling
166+ from mpos import InputManager
167+ InputManager .list_indevs ()
168+ e = InputManager .list_indevs ()[2 ]
169+ e .enable (False )
170+ # Wait to ensure more than 5ms between input polls
171+ import time
172+ time .sleep_ms (6 )
173+ # Do the read:
174+ returnval = (0.001651 * mpos .io_expander .analog [2 ] + 0.08709 ) # copied from fri3d_2024.py
175+ # Wait again to ensure more than 5ms between input polls
176+ time .sleep_ms (6 )
177+ # Enable input polling again:
178+ e .enable (True )
179+ return returnval
167180from mpos import BatteryManager
168181BatteryManager .read_raw_adc = lambda * args : mpos .io_expander .analog [2 ]
169182BatteryManager .has_battery = lambda * args : True
170183BatteryManager .read_battery_voltage = get_voltage
171- '''
184+
172185
173186# quick and dirty way to make accessible later:
174187mpos .io_expander = expander
@@ -379,16 +392,13 @@ def keypad_read_cb(indev, data):
379392def startup_wow_effect ():
380393 try :
381394 # Startup jingle: Happy upbeat sequence (ascending scale with flourish)
382- startup_jingle = "Startup:d=8,o=6,b=200:c,d,e,g,4c7,4e,4c7"
395+ # startup_jingle = "Startup:d=8,o=6,b=200:c,d,e,g,4c7,4e,4c7"
383396 #startup_jingle = "ShortBeeps:d=32,o=5,b=320:c6,c7"
397+ import time
398+ time .sleep (3 ) # wait until it's calmed down
399+ megalovania = "Megalovania:d=16,o=5,b=150:d5,d5,d6,p,a5,8p,g#5,p,g5,p,f5,p,d5,f5,g5,c5,c5,d6,p,a5,8p,g#5,p,g5,p,f5,p,d5,f5,g5,b4,b4,d6,p,a5,8p,g#5,p,g5,p,f5,p,d5,f5,g5,a#4,a#4,d6,p,a5,8p,g#5,p,g5,p,f5,p,d5,f5,g5,d5,d5"
384400
385- # Start the jingle
386- player = AudioManager .player (
387- rtttl = startup_jingle ,
388- stream_type = AudioManager .STREAM_NOTIFICATION ,
389- volume = 60 ,
390- output = buzzer_output ,
391- )
401+ player = AudioManager .player (rtttl = megalovania ,stream_type = AudioManager .STREAM_NOTIFICATION ,volume = 60 ,output = buzzer_output )
392402 player .start ()
393403
394404 # Rainbow colors for the 5 LEDs
@@ -423,6 +433,7 @@ def startup_wow_effect():
423433 except Exception as e :
424434 print (f"Startup effect error: { e } " )
425435
436+ # Would be nice if this were a setting:
426437from mpos import TaskManager
427438_thread .stack_size (TaskManager .good_stack_size ()) # default stack size won't work, crashes!
428439_thread .start_new_thread (startup_wow_effect , ())
0 commit comments