Skip to content

Commit d22d5a1

Browse files
authored
Merge pull request #25 from sommersoft/new_docs
Improve Ref Docs
2 parents 540e40c + a051c2d commit d22d5a1

10 files changed

+177
-51
lines changed
File renamed without changes.

.travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ deploy:
1616
provider: releases
1717
api_key: $GITHUB_TOKEN
1818
file_glob: true
19-
file: bundles/*
19+
file: $TRAVIS_BUILD_DIR/bundles/*
2020
skip_cleanup: true
21+
overwrite: true
2122
on:
2223
tags: true
2324

2425
install:
25-
- pip install pylint circuitpython-build-tools
26+
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
2627

2728
script:
2829
- pylint adafruit_lis3dh.py
2930
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py)
3031
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-lis3dh --library_location .
32+
- cd docs && sphinx-build -E -W -b html . _build/html

README.rst

+27-8
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,22 @@ Adafruit CircuitPython module for the LIS3DH accelerometer.
1414

1515
Note this module is made to work with CircuitPython and not MicroPython APIs.
1616

17+
Usage Example
18+
=============
19+
1720
See the guide at: https://learn.adafruit.com/circuitpython-hardware-lis3dh-accelerometer
1821

1922
Dependencies
2023
=============
2124
This driver depends on:
2225

2326
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
27+
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
2428

2529
Please ensure all dependencies are available on the CircuitPython filesystem.
2630
This is easily achieved by downloading
2731
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
2832

29-
API Reference
30-
=============
31-
32-
.. toctree::
33-
:maxdepth: 2
34-
35-
api
36-
3733
Contributing
3834
============
3935

@@ -64,3 +60,26 @@ Then run the build:
6460
.. code-block::shell
6561
6662
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-lis3dh --library_location .
63+
64+
Sphinx documentation
65+
-----------------------
66+
67+
Sphinx is used to build the documentation based on rST files and comments in the code. First,
68+
install dependencies (feel free to reuse the virtual environment from above):
69+
70+
.. code-block:: shell
71+
72+
python3 -m venv .env
73+
source .env/bin/activate
74+
pip install Sphinx sphinx-rtd-theme
75+
76+
Now, once you have the virtual environment activated:
77+
78+
.. code-block:: shell
79+
80+
cd docs
81+
sphinx-build -E -W -b html . _build/html
82+
83+
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
84+
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
85+
locally verify it will pass.

adafruit_lis3dh.py

+62-37
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
See examples in the examples directory.
1313
1414
* Author(s): Tony DiCola
15+
16+
Implementation Notes
17+
--------------------
18+
19+
**Hardware:**
20+
21+
* `Adafruit LIS3DH Triple-Axis Accelerometer Breakout
22+
<https://www.adafruit.com/product/2809>`_
23+
24+
* `Circuit Playground Express <https://www.adafruit.com/product/3333>`_
25+
26+
**Software and Dependencies:**
27+
28+
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
29+
https://github.com/adafruit/circuitpython/releases
30+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
1531
"""
1632

1733
import time
@@ -149,16 +165,20 @@ def acceleration(self):
149165
return x, y, z
150166

151167
def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1):
152-
"""Detect when the accelerometer is shaken. Optional parameters:
153-
shake_threshold - Increase or decrease to change shake sensitivity. This
154-
requires a minimum value of 10. 10 is the total
155-
acceleration if the board is not moving, therefore
156-
anything less than 10 will erroneously report a constant
157-
shake detected. (Default 30)
158-
avg_count - The number of readings taken and used for the average
159-
acceleration. (Default 10)
160-
total_delay - The total time in seconds it takes to obtain avg_count
161-
readings from acceleration. (Default 0.1)
168+
"""
169+
Detect when the accelerometer is shaken. Optional parameters:
170+
171+
:param shake_threshold: Increase or decrease to change shake sensitivity. This
172+
requires a minimum value of 10. 10 is the total
173+
acceleration if the board is not moving, therefore
174+
anything less than 10 will erroneously report a constant
175+
shake detected. (Default 30)
176+
177+
:param avg_count: The number of readings taken and used for the average
178+
acceleration. (Default 10)
179+
180+
:param total_delay: The total time in seconds it takes to obtain avg_count
181+
readings from acceleration. (Default 0.1)
162182
"""
163183
shake_accel = (0, 0, 0)
164184
for _ in range(avg_count):
@@ -204,45 +224,50 @@ def read_adc_mV(self, adc): # pylint: disable=invalid-name
204224

205225
@property
206226
def tapped(self):
207-
"""True if a tap was detected recently. Whether its a single tap or double tap is
208-
determined by the tap param on ``set_tap``. ``tapped`` may be True over
209-
multiple reads even if only a single tap or single double tap occurred if the
210-
interrupt (int) pin is not specified.
227+
"""
228+
True if a tap was detected recently. Whether its a single tap or double tap is
229+
determined by the tap param on ``set_tap``. ``tapped`` may be True over
230+
multiple reads even if only a single tap or single double tap occurred if the
231+
interrupt (int) pin is not specified.
211232
212-
The following example uses ``i2c`` and specifies the interrupt pin:
233+
The following example uses ``i2c`` and specifies the interrupt pin:
213234
214-
.. code-block:: python
235+
.. code-block:: python
215236
216-
import adafruit_lis3dh
217-
import digitalio
237+
import adafruit_lis3dh
238+
import digitalio
218239
219-
i2c = busio.I2C(board.SCL, board.SDA)
220-
int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt
221-
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
222-
lis3dh.range = adafruit_lis3dh.RANGE_8_G
240+
i2c = busio.I2C(board.SCL, board.SDA)
241+
int1 = digitalio.DigitalInOut(board.D11) # pin connected to interrupt
242+
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
243+
lis3dh.range = adafruit_lis3dh.RANGE_8_G
223244
224-
"""
245+
"""
225246
if self._int1 and not self._int1.value:
226247
return False
227248
raw = self._read_register_byte(REG_CLICKSRC)
228249
return raw & 0x40 > 0
229250

230251
def set_tap(self, tap, threshold, *,
231252
time_limit=10, time_latency=20, time_window=255, click_cfg=None):
232-
"""Set the tap detection parameters.
233-
234-
.. note:: Tap related registers are called CLICK_ in the datasheet.
235-
236-
:param int tap: 0 to disable tap detection, 1 to detect only single
237-
taps, and 2 to detect only double taps.
238-
:param int threshold: A threshold for the tap detection. The higher the value
239-
the less sensitive the detection. This changes based on the accelerometer
240-
range. Good values are 5-10 for 16G, 10-20 for 8G, 20-40 for 4G, and 40-80 for
241-
2G.
242-
:param int time_limit: TIME_LIMIT register value (default 10).
243-
:param int time_latency: TIME_LATENCY register value (default 20).
244-
:param int time_window: TIME_WINDOW register value (default 255).
245-
:param int click_cfg: CLICK_CFG register value."""
253+
"""
254+
The tap detection parameters.
255+
256+
.. note:: Tap related registers are called ``CLICK_`` in the datasheet.
257+
258+
:param int tap: 0 to disable tap detection, 1 to detect only single
259+
taps, and 2 to detect only double taps.
260+
261+
:param int threshold: A threshold for the tap detection. The higher the value
262+
the less sensitive the detection. This changes based on
263+
the accelerometer range. Good values are 5-10 for 16G,
264+
10-20 for 8G, 20-40 for 4G, and 40-80 for 2G.
265+
266+
:param int time_limit: TIME_LIMIT register value (default 10).
267+
:param int time_latency: TIME_LATENCY register value (default 20).
268+
:param int time_window: TIME_WINDOW register value (default 255).
269+
:param int click_cfg: CLICK_CFG register value.
270+
"""
246271
if (tap < 0 or tap > 2) and click_cfg is None:
247272
raise ValueError('Tap must be 0 (disabled), 1 (single tap), or 2 (double tap)!')
248273
if threshold > 127 or threshold < 0:

docs/_static/favicon.ico

4.31 KB
Binary file not shown.

api.rst renamed to docs/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
.. If you created a package, create one automodule per module in the package.
33
4-
.. automodule:: adafruit_lis3dh.lis3dh
4+
.. automodule:: adafruit_lis3dh
55
:members:

conf.py renamed to docs/conf.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('.'))
5+
sys.path.insert(0, os.path.abspath('..'))
66

77
# -- General configuration ------------------------------------------------
88

@@ -28,7 +28,7 @@
2828
source_suffix = '.rst'
2929

3030
# The master toctree document.
31-
master_doc = 'README'
31+
master_doc = 'index'
3232

3333
# General information about the project.
3434
project = u'Adafruit VL53L0X Library'
@@ -54,7 +54,7 @@
5454
# List of patterns, relative to source directory, that match files and
5555
# directories to ignore when looking for source files.
5656
# This patterns also effect to html_static_path and html_extra_path
57-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
57+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
5858

5959
# The reST default role (used for this markup: `text`) to use for all
6060
# documents.
@@ -71,6 +71,9 @@
7171
# If true, `todo` and `todoList` produce output, else they produce nothing.
7272
todo_include_todos = False
7373

74+
# If this is True, todo emits a warning for each TODO entries. The default is False.
75+
todo_emit_warnings = True
76+
7477

7578
# -- Options for HTML output ----------------------------------------------
7679

@@ -95,6 +98,12 @@
9598
# so a file named "default.css" will overwrite the builtin "default.css".
9699
html_static_path = ['_static']
97100

101+
# The name of an image file (relative to this directory) to use as a favicon of
102+
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103+
# pixels large.
104+
#
105+
html_favicon = '_static/favicon.ico'
106+
98107
# Output file base name for HTML help builder.
99108
htmlhelp_basename = 'AdafruitVL53L0XLibrarydoc'
100109

docs/examples.rst

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Simple test
2+
------------
3+
4+
Ensure your device works with this simple test.
5+
6+
.. literalinclude:: ../examples/lis3dh_simpletest.py
7+
:caption: examples/lis3dh_simpletest.py
8+
:linenos:
9+
10+
Here are some additional examples:
11+
12+
.. literalinclude:: ../examples/tap.py
13+
:caption: examples/tap.py
14+
:linenos:
15+
16+
.. literalinclude:: ../examples/adc.py
17+
:caption: examples/adc.py
18+
:linenos:
19+
20+
.. literalinclude:: ../examples/spinner.py
21+
:caption: examples/spinner.py
22+
:linenos:

docs/index.rst

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. include:: ../README.rst
2+
3+
Table of Contents
4+
=================
5+
6+
.. toctree::
7+
:maxdepth: 4
8+
:hidden:
9+
10+
self
11+
12+
.. toctree::
13+
:caption: Examples
14+
15+
examples
16+
17+
.. toctree::
18+
:caption: API Reference
19+
:maxdepth: 3
20+
21+
api
22+
23+
.. toctree::
24+
:caption: Tutorials
25+
26+
.. toctree::
27+
:caption: Related Products
28+
29+
Adafruit LIS3DH Triple-Axis Accelerometer Breakout <https://www.adafruit.com/product/2809>
30+
31+
Circuit Playground Express <https://www.adafruit.com/product/3333>
32+
33+
.. toctree::
34+
:caption: Other Links
35+
36+
Download <https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH/releases/latest>
37+
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
38+
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
39+
Discord Chat <https://adafru.it/discord>
40+
Adafruit Learning System <https://learn.adafruit.com>
41+
Adafruit Blog <https://blog.adafruit.com>
42+
Adafruit Store <https://www.adafruit.com>
43+
44+
Indices and tables
45+
==================
46+
47+
* :ref:`genindex`
48+
* :ref:`modindex`
49+
* :ref:`search`
File renamed without changes.

0 commit comments

Comments
 (0)