Skip to content
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

Add filesystem example and update filesystem api #265

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This sketch shows how to open/close file and perform read/write to it.

Example guide:
https://www.amebaiot.com/en/
*/

#include "AmebaFatFS.h"

uint64_t device_used_bytes;
uint64_t device_free_bytes;

uint16_t device_used_Mbytes;
uint16_t device_free_Mbytes;

AmebaFatFS fs;
void setup()
{
fs.begin();
device_used_bytes = fs.get_used_space();
device_used_Mbytes = (uint16_t)(device_used_bytes / 1048576); // convert bytes to Mbytes /(1024*1024)

device_free_bytes = fs.get_free_space();
device_free_Mbytes = (uint16_t)(device_free_bytes / 1048576); // convert bytes to Mbytes /(1024*1024)

printf("Use space on SD card: %llu bytes\r\n", device_used_bytes);
printf("Use space on SD card: %u Mbytes\r\n", device_used_Mbytes);

printf("Free space on SD card: %llu bytes\r\n", device_free_bytes);
printf("Free space on SD card: %u Mbytes\r\n", device_free_Mbytes);
fs.end();
}

void loop()
{
delay(1000);
}
10 changes: 10 additions & 0 deletions Arduino_package/hardware/libraries/FileSystem/src/AmebaFatFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,13 @@ int AmebaFatFS::getAttribute(char *path, unsigned char *attr)
} while (0);
return (-res);
}

long long int AmebaFatFS::get_free_space(void)
{
return fatfs_get_free_space_byte();
}

long long int AmebaFatFS::get_used_space(void)
{
return fatfs_get_used_space_byte();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class AmebaFatFS {
int setLastModTime(char *path, uint16_t year, uint16_t month, uint16_t date, uint16_t hour, uint16_t minute, uint16_t second);

int status(void);

long long int get_free_space(void);
long long int get_used_space(void);
private:
int getAttribute(char *path, unsigned char *attr);

Expand Down
Loading