本文整理汇总了Python中pigpio.pulse方法的典型用法代码示例。如果您正苦于以下问题:Python pigpio.pulse方法的具体用法?Python pigpio.pulse怎么用?Python pigpio.pulse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pigpio
的用法示例。
在下文中一共展示了pigpio.pulse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play_tone
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def play_tone(self, topic, payload):
"""
This method plays a tone on a piezo device connected to the selected
pin at the frequency and duration requested.
Frequency is in hz and duration in milliseconds.
Call set_mode_tone before using this method.
:param topic: message topic
:param payload: {"command": "play_tone", "pin": “PIN”, "tag": "TAG",
“freq”: ”FREQUENCY”, duration: “DURATION”}
"""
pin = int(payload['pin'])
self.pi.set_mode(pin, pigpio.OUTPUT)
frequency = int(payload['freq'])
frequency = int((1000 / frequency) * 1000)
tone = [pigpio.pulse(1 << pin, 0, frequency),
pigpio.pulse(0, 1 << pin, frequency)]
self.pi.wave_add_generic(tone)
wid = self.pi.wave_create()
if wid >= 0:
self.pi.wave_send_repeat(wid)
time.sleep(payload['duration'] / 1000)
self.pi.wave_tx_stop()
self.pi.wave_delete(wid)
示例2: decode
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def decode(bits: str) -> bytes:
if bits.count('X') != 0:
raise DecodeError('Message ignored (bad pulse width in {:d} bits): '.format(bits.count('X')) + bits)
raw_hex = ''
for i in range(0, len(bits), 4):
nibble = "{:X}".format(int(bits[i:i+4][::-1], 2)) # Zero-fill of partial nibbles
raw_hex += nibble
try:
origin = DeviceType(int(raw_hex[16], 16))
except:
raise DecodeError('Invalid origin: [' + raw_hex[16:18][::-1] + '], Raw: ' + raw_hex);
if origin == DeviceType.BASE_STATION:
unswapped = raw_hex[:-2] # Strip end delimeter
else:
rd = raw_hex.find('F' + raw_hex[0:4])
unswapped = raw_hex[:rd] # Strip end delimeter and repeated sequence
if len(unswapped) % 2 == 1:
raise DecodeError('Message ignored (odd byte count: ' + str(len(unswapped)) + ')')
swapped = bytes()
for i in range(0, len(unswapped), 2):
swapped += bytes([int(unswapped[i + 1] + unswapped[i], 16)]) # Swap nibbles and convert to bytes
return swapped
示例3: release
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def release(self):
"""
Simply releases the pigpio resources
"""
self.pig.stop()
#
# def make_wave(self, duration=None):
# """
# Args:
# duration:
# """
#
# # Typically duration is stored as an attribute, but if we are passed one...
# if duration:
# self.duration = int(duration)
#
# # Make a pulse (duration is in microseconds for pigpio, ours is in milliseconds
# # Pulses are (pin to turn on, pin to turn off, delay)
# # So we add two pulses, one to turn the pin on with a delay,
# # then a second to turn the pin off with no delay.
# reward_pulse = []
# reward_pulse.append(pigpio.pulse(1<<self.pin, 0, self.duration*1000))
# reward_pulse.append(pigpio.pulse(0, 1<<self.pin, 0))
#
# self.pig.wave_add_generic(reward_pulse)
# self.wave_id = self.pig.wave_create()
示例4: thresh_trig
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def thresh_trig(self):
if self.digi_out:
self.digi_out.pulse()
self.measure_evt.clear()
示例5: __init__
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def __init__(self, pin, pulse_width=100, polarity=False):
"""
Args:
pin (int):
pulse_width (int): Width of digital output pulse (us). range: 1-100
polarity (bool): Whether 'off' is Low (False, default) and pulses bring the voltage High, or vice versa (True)
"""
self.pig = pigpio.pi()
# convert from board to bcm numbering
self.pin = BOARD_TO_BCM[int(pin)]
self.pulse_width = np.clip(pulse_width, 0, 100).astype(np.int)
# get logic direction
self.on = 1
self.off = 0
self.polarity = polarity
if not self.polarity:
self.on = 0
self.off = 1
# setup pin
self.pig.set_mode(self.pin, pigpio.OUTPUT)
self.pig.write(self.pin, self.off)
示例6: pulse
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def pulse(self, duration=None):
if not duration:
self.pig.gpio_trigger(self.pin, self.pulse_width, self.on)
elif duration:
duration = np.clip(duration, 0, 100).astype(np.int)
self.pig.gpio_trigger(self.pin,
duration,
self.on)
示例7: _make_waveform
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def _make_waveform(self, waveform):
wf = []
# Bit mask for GPIO pin number
pin = 1<<self._pin
# Convert to waveformat required by pigpio
for val, t in waveform:
if val:
wf.append(pigpio.pulse(pin, 0, t))
else:
wf.append(pigpio.pulse(0, pin, t))
return wf
示例8: _nibble
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def _nibble(self, nibble):
for i in range(6):
if nibble & (1<<i):
self.wf.append(pigpio.pulse(self.txbit, 0, self.mics))
else:
self.wf.append(pigpio.pulse(0, self.txbit, self.mics))
示例9: _listen_cbf
# 需要导入模块: import pigpio [as 别名]
# 或者: from pigpio import pulse [as 别名]
def _listen_cbf(self, gpio, level, tick):
if self._rx_done:
return
if self._rx_t is None:
self._rx_t = tick
return # First edge
if self._rx_t > tick:
dt = ((tick << 32) - self._rx_t) / 1000 # Tick overflow
else:
dt = (tick - self._rx_t) / 1000 # Convert to ms
self._rx_t = tick
if dt > 2.1:
if self._rx_preamble_high:
self._rx_done = True # End of transmission
else:
self._rx_start_flag0 = False # Malformed
return
if dt > 1.9:
if self._rx_sync_buffer == '1111': # Check for at least 2 SYNC periods
if level == 1:
self._rx_preamble_low = True # Valid preamble low pulse
self._rx_preamble_high = False
elif self._rx_preamble_low:
self._rx_preamble_high = True # Valid preamble high pulse
self._rx_buffer = '' # Data follows preamble
else:
self._rx_preamble_low = False
return
if dt > 1.1:
bit = 'X' # Invalid duration
elif dt >= 0.9:
bit = '1'
elif dt > 0.6:
bit = 'X' # Invalid duration
else:
bit = '0'
self._rx_sync_buffer += bit # Append SYNC buffer
self._rx_sync_buffer = self._rx_sync_buffer[-4:] # Limit SYNC buffer to 2 periods
if self._rx_preamble_high:
self._rx_buffer += bit # Append buffer
else:
self._rx_buffer = '' # Don't append buffer if no valid preamble