Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precision info to time.monotonic() documentation #5443

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1900,10 +1900,13 @@ msgid ""
msgstr ""

#: ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
msgid "Pins must be sequential"
msgstr ""

#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
msgid "Pins must be sequential GPIO pins"
msgstr ""

#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
msgid "Pins must share PWM slice"
msgstr ""
Expand Down Expand Up @@ -3943,6 +3946,7 @@ msgstr ""
#: ports/espressif/boards/adafruit_funhouse/mpconfigboard.h
#: ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
#: ports/espressif/boards/adafruit_metro_esp32s2/mpconfigboard.h
#: ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h
#: ports/espressif/boards/ai_thinker_esp_12k_nodemcu/mpconfigboard.h
#: ports/espressif/boards/artisense_rd00/mpconfigboard.h
#: ports/espressif/boards/atmegazero_esp32s2/mpconfigboard.h
Expand All @@ -3961,6 +3965,7 @@ msgstr ""
#: ports/espressif/boards/gravitech_cucumber_rs/mpconfigboard.h
#: ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h
#: ports/espressif/boards/lolin_s2_mini/mpconfigboard.h
#: ports/espressif/boards/microdev_micro_c3/mpconfigboard.h
#: ports/espressif/boards/microdev_micro_s2/mpconfigboard.h
#: ports/espressif/boards/morpheans_morphesp-240/mpconfigboard.h
#: ports/espressif/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h
Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
pins[1] = MP_OBJ_FROM_PTR(pin_a);
self->swapped = false;
if (!common_hal_rp2pio_pins_are_sequential(2, pins)) {
mp_raise_RuntimeError(translate("Pins must be sequential"));
mp_raise_RuntimeError(translate("Pins must be sequential GPIO pins"));
}
}

Expand Down
21 changes: 18 additions & 3 deletions shared-bindings/time/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,26 @@
//| """time and timing related functions
//|
//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
//| written in MicroPython will work in CPython but not necessarily the other
//| using `time` written in CircuitPython will work in CPython but not necessarily the other
//| way around."""
//|
//| def monotonic() -> float:
//| """Returns an always increasing value of time with an unknown reference
//| point. Only use it to compare against other values from `monotonic`.
//| point. Only use it to compare against other values from `time.monotonic()`.
//|
//| On most boards, `time.monotonic()` converts a 64-bit millisecond tick counter
//| to a float. Floats on most boards are encoded in 30 bits internally, with
//| effectively 22 bits of precision. The float returned by `time.monotonic()` will
//| accurately represent time to millisecond precision only up to 2**22 milliseconds
//| (about 1.165 hours).
//| At that point it will start losing precision, and its value will change only
//| every second millisecond. At 2**23 milliseconds it will change every fourth
//| millisecond, and so forth.
//|
//| If you need more consistent precision, use `time.monotonic_ns()`, or `supervisor.ticks_ms()`.
//| `time.monotonic_ns()` is not available on boards without long integer support.
//| `supervisor.ticks_ms()` uses intervals of a millisecond, but wraps around, and is not
//| CPython-compatible.
//|
//| :return: the current monotonic time
//| :rtype: float"""
Expand Down Expand Up @@ -216,7 +230,8 @@ STATIC mp_obj_t time_time(void) {
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);

//| def monotonic_ns() -> int:
//| """Return the time of the monotonic clock, cannot go backward, in nanoseconds.
//| """Return the time of the monotonic clock, which cannot go backward, in nanoseconds.
//| Not available on boards without long integer support.
//|
//| :return: the current time
//| :rtype: int"""
Expand Down