Skip to content

Commit 36247de

Browse files
committed
typehints: Fixes for MicroPython v1.12 (Cellular x16, RF x0B)
1 parent 815c3ce commit 36247de

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

typehints/common/sys.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from typing import Any, Dict, List, Optional, Tuple
2525

2626
argv: List[str] = ...
2727
byteorder: str = ...
28-
implementation: str = ...
28+
implementation: Tuple[str, Tuple[int, int, int], int] = ...
2929
maxsize: int = ...
3030
modules: Dict[str, Any] = ... # technically [str, Module]
3131
path: List[str] = ...

typehints/common/ujson.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
from typing import Any
21+
from typing import Any, Union
2222

2323

2424
def dump(obj: Any, stream: Any) -> None:
@@ -56,11 +56,19 @@ def load(stream: Any) -> Any:
5656
"""
5757
...
5858

59-
def loads(json_string: str) -> Any:
59+
def loads(json_string: Union[str, bytes, bytearray, memoryview]) -> Any:
6060
"""
6161
Parses the given JSON string and returns a Python object. Raises
6262
``ValueError`` if the string is not correctly formed.
6363
64+
**Note:** In MicroPython versions v1.11 and earlier, the ``json_string``
65+
parameter is required to be of type ``str``. In newer version of
66+
MicroPython, it must implement the buffer protocol (i.e. it must be
67+
of type ``str``, ``bytes``, ``bytearray`` or ``memoryview``).
68+
(The MicroPython version is visible in the banner displayed at the REPL,
69+
using the **ATPYV** command, and as the second item in the
70+
``sys.implementation`` tuple.)
71+
6472
:param json_string: String containing the JSON document to deserialise.
6573
6674
:return: A Python object corresponding to the given JSON string.

typehints/common/umachine.pyi

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,38 @@ class ADC(object):
372372

373373
def read(self) -> int:
374374
"""
375-
Reads and returns a raw ADC sample. Use the following equation to
376-
convert this value to mV::
375+
Reads and returns a raw ADC sample with a range of 12 bits
376+
(0 to 4095).
377+
378+
Use the following equation to convert this value to mV::
377379
378380
sample mV = (A/D reading * Vref mV) / 4095
379381
380-
:return: A raw ADC sample
382+
:return: A raw ADC sample in 12-bit range
383+
"""
384+
...
385+
386+
def read_u16(self) -> int:
387+
"""
388+
Reads and returns a raw ADC sample with a range of 16 bits
389+
(0 to 65535). This method is provided for compatibility with
390+
other MicroPython implementations.
391+
392+
Since XBee devices only support 12-bit ADC readings,
393+
readings from ``read_u16()`` will match those from ``read()``,
394+
only scaled to a 16-bit range.
395+
396+
Use the following equation to convert this value to mV::
397+
398+
sample mV = (A/D reading * Vref mV) / 65535
399+
400+
**Note:**
401+
402+
The ``read_u16`` method is available on XBee Cellular and
403+
XBee 3 Cellular products with version ending in 16 and newer,
404+
and XBee 3 RF products with version ending in 0B and newer.
405+
406+
:return: A raw ADC sample in 16-bit range
381407
"""
382408
...
383409

0 commit comments

Comments
 (0)