Skip to content

Commit 5f9e234

Browse files
authored
Merge pull request #14 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 4b6ca8d + c6f35cc commit 5f9e234

File tree

5 files changed

+188
-163
lines changed

5 files changed

+188
-163
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_si4713.py

Lines changed: 87 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import time
3333

3434
from micropython import const
35+
3536
try:
3637
import struct
3738
except ImportError:
@@ -44,62 +45,62 @@
4445
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SI4713.git"
4546

4647

47-
#pylint: disable=bad-whitespace
48+
# pylint: disable=bad-whitespace
4849
# Internal constants:
49-
_SI4710_ADDR0 = const(0x11) # if SEN is = const(low)
50-
_SI4710_ADDR1 = const(0x63) # if SEN is high, default
51-
_SI4710_STATUS_CTS = const(0x80)
52-
_SI4710_CMD_POWER_UP = const(0x01)
53-
_SI4710_CMD_GET_REV = const(0x10)
54-
_SI4710_CMD_POWER_DOWN = const(0x11)
55-
_SI4710_CMD_SET_PROPERTY = const(0x12)
56-
_SI4710_CMD_GET_PROPERTY = const(0x13)
57-
_SI4710_CMD_GET_INT_STATUS = const(0x14)
58-
_SI4710_CMD_PATCH_ARGS = const(0x15)
59-
_SI4710_CMD_PATCH_DATA = const(0x16)
60-
_SI4710_CMD_TX_TUNE_FREQ = const(0x30)
61-
_SI4710_CMD_TX_TUNE_POWER = const(0x31)
62-
_SI4710_CMD_TX_TUNE_MEASURE = const(0x32)
63-
_SI4710_CMD_TX_TUNE_STATUS = const(0x33)
64-
_SI4710_CMD_TX_ASQ_STATUS = const(0x34)
65-
_SI4710_CMD_TX_RDS_BUFF = const(0x35)
66-
_SI4710_CMD_TX_RDS_PS = const(0x36)
67-
_SI4710_CMD_TX_AGC_OVERRIDE = const(0x48)
68-
_SI4710_CMD_GPO_CTL = const(0x80)
69-
_SI4710_CMD_GPO_SET = const(0x81)
70-
_SI4713_PROP_GPO_IEN = const(0x0001)
71-
_SI4713_PROP_DIGITAL_INPUT_FORMAT = const(0x0101)
72-
_SI4713_PROP_DIGITAL_INPUT_SAMPLE_RATE = const(0x0103)
73-
_SI4713_PROP_REFCLK_FREQ = const(0x0201)
74-
_SI4713_PROP_REFCLK_PRESCALE = const(0x0202)
75-
_SI4713_PROP_TX_COMPONENT_ENABLE = const(0x2100)
76-
_SI4713_PROP_TX_AUDIO_DEVIATION = const(0x2101)
77-
_SI4713_PROP_TX_PILOT_DEVIATION = const(0x2102)
78-
_SI4713_PROP_TX_RDS_DEVIATION = const(0x2103)
79-
_SI4713_PROP_TX_LINE_LEVEL_INPUT_LEVEL = const(0x2104)
80-
_SI4713_PROP_TX_LINE_INPUT_MUTE = const(0x2105)
81-
_SI4713_PROP_TX_PREEMPHASIS = const(0x2106)
82-
_SI4713_PROP_TX_PILOT_FREQUENCY = const(0x2107)
83-
_SI4713_PROP_TX_ACOMP_ENABLE = const(0x2200)
84-
_SI4713_PROP_TX_ACOMP_THRESHOLD = const(0x2201)
85-
_SI4713_PROP_TX_ATTACK_TIME = const(0x2202)
86-
_SI4713_PROP_TX_RELEASE_TIME = const(0x2203)
87-
_SI4713_PROP_TX_ACOMP_GAIN = const(0x2204)
88-
_SI4713_PROP_TX_LIMITER_RELEASE_TIME = const(0x2205)
89-
_SI4713_PROP_TX_ASQ_INTERRUPT_SOURCE = const(0x2300)
90-
_SI4713_PROP_TX_ASQ_LEVEL_LOW = const(0x2301)
91-
_SI4713_PROP_TX_ASQ_DURATION_LOW = const(0x2302)
92-
_SI4713_PROP_TX_AQS_LEVEL_HIGH = const(0x2303)
93-
_SI4713_PROP_TX_AQS_DURATION_HIGH = const(0x2304)
94-
_SI4713_PROP_TX_RDS_INTERRUPT_SOURCE = const(0x2C00)
95-
_SI4713_PROP_TX_RDS_PI = const(0x2C01)
96-
_SI4713_PROP_TX_RDS_PS_MIX = const(0x2C02)
97-
_SI4713_PROP_TX_RDS_PS_MISC = const(0x2C03)
98-
_SI4713_PROP_TX_RDS_PS_REPEAT_COUNT = const(0x2C04)
99-
_SI4713_PROP_TX_RDS_MESSAGE_COUNT = const(0x2C05)
100-
_SI4713_PROP_TX_RDS_PS_AF = const(0x2C06)
101-
_SI4713_PROP_TX_RDS_FIFO_SIZE = const(0x2C07)
102-
#pylint: enable=bad-whitespace
50+
_SI4710_ADDR0 = const(0x11) # if SEN is = const(low)
51+
_SI4710_ADDR1 = const(0x63) # if SEN is high, default
52+
_SI4710_STATUS_CTS = const(0x80)
53+
_SI4710_CMD_POWER_UP = const(0x01)
54+
_SI4710_CMD_GET_REV = const(0x10)
55+
_SI4710_CMD_POWER_DOWN = const(0x11)
56+
_SI4710_CMD_SET_PROPERTY = const(0x12)
57+
_SI4710_CMD_GET_PROPERTY = const(0x13)
58+
_SI4710_CMD_GET_INT_STATUS = const(0x14)
59+
_SI4710_CMD_PATCH_ARGS = const(0x15)
60+
_SI4710_CMD_PATCH_DATA = const(0x16)
61+
_SI4710_CMD_TX_TUNE_FREQ = const(0x30)
62+
_SI4710_CMD_TX_TUNE_POWER = const(0x31)
63+
_SI4710_CMD_TX_TUNE_MEASURE = const(0x32)
64+
_SI4710_CMD_TX_TUNE_STATUS = const(0x33)
65+
_SI4710_CMD_TX_ASQ_STATUS = const(0x34)
66+
_SI4710_CMD_TX_RDS_BUFF = const(0x35)
67+
_SI4710_CMD_TX_RDS_PS = const(0x36)
68+
_SI4710_CMD_TX_AGC_OVERRIDE = const(0x48)
69+
_SI4710_CMD_GPO_CTL = const(0x80)
70+
_SI4710_CMD_GPO_SET = const(0x81)
71+
_SI4713_PROP_GPO_IEN = const(0x0001)
72+
_SI4713_PROP_DIGITAL_INPUT_FORMAT = const(0x0101)
73+
_SI4713_PROP_DIGITAL_INPUT_SAMPLE_RATE = const(0x0103)
74+
_SI4713_PROP_REFCLK_FREQ = const(0x0201)
75+
_SI4713_PROP_REFCLK_PRESCALE = const(0x0202)
76+
_SI4713_PROP_TX_COMPONENT_ENABLE = const(0x2100)
77+
_SI4713_PROP_TX_AUDIO_DEVIATION = const(0x2101)
78+
_SI4713_PROP_TX_PILOT_DEVIATION = const(0x2102)
79+
_SI4713_PROP_TX_RDS_DEVIATION = const(0x2103)
80+
_SI4713_PROP_TX_LINE_LEVEL_INPUT_LEVEL = const(0x2104)
81+
_SI4713_PROP_TX_LINE_INPUT_MUTE = const(0x2105)
82+
_SI4713_PROP_TX_PREEMPHASIS = const(0x2106)
83+
_SI4713_PROP_TX_PILOT_FREQUENCY = const(0x2107)
84+
_SI4713_PROP_TX_ACOMP_ENABLE = const(0x2200)
85+
_SI4713_PROP_TX_ACOMP_THRESHOLD = const(0x2201)
86+
_SI4713_PROP_TX_ATTACK_TIME = const(0x2202)
87+
_SI4713_PROP_TX_RELEASE_TIME = const(0x2203)
88+
_SI4713_PROP_TX_ACOMP_GAIN = const(0x2204)
89+
_SI4713_PROP_TX_LIMITER_RELEASE_TIME = const(0x2205)
90+
_SI4713_PROP_TX_ASQ_INTERRUPT_SOURCE = const(0x2300)
91+
_SI4713_PROP_TX_ASQ_LEVEL_LOW = const(0x2301)
92+
_SI4713_PROP_TX_ASQ_DURATION_LOW = const(0x2302)
93+
_SI4713_PROP_TX_AQS_LEVEL_HIGH = const(0x2303)
94+
_SI4713_PROP_TX_AQS_DURATION_HIGH = const(0x2304)
95+
_SI4713_PROP_TX_RDS_INTERRUPT_SOURCE = const(0x2C00)
96+
_SI4713_PROP_TX_RDS_PI = const(0x2C01)
97+
_SI4713_PROP_TX_RDS_PS_MIX = const(0x2C02)
98+
_SI4713_PROP_TX_RDS_PS_MISC = const(0x2C03)
99+
_SI4713_PROP_TX_RDS_PS_REPEAT_COUNT = const(0x2C04)
100+
_SI4713_PROP_TX_RDS_MESSAGE_COUNT = const(0x2C05)
101+
_SI4713_PROP_TX_RDS_PS_AF = const(0x2C06)
102+
_SI4713_PROP_TX_RDS_FIFO_SIZE = const(0x2C07)
103+
# pylint: enable=bad-whitespace
103104

104105

105106
class SI4713:
@@ -141,7 +142,7 @@ def __init__(self, i2c, *, address=_SI4710_ADDR1, reset=None, timeout_s=0.1):
141142
self.reset()
142143
# Check product ID.
143144
if self._get_product_number() != 13:
144-
raise RuntimeError('Failed to find SI4713, check wiring!')
145+
raise RuntimeError("Failed to find SI4713, check wiring!")
145146

146147
def _read_u8(self, address):
147148
# Read an 8-bit unsigned value from the specified 8-bit address.
@@ -182,7 +183,7 @@ def _write_from(self, buf, count=None):
182183
if self._BUFFER[0] & _SI4710_STATUS_CTS > 0:
183184
return
184185
if time.monotonic() - start > self._timeout_s:
185-
raise RuntimeError('Timeout waiting for SI4723 response, check wiring!')
186+
raise RuntimeError("Timeout waiting for SI4723 response, check wiring!")
186187

187188
def _set_property(self, prop, val):
188189
# Set a property of the SI4713 chip. These are both 16-bit values.
@@ -205,10 +206,10 @@ def _get_product_number(self):
205206
i2c.readinto(self._BUFFER, end=9)
206207
return self._BUFFER[1]
207208
# Other potentially useful but unused data:
208-
#fw = (self._BUFFER[2] << 8) | self._BUFFER[3]
209-
#patch = (self._BUFFER[4] << 8) | self._BUFFER[5]
210-
#cmp = (self._BUFFER[6] << 8) | self._BUFFER[7]
211-
#rev = (self._BUFFER[8])
209+
# fw = (self._BUFFER[2] << 8) | self._BUFFER[3]
210+
# patch = (self._BUFFER[4] << 8) | self._BUFFER[5]
211+
# cmp = (self._BUFFER[6] << 8) | self._BUFFER[7]
212+
# rev = (self._BUFFER[8])
212213

213214
def reset(self):
214215
"""Perform a reset of the chip using the reset line. Will also
@@ -258,7 +259,7 @@ def _poll_interrupt_status(self, expected):
258259
while self.interrupt_status != expected:
259260
time.sleep(0.01) # Short delay for other processing.
260261
if time.monotonic() - start > self._timeout_s:
261-
raise RuntimeError('Timeout waiting for SI4713 to respond!')
262+
raise RuntimeError("Timeout waiting for SI4713 to respond!")
262263

263264
def _tune_status(self):
264265
# Retrieve the tune status command values from the radio. Will store
@@ -372,8 +373,7 @@ def received_noise_level(self, frequency_khz, antenna_capacitance=0):
372373
# Validate frequency and capacitance.
373374
assert 76000 <= frequency_khz <= 108000
374375
assert (frequency_khz % 50) == 0
375-
assert antenna_capacitance == 0 or \
376-
(0.25 <= antenna_capacitance <= 47.75)
376+
assert antenna_capacitance == 0 or (0.25 <= antenna_capacitance <= 47.75)
377377
# Convert frequency and capacitance to units used by the chip.
378378
frequency_khz = (frequency_khz // 10) & 0xFFFF
379379
antenna_capacitance = int(antenna_capacitance / 0.25)
@@ -398,7 +398,8 @@ def input_level(self):
398398
"""
399399
# Perform ASQ request, then parse out 8 bit _signed_ input level value.
400400
self._asq_status()
401-
return struct.unpack('bbbbb', self._BUFFER[0:5])[4]
401+
return struct.unpack("bbbbb", self._BUFFER[0:5])[4]
402+
402403
@property
403404
def audio_signal_status(self):
404405
"""Retrieve the ASQ or audio signal quality status value from the chip.
@@ -461,9 +462,9 @@ def _set_rds_station(self, station):
461462
self._BUFFER[0] = _SI4710_CMD_TX_RDS_PS
462463
self._BUFFER[1] = i // 4
463464
self._BUFFER[2] = station[i] if i < station_length else 0x00
464-
self._BUFFER[3] = station[i+1] if i+1 < station_length else 0x00
465-
self._BUFFER[4] = station[i+2] if i+2 < station_length else 0x00
466-
self._BUFFER[5] = station[i+3] if i+3 < station_length else 0x00
465+
self._BUFFER[3] = station[i + 1] if i + 1 < station_length else 0x00
466+
self._BUFFER[4] = station[i + 2] if i + 2 < station_length else 0x00
467+
self._BUFFER[5] = station[i + 3] if i + 3 < station_length else 0x00
467468
self._write_from(self._BUFFER, count=6)
468469

469470
def _set_rds_buffer(self, rds_buffer):
@@ -478,22 +479,30 @@ def _set_rds_buffer(self, rds_buffer):
478479
self._BUFFER[2] = 0x20
479480
self._BUFFER[3] = i // 4
480481
self._BUFFER[4] = rds_buffer[i] if i < buf_length else 0x00
481-
self._BUFFER[5] = rds_buffer[i+1] if i+1 < buf_length else 0x00
482-
self._BUFFER[6] = rds_buffer[i+2] if i+2 < buf_length else 0x00
483-
self._BUFFER[7] = rds_buffer[i+3] if i+3 < buf_length else 0x00
482+
self._BUFFER[5] = rds_buffer[i + 1] if i + 1 < buf_length else 0x00
483+
self._BUFFER[6] = rds_buffer[i + 2] if i + 2 < buf_length else 0x00
484+
self._BUFFER[7] = rds_buffer[i + 3] if i + 3 < buf_length else 0x00
484485
self._write_from(self._BUFFER, count=8)
485486

486-
rds_station = property(None, _set_rds_station, None,
487-
"""Set the RDS broadcast station to the specified
487+
rds_station = property(
488+
None,
489+
_set_rds_station,
490+
None,
491+
"""Set the RDS broadcast station to the specified
488492
byte string. Can be at most 96 bytes long and will
489493
be padded with blank spaces if less.
490-
""")
491-
492-
rds_buffer = property(None, _set_rds_buffer, None,
493-
"""Set the RDS broadcast buffer to the specified byte
494+
""",
495+
)
496+
497+
rds_buffer = property(
498+
None,
499+
_set_rds_buffer,
500+
None,
501+
"""Set the RDS broadcast buffer to the specified byte
494502
string. Can be at most 106 bytes long and will be
495503
padded with blank spaces if less.
496-
""")
504+
""",
505+
)
497506

498507
def configure_rds(self, program_id, station=None, rds_buffer=None):
499508
"""Configure and enable the RDS broadcast of the specified program ID.

0 commit comments

Comments
 (0)