From 1907dc8ff0f1a4f1306760e885a9939fb74c6207 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Thu, 20 Aug 2020 10:55:01 +0200 Subject: [PATCH] Updated the format of these pages --- content/firmwareapi/micropython/_index.md | 4 +- content/firmwareapi/micropython/_thread.md | 30 +++++++---- content/firmwareapi/micropython/array.md | 23 +++++++-- content/firmwareapi/micropython/builtin.md | 55 +++++++++++++++------ content/firmwareapi/pycom/machine/_index.md | 1 - content/firmwareapi/pycom/machine/adc.md | 5 ++ 6 files changed, 83 insertions(+), 35 deletions(-) diff --git a/content/firmwareapi/micropython/_index.md b/content/firmwareapi/micropython/_index.md index d13406a..69ba761 100644 --- a/content/firmwareapi/micropython/_index.md +++ b/content/firmwareapi/micropython/_index.md @@ -7,7 +7,5 @@ The following list contains the standard Python libraries, MicroPython-specific The standard Python libraries have been "micro-ified" to fit in with the philosophy of MicroPython. They provide the core functionality of that module and are intended to be a drop-in replacement for the standard Python library. -{{% hint style="info" %}} -Some modules are available by an u-name, and also by their non-u-name. The non-u-name can be overridden by a file of that name in your package path. For example, `import json` will first search for a file `json.py` or directory `json` and load that package if it's found. If nothing is found, it will fallback to loading the built-in `ujson` module. -{{% /hint %}} +> Some modules are available by an u-name, and also by their non-u-name. The non-u-name can be overridden by a file of that name in your package path. For example, `import json` will first search for a file `json.py` or directory `json` and load that package if it's found. If nothing is found, it will fallback to loading the built-in `ujson` module. diff --git a/content/firmwareapi/micropython/_thread.md b/content/firmwareapi/micropython/_thread.md index 625adf1..843a819 100644 --- a/content/firmwareapi/micropython/_thread.md +++ b/content/firmwareapi/micropython/_thread.md @@ -28,29 +28,39 @@ for i in range(2): ## Methods -#### \_thread.start\_new\_thread(function, args\[, kwargs\]) +### _thread.start_new_thread(function, args[, kwargs]) Start a new thread and return its identifier. The thread executes the function with the argument list args (which must be a tuple). The optional `kwargs` argument specifies a dictionary of keyword arguments. When the function returns, the thread silently exits. When the function terminates with an unhandled exception, a stack trace is printed and then the thread exits (but other threads continue to run). -#### \_thread.exit() +```python +import _thread + +def foo(arg): + print(arg) + +arg="hello" +_thread.start_new_thread(foo, (arg,)) +``` + +### _thread.exit() Raise the `SystemExit` exception. When not caught, this will cause the thread to exit silently. -#### \_thread.allocate\_lock() +### _thread.allocate_lock() Return a new lock object. Methods of locks are described below. The lock is initially unlocked. -#### \_thread.get\_ident() +### _thread.get_ident() Return the `thread identifier` of the current thread. This is a nonzero integer. Its value has no direct meaning; it is intended as a magic cookie to be used e.g. to index a dictionary of thread-specific data. Thread identifiers may be recycled when a thread exits and another thread is created. -#### \_thread.stack\_size(\[size\]) +### _thread.stack_size([size]) Return the thread stack size (in bytes) used when creating new threads. The optional size argument specifies the stack size to be used for subsequently created threads, and must be `0` (use platform or configured default) or a positive integer value of at least `4096` (4KiB). 4KiB is currently the minimum supported stack size value to guarantee sufficient stack space for the interpreter itself. ## Objects -#### \_thread.LockType +### _thread.LockType This is the type of lock objects. @@ -58,11 +68,11 @@ This is the type of lock objects. Used for synchronisation between threads -### Methods +## Methods Lock objects have the following methods: -#### lock.acquire(waitflag=1, timeout=-1) +### lock.acquire(waitflag=1, timeout=-1) Without any optional argument, this method acquires the lock unconditionally, if necessary waiting until it is released by another thread (only one thread at a time can acquire a lock — that's their reason for existence). @@ -72,11 +82,11 @@ If the floating-point timeout argument is present and positive, it specifies the The return value is `True` if the lock is acquired successfully, `False` if not. -#### lock.release() +### lock.release() Releases the lock. The lock must have been acquired earlier, but not necessarily by the same thread. -#### lock.locked() +### lock.locked() Return the status of the lock: `True` if it has been acquired by some thread, `False` if not. diff --git a/content/firmwareapi/micropython/array.md b/content/firmwareapi/micropython/array.md index 8b64f52..e0726b1 100644 --- a/content/firmwareapi/micropython/array.md +++ b/content/firmwareapi/micropython/array.md @@ -8,21 +8,34 @@ aliases: See [Python array](https://docs.python.org/3/library/array.html) for more information. -Supported format codes: `b, B, h, H, i, I, l, L, q, Q, f, d` (the latter 2 depending on the floating-point support). + ## Classes -#### class array.array(typecode\[, iterable\]) +### class array.array(typecode, [iterable]) -Create array with elements of given type. Initial contents of the array are given by an iterable. If it is not provided, an empty array is created. +Create array with elements of given type. Initial contents of the array are given by an iterable. If it is not provided, an empty array is created. Supported format codes: +* `b`: signed char, 1 byte +* `B`: unsigned char, 1 byte +* `h`: signed short, 2 bytes +* `H`: unsigned short, 2 bytes +* `i`: signed int, 2 bytes +* `I`: unsigned int, 2 bytes +* `l`: signed long, 4 bytes +* `L`: unsigned long, 4 bytes +* `q`: signed long long, 8 bytes +* `Q`: unsigned long long, 8 bytes +* `f`: foat, 4 bytes +* `d`: double, 8 bytes +Adapting the typecode to the array-type you want to create can save a lot of space on the microcontroller ## Methods -#### array.append(val) +### array.append(val) Append new element to the end of array, growing it. -#### array.extend(iterable) +### array.extend(iterable) Append new elements as contained in an iterable to the end of array, growing it. diff --git a/content/firmwareapi/micropython/builtin.md b/content/firmwareapi/micropython/builtin.md index cb167ad..38c45a4 100644 --- a/content/firmwareapi/micropython/builtin.md +++ b/content/firmwareapi/micropython/builtin.md @@ -8,37 +8,60 @@ aliases: All builtin functions are described here. -abs() +### abs(val) -all() +Returns the absolute value of val +### all([]) -any() +Returns true if all items in an iterable are True -bin() +### any([]) -class bool +Returns true if any of the items in an iterable are True -class bytearray +### bin(val) -class bytes +Returns the binary equivalent of the given integer -callable() +### bytearray([source, encoding, errors]) -chr() +Returns the bytearray of the bytes array passed in -class method() +### bytes() -compile() +Similar to `bytearray()` but for a single byte -class complex +### callable(object) -class dict +Returns True if the object appears callable -dir() +### chr(val) -divmod() +Returns a character from an integer -enumerate() +### classmethod(foo) + +Returns a classmethod for the passed function + +### complex([real, imag]) + +Creates a complex number from the passed variables. +> You can also use `a-bj` + +### delattr(object, name) + +Deletes attribute from the object. + +### dir([object]) + +Returns a list of valid attributes of the object. If no parameter is passed, it will return all created objects. + +### divmod(x, y) + +Divides and mods the two values. Similar to `(x / y, x % y)` +Returns a tuple `(q, r)` of the two paramters, with quotient `q` and remainder `r` + +### numerate() eval() diff --git a/content/firmwareapi/pycom/machine/_index.md b/content/firmwareapi/pycom/machine/_index.md index f3489d0..1de66e6 100644 --- a/content/firmwareapi/pycom/machine/_index.md +++ b/content/firmwareapi/pycom/machine/_index.md @@ -4,7 +4,6 @@ aliases: --- The `machine` module contains specific functions related to the board. - ### Quick Usage Example ```python diff --git a/content/firmwareapi/pycom/machine/adc.md b/content/firmwareapi/pycom/machine/adc.md index cfd9757..a9a351c 100644 --- a/content/firmwareapi/pycom/machine/adc.md +++ b/content/firmwareapi/pycom/machine/adc.md @@ -8,6 +8,11 @@ aliases: ## class ADC – Analog to Digital Conversion + +{{< development style="dev" >}} +hi + +{{< /development >}} ### Quick Usage Example ```python