How to use the pfio.read_input function in pfio

To help you get started, we’ve selected a few pfio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thomasmacpherson / piface / python / piface / emulator.py View on Github external
def run(self):
        while not self.stopped():
            # get the input pin values
            input_pin_pattern = pfio.read_input()

            # set the virt input pin values
            for i in range(len(self.emu.emu_screen.input_pins)):
                if (input_pin_pattern >> i) & 1 == 1:
                    self.emu.emu_screen.input_pins[i].turn_on(True)
                else:
                    self.emu.emu_screen.input_pins[i].turn_off(True)


            self.emu.emu_screen.queue_draw()

            # sleep
            update_interval = int(self.update_interval_entry.get_text()) / 1000.0
            sleep(update_interval)
github thomasmacpherson / piface / python / piface / pfion.py View on Github external
# make it something sensible
        packet = PfionPacket().from_network(packet)

        if packet.command == WRITE_OUT_CMD:
            pfio.write_output(packet.bit_pattern)
            p = PfionPacket(WRITE_OUT_ACK)
            sock.sendto(p.for_network(), sender)

        elif packet.command == READ_OUT_CMD:
            output_bitp = pfio.read_output()
            p = PfionPacket(READ_OUT_ACK)
            p.bit_pattern = output_bitp
            sock.sendto(p.for_network(), sender)

        elif packet.command == READ_IN_CMD:
            input_bitp = pfio.read_input()
            p = PfionPacket(READ_IN_ACK)
            p.bit_pattern = input_bitp
            sock.sendto(p.for_network(), sender)

        elif packet.command == DIGITAL_WRITE_CMD:
            pfio.digital_write(packet.pin_number, packet.pin_value)
            p = PfionPacket(DIGITAL_WRITE_ACK)
            sock.sendto(p.for_network(), sender)

        elif packet.command ==  DIGITAL_READ_CMD:
            pin_value = pfio.digital_read(packet.pin_number)
            p = PfionPacket(DIGITAL_READ_ACK)
            p.pin_number = packet.pin_number
            p.pin_value  = pin_value
            sock.sendto(p.for_network(), sender)
github thomasmacpherson / piface / python / piface / emulator.py View on Github external
def read_input():
    """Returns the values of the input pins"""
    global rpi_emulator
    data = __read_pins(rpi_emulator.emu_screen.input_pins)

    global pfio_connect
    if pfio_connect:
        data |= pfio.read_input()
    print "data: %s" % data
    return data