Пример #1
0
    def connect(self):
        try:

            # retrieve charger control GPIO line
            config = gpiod.line_request()
            config.consumer = "ChargerControl"
            config.request_type = gpiod.line_request.DIRECTION_OUTPUT
            self.charger_en = gpiod.chip(
                self._charger_control['chip']).get_line(
                    self._charger_control['line'])
            self.charger_en.request(config)

            # retrieve charger status GPIO line
            config = gpiod.line_request()
            config.consumer = "ChargerRead"
            config.request_type = gpiod.line_request.DIRECTION_INPUT
            self.charger_st = gpiod.chip(
                self._charger_status['chip']).get_line(
                    self._charger_status['line'])
            self.charger_st.request(config)
            self.disable_charge()
            return True
        except:
            self.is_connected = False
            return False
Пример #2
0
 def __init__(self, pin_id):
     self.id = pin_id
     if type(pin_id) is tuple:
         self._num = int(pin_id[1])
         self._chip = gpiod.chip(str(pin_id[0]), gpiod.chip.OPEN_BY_NUMBER)
     else:
         self._num = int(pin_id)
         self._chip = gpiod.chip("gpiochip0", gpiod.chip.OPEN_BY_NAME)
     self._line = None
Пример #3
0
 def __init__(self, pin_id):
     self.id = pin_id
     if isinstance(pin_id, tuple):
         self._num = int(pin_id[1])
         if hasattr(gpiod, "Chip"):
             self._chip = gpiod.Chip(str(pin_id[0]),
                                     gpiod.Chip.OPEN_BY_NUMBER)
         else:
             self._chip = gpiod.chip(str(pin_id[0]),
                                     gpiod.chip.OPEN_BY_NUMBER)
     else:
         self._num = int(pin_id)
         if hasattr(gpiod, "Chip"):
             self._chip = gpiod.Chip("gpiochip0", gpiod.Chip.OPEN_BY_NAME)
         else:
             self._chip = gpiod.chip("gpiochip0", gpiod.chip.OPEN_BY_NAME)
     self._line = None
Пример #4
0
    def __init__(self, chipName, line):
        ## GPIO STUFF HERE
        # Define the pin we want to use and its state (on/off)
        gpioPinsChip = gpiod.chip(chipName)
        gpioPinsLine = gpioPinsChip.get_line(line) # P9_12
        self.__gpioPin = (gpioPinsLine, False)

        # Initialize gpiod
        config = gpiod.line_request()
        config.consumer = 'Blink'
        config.request_type = gpiod.line_request.DIRECTION_OUTPUT
        self.__gpioPin[0].request(config)
Пример #5
0
    def __init__(self, config):
        global DIRECTIONS, PULLUPS, INTERRUPT
        import gpiod as gpio

        self.io = gpio
        self.chip = gpio.chip(config["chip"])
        self.pins = {}

        DIRECTIONS = {
            PinDirection.INPUT: gpio.line_request.DIRECTION_INPUT,
            PinDirection.OUTPUT: gpio.line_request.DIRECTION_OUTPUT,
        }

        INTERRUPT = {
            InterruptEdge.RISING: gpio.line_request.EVENT_RISING_EDGE,
            InterruptEdge.FALLING: gpio.line_request.EVENT_FALLING_EDGE,
            InterruptEdge.BOTH: gpio.line_request.EVENT_BOTH_EDGES,
        }
Пример #6
0
    def __init__(self):
        self.chip = gpiod.chip('9008000.gpio')
        # configure necessary lines
        self.led = self.chip.get_line(24)
        config = gpiod.line_request()
        config.consumer = "Blink"
        config.request_type = gpiod.line_request.DIRECTION_OUTPUT
        self.led.request(config)

        self.prev_button = self.chip.get_line(12)
        config = gpiod.line_request()
        config.consumer = "Prev"
        config.request_type = gpiod.line_request.EVENT_BOTH_EDGES
        self.prev_button.request(config)

        self.stop_button = self.chip.get_line(13)
        config = gpiod.line_request()
        config.consumer = "Stop"
        config.request_type = gpiod.line_request.EVENT_BOTH_EDGES
        self.stop_button.request(config)

        self.next_button = self.chip.get_line(14)
        config = gpiod.line_request()
        config.consumer = "Next"
        config.request_type = gpiod.line_request.EVENT_BOTH_EDGES
        self.next_button.request(config)

        self.vol_up_button = self.chip.get_line(22)
        config = gpiod.line_request()
        config.consumer = "Prev"
        config.request_type = gpiod.line_request.EVENT_BOTH_EDGES
        self.vol_up_button.request(config)

        self.vol_down_button = self.chip.get_line(23)
        config = gpiod.line_request()
        config.consumer = "Next"
        config.request_type = gpiod.line_request.EVENT_BOTH_EDGES
        self.vol_down_button.request(config)
Пример #7
0
    def __pushButtonUpdateInput(queue):
        btnsRaw = queue.get()
        btns = {}
        for btnKey in btnsRaw:
            chip = gpiod.chip(btnsRaw[btnKey][0])
            line = chip.get_line(btnsRaw[btnKey][1])

            config = gpiod.line_request()
            config.consumer = "Blink"
            config.request_type = gpiod.line_request.DIRECTION_INPUT
            line.request(config)

            btns[btnKey] = line
        
        quit = False
        hasProcessed = False
        while not quit:
            for btnKey in btns:
                if btns[btnKey].get_value() == 0:
                    queue.put(btnKey)
                    if btnKey == 'q':
                        quit = True
                    time.sleep(0.15)
Пример #8
0
        B3_OFFSET = int(argv[3])
        D1_OFFSET = int(argv[4])
        D2_OFFSET = int(argv[5])
        D3_OFFSET = int(argv[6])
        D4_OFFSET = int(argv[7])
        CHIP_NAME = argv[8]
    except ValueError:
        _print_usage()

elif len(argv) != 1 and not SKIP_GPIO:
    _print_usage()
if not SKIP_GPIO:
    if BUILDROOT_GPIOD:
        _chip = gpiod.Chip(CHIP_NAME)
    else:
        _chip = gpiod.chip(CHIP_NAME)
    _b1 = _chip.get_line(B1_OFFSET)
    _b2 = _chip.get_line(B2_OFFSET)
    _b3 = _chip.get_line(B3_OFFSET)
    _d1 = _chip.get_line(D1_OFFSET)
    _d2 = _chip.get_line(D2_OFFSET)
    _d3 = _chip.get_line(D3_OFFSET)
    _d4 = _chip.get_line(D4_OFFSET)
    if BUILDROOT_GPIOD:
        _d1.request(consumer='PiPlayer', type=gpiod.LINE_REQ_DIR_OUT)
        _d2.request(consumer='PiPlayer', type=gpiod.LINE_REQ_DIR_OUT)
        _d3.request(consumer='PiPlayer', type=gpiod.LINE_REQ_DIR_OUT)
        _d4.request(consumer='PiPlayer', type=gpiod.LINE_REQ_DIR_OUT)
    else:
        config = gpiod.line_request()
        config.consumer = 'PiPlayer'
Пример #9
0
else:
    print('usage: gpscomm <device> <command>')
    print('device: gps1 - commands: enable/disable')
    print('device: gps2 - commands: enable/disable')
    sys.exit()

if (cmd.get(device) is None):
    print(f'E: device {device} not found')
    sys.exit(-1)

cmdList = cmd.get(device)
if (command not in cmdList):
    print(f'E: command {command} not found for device {device}')
    sys.exit(-1)

chip = gpiod.chip('gpiochip0', gpiod.chip.OPEN_BY_NAME)

#pinName = pin.get(device);
line = chip.get_line(pin[device])

if (line is None):
    print(f'E: gpio pin {pinName} not found')
    sys.exit(-1)

config = gpiod.line_request()
config.consumer = "foobar"
config.request_type = gpiod.line_request.DIRECTION_OUTPUT

line.request(config)

if (command == 'enable'):
Пример #10
0
    def _rotaryEncoderUpdateInput(queue):
        btnsRaw = queue.get()
        encodersRaw = queue.get()

        btns = {}
        for btnKey in btnsRaw:
            chip = gpiod.chip(btnsRaw[btnKey][0])
            line = chip.get_line(btnsRaw[btnKey][1])

            config = gpiod.line_request()
            config.consumer = 'Blink'
            config.request_type = gpiod.line_request.DIRECTION_INPUT
            line.request(config)

            btns[btnKey] = line

        encoders = {}
        for encoderKey in encodersRaw:
            if encodersRaw[encoderKey] == 1:
                os.system('config-pin P8_33 eqep')
                os.system('config-pin P8_35 eqep')
                encoders[encoderKey] = \
                    [
                        Adafruit_BBIO.Encoder.RotaryEncoder(
                            Adafruit_BBIO.Encoder.eQEP1
                        ), 0
                    ]
            else:
                os.system('config-pin P8_11 eqep')
                os.system('config-pin P8_12 eqep')
                encoders[encoderKey] = \
                    [
                        Adafruit_BBIO.Encoder.RotaryEncoder(
                            Adafruit_BBIO.Encoder.eQEP2
                        ), 0
                    ]
            encoders[encoderKey][0].setAbsolute()
            encoders[encoderKey][0].enable()
            encoders[encoderKey][1] = encoders[encoderKey][0].position

        quit = False
        hasProcessed = False
        while not quit:
            for btnKey in btns:
                if btns[btnKey].get_value() == 0:
                    queue.put(btnKey)
                    if btnKey == 'q':
                        quit = True
                    time.sleep(0.15)

            for encoderKey in encoders:
                if encoderKey == 'hor':
                    if encoders[encoderKey][0].position \
                    > encoders[encoderKey][1]:
                        queue.put('d')
                        encoders[encoderKey][1] = \
                            encoders[encoderKey][0].position
                    elif encoders[encoderKey][0].position \
                    < encoders[encoderKey][1]:
                        queue.put('a')
                        encoders[encoderKey][1] = \
                            encoders[encoderKey][0].position
                elif encoderKey == 'vert':
                    if encoders[encoderKey][0].position \
                    > encoders[encoderKey][1]:
                        queue.put('s')
                        encoders[encoderKey][1] = \
                            encoders[encoderKey][0].position
                    elif encoders[encoderKey][0].position \
                    < encoders[encoderKey][1]:
                        queue.put('w')
                        encoders[encoderKey][1] = \
                            encoders[encoderKey][0].position
Пример #11
0
import gpiod
import time

chip = gpiod.chip("gpiochip0")

led_error = chip.get_line(11)
led_armed = chip.get_line(5)
led_status = chip.get_line(7)

config = gpiod.line_request()
config.consumer = "jeff"  # no idea what this does
config.request_type = gpiod.line_request.DIRECTION_OUTPUT

led_error.request(config)
led_armed.request(config)
led_status.request(config)

led_error.set_value(0)
led_armed.set_value(0)
led_status.set_value(0)

led_test = led_status

while True:
    led_test.set_value(0)
    time.sleep(0.3)
    led_test.set_value(1)
    time.sleep(0.3)
Пример #12
0
from gpiod import chip, line, line_request
gpiochip1 = chip("gpiochip1")

# for V831
PF_BASE = 160  # "PF"
PG_BASE = 192  # "PG"
PH_BASE = 224  # "PH"


def gpio(line_offset=(PH_BASE + 14)):
    try:
        tmp = None
        tmp = gpiochip1.get_line(line_offset)
        config = line_request()  # led.active_state == line.ACTIVE_LOW
        config.request_type = line_request.DIRECTION_OUTPUT  # line.DIRECTION_INPUT
        tmp.request(config)
    except Exception as e:
        print(e)
    finally:
        return tmp


import time
led = gpio(PH_BASE + 14)  # "PH14"
while led:
    led.set_value(0)
    time.sleep(0.1)
    led.set_value(1)
    time.sleep(0.1)