Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Macropad - Macro Key Demo (modification help)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Macropad - Macro Key Demo (modification help)

by MultiTech_Visions on Thu Oct 28, 2021 9:20 am

Hey everyone.

Still very new to CircuitPython, so I'm sure there's some key info I'm missing that's preventing me from getting this mod to work.

The Gist:
    Create a "Macro app" - the .py file that contains all the settings for each "screen" - that's essentially an "off" screen

- I've gotten the LEDs to turn off
- I'm struggling with getting the white rectangle, created as part of the "group" display, to not show
- It's got a background of white

I'd like to conditionally hide this white rectangle, so as to effectively turn all the lights off on the device.

What I've done so far...

    - Create a new parameter inside each "macro app" called 'show_header' that's a Boolean value

Code: Select all | TOGGLE FULL SIZE
# MACROPAD Hotkeys: off

app = {                # REQUIRED dict, must be named 'app'
    'name' : '======---OFF---======', # Application name
    'show_header' : False,
    'macros' : [       # List of button macros...
        # COLOR    LABEL    KEY SEQUENCE
        # 1st row ----------
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        # 2nd row ----------
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        # 3rd row ----------
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        # 4th row ----------
        (0x000000, '', ['']),
        (0x000000, '', ['']),
        (0x000000, '', [''])
    ]
}


    - I've created a global variable to hold this value

Code: Select all | TOGGLE FULL SIZE
# CONFIGURABLES ------------------------

MACRO_FOLDER = '/macros'
show_header = None

# CLASSES AND FUNCTIONS ----------------


    - I've successfully imported the Boolean value (from the macro app) into that global parameter

Code: Select all | TOGGLE FULL SIZE
class App:
    """ Class representing a host-side application, for which we have a set
        of macro sequences. Project code was originally more complex and
        this was helpful, but maybe it's excessive now?"""
    def __init__(self, appdata):
        self.name = appdata['name']
        self.macros = appdata['macros']
        self.header_visible = appdata['show_header']

    def switch(self):
        """ Activate application settings; update OLED labels and LED
            colors. """
        global show_header
        show_header = self.header_visible
        group[13].text = self.name   # Application name
        for i in range(12):
            if i < len(self.macros):  # Key in use, set label + LED color
                macropad.pixels[i] = self.macros[i][0]
                group[i].text = self.macros[i][1]
            else:  # Key not in use, no label or LED
                macropad.pixels[i] = 0
                group[i].text = ''
        macropad.keyboard.release_all()
        macropad.consumer_control.release()
        macropad.mouse.release_all()
        macropad.stop_tone()
        macropad.pixels.show()
        macropad.display.refresh()


I've gotten things to where if I print out the global parameter (to check what it's value is) I can see it's got the appropriate value from the macro-app.

-------------------------------------------------------------------------------------

My problem is that any time I try an USE that value in a logic statement, it's like the global variable isn't be changed during the Switch()...
- But it is, because I've printed it out to verify it's value

So how can I NOT show the white rectangle?
- Where do I put this logic?


Because I've tried all sorts of things, nothing is working.
    I've tried wrapping the whole "for" loop that updates the values inside the "group"
    I've tried using display brightness
    I've tried setting the group's hidden parameter to True
    I've tried creating a separate group (that's empty) and conditionally showing that

But every time I try something, the logic doesn't track with what's inside the macro app.

Thanks for the help! Image

MultiTech_Visions
 
Posts: 5
Joined: Tue Oct 26, 2021 1:49 pm

Re: Macropad - Macro Key Demo (modification help)

by danhalbert on Thu Oct 28, 2021 11:31 am

If you forgot to do `global show_header` in some other place, that might be your issue. Or it might be a displayio-related issue. Using globals in Python is highly error-prone, so consider reference the app object's `.header_visible` instead of assigning to a global.

danhalbert
 
Posts: 2593
Joined: Tue Aug 08, 2017 12:37 pm

Re: Macropad - Macro Key Demo (modification help)

by MultiTech_Visions on Thu Oct 28, 2021 11:39 am

danhalbert wrote:consider reference the app object's `.header_visible` instead of assigning to a global.


How do I do this?
(Sorry, very much a newb here.)

Isn't the '.header_visible' part of Self - as in
Code: Select all | TOGGLE FULL SIZE
Self.header_visible

- How do I reference this when I'm not inside the Switch()?
(It makes sense to me that that is available during the Switch part, but after that (in the main code) how do I reference it?

----------------

Thanks so much for your help! (^_^)

MultiTech_Visions
 
Posts: 5
Joined: Tue Oct 26, 2021 1:49 pm

Re: Macropad - Macro Key Demo (modification help)

by danhalbert on Thu Oct 28, 2021 2:20 pm

You can just reference `apps[app_index].header_visible` where you need to get the value. Does that make sense?

danhalbert
 
Posts: 2593
Joined: Tue Aug 08, 2017 12:37 pm

Re: Macropad - Macro Key Demo (modification help)

by MultiTech_Visions on Thu Oct 28, 2021 2:41 pm

Yes!!! That makes total sense now.

But now the question becomes how can I get that value BEFORE the array is made?

I made a quick video showing my difficulties:
https://p215.p3.n0.cdn.getcloudapp.com/items/jkuEDqGJ/ddee4e5a-c1cb-475f-8d2a-04cc8fdef361.mp4

app_index only exists inside the main loop, but the header box creation is at the start of the code.... so how can I sorta... reinitialize things inside the Switch()?

MultiTech_Visions
 
Posts: 5
Joined: Tue Oct 26, 2021 1:49 pm

Re: Macropad - Macro Key Demo (modification help)

by danhalbert on Thu Oct 28, 2021 11:43 pm

You should just be able to move the App object creation up (filling the apps[] list), to before the place where you need to reference it. You mentioned that briefly. I didn't see anything that requires it to be in the other order, though maybe I missed something.

danhalbert
 
Posts: 2593
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.