本文整理汇总了Python中spi.transfer函数的典型用法代码示例。如果您正苦于以下问题:Python transfer函数的具体用法?Python transfer怎么用?Python transfer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transfer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
# Open file descriptor for
# spi device 0 using the CE0 pin for chip select
device_0 = spi.openSPI(device="/dev/spidev0.0",
mode=0,
speed=1000000)
# Open file descriptor for
# spi device 0 using the CE1 pin for chip select
device_1 = spi.openSPI(device="/dev/spidev0.1",
mode=0,
speed=1000000)
# Transact data
data_out = (0xFF, 0x00, 0xFF)
# This is not necessary, not just demonstrate loop-back
data_in = (0x00, 0x00, 0x00)
data_in = spi.transfer(device_0, data_out)
print("Received from device 0:")
print(data_in)
data_in = (0x00, 0x00, 0x00)
data_in = spi.transfer(device_1, data_out)
print("Received from device 1:")
print(data_in)
# Close file descriptors
spi.closeSPI(device_0)
spi.closeSPI(device_1)
示例2: adc
def adc(self, cmd, osr):
# osr: 0 = 256, 1 = 512, 2 = 1024, 3 = 2048, 4 = 4096
assert 0 <= osr <= 4
spi.transfer((cmd | (2 * osr),))
time.sleep(.01) # conversion time for osr=4096 is 8.22ms
h, m, l = spi.transfer((0, 0, 0, 0))[1:]
return (h << 16) | (m << 8) | l
示例3: send
def send(self, dc, data):
gpio(self.dc, dc)
if hasattr(data, "__iter__"):
data = tuple(data)
else:
data = (data,)
spi.transfer(data)
示例4: write
def write(self, addr, vals, inc):
transfer_tuple = ()
cmd = (addr << 2) + write_cmd + (inc << 1)
transfer_tuple = transfer_tuple + ((cmd >> 8),)
transfer_tuple = transfer_tuple + ((cmd & 0x00FF),)
for v in vals:
transfer_tuple = transfer_tuple + (v,)
spi.transfer(transfer_tuple)
示例5: _send_spi_string
def _send_spi_string(self):
self._job = None
send_str = "0:%d:1:%d:\n" % (self.slider_horiz.get(), self.slider_vert.get())
print send_str
l = tuple(map(ord, send_str))
print l
spi.transfer((l))
示例6: setLaserPower
def setLaserPower(lines):
zchar_loc=lines.index('Z');
i=zchar_loc+1;
while (47<ord(lines[i])<58)|(lines[i]=='.')|(lines[i]=='-'):
i+=1;
lpowr=float(lines[zchar_loc+1:i]);
lpow=int(lpowr*255);
print 'Laser Pow= ', lpow;
spi.transfer((0xB0000, 255-lpow))
示例7: lcd_cmd
def lcd_cmd(cmd):
stat = spi.openSPI(SPI_DEVICE,speed=SPI_SPEED,bits=8)
# print "LCD CMD(1)=%X, SPI_open=" % (cmd) , stat
spi.transfer((0,cmd>>8,0x00ff&cmd,0x11)) # 0x11 - CMD_BE const from ili9341.c
spi.closeSPI()
# time.sleep(0.0001) # 100us
stat = spi.openSPI(SPI_DEVICE,speed=SPI_SPEED,bits=8)
# print "LCD CMD(2)=%X, SPI_open=" % (cmd) , stat
spi.transfer((0,cmd>>8,0x00ff&cmd,0x1B)) # x01B - CMD_AF const from ili9341.c
spi.closeSPI()
return
示例8: lcd_data
def lcd_data(data):
stat = spi.openSPI(SPI_DEVICE,speed=SPI_SPEED,bits=8)
# print "LCD DATA(1)=%X, SPI_open=" % (data) , stat
spi.transfer((0,data>>8,0x00ff&data,0x15)) # 0x15 - DATA_BE const from ili9341.c (BE is short form "before")
spi.closeSPI()
# time.sleep(0.00001) # 10us
stat = spi.openSPI(SPI_DEVICE,speed=SPI_SPEED,bits=8)
# print "LCD DATA(2)=%X, SPI_open=" % (data) , stat
spi.transfer((0,data>>8,0x00ff&data,0x1F)) # 0x1F - DATA_AF const from ili9341.c (AF is short form "after")
spi.closeSPI()
return
示例9: setTLCvalue
def setTLCvalue(data,DCMode):
# put the chip into DC mode
GPIO.output(VPRG, DCMode)
#print tuple(data)
spi.transfer(tuple(data))
# latch data
GPIO.output(XLAT, GPIO.HIGH)
#time.sleep(0.25)
GPIO.output(XLAT, GPIO.LOW)
GPIO.output(VPRG, GPIO.LOW)
示例10: lcd_reset
def lcd_reset():
# for reset I use slow clock - just my habit
stat = spi.openSPI(SPI_DEVICE,speed=1000000,bits=8)
# print "LCD RESET(1), SPI_open=",stat
spi.transfer((0,0,0,0)) # set 0 on U1-Q2
spi.closeSPI()
time.sleep(0.05) # 50ms reset
# unreset
stat = spi.openSPI(SPI_DEVICE,speed=1000000,bits=8)
# print "LCD RESET(2), SPI_open=",stat
spi.transfer((0,0,0,2)) # set 1 on U1-Q2
spi.closeSPI()
time.sleep(0.1) # 100ms after reset
return
示例11: _write_register
def _write_register(self, reg, value):
"""Writes the entire register, identified by its name (datasheet)."""
if reg in short_addr_registers:
reg_addr = short_addr_registers[reg]
bytes = [((reg_addr << 1) + self.short_write_mask), value]
else:
if reg in long_addr_registers:
reg_addr = long_addr_registers[reg]
else:
reg_addr = reg
bytes = []
bytes.append((reg_addr >> 3) + self.long_addr_bit)
bytes.append(((reg_addr << 5) & 0xE0) + self.long_write_mask)
bytes.append(value)
spi.transfer(tuple(bytes))
示例12: drive
def drive(self, dev, value):
if self.devMaxX or self.devMinX or self.devMaxY or self.devMinY is None:
raise Exception("Must override X min and max values")
try:
try:
dev = int(dev)
except ValueError,e:
print "need numeric device ID"
if dev == 1:
newVal = self.__convertValueX(value)
if dev == 2:
newVal = self.__convertValueY(value)
else:
newVal = value
spi.transfer((dev, self.__getBits(newVal)))
示例13: transfer
def transfer(self, data=[]):
if isinstance(data,str):
data = [ord(x) for x in data]
data = tuple(data)
data = spi.transfer(data)
dataout = "".join([chr(x) for x in data])
return dataout
示例14: spi_transfer
def spi_transfer(self, data):
if self.pin_ce != 0:
GPIO.output(self.pin_ce, 0)
r = SPI.transfer(data)
if self.pin_ce != 0:
GPIO.output(self.pin_ce, 1)
return r
示例15: read
def read(self, addr, nb, inc):
transfer_tuple = ()
cmd = (addr << 2) + read_cmd + + (inc << 1)
transfer_tuple = transfer_tuple + ((cmd >> 8),)
transfer_tuple = transfer_tuple + ((cmd & 0x00FF),)
transfer_tuple = transfer_tuple + tuple([0]*nb)
data = spi.transfer(transfer_tuple)
return list(data)[2:]