Macropad 2040 ducky enhancement problem

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
vincentlarsen
 
Posts: 4
Joined: Fri Jul 30, 2021 10:51 pm

Macropad 2040 ducky enhancement problem

Post by vincentlarsen »

I am new to CircuitPython and it seems to be causing me some problems. I want the ability to execute Python code, upon pressing one of the keys, on the Macropad 2040. This should give maximum flexibility, when programming a key press to do something.

I made my change, at line 151, to the attached code.py file. Prior to making this change, I confirmed the syntax operates the same as in Python.

I made changes to the linux-firefox.py script (also attached), that should get the function "func" called, if the first button, on the keypad, is pressed. However, when I press the button, the keypad screen says "Code done running" and I have to reset the device, to do anything else.

What have I done wrong? Can anyone help?

Sincerely,
Vincent
Attachments
linux-firefox.py
(1.66 KiB) Downloaded 4 times
code.py
(8.1 KiB) Downloaded 5 times

User avatar
vincentlarsen
 
Posts: 4
Joined: Fri Jul 30, 2021 10:51 pm

Re: Macropad 2040 ducky enhancement problem

Post by vincentlarsen »

After much playing, I have found the problem. For those wishing to add the functionality, here is what needs to be done:

First, remove the change I made on line 151 and 152 (if type(item).__name__ == 'function': and item()). As it turns out, when the last item is a function, the "for item in sequence:" statement fails (tough to tell what is happening, with such a small screen :)).

Second, before the line "if pressed:," enter the following four lines:

if type(sequence).__name == 'function':
if pressed:
sequence(macropad, time)
continue

I moved the logic, before the "if pressed:" line, because I don't want that line's "else" clause to get executed, on release. I also added the two parameters, to the function call, for convenience.

Enjoy,
Vincent

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”