import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
win = Gtk.Window()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import gpiod
from gpiod.line import Direction, Value
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__(title="CTRL LED")
self.button = Gtk.Button(label="LED")
self.button.connect("clicked", self.on_button_clicked)
self.add(self.button)
self.init_led()
self.led_state = 0
def init_led(self):
self.led_request = gpiod.request_lines(
"/dev/gpiochip9",
consumer="ctrl-led",
config={
14:gpiod.LineSettings(
direction=Direction.OUTPUT,output_value=Value.ACTIVE
)
},
)
def on_button_clicked(self, widget):
if self.led_state == 0:
self.led_state = 1
self.led_request.set_value(14,Value.ACTIVE)
else:
self.led_state = 0
self.led_request.set_value(14,Value.INACTIVE)
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()