From 0a00d50c46e035b2382db68d4a4fac121a380543 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Mon, 15 Jun 2020 16:22:34 +0200 Subject: [PATCH] fix(docs): Mention u-name and non-u-name modules in Documentation --- Documentation/pycardium/bhi160.rst | 6 +++--- Documentation/pycardium/bme680.rst | 4 ++-- Documentation/pycardium/stdlib.rst | 14 ++++++++++++-- Documentation/pycardium/utime.rst | 15 +++++++++------ Documentation/pycardium/ws2812.rst | 4 ++-- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Documentation/pycardium/bhi160.rst b/Documentation/pycardium/bhi160.rst index 1aaa362e0..97105387f 100644 --- a/Documentation/pycardium/bhi160.rst +++ b/Documentation/pycardium/bhi160.rst @@ -28,18 +28,18 @@ The coordinate system of the BHI160 sensor data looks like this: .. code-block:: python import bhi160 - import utime + import time bhi = bhi160.BHI160Orientation() while True: samples = bhi.read() if len(samples) == 0: - utime.sleep(0.25) + time.sleep(0.25) continue # print the latest sample print(samples[-1]) - utime.sleep(0.25) + time.sleep(0.25) Orientation diff --git a/Documentation/pycardium/bme680.rst b/Documentation/pycardium/bme680.rst index 812173a62..9bdef0245 100644 --- a/Documentation/pycardium/bme680.rst +++ b/Documentation/pycardium/bme680.rst @@ -8,7 +8,7 @@ Allows access to environmental data of card10's surroundings. .. code-block:: python - import bme680, utime + import bme680, time with bme680.Bme680() as environment: while True: @@ -19,7 +19,7 @@ Allows access to environmental data of card10's surroundings. print("Pressure: {:10.2f} hPa".format(d.pressure)) print("Gas Resistance: {:10.2f} ā¦".format(d.resistance)) - utime.sleep(1) + time.sleep(1) Sensor Class ------------ diff --git a/Documentation/pycardium/stdlib.rst b/Documentation/pycardium/stdlib.rst index 1d1b7af49..92d304e9c 100644 --- a/Documentation/pycardium/stdlib.rst +++ b/Documentation/pycardium/stdlib.rst @@ -1,7 +1,17 @@ MicroPython Standard Library ============================ -Pycardium contains some modules from the MicroPython standard library. These -are: +Pycardium contains some modules from the MicroPython standard library. + +Some modules below use a standard Python name, but prefixed with āuā, +e.g. ujson instead of json. This is to signify that such a module is a +micro-library, i.e. implements only a subset of CPython module +functionality. Please refer to the official `MicroPython docs`_ for an +explanation why. + +All u-name modules can also be imported using their non-u-name. E.g. +``import utime`` and import ``import time`` will both work. + +.. _MicroPython docs: http://docs.micropython.org/en/latest/library/index.html#python-standard-libraries-and-micro-libraries .. py:module:: framebuf diff --git a/Documentation/pycardium/utime.rst b/Documentation/pycardium/utime.rst index 03d333b20..0f5eff9f3 100644 --- a/Documentation/pycardium/utime.rst +++ b/Documentation/pycardium/utime.rst @@ -8,6 +8,9 @@ CPython but wouldn't fit anywhere else in our implementation. Most prominently, this is the :py:func:`utime.alarm` function for setting an RTC alarm. +Like all other u-name modules, ``utime`` can also imported using the standard +``import time`` statement. + .. |time| replace:: ``time`` .. _time: https://docs.python.org/3/library/time.html @@ -135,13 +138,13 @@ alarm. .. code-block:: python - import utime + import time def minute_timer(x): - current = utime.time() + current = time.time() print("Current: " + str(current)) alarm = (current // 60 + 1) * 60 - utime.alarm(alarm, minute_timer) + time.alarm(alarm, minute_timer) minute_timer(None) @@ -150,13 +153,13 @@ alarm. .. code-block:: python - import interrupt, utime + import interrupt, time def 5_second_timer(x): - current = utime.time() + current = time.time() print("Current: " + str(current)) alarm = (current // 10) * 10 + 5 - utime.alarm(alarm) + time.alarm(alarm) # This time, we need to register and enable the callback manually interrupt.set_callback(interrupt.RTC_ALARM, 5_second_timer) diff --git a/Documentation/pycardium/ws2812.rst b/Documentation/pycardium/ws2812.rst index fe36f9592..00eba24c5 100644 --- a/Documentation/pycardium/ws2812.rst +++ b/Documentation/pycardium/ws2812.rst @@ -19,7 +19,7 @@ The ``ws2812`` module controls LEDs of the WS2812 type. Just as the ``leds`` mod .. code-block:: python - import color, utime, ws2812, gpio + import color, time, ws2812, gpio i = 0 while True: @@ -28,6 +28,6 @@ The ``ws2812`` module controls LEDs of the WS2812 type. Just as the ``leds`` mod col3 = color.from_hsv((i + 40) % 360, 1.0, 0.1) ws2812.set_all(gpio.WRISTBAND_2, [col1, col2, col3]) i += 1 - utime.sleep_ms(10) + time.sleep_ms(10) .. versionadded:: 1.10 -- GitLab