From ede7e24bbf2621e38cf06e80078a2864f7ccf9b7 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 09:21:42 -0400 Subject: [PATCH 01/17] initial commit --- .gitignore | 6 + .pylintrc | 433 ++++++++++++++++++++++++++++++++ .readthedocs.yml | 3 + .travis.yml | 32 +++ CODE_OF_CONDUCT.md | 74 ++++++ LICENSE | 21 ++ README.rst | 90 +++++++ adafruit_stmpe610.py | 280 +++++++++++++++++++++ docs/_static/favicon.ico | Bin 0 -> 4414 bytes docs/api.rst | 8 + docs/conf.py | 160 ++++++++++++ docs/examples.rst | 8 + docs/index.rst | 51 ++++ examples/paint.py | 38 +++ examples/paint_nrf52.py | 38 +++ examples/stmpe610_nrf52.py | 11 + examples/stmpe610_simpletest.py | 0 examples/stmpe610_test.py | 11 + requirements.txt | 2 + 19 files changed, 1266 insertions(+) create mode 100644 .gitignore create mode 100644 .pylintrc create mode 100644 .readthedocs.yml create mode 100644 .travis.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 LICENSE create mode 100644 README.rst create mode 100644 adafruit_stmpe610.py create mode 100644 docs/_static/favicon.ico create mode 100644 docs/api.rst create mode 100644 docs/conf.py create mode 100644 docs/examples.rst create mode 100644 docs/index.rst create mode 100644 examples/paint.py create mode 100644 examples/paint_nrf52.py create mode 100644 examples/stmpe610_nrf52.py create mode 100644 examples/stmpe610_simpletest.py create mode 100644 examples/stmpe610_test.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0dd8629 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__ +_build +*.pyc +.env +build* +bundles diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..81d8170 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,433 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +# jobs=1 +jobs=2 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# 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 + +# 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 +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +# notes=FIXME,XXX,TODO +notes=FIXME,XXX + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (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= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= +expected-line-ending-format=LF + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma,dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[BASIC] + +# Naming hint for argument names +argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct argument names +argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for attribute names +attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct attribute names +attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming hint for class names +# class-name-hint=[A-Z_][a-zA-Z0-9]+$ +class-name-hint=[A-Z_][a-zA-Z0-9_]+$ + +# Regular expression matching correct class names +# class-rgx=[A-Z_][a-zA-Z0-9]+$ +class-rgx=[A-Z_][a-zA-Z0-9_]+$ + +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming hint for function names +function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct function names +function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Good variable names which should always be accepted, separated by a comma +# good-names=i,j,k,ex,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming hint for method names +method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct method names +method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming hint for variable names +variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct variable names +variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +# max-attributes=7 +max-attributes=11 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=1 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 0000000..f4243ad --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,3 @@ +python: + version: 3 +requirements_file: requirements.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f1c0164 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +# 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_stmpe610.py + - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-stmpe610 --library_location . + - cd docs && sphinx-build -E -W -b html . _build/html diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..1617586 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant 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 +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. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* 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 +* Trolling, insulting/derogatory comments, and personal or political attacks +* 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 + +## Our Responsibilities + +Project maintainers 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 +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. + +## Scope + +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. + +## 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] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9c96cad --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Jerry Needell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..5eb9ea0 --- /dev/null +++ b/README.rst @@ -0,0 +1,90 @@ +Introduction +============ + +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-stmpe610/badge/?version=latest + :target: https://circuitpython.readthedocs.io/projects/stmpe610/en/latest/ + :alt: Documentation Status + +.. image:: https://img.shields.io/discord/327254708534116352.svg + :target: https://discord.gg/nBQh6qu + :alt: Discord + +.. image:: https://travis-ci.org/adafruit/adafruit_CircuitPython_stmpe610.svg?branch=master + :target: https://travis-ci.org/adafruit/adafruit_CircuitPython_stmpe610 + :alt: Build Status + +.. todo:: Describe what the library does. + +Dependencies +============= +This driver depends on: + +* `Adafruit CircuitPython `_ +* `Bus Device `_ +* `Register `_ + +Please ensure all dependencies are available on the CircuitPython filesystem. +This is easily achieved by downloading +`the Adafruit library and driver bundle `_. + +Usage Example +============= + +.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst. + +Contributing +============ + +Contributions are welcome! Please read our `Code of Conduct +`_ +before contributing to help this project stay welcoming. + +Building locally +================ + +Zip release files +----------------- + +To build this library locally you'll need to install the +`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-stmpe610 --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. diff --git a/adafruit_stmpe610.py b/adafruit_stmpe610.py new file mode 100644 index 0000000..0072844 --- /dev/null +++ b/adafruit_stmpe610.py @@ -0,0 +1,280 @@ +# The MIT License (MIT) +# +# Copyright (c) 2017 Jerry Needell +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_stmpe610` +==================================================== + +This is a CircuitPython Driver for the STMPE610 Resistive Touch sensor + +* Author(s): Jerry Needell +""" + +# imports + +import time, math +from micropython import const +try: + import struct +except ImportError: + import ustruct as struct + + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_stmpe610.git" + + + +_STMPE_ADDR = const(0x41) +_STMPE_VERSION = const(0x0811) + +STMPE_SYS_CTRL1 = const(0x03) +STMPE_SYS_CTRL1_RESET = const(0x02) +STMPE_SYS_CTRL2 = const(0x04) + +STMPE_TSC_CTRL = const(0x40) +STMPE_TSC_CTRL_EN = const(0x01) +STMPE_TSC_CTRL_XYZ = const(0x00) +STMPE_TSC_CTRL_XY = const(0x02) + +STMPE_INT_CTRL = const(0x09) +STMPE_INT_CTRL_POL_HIGH = const(0x04) +STMPE_INT_CTRL_POL_LOW = const(0x00) +STMPE_INT_CTRL_EDGE = const(0x02) +STMPE_INT_CTRL_LEVEL = const(0x00) +STMPE_INT_CTRL_ENABLE = const(0x01) +STMPE_INT_CTRL_DISABLE = const(0x00) + + + +STMPE_INT_EN = const(0x0A) +STMPE_INT_EN_TOUCHDET = const(0x01) +STMPE_INT_EN_FIFOTH = const(0x02) +STMPE_INT_EN_FIFOOF = const(0x04) +STMPE_INT_EN_FIFOFULL = const(0x08) +STMPE_INT_EN_FIFOEMPTY = const(0x10) +STMPE_INT_EN_ADC = const(0x40) +STMPE_INT_EN_GPIO = const(0x80) + +STMPE_INT_STA = const(0x0B) +STMPE_INT_STA_TOUCHDET = const(0x01) + +STMPE_ADC_CTRL1 = const(0x20) +STMPE_ADC_CTRL1_12BIT = const(0x08) +STMPE_ADC_CTRL1_10BIT = const(0x00) + +STMPE_ADC_CTRL2 = const(0x21) +STMPE_ADC_CTRL2_1_625MHZ = const(0x00) +STMPE_ADC_CTRL2_3_25MHZ = const(0x01) +STMPE_ADC_CTRL2_6_5MHZ = const(0x02) + +STMPE_TSC_CFG = const(0x41) +STMPE_TSC_CFG_1SAMPLE = const(0x00) +STMPE_TSC_CFG_2SAMPLE = const(0x40) +STMPE_TSC_CFG_4SAMPLE = const(0x80) +STMPE_TSC_CFG_8SAMPLE = const(0xC0) +STMPE_TSC_CFG_DELAY_10US = const(0x00) +STMPE_TSC_CFG_DELAY_50US = const(0x08) +STMPE_TSC_CFG_DELAY_100US = const(0x10) +STMPE_TSC_CFG_DELAY_500US = const(0x18) +STMPE_TSC_CFG_DELAY_1MS = const(0x20) +STMPE_TSC_CFG_DELAY_5MS = const(0x28) +STMPE_TSC_CFG_DELAY_10MS = const(0x30) +STMPE_TSC_CFG_DELAY_50MS = const(0x38) +STMPE_TSC_CFG_SETTLE_10US = const(0x00) +STMPE_TSC_CFG_SETTLE_100US = const(0x01) +STMPE_TSC_CFG_SETTLE_500US = const(0x02) +STMPE_TSC_CFG_SETTLE_1MS = const(0x03) +STMPE_TSC_CFG_SETTLE_5MS = const(0x04) +STMPE_TSC_CFG_SETTLE_10MS = const(0x05) +STMPE_TSC_CFG_SETTLE_50MS = const(0x06) +STMPE_TSC_CFG_SETTLE_100MS = const(0x07) + +STMPE_FIFO_TH = const(0x4A) + +STMPE_FIFO_SIZE = const(0x4C) + +STMPE_FIFO_STA = const(0x4B) +STMPE_FIFO_STA_RESET = const(0x01) +STMPE_FIFO_STA_OFLOW = const(0x80) +STMPE_FIFO_STA_FULL = const(0x40) +STMPE_FIFO_STA_EMPTY = const(0x20) +STMPE_FIFO_STA_THTRIG = const(0x10) + +STMPE_TSC_I_DRIVE = const(0x58) +STMPE_TSC_I_DRIVE_20MA = const(0x00) +STMPE_TSC_I_DRIVE_50MA = const(0x01) + +STMPE_TSC_DATA_X = const(0x4D) +STMPE_TSC_DATA_Y = const(0x4F) +STMPE_TSC_FRACTION_Z = const(0x56) + +STMPE_GPIO_SET_PIN = const(0x10) +STMPE_GPIO_CLR_PIN = const(0x11) +STMPE_GPIO_DIR = const(0x13) +STMPE_GPIO_ALT_FUNCT = const(0x17) + + + +class Adafruit_STMPE610: + """ + A driver for the STMPE610 Resistive Touch sensor. + """ + def __init__(self): + """Check the STMPE610 was found""" + # Check device version. + version = self.getVersion + if _STMPE_VERSION != version: + raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version) + self._write_register_byte(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET) + time.sleep(.001) + + + self._write_register_byte(STMPE_SYS_CTRL2, 0x0); # turn on clocks! + self._write_register_byte(STMPE_TSC_CTRL, STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN) # XYZ and enable! + self._write_register_byte(STMPE_INT_EN, STMPE_INT_EN_TOUCHDET) + self._write_register_byte(STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion + self._write_register_byte(STMPE_ADC_CTRL2, STMPE_ADC_CTRL2_6_5MHZ) + self._write_register_byte(STMPE_TSC_CFG, STMPE_TSC_CFG_4SAMPLE | STMPE_TSC_CFG_DELAY_1MS | STMPE_TSC_CFG_SETTLE_5MS) + self._write_register_byte(STMPE_TSC_FRACTION_Z, 0x6) + self._write_register_byte(STMPE_FIFO_TH, 1) + self._write_register_byte(STMPE_FIFO_STA, STMPE_FIFO_STA_RESET) + self._write_register_byte(STMPE_FIFO_STA, 0) # unreset + self._write_register_byte(STMPE_TSC_I_DRIVE, STMPE_TSC_I_DRIVE_50MA) + self._write_register_byte(STMPE_INT_STA, 0xFF) # reset all ints + self._write_register_byte(STMPE_INT_CTRL, STMPE_INT_CTRL_POL_HIGH | STMPE_INT_CTRL_ENABLE) + + def readData(self): + d1=self._read_byte(0xD7) + d2=self._read_byte(0xD7) + d3=self._read_byte(0xD7) + d4=self._read_byte(0xD7) + x = d1 << 4 | d2 >> 4 + y = (d2 & 0xF) <<8 | d3 + z = d4 + # reset all ints (not sure what this does) + if self.bufferEmpty: + self._write_register_byte(STMPE_INT_STA, 0xFF) + return (x,y,z) + + def _read_byte(self, register): + """Read a byte register value and return it""" + return self._read_register(register, 1)[0] + + + # pylint: disable=unused-variable + @property + def touches(self): + """ + Returns a list of touchpoint dicts, with 'x' and 'y' containing the + touch coordinates, and 'pressure' + """ + touchpoints = [] + (x,y,z) = self.readData() + point = {'x':x, 'y':y, 'pressure':z} + touchpoints.append(point) + return touchpoints + # pylint: enable=unused-variable + + + @property + def getVersion(self): + "Read the version number from the sensosr" + v1=self._read_byte(0) + v2=self._read_byte(1) + version = v1<<8 | v2 + #print("version ",hex(version)) + return version + + @property + def touched(self): + "Report if any touches have been detectd" + touch=self._read_byte(STMPE_TSC_CTRL)&0x80 + return touch == 0x80 + + + @property + def bufferSize(self): + "The amount of touch data in the buffer" + return self._read_byte(STMPE_FIFO_SIZE) + + @property + def bufferEmpty(self): + "Buffer empty status" + empty=self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY + return empty != 0 + + + + @property + def getPoint(self): + "Read one touch tuple from the buffer" + return (x,y,z) + + + + +class Adafruit_STMPE610_I2C(Adafruit_STMPE610): + def __init__(self, i2c, address=_STMPE_ADDR): + """Check the STMPE610 was founnd, Default address is 0x41 but another address can be passed in as an argument""" + import adafruit_bus_device.i2c_device as i2c_device + self._i2c = i2c_device.I2CDevice(i2c, address) + super().__init__() + + def _read_register(self, register, length): + """Low level register reading over I2C, returns a list of values""" + with self._i2c as i2c: + i2c.write(bytearray([register & 0xFF])) + result = bytearray(length) + i2c.readinto(result) + #print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register, value): + """Low level register writing over I2C, writes one 8-bit value""" + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF, value & 0xFF])) + #print("$%02X <= 0x%02X" % (register, value)) + +class Adafruit_STMPE610_SPI(Adafruit_STMPE610): + def __init__(self, spi, cs, baudrate=100000): + """Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate'""" + import adafruit_bus_device.spi_device as spi_device + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) + super().__init__() + + def _read_register(self, register, length): + """Low level register reading over SPI, returns a list of values""" + register = (register | 0x80) & 0xFF # Read single, bit 7 high. + with self._spi as spi: + spi.write(bytearray([register])) + result = bytearray(length) + spi.readinto(result) +# print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register, value): + """Low level register writing over SPI, writes one 8-bit value""" + register &= 0x7F # Write, bit 7 low. + with self._spi as spi: + spi.write(bytes([register, value & 0xFF])) + + diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5aca98376a1f7e593ebd9cf41a808512c2135635 GIT binary patch literal 4414 zcmd^BX;4#F6n=SG-XmlONeGrD5E6J{RVh+e928U#MG!$jWvO+UsvWh`x&VqGNx*en zx=qox7Dqv{kPwo%fZC$dDwVpRtz{HzTkSs8QhG0)%Y=-3@Kt!4ag|JcIo?$-F|?bXVS9UDUyev>MVZQ(H8K4#;BQW-t2CPorj8^KJrMX}QK zp+e<;4ldpXz~=)2GxNy811&)gt-}Q*yVQpsxr@VMoA##{)$1~=bZ1MmjeFw?uT(`8 z^g=09<=zW%r%buwN%iHtuKSg|+r7HkT0PYN*_u9k1;^Ss-Z!RBfJ?Un4w(awqp2b3 z%+myoFis_lTlCrGx2z$0BQdh+7?!JK#9K9@Z!VrG zNj6gK5r(b4?YDOLw|DPRoN7bdP{(>GEG41YcN~4r_SUHU2hgVtUwZG@s%edC;k7Sn zC)RvEnlq~raE2mY2ko64^m1KQL}3riixh?#J{o)IT+K-RdHae2eRX91-+g!y`8^># z-zI0ir>P%Xon)!@xp-BK2bDYUB9k613NRrY6%lVjbFcQc*pRqiK~8xtkNPLxt}e?&QsTB}^!39t_%Qb)~Ukn0O%iC;zt z<&A-y;3h++)>c1br`5VFM~5(83!HKx$L+my8sW_c#@x*|*vB1yU)_dt3vH;2hqPWx zAl^6@?ipx&U7pf`a*>Yq6C85nb+B=Fnn+(id$W#WB^uHAcZVG`qg;rWB}ubvi(Y>D z$ei>REw$#xp0SHAd^|1hq&9HJ=jKK8^zTH~nk)G?yUcmTh9vUM6Y0LMw4(gYVY$D$ zGl&WY&H<)BbJ&3sYbKjx1j^=3-0Q#f^}(aP1?8^`&FUWMp|rmtpK)bLQ1Zo?^s4jqK=Lfg*9&geMGVQ z#^-*!V`fG@;H&{M9S8%+;|h&Qrxym0Ar>WT4BCVLR8cGXF=JmEYN(sNT(9vl+S|%g z8r7nXQ(95i^`=+XHo|){$vf2$?=`F$^&wFlYXyXg$B{a>$-Fp+V}+D;9k=~Xl~?C4 zAB-;RKXdUzBJE{V&d&%R>aEfFe;vxqI$0@hwVM}gFeQR@j}a>DDxR+n+-*6|_)k%% z*mSpDV|=5I9!&VC&9tD%fcVygWZV!iIo2qFtm#!*(s|@ZT33*Ad;+<|3^+yrp*;oH zBSYLV(H1zTU?2WjrCQoQW)Z>J2a=dTriuvezBmu16`tM2fm7Q@d4^iqII-xFpwHGI zn9CL}QE*1vdj2PX{PIuqOe5dracsciH6OlAZATvE8rj6ykqdIjal2 z0S0S~PwHb-5?OQ-tU-^KTG@XNrEVSvo|HIP?H;7ZhYeZkhSqh-{reE!5di;1zk$#Y zCe7rOnlzFYJ6Z#Hm$GoidKB=2HBCwm`BbZVeZY4ukmG%1uz7p2URs6c9j-Gjj^oQV zsdDb3@k2e`C$1I5ML5U0Qs0C1GAp^?!*`=|Nm(vWz3j*j*8ucum2;r0^-6Aca=Gv) zc%}&;!+_*S2tlnnJnz0EKeRmw-Y!@9ob!XQBwiv}^u9MkaXHvM=!<3YX;+2#5Cj5pp?FEK750S3BgeSDtaE^ zXUM@xoV6yBFKfzvY20V&Lr0yC + CircuitPython Reference Documentation + CircuitPython Support Forum + Discord Chat + Adafruit Learning System + Adafruit Blog + Adafruit Store + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/examples/paint.py b/examples/paint.py new file mode 100644 index 0000000..d547e87 --- /dev/null +++ b/examples/paint.py @@ -0,0 +1,38 @@ +""" +Simple painting demo that draws on an Adafruit capacitive touch shield with +ILI9341 display and STMPE610 resistive touch driver +""" + +import busio +import board +import digitalio +import adafruit_stmpe610 +from adafruit_rgb_display import ili9341, color565 + +# Create library object using our Bus I2C & SPI port +i2c = busio.I2C(board.SCL, board.SDA) +spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) + +# Adafruit Metro M0 + 2.8" Capacitive touch shield +cs_pin = digitalio.DigitalInOut(board.D9) +dc_pin = digitalio.DigitalInOut(board.D10) + +# Initialize display +display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) +# Fill with black! +display.fill(color565(0, 0, 0)) + +st_cs_pin = digitalio.DigitalInOut(board.D6) +st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi,st_cs_pin) + +while True: + if st.touched: + ts = st.touches + point = ts[0] # the shield only supports one point! + # perform transformation to get into display coordinate system! + y = point['y'] + x = 4096 - point['x'] + x = 2 * x // 30 + y = 8 * y // 90 + display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) + diff --git a/examples/paint_nrf52.py b/examples/paint_nrf52.py new file mode 100644 index 0000000..6bcd043 --- /dev/null +++ b/examples/paint_nrf52.py @@ -0,0 +1,38 @@ +""" +Simple painting demo that draws on an Adafruit capacitive touch shield with +ILI9341 display and STMPE610 resistive touch driver +""" + +import busio +import board +import digitalio +import adafruit_stmpe610 +from adafruit_rgb_display import ili9341, color565 + +# Create library object using our Bus I2C & SPI port +i2c = busio.I2C(board.SCL, board.SDA) +spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) + +# Adafruit Metro M0 + 2.8" Capacitive touch shield +cs_pin = digitalio.DigitalInOut(board.A7) +dc_pin = digitalio.DigitalInOut(board.D11) + +# Initialize display +display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) +# Fill with black! +display.fill(color565(0, 0, 0)) + +st_cs_pin = digitalio.DigitalInOut(board.A6) +st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi,st_cs_pin) + +while True: + if st.touched: + ts = st.touches + point = ts[0] # the shield only supports one point! + # perform transformation to get into display coordinate system! + y = point['y'] + x = 4096 - point['x'] + x = 2 * x // 30 + y = 8 * y // 90 + display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) + diff --git a/examples/stmpe610_nrf52.py b/examples/stmpe610_nrf52.py new file mode 100644 index 0000000..852c8ad --- /dev/null +++ b/examples/stmpe610_nrf52.py @@ -0,0 +1,11 @@ +import busio +import board +import digitalio +from adafruit_stmpe610 import Adafruit_STMPE610_SPI +spi=busio.SPI(board.SCK,board.MOSI,board.MISO) +cs = digitalio.DigitalInOut(board.A6) +st=Adafruit_STMPE610_SPI(spi,cs) +print("Go Ahead - Touch the Screen - Make My Day!") +while True: + if(not st.bufferEmpty): + print(st.readData()) diff --git a/examples/stmpe610_simpletest.py b/examples/stmpe610_simpletest.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/stmpe610_test.py b/examples/stmpe610_test.py new file mode 100644 index 0000000..a9cdcad --- /dev/null +++ b/examples/stmpe610_test.py @@ -0,0 +1,11 @@ +import busio +import board +import digitalio +from adafruit_stmpe610 import Adafruit_STMPE610_SPI +spi=busio.SPI(board.SCK,board.MOSI,board.MISO) +cs = digitalio.DigitalInOut(board.D6) +st=Adafruit_STMPE610_SPI(spi,cs) +print("Go Ahead - Touch the Screen - Make My Day!") +while True: + if(not st.bufferEmpty): + print(st.readData()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7053ecf --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +adafruit-circuitpython-bus-device +adafruit-circuitpython-register From 91abc74e0fc1c21fc504ddb1129ef94c79d38584 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 15:53:38 -0400 Subject: [PATCH 02/17] start working on pylint complaints --- adafruit_stmpe610.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/adafruit_stmpe610.py b/adafruit_stmpe610.py index 0072844..8001d7e 100644 --- a/adafruit_stmpe610.py +++ b/adafruit_stmpe610.py @@ -148,7 +148,7 @@ def __init__(self): time.sleep(.001) - self._write_register_byte(STMPE_SYS_CTRL2, 0x0); # turn on clocks! + self._write_register_byte(STMPE_SYS_CTRL2, 0x0) # turn on clocks! self._write_register_byte(STMPE_TSC_CTRL, STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN) # XYZ and enable! self._write_register_byte(STMPE_INT_EN, STMPE_INT_EN_TOUCHDET) self._write_register_byte(STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion @@ -163,17 +163,18 @@ def __init__(self): self._write_register_byte(STMPE_INT_CTRL, STMPE_INT_CTRL_POL_HIGH | STMPE_INT_CTRL_ENABLE) def readData(self): - d1=self._read_byte(0xD7) - d2=self._read_byte(0xD7) - d3=self._read_byte(0xD7) - d4=self._read_byte(0xD7) - x = d1 << 4 | d2 >> 4 - y = (d2 & 0xF) <<8 | d3 - z = d4 + """Request next stored reading - return tuple containing (x,y,pressure) """ + d1 = self._read_byte(0xD7) + d2 = self._read_byte(0xD7) + d3 = self._read_byte(0xD7) + d4 = self._read_byte(0xD7) + x = d1 << 4 | d2 >> 4 + y = (d2 & 0xF) << 8 | d3 + z = d4 # reset all ints (not sure what this does) if self.bufferEmpty: self._write_register_byte(STMPE_INT_STA, 0xFF) - return (x,y,z) + return (x, y, z) def _read_byte(self, register): """Read a byte register value and return it""" @@ -185,10 +186,10 @@ def _read_byte(self, register): def touches(self): """ Returns a list of touchpoint dicts, with 'x' and 'y' containing the - touch coordinates, and 'pressure' + touch coordinates, and 'pressure' """ touchpoints = [] - (x,y,z) = self.readData() + (x, y, z) = self.readData() point = {'x':x, 'y':y, 'pressure':z} touchpoints.append(point) return touchpoints @@ -198,8 +199,8 @@ def touches(self): @property def getVersion(self): "Read the version number from the sensosr" - v1=self._read_byte(0) - v2=self._read_byte(1) + v1 = self._read_byte(0) + v2 = self._read_byte(1) version = v1<<8 | v2 #print("version ",hex(version)) return version @@ -207,7 +208,7 @@ def getVersion(self): @property def touched(self): "Report if any touches have been detectd" - touch=self._read_byte(STMPE_TSC_CTRL)&0x80 + touch = self._read_byte(STMPE_TSC_CTRL)&0x80 return touch == 0x80 @@ -219,7 +220,7 @@ def bufferSize(self): @property def bufferEmpty(self): "Buffer empty status" - empty=self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY + empty = self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY return empty != 0 @@ -227,7 +228,7 @@ def bufferEmpty(self): @property def getPoint(self): "Read one touch tuple from the buffer" - return (x,y,z) + return self.readData() From 32b3f6a0dd375c92640377c7b49610e7e303f255 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 18:00:00 -0400 Subject: [PATCH 03/17] cleanups enspired by pylint --- adafruit_stmpe610.mpy | Bin 0 -> 5582 bytes adafruit_stmpe610.py | 50 ++++++++++++++++--------------------- examples/stmpe610_nrf52.py | 4 +-- examples/stmpe610_test.py | 4 +-- 4 files changed, 26 insertions(+), 32 deletions(-) create mode 100644 adafruit_stmpe610.mpy diff --git a/adafruit_stmpe610.mpy b/adafruit_stmpe610.mpy new file mode 100644 index 0000000000000000000000000000000000000000..e6b91bd48ad083a8eb10ca3f3b24f80905697233 GIT binary patch literal 5582 zcmd^DO>h&*74DX7{EJyHLiXYxhNW!`23r!CC9o`(^^~2t=dbHOHxHas+Mf!cggFSo{=mMfeN`rhMCu| z-+TRa_xJj>G;TKSx{|0t>~r=o`UWlTC^q$FdY0-4areT1qI@JlefN5q2L7?m-d-?Z zpPnA|P265DQ?pKYFW3?y2{&V3SP^#I86SD7RkR*k$eZ*7w85-_$tA;NKE)LF~hqCFOph#Z^6r?4&-{! zH-JqezD}C(m!ui9C|j{*5s?;rlWYTSiA?VadH%%6XbjF zJVTCw&2fB-ypMlEPT-%C53mq1Sx;igL{5Teww}Ws&@z*A(5kT}cq@Th!}agar=`N2 z{DCDZMdR5*GEZ~)`HXzTZX3uf)Z~-%vht{nrBk_l(|j_PO=lMJiF8WUa6P3L39!yjnLlsVDGum1b&s zrrKy~nn&>kL?ud_>Z3JjaKcZ=e4}Gl1HFIZU zR^_2~quVyMAxH0YbyS~dxZ&WbqD(!ueaf&d%#Q*TqdW5g$NXcbx;Xsdi3?dpJ< zm4n*p5y#N@*bLvPa>pU6=sBjc{s?8}9Js<3?xXm6{kU;c2+7Xmw%F}_@XE(w{Mb1 zQkqV`NWG^6F0s|A)dGbUPzyF|c5JetK8Ndd?F_s_LEme6gPqBoYqkx*-@#}hpB}K~ zPA2mCOzzm=;Q3@eQJ5WwrRN8=dN!y7btSVgC~!fge3i=__)-duzJB;S*spwGtyj86 z@B_=2t);KuYbti0g1cbpTM3`VE8Q-9<#OEQ=zNa4-MGyZ#}1~uS_B;v;C8pj#br&n zZ7D{$?hf-+?VOfHqBqW5)5Q-pH@J>fh~)vMH0@2x;wA2OV+jPfN@?qDxPg_c+B{iE zv741An@wje^heobUWT1HpUmZ9McMACcdp!=EN2Y+|DTm6RFjkE;<^3aXmU=LgnU|v zCsUH3omIO9S0b4a&Zrks!FI9dV!Rd(3!8neS>fJx52X3x9brFw`uaxp_A}0PkHW?K z<2ZhxOAmGFkuI&5u0C76`sXK)SAYEU`m?nszqPTafy%b+=2&N@Rr zRHWi7#SLj?xb;X~lTJu3ILaDF*#v(fDDw*95^%P-J6ti0A)*%baL{# zww+?J??;3^{f<5u;1q%t^WZp|Ha~o{9x|_5MJ%paPh;_}bsUS2OWof`_aISAVeOzX z9K5_*_#$RUhn&k5vhtQ_CL^aLj^#j|0%7Y2gRn02^?CWu75Tm`#__|_^=GS39<7Bd z6V7nRiuI@v`B1&J%1}*HY^dJ|0~$q&!*TWn?dgLOJipTBB)w_?9<>9$R>R@fIK!g; zR^1=qUC|%M;mQN`HN(BjK?Yd3uY?0S$dBUqHb5+X9o|SCttOU>UuI$R+}q76%Cju& z?^Kj*hr{KA+z?=S5BYSDslOs@JqLll_~U$J2`HqO(sQho!uRVSZeNKZtd`UuE2%EL z65gR#Z7r?Y^}=viqta;XZd@L#cyF9v<|BZ;2H|F)=*1+mlG@FeslqEPsq7u~qG$)3B zsBD>&Q|I%Eqbk%U7lZm&ft@P~&JK<wRrS?K} zt{@-hluaUzb5l>mCVhI%(u1)y^PHzOYze0 SRj6%cPQMwSb&&sw&;JHa7r~?e literal 0 HcmV?d00001 diff --git a/adafruit_stmpe610.py b/adafruit_stmpe610.py index 8001d7e..8f3c3fb 100644 --- a/adafruit_stmpe610.py +++ b/adafruit_stmpe610.py @@ -30,12 +30,8 @@ # imports -import time, math +import time from micropython import const -try: - import struct -except ImportError: - import ustruct as struct __version__ = "0.0.0-auto.0" @@ -141,7 +137,7 @@ class Adafruit_STMPE610: def __init__(self): """Check the STMPE610 was found""" # Check device version. - version = self.getVersion + version = self.get_version if _STMPE_VERSION != version: raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version) self._write_register_byte(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET) @@ -162,19 +158,19 @@ def __init__(self): self._write_register_byte(STMPE_INT_STA, 0xFF) # reset all ints self._write_register_byte(STMPE_INT_CTRL, STMPE_INT_CTRL_POL_HIGH | STMPE_INT_CTRL_ENABLE) - def readData(self): + def read_data(self): """Request next stored reading - return tuple containing (x,y,pressure) """ - d1 = self._read_byte(0xD7) - d2 = self._read_byte(0xD7) - d3 = self._read_byte(0xD7) - d4 = self._read_byte(0xD7) - x = d1 << 4 | d2 >> 4 - y = (d2 & 0xF) << 8 | d3 - z = d4 + d_1 = self._read_byte(0xD7) + d_2 = self._read_byte(0xD7) + d_3 = self._read_byte(0xD7) + d_4 = self._read_byte(0xD7) + x_loc = d_1 << 4 | d_2 >> 4 + y_loc = (d_2 & 0xF) << 8 | d_3 + pressure = d_4 # reset all ints (not sure what this does) - if self.bufferEmpty: + if self.buffer_empty: self._write_register_byte(STMPE_INT_STA, 0xFF) - return (x, y, z) + return (x_loc, y_loc, pressure) def _read_byte(self, register): """Read a byte register value and return it""" @@ -189,19 +185,19 @@ def touches(self): touch coordinates, and 'pressure' """ touchpoints = [] - (x, y, z) = self.readData() - point = {'x':x, 'y':y, 'pressure':z} + (x_loc, y_loc, pressure) = self.read_data() + point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} touchpoints.append(point) return touchpoints # pylint: enable=unused-variable @property - def getVersion(self): + def get_version(self): "Read the version number from the sensosr" - v1 = self._read_byte(0) - v2 = self._read_byte(1) - version = v1<<8 | v2 + v_1 = self._read_byte(0) + v_2 = self._read_byte(1) + version = v_1<<8 | v_2 #print("version ",hex(version)) return version @@ -213,12 +209,12 @@ def touched(self): @property - def bufferSize(self): + def buffer_size(self): "The amount of touch data in the buffer" return self._read_byte(STMPE_FIFO_SIZE) @property - def bufferEmpty(self): + def buffer_empty(self): "Buffer empty status" empty = self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY return empty != 0 @@ -226,9 +222,9 @@ def bufferEmpty(self): @property - def getPoint(self): + def get_point(self): "Read one touch tuple from the buffer" - return self.readData() + return self.read_data() @@ -277,5 +273,3 @@ def _write_register_byte(self, register, value): register &= 0x7F # Write, bit 7 low. with self._spi as spi: spi.write(bytes([register, value & 0xFF])) - - diff --git a/examples/stmpe610_nrf52.py b/examples/stmpe610_nrf52.py index 852c8ad..f1155be 100644 --- a/examples/stmpe610_nrf52.py +++ b/examples/stmpe610_nrf52.py @@ -7,5 +7,5 @@ st=Adafruit_STMPE610_SPI(spi,cs) print("Go Ahead - Touch the Screen - Make My Day!") while True: - if(not st.bufferEmpty): - print(st.readData()) + if(not st.buffer_empty): + print(st.read_data()) diff --git a/examples/stmpe610_test.py b/examples/stmpe610_test.py index a9cdcad..d4fa1f6 100644 --- a/examples/stmpe610_test.py +++ b/examples/stmpe610_test.py @@ -7,5 +7,5 @@ st=Adafruit_STMPE610_SPI(spi,cs) print("Go Ahead - Touch the Screen - Make My Day!") while True: - if(not st.bufferEmpty): - print(st.readData()) + if(not st.buffer_empty): + print(st.read_data()) From b6b80705fcd3f394d6267dfacda5d0fa2a32e204 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:03:44 -0400 Subject: [PATCH 04/17] more pylint fixes --- adafruit_stmpe610.mpy | Bin 5582 -> 5847 bytes adafruit_stmpe610.py | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/adafruit_stmpe610.mpy b/adafruit_stmpe610.mpy index e6b91bd48ad083a8eb10ca3f3b24f80905697233..9fae6269679f9350696200c54dc5e950ebbd514f 100644 GIT binary patch delta 552 zcmX@7eO-4#GILR%%*M1lM$R}!X?w;LW|g?jcNxXmr5ZVy7(hVIp7Aq7Z)-xUOeo*B78Pek=_3pYtSO8tL0}dekmUqsu>)C=U=|0E6%A%_0$F}w z78j5eJ2{85dh$mBmC4UJ%NV&Q$8m|VdTV-X=5DU!%4cF+I{78f1IEphPx1PRiL)>; zFf%Z41^^w?xQl_|zleAvFmg3Z$G>)Rw^vvRt)FRfh#GKMp2TleCMg|7{Adpc< z6BLxSjWmD;1~MGnAm_@M#t_MT=T&SVk( z0Jdll^YP>?em}++lXvn5vc-Y~K1>!6u$H$5`VR>B;($VZ-xGQ{TY)w*{Fhc>P?2X4 zi<_J&uujt)D8$0R$Sc7B)b=|;K~o2)qCqetpHVi6@yHgr6vj=P)0j4@B~P{&oW?tm zMM1+@-2IWPj0m03Dy6Q~&?~ delta 385 zcmcbvdro^oGIMgD*v7OxM$TA9X?w;LW|i2@cNxXmMXQ(?KtRf#@iRkjYeK6;D_?5D zWIj#}Yw05l3Ct;sDuIk377LK&1ZJ@USrK3s8;}(RX0ZcVeqa^{kQFnznzMSc6jvD| z=j4f8VyxPl+M2qX*Kp-CF)o}e!~1}7{p7#AetZs`3=E764E%vWs~fjX*5Q|C3tscaD-xwDg{1OnKiK+G$X3k3WaZ%*DX5Xcq-5_mXSOwd}+iUsTo z-dLbe-;3OYR-n-g|D_ceROA`NVkZ{}uG26B3b8OS@<=cMb-h&3)B!4J5X{JDlm*(g zMJ}0f)8;g$jcQ4g8AY8YcM65@HojNTFjn^fD%&8NH2Ia#Jg&wc3K~%EB;gVPYpA6e jAWQ${B}^68 diff --git a/adafruit_stmpe610.py b/adafruit_stmpe610.py index 8f3c3fb..f4d9133 100644 --- a/adafruit_stmpe610.py +++ b/adafruit_stmpe610.py @@ -145,11 +145,15 @@ def __init__(self): self._write_register_byte(STMPE_SYS_CTRL2, 0x0) # turn on clocks! - self._write_register_byte(STMPE_TSC_CTRL, STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN) # XYZ and enable! + self._write_register_byte( + STMPE_TSC_CTRL, STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN) # XYZ and enable! self._write_register_byte(STMPE_INT_EN, STMPE_INT_EN_TOUCHDET) - self._write_register_byte(STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion + self._write_register_byte( + STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion self._write_register_byte(STMPE_ADC_CTRL2, STMPE_ADC_CTRL2_6_5MHZ) - self._write_register_byte(STMPE_TSC_CFG, STMPE_TSC_CFG_4SAMPLE | STMPE_TSC_CFG_DELAY_1MS | STMPE_TSC_CFG_SETTLE_5MS) + self._write_register_byte( + STMPE_TSC_CFG, STMPE_TSC_CFG_4SAMPLE | STMPE_TSC_CFG_DELAY_1MS + | STMPE_TSC_CFG_SETTLE_5MS) self._write_register_byte(STMPE_TSC_FRACTION_Z, 0x6) self._write_register_byte(STMPE_FIFO_TH, 1) self._write_register_byte(STMPE_FIFO_STA, STMPE_FIFO_STA_RESET) @@ -176,6 +180,17 @@ def _read_byte(self, register): """Read a byte register value and return it""" return self._read_register(register, 1)[0] + def _read_register(self, register, length): + # Read an arbitrarily long register (specified by length number of + # bytes) and return a bytearray of the retrieved data. + # Subclasses MUST implement this! + raise NotImplementedError + + def _write_register_byte(self, register, value): + # Write a single byte register at the specified register address. + # Subclasses MUST implement this! + raise NotImplementedError + # pylint: disable=unused-variable @property @@ -230,8 +245,14 @@ def get_point(self): class Adafruit_STMPE610_I2C(Adafruit_STMPE610): + """ + I2C driver for the STMPE610 Resistive Touch sensor. + """ def __init__(self, i2c, address=_STMPE_ADDR): - """Check the STMPE610 was founnd, Default address is 0x41 but another address can be passed in as an argument""" + """ + Check the STMPE610 was founnd + Default address is 0x41 but another address can be passed in as an argument + """ import adafruit_bus_device.i2c_device as i2c_device self._i2c = i2c_device.I2CDevice(i2c, address) super().__init__() @@ -252,8 +273,13 @@ def _write_register_byte(self, register, value): #print("$%02X <= 0x%02X" % (register, value)) class Adafruit_STMPE610_SPI(Adafruit_STMPE610): + """ + SPI driver for the STMPE610 Resistive Touch sensor. + """ def __init__(self, spi, cs, baudrate=100000): - """Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate'""" + """ + Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate' + """ import adafruit_bus_device.spi_device as spi_device self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) super().__init__() From 142cc5c227f5995bf1809d14f9808e5f89a6b543 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:11:19 -0400 Subject: [PATCH 05/17] more pylint fixes in examples --- examples/paint.py | 1 - examples/paint_nrf52.py | 1 - examples/stmpe610_nrf52.py | 2 +- examples/stmpe610_test.py | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/paint.py b/examples/paint.py index d547e87..f59ada2 100644 --- a/examples/paint.py +++ b/examples/paint.py @@ -35,4 +35,3 @@ x = 2 * x // 30 y = 8 * y // 90 display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) - diff --git a/examples/paint_nrf52.py b/examples/paint_nrf52.py index 6bcd043..61fc6f5 100644 --- a/examples/paint_nrf52.py +++ b/examples/paint_nrf52.py @@ -35,4 +35,3 @@ x = 2 * x // 30 y = 8 * y // 90 display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) - diff --git a/examples/stmpe610_nrf52.py b/examples/stmpe610_nrf52.py index f1155be..915c649 100644 --- a/examples/stmpe610_nrf52.py +++ b/examples/stmpe610_nrf52.py @@ -7,5 +7,5 @@ st=Adafruit_STMPE610_SPI(spi,cs) print("Go Ahead - Touch the Screen - Make My Day!") while True: - if(not st.buffer_empty): + if not st.buffer_empty: print(st.read_data()) diff --git a/examples/stmpe610_test.py b/examples/stmpe610_test.py index d4fa1f6..fd0000c 100644 --- a/examples/stmpe610_test.py +++ b/examples/stmpe610_test.py @@ -7,5 +7,5 @@ st=Adafruit_STMPE610_SPI(spi,cs) print("Go Ahead - Touch the Screen - Make My Day!") while True: - if(not st.buffer_empty): + if not st.buffer_empty: print(st.read_data()) From b30ea204c6e053fa094f3de6d302193ba5f7127f Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:26:12 -0400 Subject: [PATCH 06/17] more pylint fixes in docs/conf.py add import micropython --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 8c0173c..28aace1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,6 +2,7 @@ import os import sys +import micropython sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ From bf8d92f3d202faa5b2e03d6a395ff7933a4052b8 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:36:38 -0400 Subject: [PATCH 07/17] more pylint fixes in docs/conf.py add mock_auto_imports --- docs/conf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 28aace1..a3b3ae6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,6 @@ import os import sys -import micropython sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ @@ -21,7 +20,7 @@ # 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"] +autodoc_mock_imports = ["micropython", "time","digitalio","busio"] 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)} From 838b4b3ad4965d25f5578e30cf32744f386a6fbc Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:38:25 -0400 Subject: [PATCH 08/17] more pylint fixes in docs/conf.py add mock_auto_imports --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a3b3ae6..7f9160d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,7 @@ # 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 = ["micropython", "time","digitalio","busio"] +autodoc_mock_imports = ["micropython"] 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)} From 3cf62dad3587fb80033d4a421f47235483a1461d Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:47:18 -0400 Subject: [PATCH 09/17] fix README.rst --- README.md | 2 -- README.rst | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index fbb6b98..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Adafruit_CircuitPython_STMPE610 -Adafruit CircuitPython driver for the STMPE610 resistive touchscreen controller diff --git a/README.rst b/README.rst index 5eb9ea0..8d7057a 100644 --- a/README.rst +++ b/README.rst @@ -13,7 +13,7 @@ Introduction :target: https://travis-ci.org/adafruit/adafruit_CircuitPython_stmpe610 :alt: Build Status -.. todo:: Describe what the library does. +Adafruit CirCuitPython module for the SPMPE610 resistive Touch Screen Controller Dependencies ============= @@ -30,8 +30,7 @@ This is easily achieved by downloading Usage Example ============= -.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst. - +see examples in githup repository: https://github.com/adafruit/Adafruit_CIrcuitPython_STMPE610/exmaples Contributing ============ From 5e143249ce709f4252b806a9894b57bef1fb5498 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:51:22 -0400 Subject: [PATCH 10/17] fix index.rst - no guide yet --- docs/index.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index ca8cd42..99063c5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,8 +23,6 @@ Table of Contents .. toctree:: :caption: Tutorials -.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave - the toctree above for use later. .. toctree:: :caption: Related Products From f163bfaaed9ff759ab10cf0d80a62572579b1a1c Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 22 Apr 2018 22:54:26 -0400 Subject: [PATCH 11/17] fix index.rst again - no related products yet --- docs/index.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 99063c5..e6aae38 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -27,8 +27,6 @@ Table of Contents .. toctree:: :caption: Related Products -.. todo:: Add any product links here. If there are none, then simply delete this todo and leave - the toctree above for use later. .. toctree:: :caption: Other Links From 67c7fd5dc7faa3cc1744595a280cfb6a2efcc5de Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 23 Apr 2018 14:34:14 -0400 Subject: [PATCH 12/17] add buffering to touch report - remove unnecessary examples - renamed examples ) --- README.rst | 2 +- adafruit_stmpe610.mpy | Bin 5847 -> 5925 bytes adafruit_stmpe610.py | 13 +- adafruit_stmpe610.pyx | 304 ++++++++++++++++++ examples/paint.py | 18 +- examples/stmpe610_nrf52.py | 11 - ...{paint_nrf52.py => stmpe610_paint_demo.py} | 24 +- examples/stmpe610_simpletest.py | 11 + 8 files changed, 347 insertions(+), 36 deletions(-) create mode 100644 adafruit_stmpe610.pyx delete mode 100644 examples/stmpe610_nrf52.py rename examples/{paint_nrf52.py => stmpe610_paint_demo.py} (53%) diff --git a/README.rst b/README.rst index 8d7057a..51c7fd6 100644 --- a/README.rst +++ b/README.rst @@ -13,7 +13,7 @@ Introduction :target: https://travis-ci.org/adafruit/adafruit_CircuitPython_stmpe610 :alt: Build Status -Adafruit CirCuitPython module for the SPMPE610 resistive Touch Screen Controller +Adafruit CircuitPython module for the STMPE610 Resistive Touch Screen Controller Dependencies ============= diff --git a/adafruit_stmpe610.mpy b/adafruit_stmpe610.mpy index 9fae6269679f9350696200c54dc5e950ebbd514f..ae7ad69286dc259bbb48d3db094b94793e166594 100644 GIT binary patch delta 274 zcmcbvyHsyNGGpn+l+_%J{F?z?flbXkqRGOBSS`?p}TToKTz`#KQIY?-VesHMbM!C1*rP?TC+Tw0V0wa=P` z0R;HsfJXKGnj9~9hVkEI9idH(?33>ctzs0I+$G$}C^lI{k46Wz$D JGdV)69spm@Qz!rc delta 194 zcmZ3gcU^ZvGGo!kl+_%Je47P0`Pif!I2jli85sD37(X*K9!*eC);7{$VE7-%aB#8> zzbenBxqLU}_%S}GWFT!|v@-_Y}#ygW81wt7gPo6H|$M|CMGXYNt z31+ZqT(Kb2J}3YU+92o3n8q+UQBX^ifq|tsH7CuQg#iTk;(%)UzE55&c!u%!> 4 + y_loc = (d_2 & 0xF) << 8 | d_3 + pressure = d_4 + # reset all ints (not sure what this does) + if self.buffer_empty: + self._write_register_byte(STMPE_INT_STA, 0xFF) + return (x_loc, y_loc, pressure) + + def _read_byte(self, register): + """Read a byte register value and return it""" + return self._read_register(register, 1)[0] + + def _read_register(self, register, length): + # Read an arbitrarily long register (specified by length number of + # bytes) and return a bytearray of the retrieved data. + # Subclasses MUST implement this! + raise NotImplementedError + + def _write_register_byte(self, register, value): + # Write a single byte register at the specified register address. + # Subclasses MUST implement this! + raise NotImplementedError + + + # pylint: disable=unused-variable + @property + def touches(self): + """ + Returns a list of touchpoint dicts, with 'x' and 'y' containing the + touch coordinates, and 'pressure' + """ + touchpoints = [] + while (len(touchpoints) < 32) and not self.buffer_empty: + (x_loc, y_loc, pressure) = self.read_data() + point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} + touchpoints.append(point) + return touchpoints + # pylint: enable=unused-variable + + + @property + def get_version(self): + "Read the version number from the sensosr" + v_1 = self._read_byte(0) + v_2 = self._read_byte(1) + version = v_1<<8 | v_2 + #print("version ",hex(version)) + return version + + @property + def touched(self): + "Report if any touches have been detectd" + touch = self._read_byte(STMPE_TSC_CTRL)&0x80 + return touch == 0x80 + + + @property + def buffer_size(self): + "The amount of touch data in the buffer" + return self._read_byte(STMPE_FIFO_SIZE) + + @property + def buffer_empty(self): + "Buffer empty status" + empty = self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY + return empty != 0 + + + + @property + def get_point(self): + "Read one touch from the buffer" + (x_loc, y_loc, pressure) = self.read_data() + point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} + return point + + + + +class Adafruit_STMPE610_I2C(Adafruit_STMPE610): + """ + I2C driver for the STMPE610 Resistive Touch sensor. + """ + def __init__(self, i2c, address=_STMPE_ADDR): + """ + Check the STMPE610 was founnd + Default address is 0x41 but another address can be passed in as an argument + """ + import adafruit_bus_device.i2c_device as i2c_device + self._i2c = i2c_device.I2CDevice(i2c, address) + super().__init__() + + def _read_register(self, register, length): + """Low level register reading over I2C, returns a list of values""" + with self._i2c as i2c: + i2c.write(bytearray([register & 0xFF])) + result = bytearray(length) + i2c.readinto(result) + #print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register, value): + """Low level register writing over I2C, writes one 8-bit value""" + with self._i2c as i2c: + i2c.write(bytes([register & 0xFF, value & 0xFF])) + #print("$%02X <= 0x%02X" % (register, value)) + +class Adafruit_STMPE610_SPI(Adafruit_STMPE610): + """ + SPI driver for the STMPE610 Resistive Touch sensor. + """ + def __init__(self, spi, cs, baudrate=100000): + """ + Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate' + """ + import adafruit_bus_device.spi_device as spi_device + self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) + super().__init__() + + def _read_register(self, register, length): + """Low level register reading over SPI, returns a list of values""" + register = (register | 0x80) & 0xFF # Read single, bit 7 high. + with self._spi as spi: + spi.write(bytearray([register])) + result = bytearray(length) + spi.readinto(result) +# print("$%02X => %s" % (register, [hex(i) for i in result])) + return result + + def _write_register_byte(self, register, value): + """Low level register writing over SPI, writes one 8-bit value""" + register &= 0x7F # Write, bit 7 low. + with self._spi as spi: + spi.write(bytes([register, value & 0xFF])) diff --git a/examples/paint.py b/examples/paint.py index f59ada2..581b6cf 100644 --- a/examples/paint.py +++ b/examples/paint.py @@ -27,11 +27,13 @@ while True: if st.touched: - ts = st.touches - point = ts[0] # the shield only supports one point! - # perform transformation to get into display coordinate system! - y = point['y'] - x = 4096 - point['x'] - x = 2 * x // 30 - y = 8 * y // 90 - display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) + while not st.buffer_empty: + ts = st.touches + for index in range(len(ts)): + point = ts[index] # the shield only supports one point! + # perform transformation to get into display coordinate system! + y = point['y'] + x = 4096 - point['x'] + x = 2 * x // 30 + y = 8 * y // 90 + display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 0, 0)) diff --git a/examples/stmpe610_nrf52.py b/examples/stmpe610_nrf52.py deleted file mode 100644 index 915c649..0000000 --- a/examples/stmpe610_nrf52.py +++ /dev/null @@ -1,11 +0,0 @@ -import busio -import board -import digitalio -from adafruit_stmpe610 import Adafruit_STMPE610_SPI -spi=busio.SPI(board.SCK,board.MOSI,board.MISO) -cs = digitalio.DigitalInOut(board.A6) -st=Adafruit_STMPE610_SPI(spi,cs) -print("Go Ahead - Touch the Screen - Make My Day!") -while True: - if not st.buffer_empty: - print(st.read_data()) diff --git a/examples/paint_nrf52.py b/examples/stmpe610_paint_demo.py similarity index 53% rename from examples/paint_nrf52.py rename to examples/stmpe610_paint_demo.py index 61fc6f5..581b6cf 100644 --- a/examples/paint_nrf52.py +++ b/examples/stmpe610_paint_demo.py @@ -14,24 +14,26 @@ spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Adafruit Metro M0 + 2.8" Capacitive touch shield -cs_pin = digitalio.DigitalInOut(board.A7) -dc_pin = digitalio.DigitalInOut(board.D11) +cs_pin = digitalio.DigitalInOut(board.D9) +dc_pin = digitalio.DigitalInOut(board.D10) # Initialize display display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) # Fill with black! display.fill(color565(0, 0, 0)) -st_cs_pin = digitalio.DigitalInOut(board.A6) +st_cs_pin = digitalio.DigitalInOut(board.D6) st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi,st_cs_pin) while True: if st.touched: - ts = st.touches - point = ts[0] # the shield only supports one point! - # perform transformation to get into display coordinate system! - y = point['y'] - x = 4096 - point['x'] - x = 2 * x // 30 - y = 8 * y // 90 - display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 255, 255)) + while not st.buffer_empty: + ts = st.touches + for index in range(len(ts)): + point = ts[index] # the shield only supports one point! + # perform transformation to get into display coordinate system! + y = point['y'] + x = 4096 - point['x'] + x = 2 * x // 30 + y = 8 * y // 90 + display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 0, 0)) diff --git a/examples/stmpe610_simpletest.py b/examples/stmpe610_simpletest.py index e69de29..fd0000c 100644 --- a/examples/stmpe610_simpletest.py +++ b/examples/stmpe610_simpletest.py @@ -0,0 +1,11 @@ +import busio +import board +import digitalio +from adafruit_stmpe610 import Adafruit_STMPE610_SPI +spi=busio.SPI(board.SCK,board.MOSI,board.MISO) +cs = digitalio.DigitalInOut(board.D6) +st=Adafruit_STMPE610_SPI(spi,cs) +print("Go Ahead - Touch the Screen - Make My Day!") +while True: + if not st.buffer_empty: + print(st.read_data()) From 68df5461ecc86849bcee1649adf4c15908383d51 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 23 Apr 2018 14:36:19 -0400 Subject: [PATCH 13/17] remove .mpy and other files --- adafruit_stmpe610.mpy | Bin 5925 -> 0 bytes adafruit_stmpe610.pyx | 304 ------------------------------------------ 2 files changed, 304 deletions(-) delete mode 100644 adafruit_stmpe610.mpy delete mode 100644 adafruit_stmpe610.pyx diff --git a/adafruit_stmpe610.mpy b/adafruit_stmpe610.mpy deleted file mode 100644 index ae7ad69286dc259bbb48d3db094b94793e166594..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5925 zcmd^DT~L$R89pZgA%G}r1Xh0h)B~cp5TdB{XEo#pvW5^zWW~6i1imjOUGmfXSm}*H z!BrgXI=yJGI_^bhdetF-+nL^UP;967o#}LDd(-x&Gmf^ic4xY6cl)06{Un5s%B;O> z&@b~r}D`W(&d%-43MI_9bfadg6e!at%Qe|NeV0{_@# zXD2AIPe+IRO&l&4gW05`6Lbj?g?qUNtq6UcZ-~A^#c zDv+xIH-SzKzC&v9$D|H3FI%yB29bJvk8A^-?f4OCfcdw;ZU_E^nBjXT;EiD01o}48 z49MHuau>I3f#+G$3TPYHwS(W?_(wzlKYQ>`$zE)>kbT&EoDk6H08gFZX+OS2x*(GS zc#a&zw@Ekth#Uf+?~!-l=^;JvJV$y#+rne?@pxA7c^Ld3fzd_M5B`pV#xWQTljHCl zA>V@M7&!qtC-Fma3jctd#y=$QVj*N`JcC68IRm1x@d|E%k&#@1QAJ}^8AWkJu=-Ry zDdwi6cg9LK|KFbBa?nFOKye+S<++w4dehbVfOE0q-*2nvY^@I0WHkjy#iL$KV z^aVUlzK~sO^VMb`E&VB;aoO@!t92PD6Oi*p8EiDever+a&jM4*_Ok;(149bQ_{i_R z33uxQgdr(`1LMT#+9wg<6_oU??!^9xN$GZt56ykEs=bZLNY( zt7TX{Xr(YL*rps<20LtU056sU<4Q72!!>HN2izlGdPyma>^xI=2xV zFNH%6_o(8D4{e?RbzSh<0}VFyF5t9)yI?)CbDa)#TkV_G)3NsZ+?%onJ%ce*XX$~T zcfz@Bvd5A+6U}B*nG?OeS7X^|ZlY&08Sho^vtBJxdn`Q(7o3k@U&U(bM=xSh32Z}x6Pa8tG<19z8X4~76Fmn2rgDaPzaG`6vD)bLk2R4Lq_7m zp$cNhEvqP0DPl6pr7a*0aH$HUaV}MZ6y%Z#Brlh0K>7gg)eb-d6)jN%YA14$h?J(8*!Lt2tW!WKp2|*Z zsEIjDC1Z&!s+}3%f)GZirI|IOch7cobszZfz&ZGdck>VI%tG4$UNL{%Q26XvZNBw9 zw2y@^M0^=9wA=Bmn-PPx^%ZJ&;3h)^TNyT+2aE~O5Y8y#yed30=R*qi3A2^;Y~~rF z4aRP3;(MwYbZ{kNF~CI?y=R`ep_tvB0|B}(bx(9Rx%92pjph=p8FQx7N&VfC+qBG- zB&BqB@BbMzpo)w%70DcQg=15aC}fjDB$f~bwY=>S?9o_C7?XQg!E(LhdZZHSi=}U> zj&pB^6AHu3PlSW;>FOHT-_1DJJ_x<~`w_gNNl!HCsV1!!W?wGO{`L8@#qYnk^K$9= zuar+@-g4P0N1TvbQy|VnVGKZ9o}Tt9ZyY3aVe3N zM9%wi|68V{#MNw64P$3vepw8oyX2pTs&dAjO1E;e4kfu+VV99V7~#(`&r_ABTy)SuR$p@N8Ke|M}Z&x!Dx8-<`+ zQFXH`(gI({tVT+iOfD^L38zw0LNvllShL&8TRK$5Gu=ACGX1U4)#c)QJBafNV`n1x zN#V}R#ph3#f~BQKH-{1?l!!{G&PpDtcASO!gV3V{g4!BkzsLSJ01yH=U z0DGY9*94i@Kg-O76PNcyaIo|$*`&L@N|IjY?k~b2Ey;5c{0LIae->Qx8aL_I3XK6| zS@!{R`!}K6%KgeTSb6f)Z!9nxEHWA_F&eBc2aA`RZj24KTX`!d<-g3-Ux9cJz6{+r z%>g5|*5nFnP2i6fKHR)8iLl(FKx1Nn#$+M5Q)`9P!pC|x-6ZrH41II`CZqg_>-7`J zcnor{KzJ*^*}n=22iUH_--VL6Z33?@w~KgjDPkyePU6--p+t>|w&QJ+`1F4Cbg5m!ts(-x-*|Bzi%b*cR-UWVav(9!U&ZF4nH zPKtM8Cf1~d)9LVZQGz-f7NJE-D%8;Gu2L6|%c<6~y7+Lr(52?tqU0Ho^IYV~8hEmD zZksQhB^g$-3^V1a$W`-{LfR-~^5e$PgX+1O64FLFX>Z>bHqBc29pFt^3+8Xa+LO=| zR3co*So?5S=s=%L+7xb^!p|PJCxEn#AHrte1m?!yoVl4)Ol59SG{G8V=2lOHb7DH2 zl`1GqZ%AR7GfZYQWp6E~@itE5y~4q+Ue04ysGl=FtSq#}@#%dkkHBKTrlTv{83J|sYvQKBea&}e> 4 - y_loc = (d_2 & 0xF) << 8 | d_3 - pressure = d_4 - # reset all ints (not sure what this does) - if self.buffer_empty: - self._write_register_byte(STMPE_INT_STA, 0xFF) - return (x_loc, y_loc, pressure) - - def _read_byte(self, register): - """Read a byte register value and return it""" - return self._read_register(register, 1)[0] - - def _read_register(self, register, length): - # Read an arbitrarily long register (specified by length number of - # bytes) and return a bytearray of the retrieved data. - # Subclasses MUST implement this! - raise NotImplementedError - - def _write_register_byte(self, register, value): - # Write a single byte register at the specified register address. - # Subclasses MUST implement this! - raise NotImplementedError - - - # pylint: disable=unused-variable - @property - def touches(self): - """ - Returns a list of touchpoint dicts, with 'x' and 'y' containing the - touch coordinates, and 'pressure' - """ - touchpoints = [] - while (len(touchpoints) < 32) and not self.buffer_empty: - (x_loc, y_loc, pressure) = self.read_data() - point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} - touchpoints.append(point) - return touchpoints - # pylint: enable=unused-variable - - - @property - def get_version(self): - "Read the version number from the sensosr" - v_1 = self._read_byte(0) - v_2 = self._read_byte(1) - version = v_1<<8 | v_2 - #print("version ",hex(version)) - return version - - @property - def touched(self): - "Report if any touches have been detectd" - touch = self._read_byte(STMPE_TSC_CTRL)&0x80 - return touch == 0x80 - - - @property - def buffer_size(self): - "The amount of touch data in the buffer" - return self._read_byte(STMPE_FIFO_SIZE) - - @property - def buffer_empty(self): - "Buffer empty status" - empty = self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY - return empty != 0 - - - - @property - def get_point(self): - "Read one touch from the buffer" - (x_loc, y_loc, pressure) = self.read_data() - point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} - return point - - - - -class Adafruit_STMPE610_I2C(Adafruit_STMPE610): - """ - I2C driver for the STMPE610 Resistive Touch sensor. - """ - def __init__(self, i2c, address=_STMPE_ADDR): - """ - Check the STMPE610 was founnd - Default address is 0x41 but another address can be passed in as an argument - """ - import adafruit_bus_device.i2c_device as i2c_device - self._i2c = i2c_device.I2CDevice(i2c, address) - super().__init__() - - def _read_register(self, register, length): - """Low level register reading over I2C, returns a list of values""" - with self._i2c as i2c: - i2c.write(bytearray([register & 0xFF])) - result = bytearray(length) - i2c.readinto(result) - #print("$%02X => %s" % (register, [hex(i) for i in result])) - return result - - def _write_register_byte(self, register, value): - """Low level register writing over I2C, writes one 8-bit value""" - with self._i2c as i2c: - i2c.write(bytes([register & 0xFF, value & 0xFF])) - #print("$%02X <= 0x%02X" % (register, value)) - -class Adafruit_STMPE610_SPI(Adafruit_STMPE610): - """ - SPI driver for the STMPE610 Resistive Touch sensor. - """ - def __init__(self, spi, cs, baudrate=100000): - """ - Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate' - """ - import adafruit_bus_device.spi_device as spi_device - self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate) - super().__init__() - - def _read_register(self, register, length): - """Low level register reading over SPI, returns a list of values""" - register = (register | 0x80) & 0xFF # Read single, bit 7 high. - with self._spi as spi: - spi.write(bytearray([register])) - result = bytearray(length) - spi.readinto(result) -# print("$%02X => %s" % (register, [hex(i) for i in result])) - return result - - def _write_register_byte(self, register, value): - """Low level register writing over SPI, writes one 8-bit value""" - register &= 0x7F # Write, bit 7 low. - with self._spi as spi: - spi.write(bytes([register, value & 0xFF])) From cd0193338234fe4680e427520daf319e181025b7 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 23 Apr 2018 14:52:30 -0400 Subject: [PATCH 14/17] cleanup --- examples/paint.py | 39 --------------------------------- examples/stmpe610_paint_demo.py | 4 ++-- examples/stmpe610_test.py | 11 ---------- 3 files changed, 2 insertions(+), 52 deletions(-) delete mode 100644 examples/paint.py delete mode 100644 examples/stmpe610_test.py diff --git a/examples/paint.py b/examples/paint.py deleted file mode 100644 index 581b6cf..0000000 --- a/examples/paint.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Simple painting demo that draws on an Adafruit capacitive touch shield with -ILI9341 display and STMPE610 resistive touch driver -""" - -import busio -import board -import digitalio -import adafruit_stmpe610 -from adafruit_rgb_display import ili9341, color565 - -# Create library object using our Bus I2C & SPI port -i2c = busio.I2C(board.SCL, board.SDA) -spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) - -# Adafruit Metro M0 + 2.8" Capacitive touch shield -cs_pin = digitalio.DigitalInOut(board.D9) -dc_pin = digitalio.DigitalInOut(board.D10) - -# Initialize display -display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin) -# Fill with black! -display.fill(color565(0, 0, 0)) - -st_cs_pin = digitalio.DigitalInOut(board.D6) -st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi,st_cs_pin) - -while True: - if st.touched: - while not st.buffer_empty: - ts = st.touches - for index in range(len(ts)): - point = ts[index] # the shield only supports one point! - # perform transformation to get into display coordinate system! - y = point['y'] - x = 4096 - point['x'] - x = 2 * x // 30 - y = 8 * y // 90 - display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 0, 0)) diff --git a/examples/stmpe610_paint_demo.py b/examples/stmpe610_paint_demo.py index 581b6cf..34448c1 100644 --- a/examples/stmpe610_paint_demo.py +++ b/examples/stmpe610_paint_demo.py @@ -29,8 +29,8 @@ if st.touched: while not st.buffer_empty: ts = st.touches - for index in range(len(ts)): - point = ts[index] # the shield only supports one point! + for _ in range(len(ts)): + point = ts[_] # get the next point # perform transformation to get into display coordinate system! y = point['y'] x = 4096 - point['x'] diff --git a/examples/stmpe610_test.py b/examples/stmpe610_test.py deleted file mode 100644 index fd0000c..0000000 --- a/examples/stmpe610_test.py +++ /dev/null @@ -1,11 +0,0 @@ -import busio -import board -import digitalio -from adafruit_stmpe610 import Adafruit_STMPE610_SPI -spi=busio.SPI(board.SCK,board.MOSI,board.MISO) -cs = digitalio.DigitalInOut(board.D6) -st=Adafruit_STMPE610_SPI(spi,cs) -print("Go Ahead - Touch the Screen - Make My Day!") -while True: - if not st.buffer_empty: - print(st.read_data()) From 32c936f7247cde48c8fd57142e264b7fc4419ff2 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 23 Apr 2018 15:15:57 -0400 Subject: [PATCH 15/17] fix iterable in paint example --- examples/stmpe610_paint_demo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/stmpe610_paint_demo.py b/examples/stmpe610_paint_demo.py index 34448c1..8a08254 100644 --- a/examples/stmpe610_paint_demo.py +++ b/examples/stmpe610_paint_demo.py @@ -29,8 +29,7 @@ if st.touched: while not st.buffer_empty: ts = st.touches - for _ in range(len(ts)): - point = ts[_] # get the next point + for point in ts: # perform transformation to get into display coordinate system! y = point['y'] x = 4096 - point['x'] From b461075621d1a3c5a0da7c0e0c9d38a34015f8b3 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Tue, 24 Apr 2018 06:53:40 -0400 Subject: [PATCH 16/17] fix paint example remove i2c --- examples/stmpe610_paint_demo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/stmpe610_paint_demo.py b/examples/stmpe610_paint_demo.py index 8a08254..1cb80f4 100644 --- a/examples/stmpe610_paint_demo.py +++ b/examples/stmpe610_paint_demo.py @@ -9,8 +9,7 @@ import adafruit_stmpe610 from adafruit_rgb_display import ili9341, color565 -# Create library object using our Bus I2C & SPI port -i2c = busio.I2C(board.SCL, board.SDA) +# Create library object using our Bus SPI port spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Adafruit Metro M0 + 2.8" Capacitive touch shield From 800c8d84a0a7c532622da1afb2fc023a52c49fd7 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Fri, 27 Apr 2018 16:17:21 -0400 Subject: [PATCH 17/17] cleanup - make constants private - remove unneeded pylint disable - fix typos --- README.rst | 2 +- adafruit_stmpe610.py | 213 +++++++++++++++++++++---------------------- 2 files changed, 107 insertions(+), 108 deletions(-) diff --git a/README.rst b/README.rst index 51c7fd6..176e45d 100644 --- a/README.rst +++ b/README.rst @@ -30,7 +30,7 @@ This is easily achieved by downloading Usage Example ============= -see examples in githup repository: https://github.com/adafruit/Adafruit_CIrcuitPython_STMPE610/exmaples +see examples in githup repository: https://github.com/adafruit/Adafruit_CircuitPython_STMPE610/exmaples Contributing ============ diff --git a/adafruit_stmpe610.py b/adafruit_stmpe610.py index ded26d5..223d990 100644 --- a/adafruit_stmpe610.py +++ b/adafruit_stmpe610.py @@ -35,98 +35,98 @@ __version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_stmpe610.git" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_STMPE610.git" _STMPE_ADDR = const(0x41) _STMPE_VERSION = const(0x0811) -STMPE_SYS_CTRL1 = const(0x03) -STMPE_SYS_CTRL1_RESET = const(0x02) -STMPE_SYS_CTRL2 = const(0x04) - -STMPE_TSC_CTRL = const(0x40) -STMPE_TSC_CTRL_EN = const(0x01) -STMPE_TSC_CTRL_XYZ = const(0x00) -STMPE_TSC_CTRL_XY = const(0x02) - -STMPE_INT_CTRL = const(0x09) -STMPE_INT_CTRL_POL_HIGH = const(0x04) -STMPE_INT_CTRL_POL_LOW = const(0x00) -STMPE_INT_CTRL_EDGE = const(0x02) -STMPE_INT_CTRL_LEVEL = const(0x00) -STMPE_INT_CTRL_ENABLE = const(0x01) -STMPE_INT_CTRL_DISABLE = const(0x00) - - - -STMPE_INT_EN = const(0x0A) -STMPE_INT_EN_TOUCHDET = const(0x01) -STMPE_INT_EN_FIFOTH = const(0x02) -STMPE_INT_EN_FIFOOF = const(0x04) -STMPE_INT_EN_FIFOFULL = const(0x08) -STMPE_INT_EN_FIFOEMPTY = const(0x10) -STMPE_INT_EN_ADC = const(0x40) -STMPE_INT_EN_GPIO = const(0x80) - -STMPE_INT_STA = const(0x0B) -STMPE_INT_STA_TOUCHDET = const(0x01) - -STMPE_ADC_CTRL1 = const(0x20) -STMPE_ADC_CTRL1_12BIT = const(0x08) -STMPE_ADC_CTRL1_10BIT = const(0x00) - -STMPE_ADC_CTRL2 = const(0x21) -STMPE_ADC_CTRL2_1_625MHZ = const(0x00) -STMPE_ADC_CTRL2_3_25MHZ = const(0x01) -STMPE_ADC_CTRL2_6_5MHZ = const(0x02) - -STMPE_TSC_CFG = const(0x41) -STMPE_TSC_CFG_1SAMPLE = const(0x00) -STMPE_TSC_CFG_2SAMPLE = const(0x40) -STMPE_TSC_CFG_4SAMPLE = const(0x80) -STMPE_TSC_CFG_8SAMPLE = const(0xC0) -STMPE_TSC_CFG_DELAY_10US = const(0x00) -STMPE_TSC_CFG_DELAY_50US = const(0x08) -STMPE_TSC_CFG_DELAY_100US = const(0x10) -STMPE_TSC_CFG_DELAY_500US = const(0x18) -STMPE_TSC_CFG_DELAY_1MS = const(0x20) -STMPE_TSC_CFG_DELAY_5MS = const(0x28) -STMPE_TSC_CFG_DELAY_10MS = const(0x30) -STMPE_TSC_CFG_DELAY_50MS = const(0x38) -STMPE_TSC_CFG_SETTLE_10US = const(0x00) -STMPE_TSC_CFG_SETTLE_100US = const(0x01) -STMPE_TSC_CFG_SETTLE_500US = const(0x02) -STMPE_TSC_CFG_SETTLE_1MS = const(0x03) -STMPE_TSC_CFG_SETTLE_5MS = const(0x04) -STMPE_TSC_CFG_SETTLE_10MS = const(0x05) -STMPE_TSC_CFG_SETTLE_50MS = const(0x06) -STMPE_TSC_CFG_SETTLE_100MS = const(0x07) - -STMPE_FIFO_TH = const(0x4A) - -STMPE_FIFO_SIZE = const(0x4C) - -STMPE_FIFO_STA = const(0x4B) -STMPE_FIFO_STA_RESET = const(0x01) -STMPE_FIFO_STA_OFLOW = const(0x80) -STMPE_FIFO_STA_FULL = const(0x40) -STMPE_FIFO_STA_EMPTY = const(0x20) -STMPE_FIFO_STA_THTRIG = const(0x10) - -STMPE_TSC_I_DRIVE = const(0x58) -STMPE_TSC_I_DRIVE_20MA = const(0x00) -STMPE_TSC_I_DRIVE_50MA = const(0x01) - -STMPE_TSC_DATA_X = const(0x4D) -STMPE_TSC_DATA_Y = const(0x4F) -STMPE_TSC_FRACTION_Z = const(0x56) - -STMPE_GPIO_SET_PIN = const(0x10) -STMPE_GPIO_CLR_PIN = const(0x11) -STMPE_GPIO_DIR = const(0x13) -STMPE_GPIO_ALT_FUNCT = const(0x17) +_STMPE_SYS_CTRL1 = const(0x03) +_STMPE_SYS_CTRL1_RESET = const(0x02) +_STMPE_SYS_CTRL2 = const(0x04) + +_STMPE_TSC_CTRL = const(0x40) +_STMPE_TSC_CTRL_EN = const(0x01) +_STMPE_TSC_CTRL_XYZ = const(0x00) +_STMPE_TSC_CTRL_XY = const(0x02) + +_STMPE_INT_CTRL = const(0x09) +_STMPE_INT_CTRL_POL_HIGH = const(0x04) +_STMPE_INT_CTRL_POL_LOW = const(0x00) +_STMPE_INT_CTRL_EDGE = const(0x02) +_STMPE_INT_CTRL_LEVEL = const(0x00) +_STMPE_INT_CTRL_ENABLE = const(0x01) +_STMPE_INT_CTRL_DISABLE = const(0x00) + + + +_STMPE_INT_EN = const(0x0A) +_STMPE_INT_EN_TOUCHDET = const(0x01) +_STMPE_INT_EN_FIFOTH = const(0x02) +_STMPE_INT_EN_FIFOOF = const(0x04) +_STMPE_INT_EN_FIFOFULL = const(0x08) +_STMPE_INT_EN_FIFOEMPTY = const(0x10) +_STMPE_INT_EN_ADC = const(0x40) +_STMPE_INT_EN_GPIO = const(0x80) + +_STMPE_INT_STA = const(0x0B) +_STMPE_INT_STA_TOUCHDET = const(0x01) + +_STMPE_ADC_CTRL1 = const(0x20) +_STMPE_ADC_CTRL1_12BIT = const(0x08) +_STMPE_ADC_CTRL1_10BIT = const(0x00) + +_STMPE_ADC_CTRL2 = const(0x21) +_STMPE_ADC_CTRL2_1_625MHZ = const(0x00) +_STMPE_ADC_CTRL2_3_25MHZ = const(0x01) +_STMPE_ADC_CTRL2_6_5MHZ = const(0x02) + +_STMPE_TSC_CFG = const(0x41) +_STMPE_TSC_CFG_1SAMPLE = const(0x00) +_STMPE_TSC_CFG_2SAMPLE = const(0x40) +_STMPE_TSC_CFG_4SAMPLE = const(0x80) +_STMPE_TSC_CFG_8SAMPLE = const(0xC0) +_STMPE_TSC_CFG_DELAY_10US = const(0x00) +_STMPE_TSC_CFG_DELAY_50US = const(0x08) +_STMPE_TSC_CFG_DELAY_100US = const(0x10) +_STMPE_TSC_CFG_DELAY_500US = const(0x18) +_STMPE_TSC_CFG_DELAY_1MS = const(0x20) +_STMPE_TSC_CFG_DELAY_5MS = const(0x28) +_STMPE_TSC_CFG_DELAY_10MS = const(0x30) +_STMPE_TSC_CFG_DELAY_50MS = const(0x38) +_STMPE_TSC_CFG_SETTLE_10US = const(0x00) +_STMPE_TSC_CFG_SETTLE_100US = const(0x01) +_STMPE_TSC_CFG_SETTLE_500US = const(0x02) +_STMPE_TSC_CFG_SETTLE_1MS = const(0x03) +_STMPE_TSC_CFG_SETTLE_5MS = const(0x04) +_STMPE_TSC_CFG_SETTLE_10MS = const(0x05) +_STMPE_TSC_CFG_SETTLE_50MS = const(0x06) +_STMPE_TSC_CFG_SETTLE_100MS = const(0x07) + +_STMPE_FIFO_TH = const(0x4A) + +_STMPE_FIFO_SIZE = const(0x4C) + +_STMPE_FIFO_STA = const(0x4B) +_STMPE_FIFO_STA_RESET = const(0x01) +_STMPE_FIFO_STA_OFLOW = const(0x80) +_STMPE_FIFO_STA_FULL = const(0x40) +_STMPE_FIFO_STA_EMPTY = const(0x20) +_STMPE_FIFO_STA_THTRIG = const(0x10) + +_STMPE_TSC_I_DRIVE = const(0x58) +_STMPE_TSC_I_DRIVE_20MA = const(0x00) +_STMPE_TSC_I_DRIVE_50MA = const(0x01) + +_STMPE_TSC_DATA_X = const(0x4D) +_STMPE_TSC_DATA_Y = const(0x4F) +_STMPE_TSC_FRACTION_Z = const(0x56) + +_STMPE_GPIO_SET_PIN = const(0x10) +_STMPE_GPIO_CLR_PIN = const(0x11) +_STMPE_GPIO_DIR = const(0x13) +_STMPE_GPIO_ALT_FUNCT = const(0x17) @@ -140,27 +140,28 @@ def __init__(self): version = self.get_version if _STMPE_VERSION != version: raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version) - self._write_register_byte(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET) + self._write_register_byte(_STMPE_SYS_CTRL1, _STMPE_SYS_CTRL1_RESET) time.sleep(.001) - self._write_register_byte(STMPE_SYS_CTRL2, 0x0) # turn on clocks! + self._write_register_byte(_STMPE_SYS_CTRL2, 0x0) # turn on clocks! self._write_register_byte( - STMPE_TSC_CTRL, STMPE_TSC_CTRL_XYZ | STMPE_TSC_CTRL_EN) # XYZ and enable! - self._write_register_byte(STMPE_INT_EN, STMPE_INT_EN_TOUCHDET) + _STMPE_TSC_CTRL, _STMPE_TSC_CTRL_XYZ | _STMPE_TSC_CTRL_EN) # XYZ and enable! + self._write_register_byte(_STMPE_INT_EN, _STMPE_INT_EN_TOUCHDET) self._write_register_byte( - STMPE_ADC_CTRL1, STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion - self._write_register_byte(STMPE_ADC_CTRL2, STMPE_ADC_CTRL2_6_5MHZ) + _STMPE_ADC_CTRL1, _STMPE_ADC_CTRL1_10BIT | (0x6 << 4)) # 96 clocks per conversion + self._write_register_byte(_STMPE_ADC_CTRL2, _STMPE_ADC_CTRL2_6_5MHZ) self._write_register_byte( - STMPE_TSC_CFG, STMPE_TSC_CFG_4SAMPLE | STMPE_TSC_CFG_DELAY_1MS - | STMPE_TSC_CFG_SETTLE_5MS) - self._write_register_byte(STMPE_TSC_FRACTION_Z, 0x6) - self._write_register_byte(STMPE_FIFO_TH, 1) - self._write_register_byte(STMPE_FIFO_STA, STMPE_FIFO_STA_RESET) - self._write_register_byte(STMPE_FIFO_STA, 0) # unreset - self._write_register_byte(STMPE_TSC_I_DRIVE, STMPE_TSC_I_DRIVE_50MA) - self._write_register_byte(STMPE_INT_STA, 0xFF) # reset all ints - self._write_register_byte(STMPE_INT_CTRL, STMPE_INT_CTRL_POL_HIGH | STMPE_INT_CTRL_ENABLE) + _STMPE_TSC_CFG, _STMPE_TSC_CFG_4SAMPLE | _STMPE_TSC_CFG_DELAY_1MS + | _STMPE_TSC_CFG_SETTLE_5MS) + self._write_register_byte(_STMPE_TSC_FRACTION_Z, 0x6) + self._write_register_byte(_STMPE_FIFO_TH, 1) + self._write_register_byte(_STMPE_FIFO_STA, _STMPE_FIFO_STA_RESET) + self._write_register_byte(_STMPE_FIFO_STA, 0) # unreset + self._write_register_byte(_STMPE_TSC_I_DRIVE, _STMPE_TSC_I_DRIVE_50MA) + self._write_register_byte(_STMPE_INT_STA, 0xFF) # reset all ints + self._write_register_byte( + _STMPE_INT_CTRL, _STMPE_INT_CTRL_POL_HIGH | _STMPE_INT_CTRL_ENABLE) def read_data(self): """Request next stored reading - return tuple containing (x,y,pressure) """ @@ -173,7 +174,7 @@ def read_data(self): pressure = d_4 # reset all ints (not sure what this does) if self.buffer_empty: - self._write_register_byte(STMPE_INT_STA, 0xFF) + self._write_register_byte(_STMPE_INT_STA, 0xFF) return (x_loc, y_loc, pressure) def _read_byte(self, register): @@ -192,7 +193,6 @@ def _write_register_byte(self, register, value): raise NotImplementedError - # pylint: disable=unused-variable @property def touches(self): """ @@ -205,7 +205,6 @@ def touches(self): point = {'x':x_loc, 'y':y_loc, 'pressure':pressure} touchpoints.append(point) return touchpoints - # pylint: enable=unused-variable @property @@ -220,19 +219,19 @@ def get_version(self): @property def touched(self): "Report if any touches have been detectd" - touch = self._read_byte(STMPE_TSC_CTRL)&0x80 + touch = self._read_byte(_STMPE_TSC_CTRL)&0x80 return touch == 0x80 @property def buffer_size(self): "The amount of touch data in the buffer" - return self._read_byte(STMPE_FIFO_SIZE) + return self._read_byte(_STMPE_FIFO_SIZE) @property def buffer_empty(self): "Buffer empty status" - empty = self._read_byte(STMPE_FIFO_STA) & STMPE_FIFO_STA_EMPTY + empty = self._read_byte(_STMPE_FIFO_STA) & _STMPE_FIFO_STA_EMPTY return empty != 0