Skip to content

Commit

Permalink
Merge pull request adafruit#2299 from iayanpahwa/sample-code-file-sup…
Browse files Browse the repository at this point in the history
…ervisor

Supervisor: create code.py file with sample code
  • Loading branch information
jepler authored Nov 27, 2019
2 parents cc00859 + 718a28c commit d9c808d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions supervisor/shared/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ static void make_empty_file(FATFS *fatfs, const char *path) {
f_close(&fp);
}


static void make_sample_code_file(FATFS *fatfs) {
#if CIRCUITPY_FULL_BUILD
FIL fs;
UINT char_written = 0;
const byte buffer[] = "print('Hello World!')\n";
//Create or modify existing code.py file
f_open(fatfs, &fs, "/code.py", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fs, buffer, sizeof(buffer) - 1, &char_written);
f_close(&fs);
#endif
}

// 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 +111,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

0 comments on commit d9c808d

Please sign in to comment.