本文整理汇总了Python中pyb.USB_VCP属性的典型用法代码示例。如果您正苦于以下问题:Python pyb.USB_VCP属性的具体用法?Python pyb.USB_VCP怎么用?Python pyb.USB_VCP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyb
的用法示例。
在下文中一共展示了pyb.USB_VCP属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import USB_VCP [as 别名]
def main():
import pyb
serial = pyb.USB_VCP()
midi = MidiOut(serial, channel=1)
switch = pyb.Switch()
if hasattr(pyb, 'Accel'):
accel = pyb.Accel()
SCALE = 1.27
else:
from staccel import STAccel
accel = STAccel()
SCALE = 127
while True:
while not switch():
pyb.delay(10)
note = abs(int(accel.x() * SCALE))
velocity = abs(int(accel.y() * SCALE))
midi.note_on(note, velocity)
while switch():
pyb.delay(50)
midi.note_off(note)
示例2: init
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import USB_VCP [as 别名]
def init(self):
# doesn't work if it was enabled and then disabled
if self.usb is None:
self.usb = pyb.USB_VCP()
self.usb.init(flow=(pyb.USB_VCP.RTS | pyb.USB_VCP.CTS))
示例3: set_usb_mode
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import USB_VCP [as 别名]
def set_usb_mode(dev=False, usb=False):
if simulator:
print("dev:", dev, ", usb:", usb)
# now get correct mode
if usb and not dev:
pyb.usb_mode("VCP")
if not simulator:
os.dupterm(None,0)
os.dupterm(None,1)
elif usb and dev:
pyb.usb_mode("VCP+MSC")
if not simulator:
# duplicate repl to stlink
# as usb is busy for communication
os.dupterm(stlk,0)
os.dupterm(None,1)
elif not usb and dev:
pyb.usb_mode("VCP+MSC")
usb = pyb.USB_VCP()
if not simulator:
os.dupterm(None,0)
os.dupterm(usb,1)
else:
pyb.usb_mode(None)
if not simulator:
os.dupterm(None,0)
os.dupterm(None,1)
示例4: term_size
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import USB_VCP [as 别名]
def term_size():
"""Print out a sequence of ANSI escape code which will report back the
size of the window.
"""
# ESC 7 - Save cursor position
# ESC 8 - Restore cursor position
# ESC [r - Enable scrolling for entire display
# ESC [row;colH - Move to cursor position
# ESC [6n - Device Status Report - send ESC [row;colR
repl= None
if 'repl_source' in dir(pyb):
repl = pyb.repl_source()
if repl is None:
repl = pyb.USB_VCP()
repl.send(b'\x1b7\x1b[r\x1b[999;999H\x1b[6n')
pos = b''
while True:
char = repl.recv(1)
if char == b'R':
break
if char != b'\x1b' and char != b'[':
pos += char
repl.send(b'\x1b8')
(height, width) = [int(i, 10) for i in pos.split(b';')]
return height, width
# def term_size():
# return (25, 80)
示例5: recv_file_from_host
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import USB_VCP [as 别名]
def recv_file_from_host(src_file, dst_filename, filesize, dst_mode='wb'):
"""Function which runs on the pyboard. Matches up with send_file_to_remote."""
import sys
import ubinascii
import os
if HAS_BUFFER:
try:
import pyb
usb = pyb.USB_VCP()
except:
try:
import machine
usb = machine.USB_VCP()
except:
usb = None
if usb and usb.isconnected():
# We don't want 0x03 bytes in the data to be interpreted as a Control-C
# This gets reset each time the REPL runs a line, so we don't need to
# worry about resetting it ourselves
usb.setinterrupt(-1)
try:
with open(dst_filename, dst_mode) as dst_file:
bytes_remaining = filesize
if not HAS_BUFFER:
bytes_remaining *= 2 # hexlify makes each byte into 2
buf_size = BUFFER_SIZE
write_buf = bytearray(buf_size)
read_buf = bytearray(buf_size)
while bytes_remaining > 0:
# Send back an ack as a form of flow control
sys.stdout.write('\x06')
read_size = min(bytes_remaining, buf_size)
buf_remaining = read_size
buf_index = 0
while buf_remaining > 0:
if HAS_BUFFER:
bytes_read = sys.stdin.buffer.readinto(read_buf, read_size)
else:
bytes_read = sys.stdin.readinto(read_buf, read_size)
if bytes_read > 0:
write_buf[buf_index:bytes_read] = read_buf[0:bytes_read]
buf_index += bytes_read
buf_remaining -= bytes_read
if HAS_BUFFER:
dst_file.write(write_buf[0:read_size])
else:
dst_file.write(ubinascii.unhexlify(write_buf[0:read_size]))
if hasattr(os, 'sync'):
os.sync()
bytes_remaining -= read_size
return True
except:
return False