Ran black, updated to pylint 2.x
This commit is contained in:
parent
ecac001efd
commit
89fa65813a
14 changed files with 276 additions and 237 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -40,7 +40,7 @@ jobs:
|
|||
source actions-ci/install.sh
|
||||
- name: Pip install pylint, black, & Sphinx
|
||||
run: |
|
||||
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
|
||||
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
|
||||
- name: Library version
|
||||
run: git describe --dirty --always --tags
|
||||
- name: PyLint
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ 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,TODO
|
||||
notes=FIXME,XXX
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
|
|
|||
|
|
@ -40,14 +40,17 @@ Implementation Notes
|
|||
__version__ = "0.0.0-auto.0"
|
||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HID.git"
|
||||
|
||||
|
||||
def find_device(devices, *, usage_page, usage):
|
||||
"""Search through the provided list of devices to find the one with the matching usage_page and
|
||||
usage."""
|
||||
if hasattr(devices, "send_report"):
|
||||
devices = [devices]
|
||||
for device in devices:
|
||||
if (device.usage_page == usage_page and
|
||||
device.usage == usage and
|
||||
hasattr(device, "send_report")):
|
||||
if (
|
||||
device.usage_page == usage_page
|
||||
and device.usage == usage
|
||||
and hasattr(device, "send_report")
|
||||
):
|
||||
return device
|
||||
raise ValueError("Could not find matching HID device.")
|
||||
|
|
|
|||
|
|
@ -29,14 +29,18 @@
|
|||
"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.implementation.version[0] < 3:
|
||||
raise ImportError('{0} is not supported in CircuitPython 2.x or lower'.format(__name__))
|
||||
raise ImportError(
|
||||
"{0} is not supported in CircuitPython 2.x or lower".format(__name__)
|
||||
)
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
import struct
|
||||
import time
|
||||
from . import find_device
|
||||
|
||||
|
||||
class ConsumerControl:
|
||||
"""Send ConsumerControl code reports, used by multimedia keyboards, remote controls, etc.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
* Author(s): Dan Halbert
|
||||
"""
|
||||
|
||||
|
||||
class ConsumerControlCode:
|
||||
"""USB HID Consumer Control Device constants.
|
||||
|
||||
|
|
@ -36,7 +37,8 @@ class ConsumerControlCode:
|
|||
|
||||
*New in CircuitPython 3.0.*
|
||||
"""
|
||||
#pylint: disable-msg=too-few-public-methods
|
||||
|
||||
# pylint: disable-msg=too-few-public-methods
|
||||
|
||||
RECORD = 0xB2
|
||||
"""Record"""
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import time
|
|||
|
||||
from . import find_device
|
||||
|
||||
|
||||
class Gamepad:
|
||||
"""Emulate a generic gamepad controller with 16 buttons,
|
||||
numbered 1-16, and two joysticks, one controlling
|
||||
|
|
@ -147,10 +148,16 @@ class Gamepad:
|
|||
"""Send a report with all the existing settings.
|
||||
If ``always`` is ``False`` (the default), send only if there have been changes.
|
||||
"""
|
||||
struct.pack_into('<Hbbbb', self._report, 0,
|
||||
self._buttons_state,
|
||||
self._joy_x, self._joy_y,
|
||||
self._joy_z, self._joy_r_z)
|
||||
struct.pack_into(
|
||||
"<Hbbbb",
|
||||
self._report,
|
||||
0,
|
||||
self._buttons_state,
|
||||
self._joy_x,
|
||||
self._joy_y,
|
||||
self._joy_z,
|
||||
self._joy_r_z,
|
||||
)
|
||||
|
||||
if always or self._last_report != self._report:
|
||||
self._gamepad_device.send_report(self._report)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ from . import find_device
|
|||
|
||||
_MAX_KEYPRESSES = const(6)
|
||||
|
||||
|
||||
class Keyboard:
|
||||
"""Send HID keyboard reports."""
|
||||
|
||||
|
|
@ -73,7 +74,6 @@ class Keyboard:
|
|||
time.sleep(1)
|
||||
self.release_all()
|
||||
|
||||
|
||||
def press(self, *keycodes):
|
||||
"""Send a report indicating that the given keys have been pressed.
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
from .keycode import Keycode
|
||||
|
||||
|
||||
class KeyboardLayoutUS:
|
||||
"""Map ASCII characters to appropriate keypresses on a standard US PC keyboard.
|
||||
|
||||
|
|
@ -51,134 +52,134 @@ class KeyboardLayoutUS:
|
|||
# \x00 entries have no keyboard key and so won't be sent.
|
||||
SHIFT_FLAG = 0x80
|
||||
ASCII_TO_KEYCODE = (
|
||||
b'\x00' # NUL
|
||||
b'\x00' # SOH
|
||||
b'\x00' # STX
|
||||
b'\x00' # ETX
|
||||
b'\x00' # EOT
|
||||
b'\x00' # ENQ
|
||||
b'\x00' # ACK
|
||||
b'\x00' # BEL \a
|
||||
b'\x2a' # BS BACKSPACE \b (called DELETE in the usb.org document)
|
||||
b'\x2b' # TAB \t
|
||||
b'\x28' # LF \n (called Return or ENTER in the usb.org document)
|
||||
b'\x00' # VT \v
|
||||
b'\x00' # FF \f
|
||||
b'\x00' # CR \r
|
||||
b'\x00' # SO
|
||||
b'\x00' # SI
|
||||
b'\x00' # DLE
|
||||
b'\x00' # DC1
|
||||
b'\x00' # DC2
|
||||
b'\x00' # DC3
|
||||
b'\x00' # DC4
|
||||
b'\x00' # NAK
|
||||
b'\x00' # SYN
|
||||
b'\x00' # ETB
|
||||
b'\x00' # CAN
|
||||
b'\x00' # EM
|
||||
b'\x00' # SUB
|
||||
b'\x29' # ESC
|
||||
b'\x00' # FS
|
||||
b'\x00' # GS
|
||||
b'\x00' # RS
|
||||
b'\x00' # US
|
||||
b'\x2c' # SPACE
|
||||
b'\x9e' # ! x1e|SHIFT_FLAG (shift 1)
|
||||
b'\xb4' # " x34|SHIFT_FLAG (shift ')
|
||||
b'\xa0' # # x20|SHIFT_FLAG (shift 3)
|
||||
b'\xa1' # $ x21|SHIFT_FLAG (shift 4)
|
||||
b'\xa2' # % x22|SHIFT_FLAG (shift 5)
|
||||
b'\xa4' # & x24|SHIFT_FLAG (shift 7)
|
||||
b'\x34' # '
|
||||
b'\xa6' # ( x26|SHIFT_FLAG (shift 9)
|
||||
b'\xa7' # ) x27|SHIFT_FLAG (shift 0)
|
||||
b'\xa5' # * x25|SHIFT_FLAG (shift 8)
|
||||
b'\xae' # + x2e|SHIFT_FLAG (shift =)
|
||||
b'\x36' # ,
|
||||
b'\x2d' # -
|
||||
b'\x37' # .
|
||||
b'\x38' # /
|
||||
b'\x27' # 0
|
||||
b'\x1e' # 1
|
||||
b'\x1f' # 2
|
||||
b'\x20' # 3
|
||||
b'\x21' # 4
|
||||
b'\x22' # 5
|
||||
b'\x23' # 6
|
||||
b'\x24' # 7
|
||||
b'\x25' # 8
|
||||
b'\x26' # 9
|
||||
b'\xb3' # : x33|SHIFT_FLAG (shift ;)
|
||||
b'\x33' # ;
|
||||
b'\xb6' # < x36|SHIFT_FLAG (shift ,)
|
||||
b'\x2e' # =
|
||||
b'\xb7' # > x37|SHIFT_FLAG (shift .)
|
||||
b'\xb8' # ? x38|SHIFT_FLAG (shift /)
|
||||
b'\x9f' # @ x1f|SHIFT_FLAG (shift 2)
|
||||
b'\x84' # A x04|SHIFT_FLAG (shift a)
|
||||
b'\x85' # B x05|SHIFT_FLAG (etc.)
|
||||
b'\x86' # C x06|SHIFT_FLAG
|
||||
b'\x87' # D x07|SHIFT_FLAG
|
||||
b'\x88' # E x08|SHIFT_FLAG
|
||||
b'\x89' # F x09|SHIFT_FLAG
|
||||
b'\x8a' # G x0a|SHIFT_FLAG
|
||||
b'\x8b' # H x0b|SHIFT_FLAG
|
||||
b'\x8c' # I x0c|SHIFT_FLAG
|
||||
b'\x8d' # J x0d|SHIFT_FLAG
|
||||
b'\x8e' # K x0e|SHIFT_FLAG
|
||||
b'\x8f' # L x0f|SHIFT_FLAG
|
||||
b'\x90' # M x10|SHIFT_FLAG
|
||||
b'\x91' # N x11|SHIFT_FLAG
|
||||
b'\x92' # O x12|SHIFT_FLAG
|
||||
b'\x93' # P x13|SHIFT_FLAG
|
||||
b'\x94' # Q x14|SHIFT_FLAG
|
||||
b'\x95' # R x15|SHIFT_FLAG
|
||||
b'\x96' # S x16|SHIFT_FLAG
|
||||
b'\x97' # T x17|SHIFT_FLAG
|
||||
b'\x98' # U x18|SHIFT_FLAG
|
||||
b'\x99' # V x19|SHIFT_FLAG
|
||||
b'\x9a' # W x1a|SHIFT_FLAG
|
||||
b'\x9b' # X x1b|SHIFT_FLAG
|
||||
b'\x9c' # Y x1c|SHIFT_FLAG
|
||||
b'\x9d' # Z x1d|SHIFT_FLAG
|
||||
b'\x2f' # [
|
||||
b'\x31' # \ backslash
|
||||
b'\x30' # ]
|
||||
b'\xa3' # ^ x23|SHIFT_FLAG (shift 6)
|
||||
b'\xad' # _ x2d|SHIFT_FLAG (shift -)
|
||||
b'\x35' # `
|
||||
b'\x04' # a
|
||||
b'\x05' # b
|
||||
b'\x06' # c
|
||||
b'\x07' # d
|
||||
b'\x08' # e
|
||||
b'\x09' # f
|
||||
b'\x0a' # g
|
||||
b'\x0b' # h
|
||||
b'\x0c' # i
|
||||
b'\x0d' # j
|
||||
b'\x0e' # k
|
||||
b'\x0f' # l
|
||||
b'\x10' # m
|
||||
b'\x11' # n
|
||||
b'\x12' # o
|
||||
b'\x13' # p
|
||||
b'\x14' # q
|
||||
b'\x15' # r
|
||||
b'\x16' # s
|
||||
b'\x17' # t
|
||||
b'\x18' # u
|
||||
b'\x19' # v
|
||||
b'\x1a' # w
|
||||
b'\x1b' # x
|
||||
b'\x1c' # y
|
||||
b'\x1d' # z
|
||||
b'\xaf' # { x2f|SHIFT_FLAG (shift [)
|
||||
b'\xb1' # | x31|SHIFT_FLAG (shift \)
|
||||
b'\xb0' # } x30|SHIFT_FLAG (shift ])
|
||||
b'\xb5' # ~ x35|SHIFT_FLAG (shift `)
|
||||
b'\x4c' # DEL DELETE (called Forward Delete in usb.org document)
|
||||
b"\x00" # NUL
|
||||
b"\x00" # SOH
|
||||
b"\x00" # STX
|
||||
b"\x00" # ETX
|
||||
b"\x00" # EOT
|
||||
b"\x00" # ENQ
|
||||
b"\x00" # ACK
|
||||
b"\x00" # BEL \a
|
||||
b"\x2a" # BS BACKSPACE \b (called DELETE in the usb.org document)
|
||||
b"\x2b" # TAB \t
|
||||
b"\x28" # LF \n (called Return or ENTER in the usb.org document)
|
||||
b"\x00" # VT \v
|
||||
b"\x00" # FF \f
|
||||
b"\x00" # CR \r
|
||||
b"\x00" # SO
|
||||
b"\x00" # SI
|
||||
b"\x00" # DLE
|
||||
b"\x00" # DC1
|
||||
b"\x00" # DC2
|
||||
b"\x00" # DC3
|
||||
b"\x00" # DC4
|
||||
b"\x00" # NAK
|
||||
b"\x00" # SYN
|
||||
b"\x00" # ETB
|
||||
b"\x00" # CAN
|
||||
b"\x00" # EM
|
||||
b"\x00" # SUB
|
||||
b"\x29" # ESC
|
||||
b"\x00" # FS
|
||||
b"\x00" # GS
|
||||
b"\x00" # RS
|
||||
b"\x00" # US
|
||||
b"\x2c" # SPACE
|
||||
b"\x9e" # ! x1e|SHIFT_FLAG (shift 1)
|
||||
b"\xb4" # " x34|SHIFT_FLAG (shift ')
|
||||
b"\xa0" # # x20|SHIFT_FLAG (shift 3)
|
||||
b"\xa1" # $ x21|SHIFT_FLAG (shift 4)
|
||||
b"\xa2" # % x22|SHIFT_FLAG (shift 5)
|
||||
b"\xa4" # & x24|SHIFT_FLAG (shift 7)
|
||||
b"\x34" # '
|
||||
b"\xa6" # ( x26|SHIFT_FLAG (shift 9)
|
||||
b"\xa7" # ) x27|SHIFT_FLAG (shift 0)
|
||||
b"\xa5" # * x25|SHIFT_FLAG (shift 8)
|
||||
b"\xae" # + x2e|SHIFT_FLAG (shift =)
|
||||
b"\x36" # ,
|
||||
b"\x2d" # -
|
||||
b"\x37" # .
|
||||
b"\x38" # /
|
||||
b"\x27" # 0
|
||||
b"\x1e" # 1
|
||||
b"\x1f" # 2
|
||||
b"\x20" # 3
|
||||
b"\x21" # 4
|
||||
b"\x22" # 5
|
||||
b"\x23" # 6
|
||||
b"\x24" # 7
|
||||
b"\x25" # 8
|
||||
b"\x26" # 9
|
||||
b"\xb3" # : x33|SHIFT_FLAG (shift ;)
|
||||
b"\x33" # ;
|
||||
b"\xb6" # < x36|SHIFT_FLAG (shift ,)
|
||||
b"\x2e" # =
|
||||
b"\xb7" # > x37|SHIFT_FLAG (shift .)
|
||||
b"\xb8" # ? x38|SHIFT_FLAG (shift /)
|
||||
b"\x9f" # @ x1f|SHIFT_FLAG (shift 2)
|
||||
b"\x84" # A x04|SHIFT_FLAG (shift a)
|
||||
b"\x85" # B x05|SHIFT_FLAG (etc.)
|
||||
b"\x86" # C x06|SHIFT_FLAG
|
||||
b"\x87" # D x07|SHIFT_FLAG
|
||||
b"\x88" # E x08|SHIFT_FLAG
|
||||
b"\x89" # F x09|SHIFT_FLAG
|
||||
b"\x8a" # G x0a|SHIFT_FLAG
|
||||
b"\x8b" # H x0b|SHIFT_FLAG
|
||||
b"\x8c" # I x0c|SHIFT_FLAG
|
||||
b"\x8d" # J x0d|SHIFT_FLAG
|
||||
b"\x8e" # K x0e|SHIFT_FLAG
|
||||
b"\x8f" # L x0f|SHIFT_FLAG
|
||||
b"\x90" # M x10|SHIFT_FLAG
|
||||
b"\x91" # N x11|SHIFT_FLAG
|
||||
b"\x92" # O x12|SHIFT_FLAG
|
||||
b"\x93" # P x13|SHIFT_FLAG
|
||||
b"\x94" # Q x14|SHIFT_FLAG
|
||||
b"\x95" # R x15|SHIFT_FLAG
|
||||
b"\x96" # S x16|SHIFT_FLAG
|
||||
b"\x97" # T x17|SHIFT_FLAG
|
||||
b"\x98" # U x18|SHIFT_FLAG
|
||||
b"\x99" # V x19|SHIFT_FLAG
|
||||
b"\x9a" # W x1a|SHIFT_FLAG
|
||||
b"\x9b" # X x1b|SHIFT_FLAG
|
||||
b"\x9c" # Y x1c|SHIFT_FLAG
|
||||
b"\x9d" # Z x1d|SHIFT_FLAG
|
||||
b"\x2f" # [
|
||||
b"\x31" # \ backslash
|
||||
b"\x30" # ]
|
||||
b"\xa3" # ^ x23|SHIFT_FLAG (shift 6)
|
||||
b"\xad" # _ x2d|SHIFT_FLAG (shift -)
|
||||
b"\x35" # `
|
||||
b"\x04" # a
|
||||
b"\x05" # b
|
||||
b"\x06" # c
|
||||
b"\x07" # d
|
||||
b"\x08" # e
|
||||
b"\x09" # f
|
||||
b"\x0a" # g
|
||||
b"\x0b" # h
|
||||
b"\x0c" # i
|
||||
b"\x0d" # j
|
||||
b"\x0e" # k
|
||||
b"\x0f" # l
|
||||
b"\x10" # m
|
||||
b"\x11" # n
|
||||
b"\x12" # o
|
||||
b"\x13" # p
|
||||
b"\x14" # q
|
||||
b"\x15" # r
|
||||
b"\x16" # s
|
||||
b"\x17" # t
|
||||
b"\x18" # u
|
||||
b"\x19" # v
|
||||
b"\x1a" # w
|
||||
b"\x1b" # x
|
||||
b"\x1c" # y
|
||||
b"\x1d" # z
|
||||
b"\xaf" # { x2f|SHIFT_FLAG (shift [)
|
||||
b"\xb1" # | x31|SHIFT_FLAG (shift \)
|
||||
b"\xb0" # } x30|SHIFT_FLAG (shift ])
|
||||
b"\xb5" # ~ x35|SHIFT_FLAG (shift `)
|
||||
b"\x4c" # DEL DELETE (called Forward Delete in usb.org document)
|
||||
)
|
||||
|
||||
def __init__(self, keyboard):
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
* Author(s): Scott Shawcroft, Dan Halbert
|
||||
"""
|
||||
|
||||
|
||||
class Keycode:
|
||||
"""USB HID Keycode constants.
|
||||
|
||||
|
|
@ -44,7 +45,8 @@ class Keycode:
|
|||
without changing the keycodes sent, so that different firmware was not needed for
|
||||
different variations of a keyboard.
|
||||
"""
|
||||
#pylint: disable-msg=invalid-name
|
||||
|
||||
# pylint: disable-msg=invalid-name
|
||||
A = 0x04
|
||||
"""``a`` and ``A``"""
|
||||
B = 0x05
|
||||
|
|
@ -303,9 +305,11 @@ class Keycode:
|
|||
RIGHT_GUI = 0xE7
|
||||
"""GUI modifier right of the spacebar"""
|
||||
|
||||
#pylint: enable-msg=invalid-name
|
||||
# pylint: enable-msg=invalid-name
|
||||
@classmethod
|
||||
def modifier_bit(cls, keycode):
|
||||
"""Return the modifer bit to be set in an HID keycode report if this is a
|
||||
modifier key; otherwise return 0."""
|
||||
return 1 << (keycode - 0xE0) if cls.LEFT_CONTROL <= keycode <= cls.RIGHT_GUI else 0
|
||||
return (
|
||||
1 << (keycode - 0xE0) if cls.LEFT_CONTROL <= keycode <= cls.RIGHT_GUI else 0
|
||||
)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import time
|
|||
|
||||
from . import find_device
|
||||
|
||||
|
||||
class Mouse:
|
||||
"""Send USB HID mouse reports."""
|
||||
|
||||
|
|
@ -144,9 +145,9 @@ class Mouse:
|
|||
partial_x = self._limit(x)
|
||||
partial_y = self._limit(y)
|
||||
partial_wheel = self._limit(wheel)
|
||||
self.report[1] = partial_x & 0xff
|
||||
self.report[2] = partial_y & 0xff
|
||||
self.report[3] = partial_wheel & 0xff
|
||||
self.report[1] = partial_x & 0xFF
|
||||
self.report[2] = partial_y & 0xFF
|
||||
self.report[3] = partial_wheel & 0xFF
|
||||
self._mouse_device.send_report(self.report)
|
||||
x -= partial_x
|
||||
y -= partial_y
|
||||
|
|
|
|||
111
docs/conf.py
111
docs/conf.py
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
sys.path.insert(0, os.path.abspath(".."))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
|
|
@ -10,25 +11,28 @@ sys.path.insert(0, os.path.abspath('..'))
|
|||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.viewcode',
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx.ext.viewcode",
|
||||
]
|
||||
|
||||
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
|
||||
intersphinx_mapping = {
|
||||
"python": ("https://docs.python.org/3.4", None),
|
||||
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
|
||||
}
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
templates_path = ["_templates"]
|
||||
|
||||
source_suffix = '.rst'
|
||||
source_suffix = ".rst"
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = u'Adafruit HID Library'
|
||||
copyright = u'2017 Scott Shawcroft'
|
||||
author = u'Scott Shawcroft'
|
||||
project = u"Adafruit HID Library"
|
||||
copyright = u"2017 Scott Shawcroft"
|
||||
author = u"Scott Shawcroft"
|
||||
|
||||
# Ignore imports of these modules, which sphinx will not know about.
|
||||
autodoc_mock_imports = ["usb_hid"]
|
||||
|
|
@ -38,9 +42,9 @@ autodoc_mock_imports = ["usb_hid"]
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'1.0'
|
||||
version = u"1.0"
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'1.0'
|
||||
release = u"1.0"
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
@ -52,7 +56,7 @@ language = None
|
|||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
|
||||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
|
|
@ -64,7 +68,7 @@ default_role = "any"
|
|||
add_function_parentheses = True
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
pygments_style = "sphinx"
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
|
@ -73,65 +77,67 @@ todo_include_todos = False
|
|||
todo_emit_warnings = True
|
||||
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
|
||||
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
|
||||
|
||||
if not on_rtd: # only import and set the theme if we're building docs locally
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
|
||||
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
|
||||
except:
|
||||
html_theme = 'default'
|
||||
html_theme_path = ['.']
|
||||
html_theme = "default"
|
||||
html_theme_path = ["."]
|
||||
else:
|
||||
html_theme_path = ['.']
|
||||
html_theme_path = ["."]
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
html_static_path = ["_static"]
|
||||
|
||||
# The name of an image file (relative to this directory) to use as a favicon of
|
||||
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#
|
||||
html_favicon = '_static/favicon.ico'
|
||||
html_favicon = "_static/favicon.ico"
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'AdafruitHIDLibrarydoc'
|
||||
htmlhelp_basename = "AdafruitHIDLibrarydoc"
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'AdafruitHIDLibrary.tex', u'Adafruit HID Library Documentation',
|
||||
u'Scott Shawcroft', 'manual'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitHIDLibrary.tex",
|
||||
u"Adafruit HID Library Documentation",
|
||||
u"Scott Shawcroft",
|
||||
"manual",
|
||||
),
|
||||
]
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
|
@ -139,8 +145,13 @@ latex_documents = [
|
|||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'adafruitHIDlibrary', u'Adafruit HID Library Documentation',
|
||||
[author], 1)
|
||||
(
|
||||
master_doc,
|
||||
"adafruitHIDlibrary",
|
||||
u"Adafruit HID Library Documentation",
|
||||
[author],
|
||||
1,
|
||||
)
|
||||
]
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
|
@ -149,7 +160,13 @@ man_pages = [
|
|||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'AdafruitHIDLibrary', u'Adafruit HID Library Documentation',
|
||||
author, 'AdafruitHIDLibrary', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitHIDLibrary",
|
||||
u"Adafruit HID Library Documentation",
|
||||
author,
|
||||
"AdafruitHIDLibrary",
|
||||
"One line description of project.",
|
||||
"Miscellaneous",
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -9,19 +9,23 @@ import adafruit_seesaw
|
|||
from adafruit_hid.gamepad import Gamepad
|
||||
import usb_hid
|
||||
|
||||
|
||||
def range_map(value, in_min, in_max, out_min, out_max):
|
||||
return (value - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
|
||||
|
||||
|
||||
BUTTON_RIGHT = const(6)
|
||||
BUTTON_DOWN = const(7)
|
||||
BUTTON_LEFT = const(9)
|
||||
BUTTON_UP = const(10)
|
||||
BUTTON_SEL = const(14)
|
||||
button_mask = const((1 << BUTTON_RIGHT) |
|
||||
(1 << BUTTON_DOWN) |
|
||||
(1 << BUTTON_LEFT) |
|
||||
(1 << BUTTON_UP) |
|
||||
(1 << BUTTON_SEL))
|
||||
button_mask = const(
|
||||
(1 << BUTTON_RIGHT)
|
||||
| (1 << BUTTON_DOWN)
|
||||
| (1 << BUTTON_LEFT)
|
||||
| (1 << BUTTON_UP)
|
||||
| (1 << BUTTON_SEL)
|
||||
)
|
||||
|
||||
i2c = busio.I2C(board.SCL, board.SDA)
|
||||
|
||||
|
|
@ -51,12 +55,12 @@ while True:
|
|||
for i, button in enumerate(buttons):
|
||||
buttons = ss.digital_read_bulk(button_mask)
|
||||
if not (buttons & (1 << button) and not button_state[i]):
|
||||
g.press_buttons(i+1)
|
||||
print("Press", i+1)
|
||||
g.press_buttons(i + 1)
|
||||
print("Press", i + 1)
|
||||
button_state[i] = True
|
||||
elif button_state[i]:
|
||||
g.release_buttons(i+1)
|
||||
print("Release", i+1)
|
||||
g.release_buttons(i + 1)
|
||||
print("Release", i + 1)
|
||||
button_state[i] = False
|
||||
|
||||
time.sleep(.01)
|
||||
time.sleep(0.01)
|
||||
|
|
|
|||
|
|
@ -29,18 +29,21 @@ ay = analogio.AnalogIn(board.A5)
|
|||
def range_map(x, in_min, in_max, out_min, out_max):
|
||||
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
|
||||
|
||||
|
||||
while True:
|
||||
# Buttons are grounded when pressed (.value = False).
|
||||
for i, button in enumerate(buttons):
|
||||
gamepad_button_num = gamepad_buttons[i]
|
||||
if button.value:
|
||||
gp.release_buttons(gamepad_button_num)
|
||||
print(" release", gamepad_button_num, end='')
|
||||
print(" release", gamepad_button_num, end="")
|
||||
else:
|
||||
gp.press_buttons(gamepad_button_num)
|
||||
print(" press", gamepad_button_num, end='')
|
||||
print(" press", gamepad_button_num, end="")
|
||||
|
||||
# Convert range[0, 65535] to -127 to 127
|
||||
gp.move_joysticks(x=range_map(ax.value, 0, 65535, -127, 127),
|
||||
y=range_map(ay.value, 0, 65535, -127, 127))
|
||||
gp.move_joysticks(
|
||||
x=range_map(ax.value, 0, 65535, -127, 127),
|
||||
y=range_map(ay.value, 0, 65535, -127, 127),
|
||||
)
|
||||
print(" x", ax.value, "y", ay.value)
|
||||
|
|
|
|||
52
setup.py
52
setup.py
|
|
@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
|
|||
|
||||
# Always prefer setuptools over distutils
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
# To use a consistent encoding
|
||||
from codecs import open
|
||||
from os import path
|
||||
|
|
@ -14,48 +15,39 @@ from os import path
|
|||
here = path.abspath(path.dirname(__file__))
|
||||
|
||||
# Get the long description from the README file
|
||||
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
|
||||
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
|
||||
long_description = f.read()
|
||||
|
||||
setup(
|
||||
name='adafruit-circuitpython-hid',
|
||||
|
||||
name="adafruit-circuitpython-hid",
|
||||
use_scm_version=True,
|
||||
setup_requires=['setuptools_scm'],
|
||||
|
||||
description='CircuitPython helper library for simulating HID devices.',
|
||||
setup_requires=["setuptools_scm"],
|
||||
description="CircuitPython helper library for simulating HID devices.",
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/x-rst',
|
||||
|
||||
long_description_content_type="text/x-rst",
|
||||
# The project's main homepage.
|
||||
url='https://github.com/adafruit/Adafruit_CircuitPython_HID',
|
||||
|
||||
url="https://github.com/adafruit/Adafruit_CircuitPython_HID",
|
||||
# Author details
|
||||
author='Adafruit Industries',
|
||||
author_email='circuitpython@adafruit.com',
|
||||
|
||||
install_requires=['Adafruit-Blinka'],
|
||||
|
||||
author="Adafruit Industries",
|
||||
author_email="circuitpython@adafruit.com",
|
||||
install_requires=["Adafruit-Blinka"],
|
||||
# Choose your license
|
||||
license='MIT',
|
||||
|
||||
license="MIT",
|
||||
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Intended Audience :: Developers',
|
||||
'Topic :: Software Development :: Libraries',
|
||||
'Topic :: System :: Hardware',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: System :: Hardware",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
],
|
||||
|
||||
# What does your project relate to?
|
||||
keywords='adafruit hid human interface device keyboard mouse keycode keypad'
|
||||
'hardware micropython circuitpython',
|
||||
|
||||
keywords="adafruit hid human interface device keyboard mouse keycode keypad"
|
||||
"hardware micropython circuitpython",
|
||||
# You can just specify the packages manually here if your project is
|
||||
# simple. Or you can use find_packages().
|
||||
packages=['adafruit_hid'],
|
||||
packages=["adafruit_hid"],
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue