Exemple #1
0
	def get_interrupt_status(self):
		# Read IIR, LSR, and RXLVL registers
		n, d = self.pi.i2c_zip(self.i2c, [I2C_WRITE, 1, self.reg_conv(REG_IIR), I2C_READ, 1, I2C_START, I2C_WRITE, 1, self.reg_conv(REG_LSR), I2C_READ, 1, I2C_START, I2C_WRITE, 1, self.reg_conv(REG_RXLVL), I2C_READ, 1, I2C_END])
		if n < 0: raise pigpio.error(pigpio.error_text(n))
		elif n != 3: raise ValueError("unexpected number of bytes received")
		# Mask out two MSBs in IIR value and return tuple
		return (int(d[0]) & 0x3F, int(d[1]), int(d[2]))
Exemple #2
0
    def _send(self, value, mode):
        """Send the specified value to the display with automatic 4bit / 8bit
        selection. The rs_mode is either ``RS_DATA`` or ``RS_INSTRUCTION``."""
        # Wait, if compatibility mode is enabled
        if self.compat_mode and self.compat_mode_wait_time > 0:
            self._wait()

        # Assemble the parameters sent to the pigpio script
        params = [mode]
        params.extend([(value >> i) & 0x01 for i in range(8)])
        # Switch off pigpio's exceptions, so that we get the return codes
        pigpio.exceptions = False
        while True:
            ret = self.pi.run_script(self._writescript, params)
            if ret >= 0:
                break
            elif ret != pigpio.PI_SCRIPT_NOT_READY:
                raise pigpio.error(pigpio.error_text(ret))
            # If pigpio script is not ready, sleep and try again
            c.usleep(1)
        # Switch on pigpio's exceptions
        pigpio.exceptions = True

        # Record the time for the tail-end of the last send event
        if self.compat_mode:
            self.last_send_event = now()
	def byte_write_verify(self, reg, byte):

		n, d = self.pi.i2c_zip(self.i2c, [I2C_WRITE, 2, self.reg_conv(reg), byte, I2C_READ, 1, I2C_END])
		if n < 0: raise pigpio.error(pigpio.error_text(n))
		elif n != 1: raise ValueError("unexpected number of bytes received")
		d = int(d[0])
		return (d == byte, d)
	def block_write(self, reg, bytestring):
		print(bytestring)
		self.pi.wave_clear()
		self.pi.wave_add_serial(PI_WRITE, 115200, bytestring)
		wid = self.pi.wave_create()
		cbs = self.pi.wave_send_once(wid)
		while self.pi.wave_tx_busy():
			print("waveform tx busy ", self.pi.wave_tx_at(), " ", self.pi.wave_get_cbs())
			time.sleep(.1)

		
		n, d = self.pi.i2c_zip(self.i2c, [I2C_WRITE, len(bytestring)+1, self.reg_conv(reg)] + list(bytestring) + [I2C_END])
		if n < 0: raise pigpio.error(pigpio.error_text(n))
Exemple #5
0
    def _send(self, value, mode):
        """Send the specified value to the display with automatic 4bit / 8bit
        selection. The rs_mode is either ``RS_DATA`` or ``RS_INSTRUCTION``."""

        # Assemble the parameters sent to the pigpio script
        params = [mode]
        params.extend([(value >> i) & 0x01 for i in range(8)])
        # Switch off pigpio's exceptions, so that we get the return codes
        pigpio.exceptions = False
        while True:
            ret = self.pi.run_script(self._writescript, params)
            if ret >= 0:
                break
            elif ret != pigpio.PI_SCRIPT_NOT_READY:
                raise pigpio.error(pigpio.error_text(ret))
            # If pigpio script is not ready, sleep and try again
            c.usleep(1)
        # Switch on pigpio's exceptions
        pigpio.exceptions = True
Exemple #6
0
	def block_read(self, reg, num):
		n, d = self.pi.i2c_zip(self.i2c, [I2C_WRITE, 1, self.reg_conv(reg), I2C_READ, num, I2C_END])
		if n < 0: raise pigpio.error(pigpio.error_text(n))
		elif n != num: raise ValueError("all available bytes were not successfully read")
		return d
Exemple #7
0
	def block_write(self, reg, bytestring):
		n, d = self.pi.i2c_zip(self.i2c, [I2C_WRITE, 1, self.reg_conv(reg), I2C_WRITE, len(bytestring)] + list(bytestring) + [I2C_END])
		if n < 0: raise pigpio.error(pigpio.error_text(n))
Exemple #8
0
 def mock_pigpio__u2i_exception(self, *args, **kwargs):
     value = func(self, *args, **kwargs)
     v = value if type(value) in (int, bool, float) else value[0]
     if v < 0:
         raise pigpio.error(pigpio.error_text(v))
     return value