os.rst 2.51 KB
Newer Older
Rahix's avatar
Rahix committed
1
2
3
4
.. py:module:: os

``os`` - OS Functions
=====================
Rahix's avatar
Rahix committed
5
6
The ``os`` module allows access to a few core functionalities of Epicardium and
functions found in CPythons ``os`` module.
Rahix's avatar
Rahix committed
7
8
9
10

CPython-Like
------------

11
.. py:function:: unlink(path)
Rahix's avatar
Rahix committed
12
13
14
15
16

   Unlink (remove) a file.

   :param str path: The file to remove.

17
.. py:function:: listdir(dir)
Rahix's avatar
Rahix committed
18
19
20
21
22
23
24

   List contents of a directory.

   :param str dir: Path to the directory to list.
   :returns: A list of entities (files or subdirectories) in the directory
      ``dir``.

Rahix's avatar
Rahix committed
25
26
27
28
.. py:function:: urandom(n)

   Return ``n`` random bytes.

Rahix's avatar
Rahix committed
29
30
   .. versionadded:: 1.3

Rahix's avatar
Rahix committed
31
32
33
34
   :param int n: Number of random bytes to retrieve.
   :returns: ``bytes()`` object with ``n`` random bytes.


Rahix's avatar
Rahix committed
35
36
Card10-Specific
---------------
Rahix's avatar
Rahix committed
37

38
.. py:function:: exit(ret = None)
Rahix's avatar
Rahix committed
39
40
41
42
43
44
45
46

   Exit from the current app and return to the menu.


   :param int ret: Optional return code, same semantics as Posix (``0`` means
      success).
   :return: This function will never return.

47
.. py:function:: exec(name)
Rahix's avatar
Rahix committed
48
49
50
51
52
53
54
55
56

   Try executing a new app, stopping the currently running one.

   ``name`` is the path to either a l0dable (ending in ``.elf``) or a python
   script (ending in ``.py``).  If the path does not lead to an executable file,
   ``os.exec()`` will raise an exception.

   :param str name: Path to new app/script/l0dable.
   :return: This function never returns.  It can, however raise an exception.
Rahix's avatar
Rahix committed
57

Rahix's avatar
Rahix committed
58
59
60
61
62
63
64
65
66
.. py:function:: read_battery()

   Read the current battery voltage in V.  Please keep in mind that battery
   voltage behaves exponentially when interpreting this value.

   .. warning::

      Card10 will hard-shutdown once the voltage drops below 3.4 V

67
.. py:function:: reset()
Rahix's avatar
Rahix committed
68
69
70
71
72
73
74

   Reboot card10.

   .. warning::

      Please only call this function if absolutely necessary.  In most cases
      you'll want to just :py:func:`os.exit` instead.
swym's avatar
swym committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88

.. py:function:: usbconfig(config_type)

   Change active USB configuration. By default, card10 boots with
   :py:data:`os.USB_SERIAL` active.

   This will deactivate the currently active USB configuration. This means
   that, if you activate :py:data:`os.USB_FLASH` while :py:data:`os.USB_SERIAL`
   was active, the USB serial will be disconnected.

   :param config_type: Selects which config to activate. Possible
      values are :py:data:`os.USB_SERIAL`, :py:data:`os.USB_FLASH`,
      or :py:data:`os.USB_NONE`.

Rahix's avatar
Rahix committed
89
90
   .. versionadded:: 1.11

swym's avatar
swym committed
91
92
93
94
95
96
97
98
99
100
101
.. py:data:: USB_NONE

   No USB device active.

.. py:data:: USB_SERIAL

   CDC-ACM serial device active.

.. py:data:: USB_FLASH

   Mass-Storage device active.