pylint radio example

This commit is contained in:
brentru 2018-12-28 14:23:35 -05:00
parent e8245f28c5
commit 6e8ef8b734

View file

@ -48,59 +48,28 @@ rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0)
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'
packet_data = bytes('Hello Feather!\r\n',"utf-8")
# packet = rfm69.receive()
packet = None
def receive_mode():
"""Switches the radio to only recieve packets.
"""
display.fill(0)
display.text('RX Mode', 25, 0, 1)
packet = None
while packet is None:
packet = rfm69.receive()
display.text('Waiting for packet...', 0, 20, 1)
display.show()
packet_text = str(packet, 'ascii')
draw.text((x, top+16),'RX: {0}'.format(packet_text), font=font, fill=255)
draw.text((x, top+25),'RSSI {0} dB'.format(rfm69.rssi), font=font, fill=255)
def send_mode():
"""Switches the radio to only send packets.
"""
def send_mode_interval(time):
"""Sends packets every interval.
:param int time: Time to repeatedly send the packet, in seconds.
"""
"""Switches the radio to only recieve packets.
"""
display.fill(0)
display.text('RX Mode', 25, 0, 1)
while packet is None:
#packet = rfm69.receive()
display.text('Waiting for packet...', 0, 20, 1)
display.show()
#packet_text = str(packet, 'ascii')
display.text('RX: ', 0, 35, 1)
display.text(packet_text, 5, 35, 1)
display.text('RSSI: ', 0, 45, 1)
display.text(rfm69.rssi, 7, 45, 1)
while True:
# Draw a black filled box to clear the image.
packet = None
display.fill(0)
display.text('RasPi Radio', 35, 0, 1)
if not btnA.value:
# Send Data
rfm69.send(packet_data)
display.text('Sent Packet', 35, 25, 1)
display.show()
time.sleep(0.5)
if not btnB.value:
# switch to RX only
receive_mode()
if not btnC.value:
# Display the previous packet text and rssi
if prev_packet is not None:
packet_text = str(prev_packet, 'ascii')
display.text('RX: ', 0, 35, 1)
display.text(packet_text, 5, 35, 1)
display.text('RSSI: ', 0, 45, 1)
display.text(rfm69.rssi, 7, 45, 1)
display.text('No Pkt RCVd', 0, 16, 1)
display.show()
time.sleep(1)
# default to rx mode, poll in background loop
packet = rfm69.receive()
print(packet)
@ -117,5 +86,26 @@ while True:
display.text(rfm69.rssi, 7, 45, 1)
prev_packet = packet
if not btnA.value:
# Send Data
rfm69.send(packet_data)
display.text('Sent Packet', 35, 25, 1)
display.show()
time.sleep(0.5)
if not btnB.value:
# switch to RX only
receive_mode()
if not btnC.value:
# Display the previous packet text and rssi
if prev_packet is not None:
packet_text = str(prev_packet, 'ascii')
display.text('RX: ', 0, 35, 1)
display.text(packet_text, 5, 35, 1)
display.text('RSSI: ', 0, 45, 1)
display.text(rfm69.rssi, 7, 45, 1)
display.text('No Pkt RCVd', 0, 16, 1)
display.show()
time.sleep(1)
display.show()
time.sleep(0.1)
time.sleep(0.1)