Skip to content

Commit

Permalink
autostart flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 29, 2021
1 parent ae0ef00 commit ed444af
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
18 changes: 16 additions & 2 deletions src/eez/modules/psu/gui/file_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ bool g_fileBrowserMode;
DialogType g_dialogType;
const char *g_fileBrowserTitle;
FileType g_fileBrowserFileType;
bool (*g_fileBrowserFileTypeFilter)(FileType type);
static bool (*g_fileBrowserNameFilter)(const char *fileName);
static void (*g_fileBrowserOnFileSelected)(const char *filePath);

Expand Down Expand Up @@ -123,9 +124,21 @@ bool makeAbsolutePath(const char *relativePath, char *dest) {
}

void catalogCallback(void *param, const char *name, FileType type, size_t size, bool isHiddenOrSystemFile) {
if (isHiddenOrSystemFile || name[0] == '.' || (g_fileBrowserMode && type != FILE_TYPE_DIRECTORY && type != g_fileBrowserFileType)) {
if (isHiddenOrSystemFile) {
return;
}

if (name[0] == '.') {
return;
}

if (g_fileBrowserMode) {
if (type != FILE_TYPE_DIRECTORY) {
if (!(g_fileBrowserFileTypeFilter ? g_fileBrowserFileTypeFilter(type) : type == g_fileBrowserFileType)) {
return;
}
}
}

if (g_fileBrowserMode && g_fileBrowserNameFilter) {
if (!g_fileBrowserNameFilter(name)) {
Expand Down Expand Up @@ -1066,11 +1079,12 @@ void FileBrowserPage::set() {
g_fileBrowserOnFileSelected(filePath);
}

void browseForFile(const char *title, const char *directory, FileType fileType, DialogType dialogType, void(*onFileSelected)(const char *filePath), bool (*nameFilter)(const char *)) {
void browseForFile(const char *title, const char *directory, FileType fileType, DialogType dialogType, void(*onFileSelected)(const char *filePath), bool (*nameFilter)(const char *), bool (*fileTypeFilter)(FileType)) {
g_fileBrowserMode = true;
g_dialogType = dialogType;
g_fileBrowserTitle = title;
g_fileBrowserFileType = fileType;
g_fileBrowserFileTypeFilter = fileTypeFilter;
g_fileBrowserNameFilter = nameFilter;
g_fileBrowserOnFileSelected = onFileSelected;

Expand Down
2 changes: 1 addition & 1 deletion src/eez/modules/psu/gui/file_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum DialogType {
DIALOG_TYPE_SAVE
};

void browseForFile(const char *title, const char *directory, FileType fileType, DialogType dialogType, void (*onFileSelected)(const char *filePath), bool (*nameFilter)(const char *) = nullptr);
void browseForFile(const char *title, const char *directory, FileType fileType, DialogType dialogType, void (*onFileSelected)(const char *filePath), bool (*nameFilter)(const char *) = nullptr, bool (*fileTypeFilter)(FileType) = nullptr);

extern const char *g_fileBrowserTitle;

Expand Down
9 changes: 7 additions & 2 deletions src/eez/platform/simulator/cmsis_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,14 @@ osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) {
}

osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec) {
while (queue_id->overflow) {
osDelay(0);
for (uint32_t i = 0; queue_id->overflow && i < millisec; i++) {
osDelay(1);
}

if (queue_id->overflow) {
return osOK;
}

uint16_t head = queue_id->head + 1;
if (head >= queue_id->numElements) {
head = 0;
Expand Down
14 changes: 12 additions & 2 deletions src/eez/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void resetSettings() {

bool isAutoStartEnabled() {
if (!g_autoStartConditionIsChecked) {
sendMessageToLowPriorityThread(THREAD_MESSAGE_AUTO_START_SCRIPT);
sendMessageToLowPriorityThread(THREAD_MESSAGE_AUTO_START_SCRIPT, 0, 1);
return true;
}

Expand Down Expand Up @@ -741,7 +741,17 @@ void onAutoStartScriptFileSelected(const char *filePath) {
}

void action_sys_settings_scripting_select_auto_start_script() {
browseForFile("Select auto start script", "/Scripts", FILE_TYPE_MICROPYTHON, file_manager::DIALOG_TYPE_OPEN, onAutoStartScriptFileSelected);
browseForFile(
"Select auto start script",
"/Scripts",
FILE_TYPE_MICROPYTHON,
file_manager::DIALOG_TYPE_OPEN,
onAutoStartScriptFileSelected,
nullptr,
[] (FileType type) {
return type == FILE_TYPE_MICROPYTHON || type == FILE_TYPE_APP;
}
);
}

void action_sys_settings_scripting_clear_auto_start_script() {
Expand Down

0 comments on commit ed444af

Please sign in to comment.