Skip to content

Commit 6d677f6

Browse files
committed
Improve documentation
1 parent 9cd7a6e commit 6d677f6

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

src/Folder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ Folder::Folder(const char* path) {
1616
int result = mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
1717
if (result == 0) {
1818
this->path = std::string(path);
19-
20-
} // else ...not sure about this one yet
19+
}
2120
}
2221
}
2322

src/Folder.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@ class Folder {
1515

1616
public:
1717
/**
18-
* @brief Blank Constructor.
18+
* @brief Creates an empty Folder object.
19+
* Please note that any operation on this object will fail until a valid directory is assigned to it.
1920
*/
2021
Folder();
2122

2223
/**
23-
* @brief Constructor.
24+
* @brief Creates a directory with the specified name.
25+
* If the directory already exists, it returns a Folder object representing the existing directory.
26+
* Otherwise, it tries to create a new directory with the specified name. If it failes the `path` property of the Folder object will be null.
2427
* @param const char * dirname - The name of the directory.
2528
*/
2629
Folder(const char * dirname);
2730

2831
/**
29-
* @brief Constructor.
32+
* @brief Creates a directory with the specified name.
33+
* If the directory already exists, it returns a Folder object representing the existing directory.
34+
* Otherwise, it tries to create a new directory with the specified name. If it failes the `path` property of the Folder object will be empty.
3035
* @param String dirname - The name of the directory.
3136
*/
3237
Folder(String dirname);

src/InternalStorage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ bool InternalStorage::partition(){
3333
Partitioning::partitionDrive(QSPIFBlockDeviceType::get_default_instance(), {{QSPI_STORAGE_SIZE, FS_LITTLEFS}});
3434
}
3535

36-
3736
bool InternalStorage::restoreDefaultPartitions(){
3837
Partitioning::partitionDrive(QSPIFBlockDeviceType::get_default_instance(), {
39-
{1024, FS_FAT},
40-
{5120, FS_FAT},
41-
{8192, FS_LITTLEFS}
38+
{1024, FS_FAT}, // 1 MB for certificates
39+
{5120, FS_FAT}, // 5 MB for OTA firmware updates
40+
{8192, FS_LITTLEFS} // 8 MB for user data
4241
});
4342
}
4443

src/Partitioning.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,57 @@ struct __attribute__((packed)) mbrTable {
3535
class Partitioning{
3636
public:
3737
/**
38-
* This method erases the first block (4096 bytes) of the BlockDevice to delete any already existing MBR partition table
38+
* Erases the first block (4096 bytes) of the BlockDevice to delete any already existing MBR partition table
3939
* @param The BlockDevice on which the MBR sector is situated.
4040
* @returns True upon success, False on failure
4141
*/
4242
static bool eraseMBRSector(BlockDeviceType * blockDevice);
4343

4444
/**
45-
* This method partitions the BlockDevice according to the partitioning schemme given by the vector of Partition structs
45+
* Partitions the BlockDevice according to the partitioning schemme given by the vector of Partition structs
4646
* @param blockDevice - the BlockDevice which we would like to partition.
4747
* @param partitions - a vector of Partition structs that represents the partitioning scheme
4848
* @returns True upon success, False on failure
4949
*/
5050
static bool partitionDrive(BlockDeviceType * blockDevice, std::vector<Partition> partitions);
5151

5252
/**
53-
* This method reads and unpacks the MBR partition information and returns a list of partitions it can find on the drive
53+
* Reads and unpacks the MBR partition information and returns a list of partitions it can find on the drive
5454
* @param blockDevice on which the MBR sector is situated.
5555
* @returns std::vector of Partition containing size and filesystem information about each partition
5656
*/
5757
static std::vector<Partition> readPartitions(BlockDeviceType * blockDevice);
5858
private:
59+
/**
60+
* Checks if the given partition scheme is valid for the specified block device.
61+
* It does that by checking if the sum of the partition sizes is equal to the size of the block device and
62+
* by ensuring that there are a maximum of 4 partitions.
63+
*
64+
* @param blockDevice The block device to check the partition scheme against.
65+
* @param partitions The partition scheme to check for validity.
66+
* @return True if the partition scheme is valid for the block device, false otherwise.
67+
*/
5968
static bool isPartitionSchemeValid(BlockDeviceType * blockDevice, std::vector<Partition> partitions);
69+
70+
71+
/**
72+
* Formats the specified partition of the given block device with the specified file system type.
73+
*
74+
* @param blockDevice The block device to format the partition on.
75+
* @param partitionNumber The number of the partition to format.
76+
* @param fileSystemType The file system type to format the partition with.
77+
* @return True if the partition was formatted successfully, false otherwise.
78+
*/
6079
static bool formatPartition(BlockDeviceType * blockDevice, int partitionNumber, FileSystems fileSystemType);
80+
81+
/**
82+
* Creates and formats partitions on the specified block device.
83+
* The partitioning splits the block device into partitions of the specified sizes and formats them with the specified file system types.
84+
*
85+
* @param blockDevice Pointer to the block device to partition and format.
86+
* @param partitions Vector of Partition objects representing the partitions to create and format.
87+
* @return True if all partitions were successfully created and formatted, false otherwise.
88+
*/
6189
static bool createAndFormatPartitions(BlockDeviceType * blockDevice, std::vector<Partition> partitions);
6290

6391
};

src/USBStorage.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#define USBStorage_H
55

66
#include "Arduino_UnifiedStorage.h"
7+
78
/**
8-
* Represents a USB storage using the Arduino Unified Storage library.
9+
* USBStorage class provides an interface to access USB storage devices.
10+
* It inherits from the Arduino_UnifiedStorage class and implements its pure virtual functions.
911
*/
1012
class USBStorage : public Arduino_UnifiedStorage {
1113
public:
@@ -58,12 +60,30 @@ class USBStorage : public Arduino_UnifiedStorage {
5860
*/
5961
bool isMounted();
6062

63+
/**
64+
* Sets the callback function to be called when a USB connection is established.
65+
*
66+
* @param callbackFunction A pointer to the function to be called when a USB connection is established.
67+
*/
6168
void onConnect(void (* const callbackFunction)());
6269

70+
/**
71+
* @brief Removes the callback function that is executed when the USB storage device is connected.
72+
*
73+
*/
6374
void removeOnConnectCallback();
6475

76+
/**
77+
* @brief Sets a callback function to be called when the USB storage device is disconnected.
78+
*
79+
* @param callbackFunction A pointer to the function to be called when the USB storage device is disconnected.
80+
*/
6581
void onDisconnect(void (* const callbackFunction)());
6682

83+
/**
84+
* @brief Removes the callback function that is called when the USB storage device is disconnected.
85+
*
86+
*/
6787
void removeOnDisconnectCallback();
6888

6989

0 commit comments

Comments
 (0)