Ejemplo n.º 1
0
    def read_raw(self):
        """
        Read ADC value

        :return: Raw ADC value.
        :rtype: int
        """
        return decode_sfp(self.board.uper_io(1, encode_sfp(10, [self.adc_pin])))[1][1]
Ejemplo n.º 2
0
    def read(self):
        """
        Read a digital signal value. If GPIO pis in not configure as input, set it to GPIO.PULL_UP pin mode.

        :return: Digital signal value: 0 (LOW) or 1 (HIGH).
        :rtype: int
        """
        if self.direction != GPIO.INPUT:
            self.setup(GPIO.INPUT, self.resistor)
        return decode_sfp(self.board.uper_io(1, encode_sfp(5, [self.logical_pin])))[1][1]
Ejemplo n.º 3
0
    def transaction(self, write_data, read_from_slave=True):
        """
        Perform SPI data transaction.

        :param write_data: Data to be shifted on MOSI line.
        :type write_data: str
        :param read_from_slave: Flag indicating whether the data received on MISO line should be ignored or not. Optional, default True.
        :type read_from_slave: bool

        :return: Data received on MISO line, if read_from_slave is True.
        :rtype: str
        """
        res = self.board.uper_io(read_from_slave, encode_sfp(21 + self.port * 10, [write_data, int(read_from_slave)]))

        if res:
            return decode_sfp(res)[1][0]
Ejemplo n.º 4
0
    def read(self):
        """
        Read a digital port value. If GPIO port in not configure as input, set it to GPIO.PULL_UP pin mode.

        :return: Digital port value.
        :rtype: int
        """
        if self.direction != self.INPUT:
            self.setup(GPIO.INPUT, self.resistor)

        values = decode_sfp(self.board.uper_io(1, encode_sfp(5, [self._logical_pins])))[1][1]
        value = 0
        for i, bit in enumerate(values):
            value |= (ord(bit) & 0x1) << i

        return value
Ejemplo n.º 5
0
 def test_simple_sfp_decode(self):
     self.assertEqual(sfp.decode_sfp(b'\xd4\x00\x01\xff'),[255, []])
Ejemplo n.º 6
0
 def test_decode_sfp(self):
     decode_result = sfp.decode_sfp(b'\xd4\x00i\xff\xc4P09876543210987654321098765432109876543210987654321098765432109876543210987654321J0987654321\x00\x01\xc0@\xc1\x17p\xc2\x01\x11p')
     sfp_parameters = [b'09876543210987654321098765432109876543210987654321098765432109876543210987654321', b'0987654321', 0, 1, 64, 6000, 70000]
     sfp_command = 255
     self.assertEqual(decode_result, [sfp_command, sfp_parameters])
Ejemplo n.º 7
0
    def read_pulse(self, level=GPIO.HIGH, timeout=100000):
        if self.direction != self.INPUT:
            self.setup(GPIO.INPUT, self.resistor)

        return decode_sfp(self.board.uper_io(1, encode_sfp(9, [self.logical_pin, level, timeout])))[1][0]