Skip to content

[WIP] Supervisor: create code.py file with sample code #2298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions supervisor/shared/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ static void make_empty_file(FATFS *fatfs, const char *path) {
f_close(&fp);
}


static void make_sample_code_file(FATFS *fatfs) {
FIL fs;
UINT *char_written = 0;
const byte buffer[] = "print('Hello World!')";

//Create or modify existing code.py file
f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
if(f_write(&fs, buffer, sizeof(buffer), char_written)!= 0)
f_close(&fs);
}

// we don't make this function static because it needs a lot of stack and we
// want it to be executed without using stack within main() function
void filesystem_init(bool create_allowed, bool force_create) {
Expand Down Expand Up @@ -98,6 +110,8 @@ void filesystem_init(bool create_allowed, bool force_create) {
make_empty_file(&vfs_fat->fatfs, "/.metadata_never_index");
make_empty_file(&vfs_fat->fatfs, "/.Trashes");
make_empty_file(&vfs_fat->fatfs, "/.fseventsd/no_log");
// make a sample code.py file
make_sample_code_file(&vfs_fat->fatfs);

// create empty lib directory
f_mkdir(&vfs_fat->fatfs, "/lib");
Expand Down