Beispiel #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
Beispiel #2
0
def gpio_thread(arg):
    global _state
    while _state != -1:
        if BUILDROOT_GPIOD:
            bulk_event = gpiod.LineBulk([_b1, _b2, _b3])
            bulk_event.request(consumer='PiPlayer',
                               type=gpiod.LINE_REQ_EV_FALLING_EDGE)
            events = bulk_event.event_wait(sec=2)
        else:
            bulk_event = gpiod.line_bulk([_b1, _b2, _b3])
            config = gpiod.line_request()
            config.consumer = 'PiPlayer'
            config.request_type = gpiod.line_request.EVENT_FALLING_EDGE
            bulk_event.request(config)
            events = bulk_event.event_wait(timedelta(seconds=2))
        if events is None or (not BUILDROOT_GPIOD and events.size == 0):
            bulk_event.release()
            continue
        if BUILDROOT_GPIOD:
            button = events[0]
            offset = button.offset()
        else:
            button = events.get(0)
            offset = button.offset
        sleep(0.5)
        if button.get_value() == 1:
            _select_action(offset)
        bulk_event.release()
Beispiel #3
0
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
Beispiel #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)
Beispiel #5
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)
Beispiel #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)
Beispiel #7
0
    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'
        config.request_type = gpiod.line_request.DIRECTION_OUTPUT
        _d1.request(config)
        _d2.request(config)
        _d3.request(config)
        _d4.request(config)
    _d1.set_value(1)
    _d2.set_value(1)
    _d3.set_value(0)
    _d4.set_value(0)

_state = 0  #0 - playback, 1 - selection, 2 - volume change, -1 - finish


def gpio_thread(arg):
Beispiel #8
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
Beispiel #9
0
    def init(self, mode=IN, pull=None):
        """Initialize the Pin"""
        if not self._line:
            self._line = self._chip.get_line(int(self._num))
            # print("init line: ", self.id, self._line)

        if mode is not None:
            if mode == self.IN:
                flags = 0
                self._line.release()
                if pull is not None:
                    if pull == self.PULL_UP:
                        if hasattr(gpiod, "line") and hasattr(
                                gpiod.line, "BIAS_PULL_UP"):
                            config = gpiod.line_request()
                            config.consumer = self._CONSUMER
                            config.request_type = gpiod.line.BIAS_PULL_UP
                            self._line.request(config)
                        else:
                            self._line.request(
                                consumer=self._CONSUMER,
                                type=gpiod.LINE_REQ_DIR_IN,
                                flags=flags,
                            )
                            raise NotImplementedError(
                                "Internal pullups not supported in this version of libgpiod, "
                                "use physical resistor instead!")
                    elif pull == self.PULL_DOWN:
                        if hasattr(gpiod, "line") and hasattr(
                                gpiod.line, "BIAS_PULL_DOWN"):
                            config = gpiod.line_request()
                            config.consumer = self._CONSUMER
                            config.request_type = gpiod.line.BIAS_PULL_DOWN
                            self._line.request(config)
                        else:
                            raise NotImplementedError(
                                "Internal pulldowns not supported in this version of libgpiod, "
                                "use physical resistor instead!")
                    elif pull == self.PULL_NONE:
                        if hasattr(gpiod, "line") and hasattr(
                                gpiod.line, "BIAS_DISABLE"):
                            config = gpiod.line_request()
                            config.consumer = self._CONSUMER
                            config.request_type = gpiod.line.BIAS_DISABLE
                            self._line.request(config)
                    else:
                        raise RuntimeError(f"Invalid pull for pin: {self.id}")

                self._mode = self.IN
                self._line.release()
                if hasattr(gpiod, "LINE_REQ_DIR_IN"):
                    self._line.request(consumer=self._CONSUMER,
                                       type=gpiod.LINE_REQ_DIR_IN,
                                       flags=flags)
                else:
                    config = gpiod.line_request()
                    config.consumer = self._CONSUMER
                    config.request_type = gpiod.line_request.DIRECTION_INPUT
                    self._line.request(config)

            elif mode == self.OUT:
                if pull is not None:
                    raise RuntimeError("Cannot set pull resistor on output")
                self._mode = self.OUT
                self._line.release()
                if hasattr(gpiod, "LINE_REQ_DIR_OUT"):
                    self._line.request(consumer=self._CONSUMER,
                                       type=gpiod.LINE_REQ_DIR_OUT)
                else:
                    config = gpiod.line_request()
                    config.consumer = self._CONSUMER
                    config.request_type = gpiod.line_request.DIRECTION_OUTPUT
                    self._line.request(config)
            else:
                raise RuntimeError("Invalid mode for pin: %s" % self.id)