Compare commits

..

37 commits

Author SHA1 Message Date
dherrada
9a6710b003 Fixed discord invite link 2020-07-08 16:49:04 -04:00
Kattni
8df00d8992
Merge pull request #14 from caternuson/uart
Add UART support
2020-05-04 12:20:18 -04:00
caternuson
c15610edb2 no, really, don't 2020-04-18 10:19:08 -07:00
caternuson
1aa1ccb0e9 they do 2020-04-18 10:15:16 -07:00
caternuson
fb443643f8 and now black is unhappy again? 2020-04-18 10:09:49 -07:00
caternuson
c60848f1ce this one is lint 2020-04-18 10:06:55 -07:00
caternuson
db60c0ffb5 linted, i mean blacked, or..whatever 2020-04-18 10:00:11 -07:00
caternuson
ead4d7b6f2 clean up 2020-04-18 09:46:08 -07:00
caternuson
2139ea7f31 initial working 2020-04-17 19:24:08 -07:00
Scott Shawcroft
7983c0ff00
Merge pull request #13 from adafruit/black-update
Black reformatting with Python 3 target.
2020-04-08 10:13:15 -07:00
Kattni Rembor
39f9fa8b58 Black reformatting with Python 3 target. 2020-04-08 13:03:34 -04:00
sommersoft
cb35bed783 build.yml: add black formatting check
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-04-07 16:00:52 -05:00
Kattni
5ae235cf5e
Merge pull request #12 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2020-03-16 16:40:17 -04:00
sommersoft
ad8c3d2325 update code of coduct: discord moderation contact section
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-15 18:30:40 -05:00
dherrada
7ac2b297ed Ran black, updated to pylint 2.x 2020-03-15 14:45:42 -04:00
Kattni
6919489a53
Merge pull request #11 from sommersoft/patch_coc
Update Code of Conduct
2020-03-13 15:55:47 -04:00
sommersoft
4e55ebef34 update code of conduct 2020-03-13 13:49:02 -05:00
sommersoft
8627e9e94e update pylintrc for black
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-08 19:09:33 -05:00
sommersoft
b619c5e97f build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh'
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-05 10:08:45 -06:00
Kattni
ad8fcc5e1a
Merge pull request #10 from adafruit/dherrada-patch-2
Updated intersphinx link
2020-02-04 14:25:15 -05:00
dherrada
d12e2a80e7
Updated intersphinx link 2020-02-03 08:59:43 -05:00
sommersoft
fda5535f19 update pylint examples directive
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-01-14 17:07:43 -06:00
Limor "Ladyada" Fried
d242dc0f93
Merge pull request #9 from adafruit/dherrada-patch-1
Moved repository from Travis to GitHub Actions
2019-12-27 23:34:31 -05:00
dherrada
16b5b98e0a Moved repository from Travis to GitHub Actions 2019-12-27 22:23:38 -05:00
siddacious
8833bb6a7e
Merge pull request #7 from adafruit/dherrada-patch-1
Removed building locally section from README, replaced with documenta…
2019-10-17 15:37:30 -07:00
dherrada
c5e4599237
Removed building locally section from README, replaced with documentation section 2019-10-17 18:01:11 -04:00
Kattni
b446f14314
Merge pull request #6 from sommersoft/readme_fix_travis
Update README Travis Badge
2018-12-21 13:22:57 -06:00
sommersoft
0ef9b2be7f change 'travis-ci.org' to 'travis-ci.com' 2018-12-21 13:15:05 -06:00
Brennen Bearnes
2ae40d2119
Merge pull request #5 from adafruit/pypi-readme-update
PyPI readme update
2018-10-31 17:56:03 -06:00
Kattni
b26b341445
PyPI readme update 2018-10-31 17:03:39 -04:00
sommersoft
61abf4100c ignore the board module imports in .pylintrc
Signed-off-by: sommersoft <sommersoft@gmail.com>
2018-08-25 14:06:02 +00:00
Kattni
c64d6f7fc1
Merge pull request #4 from adafruit/pypi_readme
add pypi instructions to README.rst
2018-08-09 14:03:06 -04:00
Brennen Bearnes
02ed2b572f add pypi downgrade per @kattni 2018-08-09 11:30:11 -06:00
Brennen Bearnes
15ab6f55d3 add pypi instructions to README.rst
Also some minor whitespace tweaks.
2018-08-09 10:32:59 -06:00
Brennen Bearnes
0a6f3afd83 .travis.yml: add missing pip invocation 2018-07-03 16:19:43 -06:00
Brennen Bearnes
050f1cc97a add setup.py, add pypi to .travis.yml, misc. tweaks for pypi, .gitignore
Per instructions at:

adafruit/circuitpython#979
2018-07-03 15:58:48 -06:00
deanm1278
3e2e8e1ab1
Merge pull request #3 from adafruit/tannewt-patch-2
Fix release file path
2018-03-27 17:31:25 -04:00
12 changed files with 575 additions and 222 deletions

57
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: Build CI
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install dependencies
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
run: |
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: Check formatting
run: |
black --check --target-version=py35 .
- name: PyLint
run: |
pylint $( find . -path './adafruit*.py' )
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Build docs
working-directory: docs
run: sphinx-build -E -W -b html . _build/html

81
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,81 @@
name: Release Actions
on:
release:
types: [published]
jobs:
upload-release-assets:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install deps
run: |
source actions-ci/install.sh
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Upload Release Assets
# the 'official' actions version does not yet support dynamically
# supplying asset names to upload. @csexton's version chosen based on
# discussion in the issue below, as its the simplest to implement and
# allows for selecting files with a pattern.
# https://github.com/actions/upload-release-asset/issues/4
#uses: actions/upload-release-asset@v1.0.1
uses: csexton/release-asset-action@master
with:
pattern: "bundles/*"
github-token: ${{ secrets.GITHUB_TOKEN }}
upload-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Check For setup.py
id: need-pypi
run: |
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
- name: Set up Python
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
run: |
python setup.py sdist
twine upload dist/*

7
.gitignore vendored
View file

@ -1,6 +1,11 @@
*.mpy
.idea
__pycache__
_build
*.pyc
.env
build*
bundles
*.DS_Store
.eggs
dist
**/*.egg-info

View file

@ -52,7 +52,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
@ -156,7 +156,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
ignored-modules=board
# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.

View file

@ -1,32 +0,0 @@
# This is a common .travis.yml for generating library release zip files for
# CircuitPython library releases using circuitpython-build-tools.
# See https://github.com/adafruit/circuitpython-build-tools for detailed setup
# instructions.
dist: trusty
sudo: false
language: python
python:
- "3.6"
cache:
pip: true
deploy:
provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file: $TRAVIS_BUILD_DIR/bundles/*
skip_cleanup: true
overwrite: true
on:
tags: true
install:
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
script:
- pylint adafruit_as726x.py
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-as726x --library_location .
- cd docs && sphinx-build -E -W -b html . _build/html

View file

@ -1,74 +1,129 @@
# Contributor Covenant Code of Conduct
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Promoting or spreading disinformation, lies, or conspiracy theories against
a person, group, organisation, project, or community
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Moderators by tagging @community moderators. You may
also send an open message from any channel, or a direct message to
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at support@adafruit.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View file

@ -6,17 +6,18 @@ Introduction
:alt: Documentation Status
.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu
:target: https://adafru.it/discord
:alt: Discord
.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_AS726x.svg?branch=master
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_AS726x
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_AS726x/workflows/Build%20CI/badge.svg
:target: https://github.com/adafruit/Adafruit_CircuitPython_AS726x/actions/
:alt: Build Status
Driver for the AS726x spectral sensors
Dependencies
=============
Installation and Dependencies
=============================
This driver depends on:
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
@ -27,6 +28,32 @@ Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
Installing from PyPI
--------------------
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally
`from PyPI <https://pypi.org/project/adafruit-circuitpython-as726x/>`_. To install for
current user:
.. code-block:: shell
pip3 install adafruit-circuitpython-as726x
To install system-wide (this may be required in some cases:
.. code-block:: shell
sudo pip3 install adafruit-circuitpython-as726x
To install in a virtual environment in your current project:
.. code-block:: shell
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-as726x
Contributing
============
@ -34,52 +61,7 @@ Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/adafruit_CircuitPython_AS726x/blob/master/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.
Building locally
================
Documentation
=============
Zip release files
-----------------
To build this library locally you'll need to install the
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
.. code-block:: shell
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
.. code-block:: shell
source .env/bin/activate
Then run the build:
.. code-block:: shell
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-as726x --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.
For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.

View file

@ -92,12 +92,33 @@ _AS7262_RED_CALIBRATED = const(0x28)
_AS726X_NUM_CHANNELS = const(6)
_COLOR_REGS = (
_AS7262_VIOLET,
_AS7262_BLUE,
_AS7262_GREEN,
_AS7262_YELLOW,
_AS7262_ORANGE,
_AS7262_RED,
)
_COLOR_REGS_CALIBRATED = (
_AS7262_VIOLET_CALIBRATED,
_AS7262_BLUE_CALIBRATED,
_AS7262_GREEN_CALIBRATED,
_AS7262_YELLOW_CALIBRATED,
_AS7262_ORANGE_CALIBRATED,
_AS7262_RED_CALIBRATED,
)
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-public-methods
class Adafruit_AS726x(object):
"""AS726x spectral sensor.
# pylint: disable=invalid-name
# pylint: disable=no-else-return
# pylint: disable=inconsistent-return-statements
class AS726x:
"""AS726x spectral sensor base class.
:param ~busio.I2C i2c_bus: The I2C bus connected to the sensor
"""
MODE_0 = 0b00
@ -120,18 +141,16 @@ class Adafruit_AS726x(object):
DRIVER_CURRENT_LIMITS = (12.5, 25, 50, 100)
def __init__(self, i2c_bus):
def __init__(self):
self._driver_led = False
self._indicator_led = False
self._driver_led_current = Adafruit_AS726x.DRIVER_CURRENT_LIMITS.index(12.5)
self._indicator_led_current = Adafruit_AS726x.INDICATOR_CURRENT_LIMITS.index(1)
self._conversion_mode = Adafruit_AS726x.MODE_2
self._driver_led_current = AS726x.DRIVER_CURRENT_LIMITS.index(12.5)
self._indicator_led_current = AS726x.INDICATOR_CURRENT_LIMITS.index(1)
self._conversion_mode = AS726x.MODE_2
self._integration_time = 0
self._gain = Adafruit_AS726x.GAIN.index(1)
self._gain = AS726x.GAIN.index(1)
self.buf2 = bytearray(2)
self.i2c_device = I2CDevice(i2c_bus, _AS726X_ADDRESS)
# reset device
self._virtual_write(_AS726X_CONTROL_SETUP, 0x80)
@ -143,10 +162,12 @@ class Adafruit_AS726x(object):
# TODO: add support for other devices
if version != 0x40:
raise ValueError("device could not be reached or this device is not supported!")
raise ValueError(
"device could not be reached or this device is not supported!"
)
self.integration_time = 140
self.conversion_mode = Adafruit_AS726x.MODE_2
self.conversion_mode = AS726x.MODE_2
self.gain = 64
@property
@ -191,14 +212,14 @@ class Adafruit_AS726x(object):
@driver_led_current.setter
def driver_led_current(self, val):
if val not in Adafruit_AS726x.DRIVER_CURRENT_LIMITS:
if val not in AS726x.DRIVER_CURRENT_LIMITS:
raise ValueError("Must be 12.5, 25, 50 or 100")
if self._driver_led_current == val:
return
self._driver_led_current = val
state = self._virtual_read(_AS726X_LED_CONTROL)
state &= ~(0x3 << 4)
state = state | (Adafruit_AS726x.DRIVER_CURRENT_LIMITS.index(val) << 4)
state = state | (AS726x.DRIVER_CURRENT_LIMITS.index(val) << 4)
self._virtual_write(_AS726X_LED_CONTROL, state)
@property
@ -213,14 +234,14 @@ class Adafruit_AS726x(object):
@indicator_led_current.setter
def indicator_led_current(self, val):
if val not in Adafruit_AS726x.INDICATOR_CURRENT_LIMITS:
if val not in AS726x.INDICATOR_CURRENT_LIMITS:
raise ValueError("Must be 1, 2, 4 or 8")
if self._indicator_led_current == val:
return
self._indicator_led_current = val
state = self._virtual_read(_AS726X_LED_CONTROL)
state &= ~(0x3 << 1)
state = state | (Adafruit_AS726x.INDICATOR_CURRENT_LIMITS.index(val) << 4)
state = state | (AS726x.INDICATOR_CURRENT_LIMITS.index(val) << 4)
self._virtual_write(_AS726X_LED_CONTROL, state)
@property
@ -251,14 +272,14 @@ class Adafruit_AS726x(object):
@gain.setter
def gain(self, val):
if val not in Adafruit_AS726x.GAIN:
if val not in AS726x.GAIN:
raise ValueError("Must be 1, 3.7, 16 or 64")
if self._gain == val:
return
self._gain = val
state = self._virtual_read(_AS726X_CONTROL_SETUP)
state &= ~(0x3 << 4)
state |= (Adafruit_AS726x.GAIN.index(val) << 4)
state |= AS726x.GAIN.index(val) << 4
self._virtual_write(_AS726X_CONTROL_SETUP, state)
@property
@ -298,7 +319,7 @@ class Adafruit_AS726x(object):
val[1] = self._virtual_read(channel + 1)
val[2] = self._virtual_read(channel + 2)
val[3] = self._virtual_read(channel + 3)
return struct.unpack('!f', val)[0]
return struct.unpack("!f", val)[0]
@property
def data_ready(self):
@ -370,6 +391,23 @@ class Adafruit_AS726x(object):
"""Raw red (650nm) 16-bit value"""
return self.read_channel(_AS7262_RED)
def _virtual_read(self, addr):
raise NotImplementedError("Must be implemented.")
def _virtual_write(self, addr, value):
raise NotImplementedError("Must be implemented.")
class AS726x_I2C(AS726x):
"""AS726x spectral sensor via I2C.
:param ~busio.I2C i2c_bus: The I2C bus connected to the sensor
"""
def __init__(self, i2c_bus, address=_AS726X_ADDRESS):
self.i2c_device = I2CDevice(i2c_bus, address)
super().__init__()
def _read_u8(self, command):
"""read a single byte from a specified register"""
buf = self.buf2
@ -426,5 +464,84 @@ class Adafruit_AS726x(object):
self.__write_u8(_AS726X_SLAVE_WRITE_REG, value)
class AS726x_UART(AS726x):
"""AS726x spectral sensor via UART.
:param ~busio.UART uart: The UART connected to the sensor
"""
def __init__(self, uart):
self._uart = uart
self._uart.baudrate = 115200
super().__init__()
def read_channel(self, channel):
"""Read an individual sensor channel"""
return self._virtual_read(channel)
def read_calibrated_value(self, channel):
"""Read a calibrated sensor channel"""
return self._virtual_read(channel)
def _uart_xfer(self, cmd):
self._uart.reset_input_buffer()
cmd += "\n"
self._uart.write(cmd.encode())
time.sleep(0.1)
if self._uart.in_waiting:
resp = self._uart.read(self._uart.in_waiting)
return resp.rstrip(b" OK\n")
return None
def _virtual_read(self, addr):
if addr == _AS726X_HW_VERSION:
# just return what is expected
return 0x40
elif addr == _AS726X_DEVICE_TEMP:
return int(self._uart_xfer("ATTEMP"))
elif addr == _AS726X_LED_CONTROL:
LED_IND = int(self._uart_xfer("ATLED0"))
LED_DRV = int(self._uart_xfer("ATLED1"))
return LED_IND << 3 | LED_DRV
elif addr == _AS726X_CONTROL_SETUP:
GAIN = int(self._uart_xfer("ATGAIN"))
BANK = int(self._uart_xfer("ATTCSMD"))
return GAIN << 4 | BANK << 2 | 1 << 1
elif addr in _COLOR_REGS:
resp = self._uart_xfer("ATDATA")
resp = resp.decode().split(",")
return int(resp[_COLOR_REGS.index(addr)])
elif addr in _COLOR_REGS_CALIBRATED:
resp = self._uart_xfer("ATCDATA")
resp = resp.decode().split(",")
return float(resp[_COLOR_REGS_CALIBRATED.index(addr)])
def _virtual_write(self, addr, value):
if addr == _AS726X_CONTROL_SETUP:
# check for reset
if (value >> 7) & 0x01:
self._uart.write(b"ATRST\n")
return
# otherwise proceed
GAIN = (value >> 4) & 0x03
BANK = (value >> 2) & 0x03
self._uart_xfer("ATGAIN={}".format(GAIN))
self._uart_xfer("ATTCSMD={}".format(BANK))
elif addr == _AS726X_LED_CONTROL:
ICL_DRV = (value >> 4) & 0x07
LED_DRV = 100 if value & 0x08 else 0
ICL_IND = (value >> 1) & 0x07
LED_IND = 100 if value & 0x01 else 0
self._uart_xfer("ATLED0={}".format(LED_IND))
self._uart_xfer("ATLED1={}".format(LED_DRV))
self._uart_xfer("ATLEDC={}".format(ICL_DRV << 4 | ICL_IND))
elif addr == _AS726X_INT_T:
value = int(value / 2.8)
self._uart_xfer("ATINTTIME={}".format(value))
# pylint: enable=too-many-instance-attributes
# pylint: enable=too-many-public-methods
# pylint: enable=invalid-name
# pylint: enable=no-else-return
# pylint: enable=inconsistent-return-statements

View file

@ -2,7 +2,8 @@
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
# -- General configuration ------------------------------------------------
@ -10,41 +11,47 @@ sys.path.insert(0, os.path.abspath('..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
]
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["digitalio", "busio", "adafruit_bus_device", "micropython", "ustruct"]
autodoc_member_order = "bysource"
autodoc_member_order = 'bysource'
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/bus_device/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
None,
),
"Register": (
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
None,
),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]
source_suffix = '.rst'
source_suffix = ".rst"
# The master toctree document.
master_doc = 'index'
master_doc = "index"
# General information about the project.
project = u'Adafruit AS726x Library'
copyright = u'2017 Dean Miller'
author = u'Dean Miller'
project = "Adafruit AS726x Library"
copyright = "2017 Dean Miller"
author = "Dean Miller"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'1.0'
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = u'1.0'
release = "1.0"
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -56,7 +63,7 @@ language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
# The reST default role (used for this markup: `text`) to use for all
# documents.
@ -68,7 +75,7 @@ default_role = "any"
add_function_parentheses = True
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
@ -82,26 +89,27 @@ todo_emit_warnings = True
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd: # only import and set the theme if we're building docs locally
try:
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
except:
html_theme = 'default'
html_theme_path = ['.']
html_theme = "default"
html_theme_path = ["."]
else:
html_theme_path = ['.']
html_theme_path = ["."]
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
# Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitAs726xLibrarydoc'
htmlhelp_basename = "AdafruitAs726xLibrarydoc"
# -- Options for LaTeX output ---------------------------------------------
@ -109,15 +117,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
@ -127,8 +132,13 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'AdafruitAS726xLibrary.tex', u'AdafruitAS726x Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitAS726xLibrary.tex",
"AdafruitAS726x Library Documentation",
author,
"manual",
),
]
# -- Options for manual page output ---------------------------------------
@ -136,8 +146,13 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitAS726xlibrary', u'Adafruit AS726x Library Documentation',
[author], 1)
(
master_doc,
"AdafruitAS726xlibrary",
"Adafruit AS726x Library Documentation",
[author],
1,
)
]
# -- Options for Texinfo output -------------------------------------------
@ -146,7 +161,13 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitAS726xLibrary', u'Adafruit AS726x Library Documentation',
author, 'AdafruitAS726xLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitAS726xLibrary",
"Adafruit AS726x Library Documentation",
author,
"AdafruitAS726xLibrary",
"One line description of project.",
"Miscellaneous",
),
]

View file

@ -3,7 +3,11 @@ import time
import board
import busio
from adafruit_as726x import Adafruit_AS726x
# for I2C use:
from adafruit_as726x import AS726x_I2C
# for UART use:
# from adafruit_as726x import AS726x_UART
# maximum value for sensor reading
max_val = 16000
@ -11,27 +15,33 @@ max_val = 16000
# max number of characters in each graph
max_graph = 80
def graph_map(x):
return min(int(x * max_graph / max_val), max_graph)
# Initialize I2C bus and sensor.
# for I2C use:
i2c = busio.I2C(board.SCL, board.SDA)
sensor = Adafruit_AS726x(i2c)
sensor = AS726x_I2C(i2c)
# for UART use:
# uart = busio.UART(board.TX, board.RX)
# sensor = AS726x_UART(uart)
sensor.conversion_mode = sensor.MODE_2
while True:
# Wait for data to be ready
while not sensor.data_ready:
time.sleep(.1)
time.sleep(0.1)
# plot plot the data
print("\n")
print("V: " + graph_map(sensor.violet)*'=')
print("B: " + graph_map(sensor.blue)*'=')
print("G: " + graph_map(sensor.green)*'=')
print("Y: " + graph_map(sensor.yellow)*'=')
print("O: " + graph_map(sensor.orange)*'=')
print("R: " + graph_map(sensor.red)*'=')
print("V: " + graph_map(sensor.violet) * "=")
print("B: " + graph_map(sensor.blue) * "=")
print("G: " + graph_map(sensor.green) * "=")
print("Y: " + graph_map(sensor.yellow) * "=")
print("O: " + graph_map(sensor.orange) * "=")
print("R: " + graph_map(sensor.red) * "=")
time.sleep(1)

View file

@ -1,2 +1,3 @@
adafruit-circuitpython-bus-device
Adafruit-Blinka
adafruit-circuitpython-busdevice
adafruit-circuitpython-register

56
setup.py Normal file
View file

@ -0,0 +1,56 @@
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read()
setup(
name="adafruit-circuitpython-as726x",
use_scm_version=True,
setup_requires=["setuptools_scm"],
description="CircuitPython driver for AS726x spectral sensor.",
long_description=long_description,
long_description_content_type="text/x-rst",
# The project's main homepage.
url="https://github.com/adafruit/Adafruit_CircuitPython_AS726x",
# Author details
author="Adafruit Industries",
author_email="circuitpython@adafruit.com",
install_requires=[
"Adafruit-Blinka",
"adafruit-circuitpython-register",
"adafruit-circuitpython-busdevice",
],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries",
"Topic :: System :: Hardware",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
],
# What does your project relate to?
keywords="adafruit as726x light sensor hardware micropython circuitpython",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
py_modules=["adafruit_as726x"],
)