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

Merge 'make the menu automatically return from USB mode'

See merge request card10/firmware!470
parents 7376a31c cf49e627
No related branches found
No related tags found
No related merge requests found
......@@ -115,3 +115,17 @@ Card10-Specific
.. py:data:: USB_FLASH
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
......@@ -78,6 +78,7 @@ typedef _Bool bool;
#define API_FILE_UNLINK 0x4b
#define API_FILE_RENAME 0x4c
#define API_FILE_MKDIR 0x4d
#define API_FILE_FS_ATTACHED 0x4e
#define API_RTC_GET_SECONDS 0x50
#define API_RTC_SCHEDULE_ALARM 0x51
......@@ -2064,6 +2065,15 @@ API(API_FILE_RENAME, int epic_file_rename(const char *oldp, const char* newp));
*/
API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname));
/**
* Check whether the filesystem is currently attached and a call like
* :c:func:`epic_file_open` has a chance to succeed.
*
* :return: ``true`` if the filesystem is attached and ``false`` if the
* filesystem is not attached.
*/
API(API_FILE_FS_ATTACHED, bool epic_fs_is_attached(void));
/**
* RTC
* ===
......
......@@ -29,6 +29,17 @@ int epic_file_open(const char *filename, const char *mode)
return res;
}
bool epic_fs_is_attached(void)
{
EpicFileSystem *fs;
if (efs_lock_global(&fs) == 0) {
efs_unlock_global(fs);
return true;
} else {
return false;
}
}
int epic_file_close(int fd)
{
EpicFileSystem *fs;
......
......@@ -82,7 +82,7 @@ def usb_mode(disp):
pass
# Wait for any button to be pressed and disable USB storage again
while buttons.read() == 0:
while buttons.read() == 0 and not os.fs_is_attached():
pass
os.usbconfig(os.USB_SERIAL)
......
......@@ -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_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[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) },
{ 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[] = {
{ 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_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_FLASH), MP_ROM_INT(USB_DEVICE_FLASH) },
......
......@@ -154,6 +154,7 @@ Q(usbconfig)
Q(USB_FLASH)
Q(USB_SERIAL)
Q(USB_NONE)
Q(fs_is_attached)
/* 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