def write_byte(self, index, value): assert (index < self.size and index >= 0) with (yield self.i2cbus.iolock.acquire()): # write byte extents = [struct.pack("I", (value & 0xff))] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, index, 4, extents) pigpio._u2i(result) # check errors
def set_value(self, value): value10 = self.__calc_value(value) result = pigpio._u2i( (yield self.bus.apigpio_command(pigpio._PI_CMD_PWM, self.pin, value10))) self.value = value devents.status(self) raise gen.Return(result)
def set_bitmap(self, mask, bitmap): byte_val = (self.value & ~mask) | (bitmap & mask) with (yield self.i2cbus.iolock.acquire()): #write byte extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, MCP23008_GPIO, 4, extents) pigpio._u2i(result) # check errors #read byte result = yield self.i2cbus.apigpio_command(pigpio._PI_CMD_I2CRB, self.i2c, MCP23008_OLAT) mask = self.value self.value = pigpio._u2i(result) mask = mask ^ self.value for r in filter(lambda r: r._mask & mask, self.relays): devents.status(r)
def set(self, channel, on, off): """ Set LED_on and LED_OFF registers value on channel, on(off) values between 0-4096 """ if channel > self.nr_channels - 1: #numbering from 0 to 15 return on = on if on <= 4096 else 4096 on = on if on >= 0 else 0 off = off if off <= 4096 else 4096 off = off if off >= 0 else 0 with (yield self.i2cbus.iolock.acquire()): byte_val = on & 0xFF extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_ON_L + self.__LED_MULTIPLIER * channel, 4, extents) result = yield self.i2cbus.apigpio_command( pigpio._PI_CMD_I2CRB, self.i2c, self.__LED0_ON_L + self.__LED_MULTIPLIER * channel) pigpio._u2i(result) # check errors byte_val = on >> 8 extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_ON_H + self.__LED_MULTIPLIER * channel, 4, extents) pigpio._u2i(result) # check errors byte_val = off & 0xFF extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_OFF_L + self.__LED_MULTIPLIER * channel, 4, extents) pigpio._u2i(result) # check errors byte_val = off >> 8 extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_OFF_H + self.__LED_MULTIPLIER * channel, 4, extents) pigpio._u2i(result) # check errors #update object's channels registers self.channels[channel] = (on, off) #print "PCA9685 "+ str(self.circuit) +" Channel: " + str(channel) + " - " + str((on, off)) raise gen.Return(True)
def set_masked_value(self, mask, value): if value: byte_val = (self.value | mask) & 0xff else: byte_val = (self.value & ~mask) & 0xff with (yield self.i2cbus.iolock.acquire()): #write byte extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, MCP23008_GPIO, 4, extents) pigpio._u2i(result) # check errors #read byte result = yield self.i2cbus.apigpio_command( pigpio._PI_CMD_I2CRB, self.i2c, MCP23008_OLAT) mask = self.value self.value = pigpio._u2i(result) mask = mask ^ self.value for r in filter(lambda r: r._mask & mask, self.relays): devents.status(r)
def set(self, channel, on, off): """ Set LED_on and LED_OFF registers value on channel, on(off) values between 0-4096 """ if channel > self.nr_channels - 1: #numbering from 0 to 15 return on = on if on <= 4096 else 4096 on = on if on >= 0 else 0 off = off if off <= 4096 else 4096 off = off if off >= 0 else 0 with (yield self.i2cbus.iolock.acquire()): byte_val = on & 0xFF extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_ON_L + self.__LED_MULTIPLIER*channel, 4, extents) result = yield self.i2cbus.apigpio_command( pigpio._PI_CMD_I2CRB, self.i2c, self.__LED0_ON_L + self.__LED_MULTIPLIER*channel) pigpio._u2i(result) # check errors byte_val = on >> 8 extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_ON_H + self.__LED_MULTIPLIER*channel, 4, extents) pigpio._u2i(result) # check errors byte_val = off & 0xFF extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_OFF_L + self.__LED_MULTIPLIER*channel, 4, extents) pigpio._u2i(result) # check errors byte_val = off >> 8 extents = [struct.pack("I", byte_val)] result = yield self.i2cbus.apigpio_command_ext( pigpio._PI_CMD_I2CWB, self.i2c, self.__LED0_OFF_H + self.__LED_MULTIPLIER*channel, 4, extents) pigpio._u2i(result) # check errors #update object's channels registers self.channels[channel] = (on, off) #print "PCA9685 "+ str(self.circuit) +" Channel: " + str(channel) + " - " + str((on, off)) raise gen.Return(True)
def set(self, value=None, frequency=None): result = None if not (frequency is None) and (frequency != self.frequency): print int(frequency) result = pigpio._u2i((yield self.bus.apigpio_command(pigpio._PI_CMD_PFS, self.pin, int(frequency)))) self.frequency = frequency if not (value is None): result = yield self.set_value(float(value)) else: result = yield self.set_value(self.value) devents.config(self) raise gen.Return(result) if not (value is None) and (value != self.value): result = yield self.set_value(float(value)) raise gen.Return(result)
def set(self, value=None, frequency=None): result = None if not (frequency is None) and (frequency != self.frequency): # print int(frequency) result = pigpio._u2i((yield self.bus.apigpio_command(pigpio._PI_CMD_PFS, self.pin, int(frequency)))) self.frequency = frequency if not (value is None): result = yield self.set_value(float(value)) else: result = yield self.set_value(self.value) devents.config(self) raise gen.Return(result) if not (value is None) and (value != self.value): result = yield self.set_value(float(value)) raise gen.Return(result)
def set_value(self, value): value10 = self.__calc_value(value) result = pigpio._u2i((yield self.bus.apigpio_command(pigpio._PI_CMD_PWM, self.pin, value10))) self.value = value devents.status(self) raise gen.Return(result)
def read_byte(self, index): assert (index < 256 and index >= 0) with (yield self.i2cbus.iolock.acquire()): result = yield self.i2cbus.apigpio_command( pigpio._PI_CMD_I2CRB, self.i2c, index) raise gen.Return(pigpio._u2i(result))
def read_byte(self, index): assert (index < 256 and index >= 0) with (yield self.i2cbus.iolock.acquire()): result = yield self.i2cbus.apigpio_command(pigpio._PI_CMD_I2CRB, self.i2c, index) raise gen.Return(pigpio._u2i(result))