another attempt at fixing docs

This commit is contained in:
pelikhan 2021-11-18 13:50:46 -08:00
Родитель 1fb95a2dd3
Коммит 0fb27f0563
15 изменённых файлов: 150 добавлений и 196 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -127,3 +127,5 @@ dmypy.json
# Pyre type checker
.pyre/
docs/generated/

20
docs/Makefile Normal file
Просмотреть файл

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

Просмотреть файл

@ -1,13 +1,8 @@
API
===
.. autosummary::
:toctree: generated
:recursive:
jacdac
.. automodule:: jacdac
:members:
.. automodule:: jacdac.bus
:members:
.. automodule:: jacdac.button
:members:
jacdac

Просмотреть файл

@ -1,39 +1,63 @@
# Configuration file for the Sphinx documentation builder.
# -- Project information
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../jacdac'))
sys.path.insert(0, os.path.abspath('..'))
# -- Project information -----------------------------------------------------
project = 'Jacdac Python'
copyright = '2021, Microsoft Corporation'
author = 'Microsoft'
author = 'Microsoft Corporation'
release = '0.1'
version = '0.1.0'
# The full version, including alpha/beta/rc tags
release = '0.0.0'
# -- General configuration
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'myst_parser',
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.intersphinx',
"sphinx.ext.viewcode",
'sphinx.ext.intersphinx',
]
intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
'jacdac': ('https://aka.ms/jacdac/', None)
}
intersphinx_disabled_domains = ['std']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# 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']
# -- Options for HTML output
html_theme = 'sphinx_rtd_theme'
# -- Options for EPUB output
epub_show_urls = 'footnote'
html_theme_path = ["_themes", ]

Просмотреть файл

@ -1,5 +1,5 @@
Welcome to Jacdac-Python's documentation!
=========================================
Welcome to Jacdac Python documentation!
=======================================
**Jacdac** is a plug-and-play hardware/software stack
for **microcontrollers** and their peripherals (sensors/actuators),

35
docs/make.bat Normal file
Просмотреть файл

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

Просмотреть файл

@ -1 +1,2 @@
sphinx>=4.0.0
myst-parser
sphinx-rtd-theme

Просмотреть файл

@ -6,28 +6,9 @@ Usage
Installation
------------
To use Jacdac-Python, first install it using pip:
To use Lumache, first install it using pip:
.. code-block:: console
(.venv) $ pip install jacdac-python
Creating recipes
----------------
To retrieve a list of random ingredients,
you can use the ``lumache.get_random_ingredients()`` function:
.. autofunction:: lumache.get_random_ingredients
The ``kind`` parameter should be either ``"meat"``, ``"fish"``,
or ``"veggies"``. Otherwise, :py:func:`lumache.get_random_ingredients`
will raise an exception.
.. autoexception:: lumache.InvalidKindError
For example:
>>> import lumache
>>> lumache.get_random_ingredients()
['shells', 'gorgonzola', 'parsley']

Просмотреть файл

@ -3,22 +3,19 @@ from jacdac.devtools import create_dev_tools_bus
from .client import BarometerClient
from time import sleep
bus = create_dev_tools_bus()
if __name__ == '__main__':
bus = create_dev_tools_bus()
def up(data: Any):
print("up")
def up(data: Any):
print("up")
def down(data: Any):
print("down")
def hold(data: list[Type[int]]):
print("hold", data[0])
def down(data: Any):
print("down")
def hold(data: list[Type[int]]):
print("hold", data[0])
barometer = BarometerClient(bus, "barometer")
while True:
print("pressure: ", barometer.pressure, "e:", barometer.pressure_error)
sleep(0.2)
barometer = BarometerClient(bus, "barometer")
while True:
print("pressure: ", barometer.pressure, "e:", barometer.pressure_error)
sleep(0.2)

Просмотреть файл

@ -3,27 +3,25 @@ from jacdac.devtools import create_dev_tools_bus
from .client import ButtonClient
from time import sleep
bus = create_dev_tools_bus()
if __name__ == '__main__':
bus = create_dev_tools_bus()
def up(data: Any):
print("up")
def up(data: Any):
print("up")
def down(data: Any):
print("down")
def down(data: Any):
print("down")
def hold(data: list[Type[int]]):
print("hold", data[0])
btn1 = ButtonClient(bus, "btn1")
btn1.on_up(up)
btn1.on_down(down)
btn1.on_hold(hold)
def hold(data: list[Type[int]]):
print("hold", data[0])
btn1 = ButtonClient(bus, "btn1")
btn1.on_up(up)
btn1.on_down(down)
btn1.on_hold(hold)
while True:
print("pressed: ", btn1.pressed)
print("pressure: ", btn1.pressure)
sleep(1)
while True:
print("pressed: ", btn1.pressed)
print("pressure: ", btn1.pressure)
sleep(1)

Просмотреть файл

@ -1,2 +0,0 @@
# Autogenerated file.
from .client import *

Просмотреть файл

@ -1,76 +0,0 @@
# Autogenerated file. Do not edit.
from jacdac.bus import Bus, Client
from .constants import *
from typing import Optional, cast
from jacdac.events import EventHandlerFn, UnsubscribeFn
class HidAdapterClient(Client):
"""
A service for configuring how Jacdac device map to HID input events. Users can have multiple configurations and swap between them by writing to `current_configuration`.
"""
def __init__(self, bus: Bus, role: str) -> None:
super().__init__(bus, JD_SERVICE_CLASS_HID_ADAPTER, JD_HID_ADAPTER_PACK_FORMATS, role)
@property
def num_configurations(self) -> Optional[int]:
"""
The number of configurations stored on the server.,
"""
reg = self.register(JD_HID_ADAPTER_REG_NUM_CONFIGURATIONS)
values = reg.values()
return cast(Optional[int], values[0] if values else None)
@num_configurations.setter
def num_configurations(self, value: int) -> None:
reg = self.register(JD_HID_ADAPTER_REG_NUM_CONFIGURATIONS)
reg.set_values(value)
@property
def current_configuration(self) -> Optional[int]:
"""
The current configuration the server is using.,
"""
reg = self.register(JD_HID_ADAPTER_REG_CURRENT_CONFIGURATION)
values = reg.values()
return cast(Optional[int], values[0] if values else None)
@current_configuration.setter
def current_configuration(self, value: int) -> None:
reg = self.register(JD_HID_ADAPTER_REG_CURRENT_CONFIGURATION)
reg.set_values(value)
def on_changed(self, handler: EventHandlerFn) -> UnsubscribeFn:
"""
Event that notifies clients that the server has swapped to a new configuration or changed key bindings.
"""
return self.on_event(JD_HID_ADAPTER_EV_CHANGED, handler)
def set_binding(self, configuration_number: int, binding_index: int, padding: int, device_id: int, service_class: int, trigger_value: int, trigger_context: int, service_index: int, selector: int, modifiers: undefined) -> None:
"""
Stores the given binding on the server. If a binding exists at this index, the new binding will replace it.
"""
self.send_cmd_packed(JD_HID_ADAPTER_CMD_SET_BINDING, configuration_number, binding_index, padding, device_id, service_class, trigger_value, trigger_context, service_index, selector, modifiers)
def clear_binding(self, configuration_number: int, binding_index: int) -> None:
"""
Clears a specific binding stored on the device.
"""
self.send_cmd_packed(JD_HID_ADAPTER_CMD_CLEAR_BINDING, configuration_number, binding_index)
def clear_configuration(self, configuration_number: int) -> None:
"""
Clears a specific configuration stored on the device.
"""
self.send_cmd_packed(JD_HID_ADAPTER_CMD_CLEAR_CONFIGURATION, configuration_number)
def clear(self, ) -> None:
"""
Clears all configurations and bindings stored on the device.
"""
self.send_cmd_packed(JD_HID_ADAPTER_CMD_CLEAR, )

Просмотреть файл

@ -1,20 +0,0 @@
# Autogenerated constants for HID Adapter service
from jacdac.constants import *
from jacdac.system.constants import *
JD_SERVICE_CLASS_HID_ADAPTER = const(0x1e5758b5)
JD_HID_ADAPTER_REG_NUM_CONFIGURATIONS = const(0x80)
JD_HID_ADAPTER_REG_CURRENT_CONFIGURATION = const(0x81)
JD_HID_ADAPTER_CMD_GET_CONFIGURATION = const(0x80)
JD_HID_ADAPTER_CMD_SET_BINDING = const(0x82)
JD_HID_ADAPTER_CMD_CLEAR_BINDING = const(0x83)
JD_HID_ADAPTER_CMD_CLEAR_CONFIGURATION = const(0x84)
JD_HID_ADAPTER_CMD_CLEAR = const(0x85)
JD_HID_ADAPTER_EV_CHANGED = const(JD_EV_CHANGE)
JD_HID_ADAPTER_PACK_FORMATS = {
JD_HID_ADAPTER_REG_NUM_CONFIGURATIONS: "u8",
JD_HID_ADAPTER_REG_CURRENT_CONFIGURATION: "u8",
JD_HID_ADAPTER_CMD_GET_CONFIGURATION: "b[12] u8",
JD_HID_ADAPTER_CMD_SET_BINDING: "u8 u8 b[2] u64 u32 u32 u8 u8 u16 u16",
JD_HID_ADAPTER_CMD_CLEAR_BINDING: "u8 u8",
JD_HID_ADAPTER_CMD_CLEAR_CONFIGURATION: "u8"
}

Просмотреть файл

@ -3,25 +3,23 @@ from jacdac.devtools import create_dev_tools_bus
from .client import RelayClient
from time import sleep
bus = create_dev_tools_bus()
if __name__ == '__main__':
bus = create_dev_tools_bus()
def active(data: Any):
print("active")
def active(data: Any):
print("active")
def inactive(data: Any):
print("inactive")
rel = RelayClient(bus, "relay")
rel.on_active(active)
rel.on_inactive(inactive)
def inactive(data: Any):
print("inactive")
rel = RelayClient(bus, "relay")
rel.on_active(active)
rel.on_inactive(inactive)
while True:
rel.closed = False
sleep(1)
print("open: ", rel.closed)
rel.closed = True
sleep(1)
print("closed: ", rel.closed)
while True:
rel.closed = False
sleep(1)
print("open: ", rel.closed)
rel.closed = True
sleep(1)
print("closed: ", rel.closed)

Просмотреть файл

@ -2,4 +2,5 @@ import sys
from jacdac.bus import Bus
from jacdac.transports.hf2 import HF2Transport
bus = Bus(HF2Transport(sys.argv[1]))
if __name__ == '__main__':
bus = Bus(HF2Transport(sys.argv[1]))