FatFsSD Class

FatFsSD Class

Description
A class for SD FAT File system.

Syntax
class FatFsSD

Members

Public Constructors 
FatFsSD::FatFsSDConstructs a FatFsSD object.
FatFsSD::~FatFsSDDestructs a FatFsSD object.
Public Methods 
FatFsSD::beginInitialize SD FAT File System.
FatFsSD::endDeinitialize SD FAT File System.
FatFsSD::*getRootPathGet the root path of the SD FAT File System.
FatFsSD::readDirList items under a specific folder.
FatFsSD::mkdirCreate a new folder.
FatFsSD::rmRemove folder or file.
FatFsSD::isDirCheck if a specific path is a directory.
FatFsSD::isFileCheck if a specific path is a file.
FatFsSD::getLastModTimeGet the last modified timestamp for a file or directory.
FatFsSD::setLastModTimeSet the last modified timestamp for a file or directory.
FatFsSD::statusGet the current status of SD card.
FatFsSD::openOpen a file.

FatFsSD::begin

Description
Initialize SD FAT File System.

Syntax
int begin(void);

Parameters
NA

Returns
This function returns 0 if the execution is successful, else returns a negative value.

Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::end

Description
De-initialize SD FAT File System.

Syntax
int end(void);

Parameters
NA

Returns
This function returns 0 if the execution is successful, else returns a negative value.

Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::*getRootPath

Description
Get the root path of the SD FAT File System. The logical volume character is starting from ‘0’, so the root path would like “0:/”.

Syntax
char *getRootPath(void);

Parameters
NA

Returns
This function returns the root path.

Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::readDir

Description
Lists items under a specific folder and stores the result in the buffer that user specified. Each item is separated by ‘\0’.

Syntax
int readDir(char *path, char *result_buf, unsigned int bufsize);

Parameters
path: The absolute directory path to be listed.
result_buf: The buffer to stores the results.
bufsize: The size of result_buf. If results exceed this size, then the results larger than this size would be discarded.

Returns
This function returns “0” if successful, else returns a negative value.

Example Code
Example: get_file_attribute
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/get_file_attribute/get_file_attribute.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::mkdir

Description
Create a new folder. The newly created folder shall be an empty folder.

Syntax
int mkdir(char *absolute_path);

Parameters
absolute_path: The path to create a folder with preferred name.

Returns
This function returns “0” if successful, else returns a negative value.

Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::rm

Description
Remove folder or file.

Syntax
int rm(char *absolute_path);

Parameters
absolute_path: The absolute directory or file path to be deleted.

Returns
This function returns “0” if successful, else returns a negative value.

Example Code
NA

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::isDir

Description
Check if a specific path is a directory.

Syntax
unsigned char isDir(char *absolute_path);

Parameters
absolute_path: The absolute path to be queried.

Returns
This function returns “1” if it is a directory, else returns “0”.

Example Code
Example: get_file_attribute
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/get_file_attribute/get_file_attribute.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::isFile

Description
Check if a specific path is a file.

Syntax
unsigned char isFile(char *absolute_path);

Parameters
absolute_path: The absolute path to be queried.

Returns
This function returns “1” if it is a directory, else returns “0”.

Example Code
Example: get_file_attribute
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/get_file_attribute/get_file_attribute.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::getLastModTime

Description
Get the last modified timestamp for a file or directory.

Syntax
int getLastModTime(char *absolute_path, uint16_t *year, uint16_t *month, uint16_t *date, uint16_t *hour, uint16_t *minute, uint16_t *second);

Parameters
absolute_path: The absolute path to be queried.
year: The value of the year.
month: The value of the month.
date: The value of the date.
hour: The value of an hour.
minute: The value of a minute.
second: field “second” contains no valid information in the current version.

Returns
This function returns “0” if the last modified timestamp is achieved successfully, otherwise returns a negative value.

Example Code
Example: last_modified_time
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/last_modified_time/last_modified_time.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::setLastModTime

Description
Set the last modified timestamp for a file or directory. Ameba doesn’t have built-in RTC. So, we manually change file/directory last modified time.

Syntax
int setLastModTime(char *absolute_path, uint16_t year, uint16_t month, uint16_t date, uint16_t hour, uint16_t minute, uint16_t second);

Parameters
absolute_path: The absolute path to be queried.
year: The value of the year.
month: The value of the month.
date: The value of the date.
hour: The value of an hour.
minute: The value of a minute.
second: field “second” contains no valid information in the current version.

Returns
This function returns “0” if success, otherwise returns a negative value for failure.

Example Code
Example: last_modified_time
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/last_modified_time/last_modified_time.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::status

Description
Get the current status of SD card.

Syntax
int status(void);

Parameters
NA

Returns
This function returns “1” if SD card is ready to use, else return “0” if the status is inactivating or abnormal.

Example Code
NA

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.

FatFsSD::open

Description
Open a file.

Syntax
SdFatFile open(char *absolute_path);

Parameters
absolute_path: The path to a file.

Returns
This function returns file object which is an instance of SdFatFile.

Example Code
Example: create_folder
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/FatfsSDIO/examples/create_folder/create_folder.ino)

Notes and Warnings
“FatFs_SD.h” must be included to use the class function.