Trying to combine the HID Keys Advanced with Rpico OBS

Good Morning All,

So I’ve started messing around with my Keybow finally and I’ve gotten a bit stuck on a particular issue. I’m trying to replace a layer on the HID Keys Advance with the RPICO_RGB_Keypad_OBS.

I want to replace Layer 2 with elements from the RPICO_RGD_Keypad, I don’t mind sitting and learning how to do it but I have not a clue how to get it to work properly or even get it to fit correctly. My knowledge and time with CircuitPython is limited at best. It took me hours to figure out how to comment/uncomment. D:

Those two examples use very different styles of execution (direct look up vs assigned decorators), so aren’t directly compatible, and would require heavy rewrites to add the functions of the other. Assuming the goal is to add layer functionality to the OBS toggle/lighting it is possible, but it’s not going to be a quick and easy thing. It is probably easier to modify the OBS side.

a sketch of the shallowest required changes would be:

  • add a setup for the USER_KEY so you can detect keypress on it
  • duplicate “config” in a new variable for your additional layer, change both variable names
  • insert all duplicate “config” variables into a new dictionary and add a selector variable, and a config = new_dictionary[ selector_variable] assignment
  • optional: add a mirror dictionary of toggle states for each layer that consists of {selector: state} with the default being off
  • turn the “add runtime data” into a function then call the function
  • in the “main” section, add detection for the USER_KEY, and on detection
    • either check for toggled keys and untoggle them, or save the toggle state for previous layer
      • not doing this will give you annoying bugs related to toggled keys
    • selector change can be complex or as a simple as “selector = not selector”
    • reassign the layer with "config = new_dictionary[ selector ]
    • call the “add runtime data” function
    • load the new layer toggle states (if you are saving the previous ones)

*: USER_KEY is the side button right of usb-c port on the keybow2040

Why modify the OBS file and not the “advanced” example? The toggle functions of the OBS example, as written, rely decorators, and since you cannot turn off decorators once assigned, you’d have to add toggle and tracking logic to the “advanced” example along with multiple key actions. adding layer functions to the OBS side lets you do less code writing

1 Like

Ahh! Thanks for all of this and I actually understand it more now that you’ve explained it! Thanks for you help again!!!

I figured I’d just use the OBS one for now but I’ll do some practice with the OBS file as mentioned.

I may (ok definitely) have been thinking a bit to deeply on this, and I realized that I was technically right about not being able to disable the decorations… but effectively wrong because the code inside the decorators can be disabled by checking the layer variable

four tweaks in the OBS code.py file

config = [
    {}, # 0 <-- this line changed
    {"hue": hue["yellow"] , "group": "scene", "keycodes_on": [Keycode.F14],                  "keycodes_off": None                      }, # 1
...
for i in range(16): # there are three lines that have this text
for i in range(1, 16) # replace them all with this text (keep the same indent)
...
def press_kcs(kcs): # original file line
    If( current_layer == 2 ): # add new line below original
        print(f'keycode press {kcs} {KC_LIVE}') # Indent the rest of the block 1 level (block end at next blank line)
...
def release_kcs(kcs):  # original file line
    If( current_layer == 2 ): # add new line below original
        print(f'keycode release {kcs} {KC_LIVE}') # Indent the rest of the block 1 level (block end at next blank line)

then copy everything above

# Main loop
while True:

into the “advanced” example, above

while True:
    # Always remember to call keybow.update()!
    keybow.update()

and make sure to move any lines that start with “import” up to the top with the other “import” lines (and remove any duplicates)

copy everything from the OBS file below

    keybow.update()

to the following position in the “advanced” example

                elif current_layer == 2: # Original line, no changes
                    # Replace anything between the original lines with what you just copied, and add 3 indent levels to everthing pasted
                elif current_layer == 3: # Original line, no changes

and one tweak in the advanced file, replace all of this…

layer_2 =     {7: "pack ",
               11: "my ",
               15: "box ",
               6: "with ",
               10: "five ",
               14: "dozen ",
               5: "liquor ",
               9: "jugs "}

with this

layer_2 =     {} #use config for the OBS layer

and that hack should work, and even preserve the lighting and toggles of the “OBS” file

the only downside is that you’ll lose the 0 key from the “OBS” file (you can rearrange them to keep the 15 you want), because the “advanced” example needs it to switch layers, unless as mentioned in previous post you set up the user key for layer switching, which will require several more edits to the “advanced” example, but does open up the possibility to use all 16 main keys for macros

ETA:
yes, I nerd-sniped myself, also, here’s links to the repositories being used for anyone else that comes along and is curious
PMK/hid-keys-advanced example
rpico_rgb_keypad_obs

Sorry for taking long to respond, things got a bit hectic on my end.

Okay just so I’m making sure, as mentioned my knowledge of the coding is fairly new.

I’m putting the four tweaks here:

then I’m copying everything above the # Main Loop from Line 264 all the way back up?

I don’t mind losing the 0 key really, just wanted to be able to multi-use the device when I’m not streaming.

I edited my previous post to be a bit more explicit on the changes

1 Like

Alrighty, I think I follow the directions. Thank you for making them much clearer to understand.

In any case I’ve pasted the code here for a correction if it doesn’t look like you said.

https://github.com/firstfridayfunk/HIDpractice