forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
CircuitPython version and board name
Adafruit CircuitPython 9.2.0 on 2024-10-28; M5Stack Dial with ESP32S3
Code/REPL
import board, os
from digitalio import DigitalInOut, Pull
import usb_hid, time # , neopixel
import time, busio, rotaryio, terminalio, displayio
import adafruit_focaltouch
KEYCODE_ON_RINGBUTTON = KEYCODE_ON_MULTITOUCH = KEYCODE_ON_TOUCH= [1,2,3] # Faked for Github
TOUCH_DEBOUNCE=.0005
textColour=0xfe8a2c
print(os.uname().machine)
# create the switch, add a pullup, start it with not being pressed
button = DigitalInOut(board.KNOB_BUTTON)
button.switch_to_input(pull=Pull.UP)
button_state = False
# our helper function will press the keys themselves
def make_keystrokes(keys, delay=0):
None
# Omitted for github issue
def get_touches(debug_str=""):
touch_touched = None
try:
if 'touches' in dir(touch):
touch_touched=touch.touches
else:
touch_touched=touch.touched
except OSError as e:
print(f"{debug_str} "+str(e))
except RuntimeError as e:
print(f"RuntimeError {debug_str} "+str(e))
return touch_touched
try:
touch = None
while not touch:
try:
touch = adafruit_focaltouch.Adafruit_FocalTouch(board.I2C(), debug=False)
except ValueError as e:
print("retrying Touch device initialization")
touch = None
touch_state = False
while True:
if not button.value and not button_state:
button_state = True
print("Button pressed.")
make_keystrokes(KEYCODE_ON_RINGBUTTON)
if button.value and button_state:
button_state = False
print("Button released.")
# keyboard.release_all() # ..."Release"!
touch_touched = get_touches("Touch1")
# if the screen is being touched print the touches
if touch_touched and not touch_state:
time.sleep(TOUCH_DEBOUNCE)
touch_touched = get_touches("Touch2")
if touch_touched: # attempting a debounce
lastTouch=None
touch_state = True
sendKeystroke = True
t = touch_touched # check if the screen is being touched
while t:
print(f"\t\t{t} {len(t)} touches")
if isinstance(t,(list, tuple)) and len(t) >1: # multi touch
print("Multi Touched!")
make_keystrokes(KEYCODE_ON_MULTITOUCH)
elif isinstance(t,(list, tuple)) and len(t) > 0:
print("Touched!")
lastTouch=t
if sendKeystroke:
make_keystrokes(KEYCODE_ON_TOUCH, delay=0)
sendKeystroke = False
t = get_touches("Touch3")
print("") #newline
time.sleep(.15)
if not touch_touched and touch_state:
time.sleep(TOUCH_DEBOUNCE)
touch_touched = get_touches("Touch4")
if not touch_touched: # attempting a debounce
print("Untouched!")
touch_state = False
time.sleep(.15)
finally:
None
Behavior
Code crashes with a memory access or instruction error.
I can't capture the exact message because the screen is small and round.
After I enter the REPL and try to get it to restart my code, I get this message...
You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.
Description
removing the touch read in get_touches() seems to make the issue go away (but then the code doesn't do what I need it to do)
The duration between when my program starts and when it crashes varies.
Additional information
I minimized my code down to the minimum that still causes the error.
When I had the full code, I tested it at many CircuitPython versions.
9.1.4 works, 9.2.0 fails, everything beyond 9.2.0 also fails (including 10.0.0-beta2)