Trying to write a plugin for the pimoroni button shim

hi

i am trying to make the button shim work
hi
i’m trying to write a plugin utilizing the pimoroni button shim


they offer a python lib which is here
–link redacted for 2 links limit of new users
i started by combining this example with the already existing GPIO plugin

and this is my preliminary code which works that the led lights up on button press, but access to self is not possible

import logging
import RPi.GPIO as GPIO
import subprocess
import pwnagotchi.plugins as plugins
import signal
import buttonshim

class Buttonshim(plugins.Plugin):
    __author__ = '[email protected]'
    __version__ = '0.0.1'
    __license__ = 'GPL3'
    __description__ = 'Pimoroni Button Shim GPIO Button and RGB LED support plugin'

    def __init__(self):
        self.running = False
        self.options = dict()
        self.commands = ['', '', '', '', '']

    def on_loaded(self):
        i = 0
        for b in self.options['buttons']:
            self.commands[i] = b
            logging.info(f"Loaded command '{b}' into slot '{i}'.")
            i=i+1
        logging.info("Button Shim GPIO Button plugin loaded.")
        self.running = True

    def runCommand(self, channel):
        logging.info(f"Button Pressed! Loading command from slot '{channel}'")
        command = self.commands[channel]
        logging.info(f"Button Pressed! Running command: {command}")

    @buttonshim.on_press(buttonshim.BUTTON_A)
    def button_a(button, pressed):
        buttonshim.set_pixel(0x94, 0x00, 0xd3)
        channel = 0
        global commands
        logging.info("commands: %s" % commands)
        logging.info("self.commands: %s" % self.commands)
        logging.info(f"Button Pressed! Loading command from slot '{channel}'")
        logging.info("self.commands: %s" % self.commands)
        logging.info(self.commands[channel])
        logging.info(f"Button Pressed! Running command: {self.commands[channel]}")
        command = self.commands[channel]
        logging.info(f"Button Pressed! Running command: {command}")

    @buttonshim.on_press(buttonshim.BUTTON_B)
    def button_b(button, pressed):
        logging.info("runCommand(1)")
        buttonshim.set_pixel(0x00, 0x00, 0xff)
        runCommand(1)

    @buttonshim.on_press(buttonshim.BUTTON_C)
    def button_c(button, pressed):
        logging.info("runCommand(2)")
        buttonshim.set_pixel(0x00, 0xff, 0x00)
        runCommand(2)

    @buttonshim.on_press(buttonshim.BUTTON_D)
    def button_d(button, pressed):
        logging.info("runCommand(3)")
        buttonshim.set_pixel(0xff, 0xff, 0x00)
        runCommand(3)

    @buttonshim.on_press(buttonshim.BUTTON_E)
    def button_e(button, pressed):
        logging.info("runCommand(4)")
        buttonshim.set_pixel(0xff, 0x00, 0x00)
        runCommand(4)

how do i get a reference to self inside these methods marked with @ ?

done
pull request filed

interesting, i have one on by box of hats :slight_smile: