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

UI updates & SD card formatting #13

Merged
merged 2 commits into from
Mar 20, 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
2 changes: 1 addition & 1 deletion firmware/doom/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void setup() {
if (!found) {
lilka::Alert alert("Doom", "Не знайдено .WAD-файлу на картці пам'яті");
alert.draw(&lilka::display);
while (!alert.isDone()) {
while (!alert.isFinished()) {
alert.update();
}
esp_restart();
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/lib/SimpleFTPServer/src/FtpServerKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ However, the last one, that will break anything that uses the ESP32 WiFi library
#define FTP_TIME_OUT 5 * 60


// Wait for authentication for 10 seconds (expressed in seconds)
#define FTP_AUTH_TIME_OUT 10
// Wait for authentication for 30 seconds (expressed in seconds)
#define FTP_AUTH_TIME_OUT 30


// Size of file buffer for read/write
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/demos/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void KeyboardApp::run() {
dialog.update();
dialog.draw(canvas);
queueDraw();
if (dialog.isDone()) {
if (dialog.isFinished()) {
break;
}
}
Expand All @@ -20,7 +20,7 @@ void KeyboardApp::run() {
queueDraw();
while (true) {
alert.update();
if (alert.isDone()) {
if (alert.isFinished()) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/letris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void LetrisApp::run() {
queueDraw();
while (1) {
alert.update();
if (alert.isDone()) {
if (alert.isFinished()) {
break;
}
taskYIELD();
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/scan_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ScanI2CApp::run() {
lilka::Alert alert("Помилка", "Ця програма потребує Лілку версії 2 або вище.");
alert.draw(canvas);
queueDraw();
while (!alert.isDone()) {
while (!alert.isFinished()) {
alert.update();
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void TransformApp::run() {
lilka::Alert alert("Помилка", "Не вдалось завантажити face.bmp з SD-карти.");
alert.draw(canvas);
queueDraw();
while (!alert.isDone()) {
while (!alert.isFinished()) {
alert.update();
}
return;
Expand Down
263 changes: 145 additions & 118 deletions firmware/keira/src/apps/launcher.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <ff.h>

#include "launcher.h"
#include "appmanager.h"

Expand Down Expand Up @@ -45,25 +47,24 @@ void LauncherApp::run() {
menu.addItem("Налаштування", &settings, lilka::display.color565(255, 200, 224));

while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index == 0) {
appsMenu();
} else if (index == 1) {
sdBrowserMenu("/");
} else if (index == 2) {
spiffsBrowserMenu();
} else if (index == 3) {
// dev_menu();
devMenu();
} else if (index == 4) {
settingsMenu();
}
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
int16_t index = menu.getCursor();
if (index == 0) {
appsMenu();
} else if (index == 1) {
sdBrowserMenu("/");
} else if (index == 2) {
spiffsBrowserMenu();
} else if (index == 3) {
// dev_menu();
devMenu();
} else if (index == 4) {
settingsMenu();
}
taskYIELD();
}
}

Expand All @@ -86,17 +87,16 @@ void LauncherApp::appsMenu() {
}
menu.addItem("<< Назад");
while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index == appCount) {
break;
}
AppManager::getInstance()->runApp(app_items[index].construct());
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
taskYIELD();
int16_t index = menu.getCursor();
if (index == appCount) {
break;
}
AppManager::getInstance()->runApp(app_items[index].construct());
}
}

Expand Down Expand Up @@ -162,19 +162,18 @@ void LauncherApp::sdBrowserMenu(String path) {
menu.addItem("<< Назад", 0, 0);

while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index >= numEntries - 1) break;
if (entries[index].type == lilka::EntryType::ENT_DIRECTORY) {
sdBrowserMenu(path + entries[index].name + "/");
} else {
selectFile(lilka::sdcard.abspath(path + entries[index].name));
}
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
int16_t index = menu.getCursor();
if (index >= numEntries - 1) break;
if (entries[index].type == lilka::EntryType::ENT_DIRECTORY) {
sdBrowserMenu(path + entries[index].name + "/");
} else {
selectFile(lilka::sdcard.abspath(path + entries[index].name));
}
taskYIELD();
}

return;
Expand Down Expand Up @@ -209,16 +208,16 @@ void LauncherApp::spiffsBrowserMenu() {
menu.addItem(filenames[i], icons[i], colors[i]);
}
while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index == numEntries - 1) {
return;
}
selectFile(lilka::filesystem.abspath(filenames[index]));
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
int16_t index = menu.getCursor();
if (index == numEntries - 1) {
return;
}
selectFile(lilka::filesystem.abspath(filenames[index]));
}
}

Expand Down Expand Up @@ -292,16 +291,16 @@ void LauncherApp::devMenu() {
}
menu.addItem("<< Назад");
while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index == appCount) {
return;
}
AppManager::getInstance()->runApp(app_items[index].construct());
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
int16_t index = menu.getCursor();
if (index == appCount) {
return;
}
AppManager::getInstance()->runApp(app_items[index].construct());
}
}

Expand All @@ -311,6 +310,7 @@ void LauncherApp::settingsMenu() {
"Про систему",
"Інфо про пристрій",
"Таблиця розділів",
"Форматування SD-карти",
"Перезавантаження",
"<< Назад",
};
Expand All @@ -320,68 +320,98 @@ void LauncherApp::settingsMenu() {
menu.addItem(titles[i]);
}
while (1) {
menu.update();
menu.draw(canvas);
queueDraw();
int16_t index = menu.getSelectedIndex();
if (index != -1) {
if (index == count - 1) {
return;
while (!menu.isFinished()) {
menu.update();
menu.draw(canvas);
queueDraw();
}
int16_t index = menu.getCursor();
if (index == count - 1) {
return;
}
if (index == 0) {
AppManager::getInstance()->runApp(new WiFiConfigApp());
} else if (index == 1) {
alert("Keira OS", "by Андерсон & friends");
} else if (index == 2) {
char buf[256];
NetworkService* networkService =
static_cast<NetworkService*>(ServiceManager::getInstance()->getService<NetworkService>());
// TODO: use dynamic_cast and assert networkService != nullptr
sprintf(
buf,
"Модель: %s\n"
"Ревізія: %d\n"
"Версія ESP-IDF: %s\n"
"Частота: %d МГц\n"
"Кількість ядер: %d\n"
"IP: %s",
ESP.getChipModel(),
ESP.getChipRevision(),
esp_get_idf_version(),
ESP.getCpuFreqMHz(),
ESP.getChipCores(),
networkService->getIpAddr().c_str()
);
alert("Інфо про пристрій", buf);
} else if (index == 3) {
String labels[16];
int labelCount = lilka::sys.get_partition_labels(labels);
labels[labelCount++] = "<< Назад";
lilka::Menu partitionMenu("Таблиця розділів");
for (int i = 0; i < labelCount; i++) {
partitionMenu.addItem(labels[i]);
}
if (index == 0) {
AppManager::getInstance()->runApp(new WiFiConfigApp());
} else if (index == 1) {
alert("Keira OS", "by Андерсон & friends");
} else if (index == 2) {
char buf[256];
NetworkService* networkService =
static_cast<NetworkService*>(ServiceManager::getInstance()->getService<NetworkService>());
// TODO: use dynamic_cast and assert networkService != nullptr
sprintf(
buf,
"Модель: %s\n"
"Ревізія: %d\n"
"Версія ESP-IDF: %s\n"
"Частота: %d МГц\n"
"Кількість ядер: %d\n"
"IP: %s",
ESP.getChipModel(),
ESP.getChipRevision(),
esp_get_idf_version(),
ESP.getCpuFreqMHz(),
ESP.getChipCores(),
networkService->getIpAddr().c_str()
);
alert("Інфо про пристрій", buf);
} else if (index == 3) {
String labels[16];
int labelCount = lilka::sys.get_partition_labels(labels);
labels[labelCount++] = "<< Назад";
lilka::Menu partitionMenu("Таблиця розділів");
for (int i = 0; i < labelCount; i++) {
partitionMenu.addItem(labels[i]);
}
while (1) {
while (1) {
while (!partitionMenu.isFinished()) {
partitionMenu.update();
partitionMenu.draw(canvas);
queueDraw();
int16_t partitionIndex = partitionMenu.getSelectedIndex();
if (partitionIndex != -1) {
if (partitionIndex == labelCount - 1) {
break;
}
alert(
labels[partitionIndex],
String("Адреса: 0x") +
String(lilka::sys.get_partition_address(labels[partitionIndex].c_str()), HEX) + "\n" +
"Розмір: 0x" +
String(lilka::sys.get_partition_size(labels[partitionIndex].c_str()), HEX)
);
}
}
} else if (index == 4) {
esp_restart();
int16_t partitionIndex = partitionMenu.getCursor();
if (partitionIndex == labelCount - 1) {
break;
}
alert(
labels[partitionIndex],
String("Адреса: 0x") +
String(lilka::sys.get_partition_address(labels[partitionIndex].c_str()), HEX) + "\n" +
"Розмір: 0x" + String(lilka::sys.get_partition_size(labels[partitionIndex].c_str()), HEX)
);
}
} else if (index == 4) {
if (!lilka::sdcard.available()) {
alert("Помилка", "SD-карта не знайдена");
continue;
}
lilka::Alert confirm(
"Форматування", "УВАГА: Це очистить ВСІ дані з SD-карти!\n\nПродовжити?\n\nSTART - так\nA - скасувати"
);
confirm.draw(canvas);
queueDraw();
while (!confirm.isFinished()) {
confirm.update();
taskYIELD();
}
if (confirm.getButton() != lilka::Button::START) {
continue;
}
lilka::ProgressDialog dialog("Форматування", "Будь ласка, зачекайте...");
dialog.draw(canvas);
queueDraw();
const uint32_t workSize = FF_MAX_SS * 4;
void* work = ps_malloc(workSize
); // Buffer (4 sectors), otherwise f_mkfs tries to allocate in stack and fails due to task stack size
FRESULT result = f_mkfs("/sd", FM_ANY, 0, work, workSize); // TODO - hardcoded mountpoint
free(work);
if (result != FR_OK) {
this->alert("Помилка", "Не вдалося сформатувати SD-карту, код помилки: " + String(result));
continue;
}
this->alert("Форматування", "Форматування SD-карти завершено!");

} else if (index == 5) {
esp_restart();
}
}
}
Expand All @@ -390,11 +420,8 @@ void LauncherApp::alert(String title, String message) {
lilka::Alert alert(title, message);
alert.draw(canvas);
queueDraw();
while (1) {
while (!alert.isFinished()) {
alert.update();
if (alert.isDone()) {
break;
}
taskYIELD();
}
}
Loading
Loading