Skip to content

Commit 8db9d9a

Browse files
committed
update docs
1 parent f0749e5 commit 8db9d9a

6 files changed

Lines changed: 657 additions & 8 deletions

File tree

docs/pages/conf.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@
55
base = pathlib.Path(__file__).parent.parent.parent
66
root = base.__str__()
77
flipperzero = base.joinpath('flipperzero').__str__()
8-
now = datetime.datetime.now()
98

109
sys.path.append(root)
1110
sys.path.append(flipperzero)
1211

12+
def copy_dict(source, target):
13+
for key, value in source.__dict__.items():
14+
target.__dict__[key] = value
15+
16+
import flipperzero.logging
17+
import logging
18+
19+
copy_dict(flipperzero.logging, logging)
20+
21+
import flipperzero.io
22+
import io
23+
24+
copy_dict(flipperzero.io, io)
25+
26+
now = datetime.datetime.now()
27+
1328
project = 'uPython'
1429
copyright = str(now.year) + ', Oliver Fabel'
1530
author = 'Oliver Fabel'

docs/pages/reference.rst

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,84 @@ Classes
416416
~~~~~~~
417417

418418
.. autoclass:: flipperzero.UART
419-
:members: read, readline, readlines, write, flush
419+
:members: read, readline, readlines, write, flush, close, __enter__, __exit__, __del__
420+
421+
Logging
422+
-------
423+
424+
Log messages to the Flipper's own logging backend.
425+
Check out the `Flipper Zero docs <https://docs.flipper.net/development/cli#_yZ2E>`_ on how to reveal them in the CLI.
426+
Be aware, that you can't change Flipper's global log level from within your script.
427+
Change the `corresponding settings <https://docs.flipper.net/basics/settings#d5TAt>`_ instead or use the **log** command in the CLI with the desired log level as the first argument.
428+
429+
Levels
430+
~~~~~~
431+
432+
.. autodata:: logging.TRACE
433+
.. autodata:: logging.DEBUG
434+
.. autodata:: logging.INFO
435+
.. autodata:: logging.WARN
436+
.. autodata:: logging.ERROR
437+
.. autodata:: logging.NONE
438+
.. autodata:: logging.level
439+
440+
Functions
441+
~~~~~~~~~
442+
443+
.. autofunction:: logging.setLevel
444+
.. autofunction:: logging.getEffectiveLevel
445+
.. autofunction:: logging.trace
446+
.. autofunction:: logging.debug
447+
.. autofunction:: logging.info
448+
.. autofunction:: logging.warn
449+
.. autofunction:: logging.error
450+
.. autofunction:: logging.log
451+
452+
I/O
453+
---
454+
455+
Constants
456+
~~~~~~~~~
457+
458+
.. autodata:: io.SEEK_SET
459+
.. autodata:: io.SEEK_CUR
460+
.. autodata:: io.SEEK_END
461+
462+
Functions
463+
~~~~~~~~~
464+
465+
.. autofunction:: io.open
466+
467+
Classes
468+
~~~~~~~
469+
470+
.. autoclass:: io.BinaryFileIO
471+
:members: name, read, readline, readlines, readable, writable, write, flush, seek, tell, close, __enter__, __exit__, __del__
472+
473+
.. autoclass:: io.TextFileIO
474+
:members: name, read, readline, readlines, readable, writable, write, flush, seek, tell, close, __enter__, __exit__, __del__
420475

421476
Built-In
422477
--------
423478

424479
The functions in this section are `not` part of the ``flipperzero`` module.
425480
They're members of the global namespace instead.
426481

427-
.. py:function:: print(*objects, sep=' ', end='\n', file=None, flush=False) -> None
482+
.. py:function:: print(*objects, sep=' ', end='\n') -> None
428483
429484
The standard Python `print <https://docs.python.org/3/library/functions.html#print>`_ function.
485+
Where the output of this function will be redirected depends on how the script is invoked:
486+
487+
* When invoked from the UI, the output will be sent to the Flipper's log buffer.
488+
Check out the `Flipper Zero docs <https://docs.flipper.net/development/cli#_yZ2E>`_ on how to view them in the CLI interface.
489+
* In the REPL, the output will be sent to the standard output buffer.
490+
* When invoked by the **py** command, the output will be sent to the standard output buffer.
430491

431492
:param objects: The objects to print (mostly a single string).
432493
:param sep: The separator to use between the objects.
433494
:param end: The line terminator character to use.
434495

435496
.. versionadded:: 1.0.0
497+
.. versionchanged:: 1.5.0
436498

437-
.. attention::
438-
439-
This function prints to the internal log buffer.
440-
Check out the `Flipper Zero docs <https://docs.flipper.net/development/cli#_yZ2E>`_ on how to reveal them in the CLI interface.
499+
Output redirection, based on script invocation.

flipperzero/_uart.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ class UART:
2929
3030
with f0.open(f0.UART_MODE_USART, 115200) as uart:
3131
lines = [line for line in uart]
32+
33+
An :class:`UART` instance can be used with a `context manager <https://docs.python.org/3/reference/datamodel.html#with-statement-context-managers>`_:
34+
35+
.. code-block::
36+
37+
import flipperzero as f0
38+
39+
with f0.open(f0.UART_MODE_USART, 115200) as uart:
40+
...
3241
3342
.. hint::
3443
@@ -94,6 +103,44 @@ def flush(self) -> None:
94103
'''
95104
Flush the transmission buffer to the underlying UART connection.
96105
This method blocks until all data is sent.
106+
107+
.. versionadded:: 1.5.0
108+
'''
109+
pass
110+
111+
def close(self) -> None:
112+
'''
113+
Close the UART connection.
114+
115+
.. versionadded:: 1.5.0
116+
'''
117+
pass
118+
119+
def __enter__(self) -> 'UART':
120+
'''
121+
This method is invoked, when the instance enters a runtime context.
122+
123+
:returns: The :class:`UART` connection.
124+
125+
.. versionadded:: 1.5.0
126+
'''
127+
pass
128+
129+
def __exit__(self, *args, **kwargs) -> None:
130+
'''
131+
This method is invoked, when the instance leavs a runtime context.
132+
This basically calls :meth:`close` on the instance.
133+
134+
.. versionadded:: 1.5.0
135+
'''
136+
pass
137+
138+
def __del__(self) -> None:
139+
'''
140+
This method is invoked, when the garbage collector removes the object.
141+
This basically calls :meth:`close` on the instance.
142+
143+
.. versionadded:: 1.5.0
97144
'''
98145
pass
99146

0 commit comments

Comments
 (0)