Skip to content

Commit

Permalink
sdk: update docs, tweak FileUtils method/argument naming
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Apr 9, 2024
1 parent e8b3388 commit 1ac9ef7
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 92 deletions.
15 changes: 15 additions & 0 deletions docs/library/fileutils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
``FileUtils``: Допоміжні функції для роботи з файлами
=====================================================

.. doxygenvariable:: lilka::fileutils

.. doxygenclass:: lilka::FileUtils
:members:

.. doxygenstruct:: lilka::PathInfo
:members:

.. doxygenstruct:: lilka::Entry
:members:

.. doxygenenum:: lilka::EntryType
17 changes: 9 additions & 8 deletions docs/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@
void loop() {
// Заповнити екран чорним кольором
lilka::display.fillScreen(lilka::display.color565(0, 255, 0));
lilka::display.fillScreen(lilka::colors::Black);
while (1) {
// Отримати стан кнопок
lilka::State state = lilka::controller.getState();
if (state.a.justPressed) { // Якщо щойно була натиснута кнопка "A"...
// Розпочати відтворення звуку на частоті 440 Гц
lilka::buzzer.play(440);
lilka::buzzer.play(lilka::NOTE_A4);
// Заповнити екран червоним кольором
lilka::display.fillScreen(lilka::display.color565(255, 0, 0));
lilka::display.fillScreen(lilka::colors::Red);
} else if (state.a.justReleased) { // Якщо кнопка "A" щойно була відпущена...
// Зупинити відтворення звуку
lilka::buzzer.stop();
// Заповнити екран зеленим кольором
lilka::display.fillScreen(lilka::display.color565(0, 255, 0));
lilka::display.fillScreen(lilka::colors::Green);
}
}
}
Expand Down Expand Up @@ -76,22 +76,22 @@
void loop() {
// Заповнити екран чорним кольором
display.fillScreen(display.color565(0, 255, 0));
display.fillScreen(colors::Black);
while (1) {
// Отримати стан кнопок
State state = controller.getState();
if (state.a.justPressed) { // Якщо щойно була натиснута кнопка "A"...
// Розпочати відтворення звуку на частоті 440 Гц
buzzer.play(440);
buzzer.play(NOTE_A4);
// Заповнити екран червоним кольором
display.fillScreen(display.color565(255, 0, 0));
display.fillScreen(colors::Red);
} else if (state.a.justReleased) { // Якщо кнопка "A" щойно була відпущена...
// Зупинити відтворення звуку
buzzer.stop();
// Заповнити екран зеленим кольором
display.fillScreen(display.color565(0, 255, 0));
display.fillScreen(colors::Green);
}
}
}
Expand All @@ -105,6 +105,7 @@
buzzer
controller
display
fileutils
multiboot
resources
spi
Expand Down
8 changes: 5 additions & 3 deletions firmware/keira/src/apps/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ void LauncherApp::sdBrowserMenu(FS* fSysDriver, const String& path) {
if (currentPath == "/") sdBrowserMenu(fSysDriver, currentPath + entries[index].name);
else sdBrowserMenu(fSysDriver, currentPath + "/" + entries[index].name);
} else {
if (currentPath == "/")
selectFile(lilka::fileutils.getFullPath(fSysDriver, currentPath + entries[index].name));
else selectFile(lilka::fileutils.getFullPath(fSysDriver, currentPath + "/" + entries[index].name));
if (currentPath == "/") {
selectFile(lilka::fileutils.getCannonicalPath(fSysDriver, currentPath + entries[index].name));
} else {
selectFile(lilka::fileutils.getCannonicalPath(fSysDriver, currentPath + "/" + entries[index].name));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/lib/lilka/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void setup() {

void loop() {
// Заповнити екран чорним кольором
lilka::display.fillScreen(lilka::colors::Green);
lilka::display.fillScreen(lilka::colors::Black);

lilka::Image* image = lilka::resources.loadImage("/sd/hello.bmp", lilka::display.lilka::colors::Fuchsia);
lilka::Image* image = lilka::resources.loadImage("/sd/hello.bmp", lilka::colors::Fuchsia);
lilka::display.drawImage(image, 32, 64);
delay(1000);

Expand All @@ -19,7 +19,7 @@ void loop() {

if (state.a.justPressed) { // Якщо щойно була натиснута кнопка "A"...
// Розпочати відтворення звуку на частоті 440 Гц
lilka::buzzer.play(440);
lilka::buzzer.play(lilka::NOTE_A4);
// Заповнити екран червоним кольором
lilka::display.fillScreen(lilka::colors::Red);
} else if (state.a.justReleased) { // Якщо кнопка "A" щойно була відпущена...
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/lilka/src/lilka/buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct {
/// }
///
/// void loop() {
/// lilka::buzzer.play(440); // Грати ноту "Ля"
/// lilka::buzzer.play(lilka::NOTE_A4); // Грати ноту "Ля"
/// delay(500);
/// lilka::buzzer.stop(); // Зупинити відтворення
/// delay(1500);
Expand Down
79 changes: 40 additions & 39 deletions sdk/lib/lilka/src/lilka/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ FileUtils::FileUtils() : sdMutex(xSemaphoreCreateMutex()) {
spiffs = &SPIFFS;
}

void FileUtils::begin() {
initSD();
initSPIFFS();
void FileUtils::begin(bool beginSD, bool beginSPIFFS) {
if (beginSD) {
initSD();
}
if (beginSPIFFS) {
initSPIFFS();
}
}

void FileUtils::initSPIFFS() {
Expand Down Expand Up @@ -59,23 +63,21 @@ bool FileUtils::initSD() {
return false;
}

uint32_t FileUtils::getEntryCount(FS* fSysDriver, const String& relPath) {
FS* fs = fSysDriver;

if (fs == NULL) {
serial_err("Path (%s) reffers to unknown filesystem type", relPath.c_str());
uint32_t FileUtils::getEntryCount(FS* driver, const String& localPath) {
if (driver == NULL) {
serial_err("Path (%s) reffers to unknown filesystem type", localPath.c_str());
return 0;
}

File root = fs->open(stripPath(relPath));
File root = driver->open(stripPath(localPath));
// Below we assume if folder can't be open then it has zero files
// Btw we will show this error using serial
if (!root) {
serial_err("getEntryCount: failed to open directory: %s", relPath.c_str());
serial_err("getEntryCount: failed to open directory: %s", localPath.c_str());
return 0;
}
if (!root.isDirectory()) {
serial_err("getEntryCount: not a directory: %s", relPath.c_str());
serial_err("getEntryCount: not a directory: %s", localPath.c_str());
return 0;
}

Expand All @@ -101,20 +103,19 @@ const String FileUtils::stripPath(const String& path) {
return striped_path;
}

size_t FileUtils::listDir(FS* fSysDriver, const String& relPath, Entry entries[]) {
FS* fs = fSysDriver;
if (fs == NULL) {
serial_err("Path (%s) reffers to unknown filesystem type", relPath.c_str());
size_t FileUtils::listDir(FS* driver, const String& localPath, Entry entries[]) {
if (driver == NULL) {
serial_err("Path (%s) reffers to unknown filesystem type", localPath.c_str());
return 0;
}

File root = fs->open(stripPath(relPath));
File root = driver->open(stripPath(localPath));
if (!root) {
serial_err("listDir: failed to open directory: %s", relPath.c_str());
serial_err("listDir: failed to open directory: %s", localPath.c_str());
return -1;
}
if (!root.isDirectory()) {
serial_err("listDir: not a directory: %s", relPath.c_str());
serial_err("listDir: not a directory: %s", localPath.c_str());
return -1;
}

Expand Down Expand Up @@ -147,35 +148,35 @@ size_t FileUtils::listDir(FS* fSysDriver, const String& relPath, Entry entries[]
return i;
}

const String FileUtils::getFullPath(const FS* fSysDriver, const String& relPath) {
const String FileUtils::getCannonicalPath(const FS* driver, const String& localPath) {
// Allready okay
if (relPath.startsWith(LILKA_SD_ROOT LILKA_SLASH) || relPath.startsWith(LILKA_SPIFFS_ROOT LILKA_SLASH))
return relPath;
if (localPath.startsWith(LILKA_SD_ROOT LILKA_SLASH) || localPath.startsWith(LILKA_SPIFFS_ROOT LILKA_SLASH))
return localPath;

if (fSysDriver == sdfs) {
return String(LILKA_SD_ROOT) + relPath;
} else if (fSysDriver == spiffs) {
return String(LILKA_SPIFFS_ROOT) + relPath;
if (driver == sdfs) {
return String(LILKA_SD_ROOT) + localPath;
} else if (driver == spiffs) {
return String(LILKA_SPIFFS_ROOT) + localPath;
}
serial_err("Unknown fSysDriver provided");
return relPath;
serial_err("Unknown driver provided");
return localPath;
}

const PathInfo FileUtils::getRelativePathInfo(const String& canPath) {
const PathInfo FileUtils::getLocalPathInfo(const String& cannonicalPath) {
PathInfo pathInfo;
if (canPath.startsWith(LILKA_SD_ROOT LILKA_SLASH)) {
pathInfo.path = canPath.substring(sizeof(LILKA_SD_ROOT) - 1);
pathInfo.fSysDriver = sdfs;
} else if (canPath.startsWith(LILKA_SPIFFS_ROOT LILKA_SLASH)) {
pathInfo.path = canPath.substring(sizeof(LILKA_SPIFFS_ROOT) - 1);
pathInfo.fSysDriver = spiffs;
if (cannonicalPath.startsWith(LILKA_SD_ROOT LILKA_SLASH)) {
pathInfo.path = cannonicalPath.substring(sizeof(LILKA_SD_ROOT) - 1);
pathInfo.driver = sdfs;
} else if (cannonicalPath.startsWith(LILKA_SPIFFS_ROOT LILKA_SLASH)) {
pathInfo.path = cannonicalPath.substring(sizeof(LILKA_SPIFFS_ROOT) - 1);
pathInfo.driver = spiffs;
} else
// Maybe path is allready relative?
// Maybe path is allready local?
{
pathInfo.path = canPath;
// Can't determine fSysDriver from
pathInfo.path = cannonicalPath;
// Can't determine driver from
// given path
pathInfo.fSysDriver = NULL;
pathInfo.driver = NULL;
}
return pathInfo;
}
Expand Down Expand Up @@ -301,4 +302,4 @@ const String FileUtils::joinPath(const String& lPath, const String& rPath) {
}

FileUtils fileutils;
} // namespace lilka
} // namespace lilka
Loading

0 comments on commit 1ac9ef7

Please sign in to comment.