os - OS Functions

The os module allows access to a few core functionalities of Epicardium and functions found in CPythons os module.

CPython-Like

os.listdir(dir)

List contents of a directory.

Parameters

dir (str) – Path to the directory to list.

Returns

A list of entities (files or subdirectories) in the directory dir.

os.mkdir(path)

Create a directory named path.

Parameters

path (str) – Path to the directory to create. Only the last component of this path will be created.

os.rename(src, dst)

Rename the file or directory src to dst. If dst exists, the operation will fail.

Parameters
  • src (str) – Path to source file to rename.

  • dst (str) – Destination path to rename to. Must not exist before calling os.rename().

Unlink (remove) a file.

Parameters

path (str) – The file to remove.

os.urandom(n)

Return n random bytes.

New in version 1.3.

Parameters

n (int) – Number of random bytes to retrieve.

Returns

bytes() object with n random bytes.

Card10-Specific

os.exit(ret=None)

Exit from the current app and return to the menu.

Parameters

ret (int) – Optional return code, same semantics as Posix (0 means success).

Returns

This function will never return.

os.exec(name)

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.

Parameters

name (str) – Path to new app/script/l0dable.

Returns

This function never returns. It can, however raise an exception.

os.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

os.reset()

Reboot card10.

Warning

Please only call this function if absolutely necessary. In most cases you’ll want to just os.exit() instead.

os.usbconfig(config_type)

Change active USB configuration. By default, card10 boots with os.USB_SERIAL active.

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

Parameters

config_type – Selects which config to activate. Possible values are os.USB_SERIAL, os.USB_FLASH, or os.USB_NONE.

New in version 1.11.

os.USB_NONE

No USB device active.

os.USB_SERIAL

CDC-ACM serial device active.

os.USB_FLASH

Mass-Storage device active.

os.fs_is_attached()

Check whether the filesystem is currently attached to card10 (or whether a connected USB host is currently holding control over it and possibly writing to it).

Returns

  • True if the filesystem is attached to card10 and an app can read and write files.

  • False if the filesystem is not available to card10 because a USB host is currently controlling it.