Skip to content

Improve Ref Docs #10

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

Merged
merged 14 commits into from
Mar 5, 2018
File renamed without changes.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ deploy:
provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file: bundles/*
file: $TRAVIS_BUILD_DIR/bundles/*
skip_cleanup: true
overwrite: true
on:
tags: true

install:
- pip install pylint circuitpython-build-tools
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme

script:
- pylint adafruit_max7219/*.py
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-max7219 --library_location .
- cd docs && sphinx-build -E -W -b html . _build/html
34 changes: 23 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ This is easily achieved by downloading
Usage Example
=============

Examples
********

adafruit_max7219.Matrix8x8 Example
----------------------------------

Expand Down Expand Up @@ -87,14 +84,6 @@ adafruit_max7219.BCDDigits Example
display.show_str(0,'{:9.2f}'.format(-1234.56))
display.show()

API Reference
=============

.. toctree::
:maxdepth: 2

api

Contributing
============

Expand Down Expand Up @@ -125,3 +114,26 @@ Then run the build:
.. code-block:: shell

circuitpython-build-bundles --filename_prefix adafruit-circuitpython-max7219 --library_location .

Sphinx documentation
-----------------------

Sphinx is used to build the documentation based on rST files and comments in the code. First,
install dependencies (feel free to reuse the virtual environment from above):

.. code-block:: shell

python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme

Now, once you have the virtual environment activated:

.. code-block:: shell

cd docs
sphinx-build -E -W -b html . _build/html

This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
29 changes: 16 additions & 13 deletions adafruit_max7219/bcddigits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#

"""
:mod:`adafruit_max7219.bcddigits.BCDDigits`
`adafruit_max7219.bcddigits.BCDDigits`
====================================================
"""
from adafruit_max7219 import max7219
Expand All @@ -40,14 +40,12 @@ class BCDDigits(max7219.MAX7219):
"""
Basic support for display on a 7-Segment BCD display controlled
by a Max7219 chip using SPI.

:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
:param int nDigits: number of led 7-segment digits; default 1; max 8
"""
def __init__(self, spi, cs, nDigits=1):
"""
:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select
signal
:param int nDigits: number of led 7-segment digits; default 1; max 8
"""
self._ndigits = nDigits
super().__init__(self._ndigits, 8, spi, cs)

Expand All @@ -66,7 +64,8 @@ def init_display(self):

def set_digit(self, dpos, value):
"""
set one digit in the display
Set one digit in the display.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Display one digit."


:param int dpos: the digit position; zero-based
:param int value: integer ranging from 0->15
"""
Expand All @@ -78,7 +77,8 @@ def set_digit(self, dpos, value):

def set_digits(self, start, values):
"""
set the display from a list
Set the display from a list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Display digits from a list."


:param int s: digit to start display zero-based
:param list ds: list of integer values ranging from 0->15
"""
Expand All @@ -89,7 +89,8 @@ def set_digits(self, start, values):

def show_dot(self, dpos, bit_value=None):
"""
set the decimal point for a digit
Set the decimal point for a digit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The decimal point for a digit."


:param int dpos: the digit to set the decimal point zero-based
:param int value: value > zero lights the decimal point, else unlights the point
"""
Expand All @@ -99,15 +100,16 @@ def show_dot(self, dpos, bit_value=None):

def clear_all(self):
"""
clear all digits and decimal points
Clear all digits and decimal points.
"""
self.fill(1)
for i in range(self._ndigits):
self.show_dot(i)

def show_str(self, start, strg):
"""
displays a numeric str in the display. shows digits 0-9, -, and .
Displays a numeric str in the display. Shows digits ``0-9``, ``-``, and ``.``.

:param int start: start position to show the numeric string
:param string str: the numeric string
"""
Expand All @@ -127,7 +129,8 @@ def show_str(self, start, strg):

def show_help(self, start):
"""
display the word HELP in the display
Display the word HELP in the display.

:param int start: start position to show HELP
"""
digits = [12, 11, 13, 14]
Expand Down
17 changes: 9 additions & 8 deletions adafruit_max7219/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#

"""
:mod:`adafruit_max7219.matrices.Matrix8x8`
`adafruit_max7219.matrices.Matrix8x8`
====================================================
"""
from adafruit_max7219 import max7219
Expand All @@ -37,12 +37,13 @@
_DISPLAYTEST = const(15)

class Matrix8x8(max7219.MAX7219):
"""Driver for a 8x8 LED matrix based on the MAX7219 chip"""
"""
Driver for a 8x8 LED matrix based on the MAX7219 chip.

:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
"""
def __init__(self, spi, cs):
"""
:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
"""
super().__init__(8, 8, spi, cs)

def init_display(self):
Expand All @@ -59,7 +60,7 @@ def init_display(self):

def text(self, strg, xpos, ypos, bit_value=1):
"""
draw text in the 8x8 matrix.
Draw text in the 8x8 matrix.

:param int xpos: x position of LED in matrix
:param int ypos: y position of LED in matrix
Expand All @@ -70,6 +71,6 @@ def text(self, strg, xpos, ypos, bit_value=1):

def clear_all(self):
"""
unlights all matrix leds
Clears all matrix leds.
"""
self.fill(0)
56 changes: 33 additions & 23 deletions adafruit_max7219/max7219.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,36 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_max7219.MAX7219` - MAX7219 LED Matrix/Digit Display Driver
`adafruit_max7219.max7219` - MAX7219 LED Matrix/Digit Display Driver
========================================================================
CircuitPython library to support MAX7219 LED Matrix/Digit Display Driver.
This library supports the use of the MAX7219-based display in CircuitPython,
either an 8x8 matrix or a 8 digit 7-segment numeric display.

see also
========
See Also
=========
* matrices.Maxtrix8x8 is a class support an 8x8 led matrix display
* bcddigits.BCDDigits is a class that support the 8 digit 7-segment display

Beware that most CircuitPython compatible hardware are 3.3v logic level! Make
sure that the input pin is 5v tolerant.

* Author(s): Michael McWethy

Implementation Notes
--------------------
**Hardware:**

* Adafruit `MAX7219CNG LED Matrix/Digit Display Driver -
MAX7219 <https://www.adafruit.com/product/453>`_ (Product ID: 453)
MAX7219 <https://www.adafruit.com/product/453>`_ (Product ID: 453)

**Software and Dependencies:**
* Adafruit CircuitPython firmware (1.0.0+) for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases

* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

**Notes:**
#. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf
"""
Expand All @@ -63,18 +69,19 @@


class MAX7219:
""" MAX2719 - driver for displays based on max719 chip_select"""
"""
MAX2719 - driver for displays based on max719 chip_select

:param int width: the number of pixels wide
:param int height: the number of pixels high
:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut chip_select: digital in/out to use as chip select signal
:param baudrate: for SPIDevice baudrate (default 8000000)
:param polarity: for SPIDevice polarity (default 0)
:param phase: for SPIDevice phase (default 0)
"""
def __init__(self, width, height, spi, cs, *,
baudrate=8000000, polarity=0, phase=0):
"""
:param int width: the number of pixels wide
:param int height: the number of pixels high
:param object spi: an spi busio or spi bitbangio object
:param ~digitalio.DigitalInOut chip_select: digital in/out to use as chip select signal
:param baudrate: for SPIDevice baudrate (default 8000000)
:param polarity: for SPIDevice polarity (default 0)
:param phase: for SPIDevice phase (default 0)
"""

self._chip_select = cs
self._chip_select.direction = digitalio.Direction.OUTPUT
Expand All @@ -91,12 +98,13 @@ def __init__(self, width, height, spi, cs, *,
self.init_display()

def init_display(self):
"""must be implement by derived class"""
"""Must be implemented by derived class (``matrices``, ``bcddigits``)"""
pass

def brightness(self, value):
"""
control the brightness of the display
Controls the brightness of the display.

:param int value: 0->15 dimmest to brightest
"""
if not 0 <= value <= 15:
Expand All @@ -105,21 +113,23 @@ def brightness(self, value):

def show(self):
"""
update the display with recent changes in buffer
Updates the display with recent changes in buffer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Updates the display."

"""
for ypos in range(8):
self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos])

def fill(self, bit_value):
"""
set all buffer bits to a col
Sets all buffer bits to a col
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be changed, but I'm not entirely sure what it does, so I'm not entirely sure what to set it to. If you can't think of something reasonable, then leave it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I know what it's doing, but haven't worked with a MAX7219 before so I can't say for sure. I made it a little more understandable, but still vague. I can put in an issue to have mrmcwethy clear up the docstring, and what it does...


:param bit_value: int value > 0 set the buffer bit, else clears the buffer bit
"""
self.framebuf.fill(bit_value)

def pixel(self, xpos, ypos, bit_value=None):
"""
set one buffer bit
Set one buffer bit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I know what it's doing, but haven't worked with a MAX7219 before so I can't say for sure. I made it a little more understandable, but still vague. I can put in an issue to have mrmcwethy clear up the docstring, and what it does...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks!


:param xpos: x position to set bit
:param ypos: y position to set bit
:param bit_value: int value > 0 sets the buffer bit, else clears the buffer bit
Expand All @@ -128,11 +138,11 @@ def pixel(self, xpos, ypos, bit_value=None):
self.framebuf.pixel(xpos, ypos, bit_value)

def scroll(self, delta_x, delta_y):
"""scolls the display using delta_x,delta_y"""
"""Scolls the display using delta_x,delta_y."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Scrolls"

self.framebuf.scroll(delta_x, delta_y)

def write_cmd(self, cmd, data):
"""writes a command to spi device"""
"""Writes a command to spi device."""
#print('cmd {} data {}'.format(cmd,data))
self._chip_select.value = False
with self._spi_device as my_spi_device:
Expand Down
15 changes: 0 additions & 15 deletions api.rst

This file was deleted.

Binary file added docs/_static/favicon.ico
Binary file not shown.
11 changes: 11 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

.. If you created a package, create one automodule per module in the package.

.. automodule:: adafruit_max7219.max7219
:members:

.. automodule:: adafruit_max7219.matrices
:members:

.. automodule:: adafruit_max7219.bcddigits
:members:
Loading