Trying to write a plugin for the pimoroni button shim


i am trying to make the button shim work
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
  "Loaded command '{b}' into slot '{i}'.")
            i=i+1"Button Shim GPIO Button plugin loaded.")
        self.running = True

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

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

    def button_b(button, pressed):"runCommand(1)")
        buttonshim.set_pixel(0x00, 0x00, 0xff)

    def button_c(button, pressed):"runCommand(2)")
        buttonshim.set_pixel(0x00, 0xff, 0x00)

    def button_d(button, pressed):"runCommand(3)")
        buttonshim.set_pixel(0xff, 0xff, 0x00)

    def button_e(button, pressed):"runCommand(4)")
        buttonshim.set_pixel(0xff, 0x00, 0x00)

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

pull request filed

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