1
- # The MIT License (MIT)
1
+ # SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
2
2
#
3
- # Copyright (c) 2017 Tony DiCola for Adafruit Industries
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # SPDX-License-Identifier: MIT
4
+
22
5
"""
23
6
`adafruit_rfm69`
24
7
====================================================
@@ -431,7 +414,7 @@ def sleep(self):
431
414
432
415
def listen (self ):
433
416
"""Listen for packets to be received by the chip. Use :py:func:`receive` to listen, wait
434
- and retrieve packets as they're available.
417
+ and retrieve packets as they're available.
435
418
"""
436
419
# Like RadioHead library, turn off high power boost if enabled.
437
420
if self ._tx_power >= 18 :
@@ -444,8 +427,8 @@ def listen(self):
444
427
445
428
def transmit (self ):
446
429
"""Transmit a packet which is queued in the FIFO. This is a low level function for
447
- entering transmit mode and more. For generating and transmitting a packet of data use
448
- :py:func:`send` instead.
430
+ entering transmit mode and more. For generating and transmitting a packet of data use
431
+ :py:func:`send` instead.
449
432
"""
450
433
# Like RadioHead library, turn on high power boost if enabled.
451
434
if self ._tx_power >= 18 :
@@ -459,9 +442,9 @@ def transmit(self):
459
442
@property
460
443
def temperature (self ):
461
444
"""The internal temperature of the chip in degrees Celsius. Be warned this is not
462
- calibrated or very accurate.
445
+ calibrated or very accurate.
463
446
464
- .. warning:: Reading this will STOP any receiving/sending that might be happening!
447
+ .. warning:: Reading this will STOP any receiving/sending that might be happening!
465
448
"""
466
449
# Start a measurement then poll the measurement finished bit.
467
450
self .temp_start = 1
@@ -475,9 +458,9 @@ def temperature(self):
475
458
@property
476
459
def operation_mode (self ):
477
460
"""The operation mode value. Unless you're manually controlling the chip you shouldn't
478
- change the operation_mode with this property as other side-effects are required for
479
- changing logical modes--use :py:func:`idle`, :py:func:`sleep`, :py:func:`transmit`,
480
- :py:func:`listen` instead to signal intent for explicit logical modes.
461
+ change the operation_mode with this property as other side-effects are required for
462
+ changing logical modes--use :py:func:`idle`, :py:func:`sleep`, :py:func:`transmit`,
463
+ :py:func:`listen` instead to signal intent for explicit logical modes.
481
464
"""
482
465
op_mode = self ._read_u8 (_REG_OP_MODE )
483
466
return (op_mode >> 2 ) & 0b111
@@ -497,10 +480,10 @@ def operation_mode(self, val):
497
480
@property
498
481
def sync_word (self ):
499
482
"""The synchronization word value. This is a byte string up to 8 bytes long (64 bits)
500
- which indicates the synchronization word for transmitted and received packets. Any
501
- received packet which does not include this sync word will be ignored. The default value
502
- is 0x2D, 0xD4 which matches the RadioHead RFM69 library. Setting a value of None will
503
- disable synchronization word matching entirely.
483
+ which indicates the synchronization word for transmitted and received packets. Any
484
+ received packet which does not include this sync word will be ignored. The default value
485
+ is 0x2D, 0xD4 which matches the RadioHead RFM69 library. Setting a value of None will
486
+ disable synchronization word matching entirely.
504
487
"""
505
488
# Handle when sync word is disabled..
506
489
if not self .sync_on :
@@ -529,8 +512,8 @@ def sync_word(self, val):
529
512
@property
530
513
def preamble_length (self ):
531
514
"""The length of the preamble for sent and received packets, an unsigned 16-bit value.
532
- Received packets must match this length or they are ignored! Set to 4 to match the
533
- RadioHead RFM69 library.
515
+ Received packets must match this length or they are ignored! Set to 4 to match the
516
+ RadioHead RFM69 library.
534
517
"""
535
518
msb = self ._read_u8 (_REG_PREAMBLE_MSB )
536
519
lsb = self ._read_u8 (_REG_PREAMBLE_LSB )
@@ -545,7 +528,7 @@ def preamble_length(self, val):
545
528
@property
546
529
def frequency_mhz (self ):
547
530
"""The frequency of the radio in Megahertz. Only the allowed values for your radio must be
548
- specified (i.e. 433 vs. 915 mhz)!
531
+ specified (i.e. 433 vs. 915 mhz)!
549
532
"""
550
533
# FRF register is computed from the frequency following the datasheet.
551
534
# See section 6.2 and FRF register description.
@@ -573,9 +556,9 @@ def frequency_mhz(self, val):
573
556
@property
574
557
def encryption_key (self ):
575
558
"""The AES encryption key used to encrypt and decrypt packets by the chip. This can be set
576
- to None to disable encryption (the default), otherwise it must be a 16 byte long byte
577
- string which defines the key (both the transmitter and receiver must use the same key
578
- value).
559
+ to None to disable encryption (the default), otherwise it must be a 16 byte long byte
560
+ string which defines the key (both the transmitter and receiver must use the same key
561
+ value).
579
562
"""
580
563
# Handle if encryption is disabled.
581
564
if self .aes_on == 0 :
@@ -599,8 +582,8 @@ def encryption_key(self, val):
599
582
@property
600
583
def tx_power (self ):
601
584
"""The transmit power in dBm. Can be set to a value from -2 to 20 for high power devices
602
- (RFM69HCW, high_power=True) or -18 to 13 for low power devices. Only integer power
603
- levels are actually set (i.e. 12.5 will result in a value of 12 dBm).
585
+ (RFM69HCW, high_power=True) or -18 to 13 for low power devices. Only integer power
586
+ levels are actually set (i.e. 12.5 will result in a value of 12 dBm).
604
587
"""
605
588
# Follow table 10 truth table from the datasheet for determining power
606
589
# level from the individual PA level bits and output power register.
@@ -661,17 +644,17 @@ def tx_power(self, val):
661
644
@property
662
645
def rssi (self ):
663
646
"""The received strength indicator (in dBm).
664
- May be inaccuate if not read immediatey. last_rssi contains the value read immediately
665
- receipt of the last packet.
647
+ May be inaccuate if not read immediatey. last_rssi contains the value read immediately
648
+ receipt of the last packet.
666
649
"""
667
650
# Read RSSI register and convert to value using formula in datasheet.
668
651
return - self ._read_u8 (_REG_RSSI_VALUE ) / 2.0
669
652
670
653
@property
671
654
def bitrate (self ):
672
655
"""The modulation bitrate in bits/second (or chip rate if Manchester encoding is enabled).
673
- Can be a value from ~489 to 32mbit/s, but see the datasheet for the exact supported
674
- values.
656
+ Can be a value from ~489 to 32mbit/s, but see the datasheet for the exact supported
657
+ values.
675
658
"""
676
659
msb = self ._read_u8 (_REG_BITRATE_MSB )
677
660
lsb = self ._read_u8 (_REG_BITRATE_LSB )
@@ -719,17 +702,17 @@ def send(
719
702
flags = None
720
703
):
721
704
"""Send a string of data using the transmitter.
722
- You can only send 60 bytes at a time
723
- (limited by chip's FIFO size and appended headers).
724
- This appends a 4 byte header to be compatible with the RadioHead library.
725
- The header defaults to using the initialized attributes:
726
- (destination,node,identifier,flags)
727
- It may be temporarily overidden via the kwargs - destination,node,identifier,flags.
728
- Values passed via kwargs do not alter the attribute settings.
729
- The keep_listening argument should be set to True if you want to start listening
730
- automatically after the packet is sent. The default setting is False.
731
-
732
- Returns: True if success or False if the send timed out.
705
+ You can only send 60 bytes at a time
706
+ (limited by chip's FIFO size and appended headers).
707
+ This appends a 4 byte header to be compatible with the RadioHead library.
708
+ The header defaults to using the initialized attributes:
709
+ (destination,node,identifier,flags)
710
+ It may be temporarily overidden via the kwargs - destination,node,identifier,flags.
711
+ Values passed via kwargs do not alter the attribute settings.
712
+ The keep_listening argument should be set to True if you want to start listening
713
+ automatically after the packet is sent. The default setting is False.
714
+
715
+ Returns: True if success or False if the send timed out.
733
716
"""
734
717
# Disable pylint warning to not use length as a check for zero.
735
718
# This is a puzzling warning as the below code is clearly the most
@@ -780,9 +763,9 @@ def send(
780
763
781
764
def send_with_ack (self , data ):
782
765
"""Reliable Datagram mode:
783
- Send a packet with data and wait for an ACK response.
784
- The packet header is automatically generated.
785
- If enabled, the packet transmission will be retried on failure
766
+ Send a packet with data and wait for an ACK response.
767
+ The packet header is automatically generated.
768
+ If enabled, the packet transmission will be retried on failure
786
769
"""
787
770
if self .ack_retries :
788
771
retries_remaining = self .ack_retries
@@ -820,18 +803,18 @@ def receive(
820
803
self , * , keep_listening = True , with_ack = False , timeout = None , with_header = False
821
804
):
822
805
"""Wait to receive a packet from the receiver. If a packet is found the payload bytes
823
- are returned, otherwise None is returned (which indicates the timeout elapsed with no
824
- reception).
825
- If keep_listening is True (the default) the chip will immediately enter listening mode
826
- after reception of a packet, otherwise it will fall back to idle mode and ignore any
827
- future reception.
828
- All packets must have a 4 byte header for compatibilty with the
829
- RadioHead library.
830
- The header consists of 4 bytes (To,From,ID,Flags). The default setting will strip
831
- the header before returning the packet to the caller.
832
- If with_header is True then the 4 byte header will be returned with the packet.
833
- The payload then begins at packet[4].
834
- If with_ack is True, send an ACK after receipt (Reliable Datagram mode)
806
+ are returned, otherwise None is returned (which indicates the timeout elapsed with no
807
+ reception).
808
+ If keep_listening is True (the default) the chip will immediately enter listening mode
809
+ after reception of a packet, otherwise it will fall back to idle mode and ignore any
810
+ future reception.
811
+ All packets must have a 4 byte header for compatibilty with the
812
+ RadioHead library.
813
+ The header consists of 4 bytes (To,From,ID,Flags). The default setting will strip
814
+ the header before returning the packet to the caller.
815
+ If with_header is True then the 4 byte header will be returned with the packet.
816
+ The payload then begins at packet[4].
817
+ If with_ack is True, send an ACK after receipt (Reliable Datagram mode)
835
818
"""
836
819
timed_out = False
837
820
if timeout is None :
0 commit comments