Skip to content

Commit 55d3eb4

Browse files
committed
docs done for now
1 parent bcf211c commit 55d3eb4

File tree

5 files changed

+66
-63
lines changed

5 files changed

+66
-63
lines changed

adafruit_tla202x/__init__.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
21
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
32
#
43
# SPDX-License-Identifier: MIT
@@ -202,18 +201,13 @@ class Mux(CV):
202201
)
203202

204203

205-
# TODO: Verify/fix negative voltages
206-
# * check sign conversion
207-
# implement AnalogIo/ AnalogRead API
208-
# GND – 0.3 V < V(AINX) < VDD + 0.3 V
209-
210-
211204
class TLA2024: # pylint:disable=too-many-instance-attributes
212-
"""I2C Interface for analog voltage measurements using the TI TLA2024 12-bit 4-channel ADC
205+
"""
206+
207+
I2C Interface for analog voltage measurements using the TI TLA2024 12-bit 4-channel ADC
213208
214-
params:
215-
:param ~busio.I2C i2c_bus: The I2C bus that the ADC is on.
216-
:param int address: The I2C address for the ADC. Defaults to 0x48
209+
:param i2c_bus: The I2C bus that the ADC is on.
210+
:param int address: The I2C address for the ADC. Defaults to ~0x48
217211
"""
218212

219213
_raw_adc_read = ROUnaryStruct(_DATA_REG, ">h")
@@ -225,6 +219,7 @@ class TLA2024: # pylint:disable=too-many-instance-attributes
225219
_data_rate = RWBits(3, _CONFIG_REG, 5, 2, lsb_first=False)
226220

227221
def __init__(self, i2c_bus, address=_TLA_DEFAULT_ADDRESS):
222+
228223
# pylint:disable=no-member
229224

230225
self.i2c_device = I2CDevice(i2c_bus, address)
@@ -249,23 +244,24 @@ def input_channel(self):
249244

250245
@input_channel.setter
251246
def input_channel(self, channel):
252-
"""The input number to measure the voltage at, referenced to GND. Options are 0, 1, 2, 3"""
247+
"""The input number to measure the voltage at, referenced to GND.
248+
249+
:param channel: The channel number to switch to, from 0-4"""
250+
253251
if channel not in range(4):
254-
raise AttributeError(
255-
"``input_channel`` must be set to a number from 0 to 3"
256-
)
252+
raise AttributeError("input_channel must be set to a number from 0 to 3")
257253
self._mux = 4 + channel
258254

259255
@property
260256
def mode(self):
261-
"""The measurement mode of the sensor, either Mode.ONE_SHOT or Mode.CONTINUOUS
262-
See the documentation for ``adafruit_tla202x.Mode`` for more information"""
257+
"""The measurement mode of the sensor. Must be a :py:const:`~Mode`. See the documentation
258+
for :py:const:`~Mode` for more information"""
263259
return self._mode
264260

265261
@mode.setter
266262
def mode(self, mode):
267263
if not Mode.is_valid(mode):
268-
raise AttributeError("``mode`` must be a valid Mode")
264+
raise AttributeError("mode must be a valid Mode")
269265
if mode == Mode.CONTINUOUS: # pylint:disable=no-member
270266
self._mode = mode
271267
return
@@ -280,7 +276,8 @@ def mode(self, mode):
280276
@property
281277
def range(self):
282278
"""The measurement range of the ADC, changed by adjusting the Programmable Gain Amplifier
283-
`range` must be an ``adafruit_tla202x.Range``"""
279+
`range` must be a :py:const:`~Range`. See the documentation for :py:const:`~Range`
280+
for more information"""
284281
return self._pga
285282

286283
@range.setter
@@ -291,56 +288,42 @@ def range(self, measurement_range):
291288

292289
@property
293290
def data_rate(self):
294-
"""selects the rate at which measurement samples are taken. Must be an
295-
``adafruit_tla202x.DataRate``"""
291+
"""selects the rate at which measurement samples are taken. Must be a :py:const:`~DataRate`
292+
. See the documentation for :py:const:`~DataRate` for more information"""
296293
return self._data_rate
297294

298295
@data_rate.setter
299296
def data_rate(self, rate):
300297
if not DataRate.is_valid(rate): # pylint:disable=no-member
301-
raise AttributeError("``data_rate`` must be a valid DataRate")
298+
raise AttributeError("data_rate must be a valid DataRate")
302299
self._data_rate = rate
303300

304301
@property
305302
def mux(self):
306-
"""selects the inputs that voltage will be measured between. Must be an
307-
``adafruit_tla202x.Mux``. See the ``adafruit_tla202x.Mux`` documentation for more
308-
information about the available options"""
303+
"""selects the inputs that voltage will be measured between. Must be a
304+
:py:const:`~adafruit_tla202x.Mux`. See the :py:const:`~adafruit_tla202x.Mux` documentation
305+
for more information about the available options"""
309306
return self._mux
310307

311308
@mux.setter
312309
def mux(self, mux_connection):
313-
print("muxin'")
314310
if not Mux.is_valid(mux_connection): # pylint:disable=no-member
315-
raise AttributeError("``mux`` must be a valid Mux")
311+
raise AttributeError("mux must be a valid Mux")
316312
self._mux = mux_connection
317313

318314
def read(self, channel):
319-
"""Switch to the given channel and take a single ADC reading in One Shot mode"""
315+
"""Switch to the given channel and take a single ADC reading in One Shot mode
316+
317+
:param channel: The channel number to switch to, from 0-3
318+
319+
"""
320320
if not self.input_channel == channel:
321321
self.input_channel = channel
322322
self.mode = Mode.ONE_SHOT # pylint:disable=no-member
323323
return self._read_adc()
324324

325325
def _read_volts(self):
326-
"""From datasheet:
327-
≥ +FS (2^11 – 1) / 2^11 ==> 0x7FF0
328-
+FS /2^11 ==> 0x0010
329-
0 ==> 0x0000
330-
-FS /2^11 ==> 0xFFF0
331-
≤ –FS ==> 0x8000
332-
333-
"""
334-
335326
value_lsb = self._read_adc()
336-
# print("value_lsb:", hex(value_lsb))
337-
# v_fsr = 8192 >> self.range
338-
# if self.range == 0:
339-
# v_fsr = 6144
340-
# v_fsr = float(v_fsr)
341-
# converted = (value_lsb / 2047.0) * v_fsr
342-
343-
# return converted / 1000.0
344327
return value_lsb * Range.lsb[self.range] / 1000.0
345328

346329
def _read_adc(self):

adafruit_tla202x/analog_in.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def value(self):
6868
@property
6969
def reference_voltage(self):
7070
"""The maximum voltage measurable (also known as the reference voltage) as a float in
71-
Volts. Assumed to be 3.3V but can be overridden using the `TLA202x` constructor"""
71+
Volts. Assumed to be 3.3V but can be overridden using the
72+
:py:class:`~adafruit_tla202x.TLA2024` constructor"""
7273
if not self._tla:
7374
raise RuntimeError(
7475
"Underlying ADC does not exist, likely due to callint `deinit`"

adafruit_tla202x/tla2024.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
"""A TLA202x subclass to represent the TLA2024"""
5-
from . import TLA2024 as TLA202x
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.
22+
"""
23+
`tla2024`
24+
==============================
25+
A TLA202x subclass to represent the TLA2024
26+
27+
* Author(s): Bryan Siepert
28+
"""
629

730
A0 = 0
831
A1 = 1
932
A2 = 2
1033
A3 = 3
1134

1235

13-
class TTLA202x:
14-
"""New slaaa"""
36+
class TLA202x:
37+
"""Temporary placeholder class"""
1538

1639
@staticmethod
17-
def foozer2():
18-
"""gooooo"""
19-
print("foo? zern")
40+
def temp():
41+
"""Temporary placeholder class"""
2042

2143

2244
class TLA2024(TLA202x):
23-
"""Dock String"""
45+
"""Temporary placeholder class"""
2446

2547
@staticmethod
26-
def foozer2():
27-
"""gooooo"""
28-
print("foo2? zern2")
48+
def temp():
49+
"""Temporary placeholder class"""

docs/api.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

2-
.. If you created a package, create one automodule per module in the package.
3-
4-
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
5-
.. use this format as the module name: "adafruit_foo.foo"
6-
72
.. automodule:: adafruit_tla202x
83
:members:
4+
5+
.. automodule:: adafruit_tla202x.analog_in
6+
:members:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
# simple. Or you can use find_packages().
6060
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
6161
# CHANGE `py_modules=['...']` TO `packages=['...']`
62-
py_modules=["adafruit_tla202x"],
62+
packages=["adafruit_tla202x"],
6363
)

0 commit comments

Comments
 (0)