-
Notifications
You must be signed in to change notification settings - Fork 26
implement a few size reduction changes #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3e64211
c681be6
2c0bfc2
af447e4
873ff8c
85c6655
e5bd457
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,12 +253,9 @@ def __set__(self, obj, val): | |
crc_auto_clear_off = _RegisterBits(_REG_PACKET_CONFIG1, offset=3, bits=1) | ||
address_filter = _RegisterBits(_REG_PACKET_CONFIG1, offset=1, bits=2) | ||
mode_ready = _RegisterBits(_REG_IRQ_FLAGS1, offset=7) | ||
rx_ready = _RegisterBits(_REG_IRQ_FLAGS1, offset=6) | ||
tx_ready = _RegisterBits(_REG_IRQ_FLAGS1, offset=5) | ||
dio_0_mapping = _RegisterBits(_REG_DIO_MAPPING1, offset=6, bits=2) | ||
packet_sent = _RegisterBits(_REG_IRQ_FLAGS2, offset=3) | ||
payload_ready = _RegisterBits(_REG_IRQ_FLAGS2, offset=2) | ||
|
||
# pylint: disable=too-many-statements | ||
def __init__( | ||
self, | ||
spi, | ||
|
@@ -300,8 +297,26 @@ def __init__( | |
self.preamble_length = preamble_length # Set the preamble length. | ||
self.frequency_mhz = frequency # Set frequency. | ||
self.encryption_key = encryption_key # Set encryption key. | ||
# set radio configuration parameters | ||
self._configure_radio() | ||
# Configure modulation for RadioHead library GFSK_Rb250Fd250 mode | ||
# by default. Users with advanced knowledge can manually reconfigure | ||
# for any other mode (consulting the datasheet is absolutely | ||
# necessary!). | ||
self.data_mode = 0b00 # Packet mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This got me thinking - are any of these values default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. data_mode and modulation_type are the defaults -- I'll remove them |
||
self.modulation_type = 0b00 # FSK modulation | ||
self.modulation_shaping = 0b01 # Gaussian filter, BT=1.0 | ||
self.bitrate = 250000 # 250kbs | ||
self.frequency_deviation = 250000 # 250khz | ||
self.rx_bw_dcc_freq = 0b111 # RxBw register = 0xE0 | ||
self.rx_bw_mantissa = 0b00 | ||
self.rx_bw_exponent = 0b000 | ||
self.afc_bw_dcc_freq = 0b111 # AfcBw register = 0xE0 | ||
self.afc_bw_mantissa = 0b00 | ||
self.afc_bw_exponent = 0b000 | ||
self.packet_format = 1 # Variable length. | ||
self.dc_free = 0b10 # Whitening | ||
# Set transmit power to 13 dBm, a safe value any module supports. | ||
self.tx_power = 13 | ||
|
||
# initialize last RSSI reading | ||
self.last_rssi = 0.0 | ||
"""The RSSI of the last received packet. Stored when the packet was received. | ||
|
@@ -354,29 +369,7 @@ def __init__( | |
Fourth byte of the RadioHead header. | ||
""" | ||
|
||
def _configure_radio(self): | ||
# Configure modulation for RadioHead library GFSK_Rb250Fd250 mode | ||
# by default. Users with advanced knowledge can manually reconfigure | ||
# for any other mode (consulting the datasheet is absolutely | ||
# necessary!). | ||
self.data_mode = 0b00 # Packet mode | ||
self.modulation_type = 0b00 # FSK modulation | ||
self.modulation_shaping = 0b01 # Gaussian filter, BT=1.0 | ||
self.bitrate = 250000 # 250kbs | ||
self.frequency_deviation = 250000 # 250khz | ||
self.rx_bw_dcc_freq = 0b111 # RxBw register = 0xE0 | ||
self.rx_bw_mantissa = 0b00 | ||
self.rx_bw_exponent = 0b000 | ||
self.afc_bw_dcc_freq = 0b111 # AfcBw register = 0xE0 | ||
self.afc_bw_mantissa = 0b00 | ||
self.afc_bw_exponent = 0b000 | ||
self.packet_format = 1 # Variable length. | ||
self.dc_free = 0b10 # Whitening | ||
self.crc_on = 1 # CRC enabled | ||
self.crc_auto_clear = 0 # Clear FIFO on CRC fail | ||
self.address_filtering = 0b00 # No address filtering | ||
# Set transmit power to 13 dBm, a safe value any module supports. | ||
self.tx_power = 13 | ||
# pylint: enable=too-many-statements | ||
|
||
# pylint: disable=no-member | ||
# Reconsider this disable when it can be tested. | ||
|
@@ -722,6 +715,14 @@ def frequency_deviation(self, val): | |
self._write_u8(_REG_FDEV_MSB, fdev >> 8) | ||
self._write_u8(_REG_FDEV_LSB, fdev & 0xFF) | ||
|
||
def packet_sent(self): | ||
"""Transmit status""" | ||
return (self._read_u8(_REG_IRQ_FLAGS2) & 0x8) >> 3 | ||
|
||
def payload_ready(self): | ||
"""Receive status""" | ||
return (self._read_u8(_REG_IRQ_FLAGS2) & 0x4) >> 2 | ||
|
||
def send( | ||
self, | ||
data, | ||
|
@@ -781,7 +782,7 @@ def send( | |
# best that can be done right now without interrupts). | ||
start = time.monotonic() | ||
timed_out = False | ||
while not timed_out and not self.packet_sent: | ||
while not timed_out and not self.packet_sent(): | ||
if (time.monotonic() - start) >= self.xmit_timeout: | ||
timed_out = True | ||
# Listen again if requested. | ||
|
@@ -858,7 +859,7 @@ def receive( | |
self.listen() | ||
start = time.monotonic() | ||
timed_out = False | ||
while not timed_out and not self.payload_ready: | ||
while not timed_out and not self.payload_ready(): | ||
if (time.monotonic() - start) >= timeout: | ||
timed_out = True | ||
# Payload ready is set, a packet is in the FIFO. | ||
|
@@ -893,10 +894,9 @@ def receive( | |
# delay before sending Ack to give receiver a chance to get ready | ||
if self.ack_delay is not None: | ||
time.sleep(self.ack_delay) | ||
# send ACK packet to sender | ||
data = bytes("!", "UTF-8") | ||
# send ACK packet to sender (data is b'!') | ||
self.send( | ||
data, | ||
b"!", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just seemed simpler to do it this way. The ACK packet is always just "!" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the original |
||
destination=packet[1], | ||
node=packet[0], | ||
identifier=packet[2], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason you removed
configure_radio
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting the code inline rather than as a function call saved 80 bytes!