Skip to content
Snippets Groups Projects
Commit a8f5cb56 authored by rahix's avatar rahix
Browse files

feat(pycardium): Expose epic_fs_is_attached() in the `os` module

Add an `os.fs_is_attached()` function to allow apps to check whether the
filesystem is available.
parent 8caaeeee
No related branches found
No related tags found
1 merge request!470Add epic_fs_is_attached(), os.fs_is_attached(), and make the menu automatically return from USB mode
...@@ -115,3 +115,17 @@ Card10-Specific ...@@ -115,3 +115,17 @@ Card10-Specific
.. py:data:: USB_FLASH .. py:data:: USB_FLASH
Mass-Storage device active. Mass-Storage device active.
.. py:function:: 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.
.. versionadded: 1.18
...@@ -220,6 +220,16 @@ static mp_obj_t mp_os_usbconfig(mp_obj_t dev) ...@@ -220,6 +220,16 @@ static mp_obj_t mp_os_usbconfig(mp_obj_t dev)
} }
static MP_DEFINE_CONST_FUN_OBJ_1(usbconfig_obj, mp_os_usbconfig); static MP_DEFINE_CONST_FUN_OBJ_1(usbconfig_obj, mp_os_usbconfig);
static mp_obj_t mp_os_fs_is_attached(void)
{
if (epic_fs_is_attached()) {
return mp_const_true;
} else {
return mp_const_false;
}
}
static MP_DEFINE_CONST_FUN_OBJ_0(fs_is_attached_obj, mp_os_fs_is_attached);
static const mp_rom_map_elem_t os_module_globals_table[] = { static const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&exit_obj) }, { MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&exit_obj) },
...@@ -232,6 +242,8 @@ static const mp_rom_map_elem_t os_module_globals_table[] = { ...@@ -232,6 +242,8 @@ static const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_read_battery), MP_ROM_PTR(&read_battery_obj) }, { MP_ROM_QSTR(MP_QSTR_read_battery), MP_ROM_PTR(&read_battery_obj) },
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&urandom_obj) }, { MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&urandom_obj) },
{ MP_ROM_QSTR(MP_QSTR_usbconfig), MP_ROM_PTR(&usbconfig_obj) }, { MP_ROM_QSTR(MP_QSTR_usbconfig), MP_ROM_PTR(&usbconfig_obj) },
{ MP_ROM_QSTR(MP_QSTR_fs_is_attached),
MP_ROM_PTR(&fs_is_attached_obj) },
{ MP_ROM_QSTR(MP_QSTR_USB_SERIAL), MP_ROM_INT(USB_DEVICE_SERIAL) }, { MP_ROM_QSTR(MP_QSTR_USB_SERIAL), MP_ROM_INT(USB_DEVICE_SERIAL) },
{ MP_ROM_QSTR(MP_QSTR_USB_FLASH), MP_ROM_INT(USB_DEVICE_FLASH) }, { MP_ROM_QSTR(MP_QSTR_USB_FLASH), MP_ROM_INT(USB_DEVICE_FLASH) },
......
...@@ -154,6 +154,7 @@ Q(usbconfig) ...@@ -154,6 +154,7 @@ Q(usbconfig)
Q(USB_FLASH) Q(USB_FLASH)
Q(USB_SERIAL) Q(USB_SERIAL)
Q(USB_NONE) Q(USB_NONE)
Q(fs_is_attached)
/* gpio */ /* gpio */
Q(gpio) Q(gpio)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment