Skip to content

Commit

Permalink
lib: Experimental mJS support
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Feb 23, 2024
1 parent bdc085d commit 3ce9eea
Show file tree
Hide file tree
Showing 10 changed files with 16,034 additions and 23 deletions.
584 changes: 584 additions & 0 deletions firmware/main/src/icons/js.h

Large diffs are not rendered by default.

Binary file added firmware/main/src/icons/js.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified firmware/main/src/icons/lua.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 40 additions & 23 deletions firmware/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {
#include "icons/nes.h"
#include "icons/bin.h"
#include "icons/lua.h"
#include "icons/js.h"

#include "demos/demos.h"

Expand All @@ -41,6 +42,20 @@ void demos_menu() {
}
}

const menu_icon_t *get_file_icon(const String &filename) {
if (filename.endsWith(".rom") || filename.endsWith(".nes")) {
return &nes;
} else if (filename.endsWith(".bin")) {
return &bin;
} else if (filename.endsWith(".lua")) {
return &lua;
} else if (filename.endsWith(".js")) {
return &js;
} else {
return &file;
}
}

void select_file(String path) {
if (path.endsWith(".rom") || path.endsWith(".nes")) {
char *argv[1];
Expand Down Expand Up @@ -79,8 +94,13 @@ void select_file(String path) {
lilka::display.getTextBounds(buf, lilka::display.getCursorX(), lilka::display.getCursorY(), &x, &y, &w, &h);
lilka::display.fillRect(x, y, w, h, lilka::display.color565(0, 0, 0));
lilka::display.println(buf);
lilka::display.fillRect(16, LILKA_DISPLAY_HEIGHT / 2 + 40, LILKA_DISPLAY_WIDTH - 32, 5, lilka::display.color565(64, 64, 64));
lilka::display.fillRect(16, LILKA_DISPLAY_HEIGHT / 2 + 40, (LILKA_DISPLAY_WIDTH - 32) * progress, 5, lilka::display.color565(255, 128, 0));
lilka::display.fillRect(
16, LILKA_DISPLAY_HEIGHT / 2 + 40, LILKA_DISPLAY_WIDTH - 32, 5, lilka::display.color565(64, 64, 64)
);
lilka::display.fillRect(
16, LILKA_DISPLAY_HEIGHT / 2 + 40, (LILKA_DISPLAY_WIDTH - 32) * progress, 5,
lilka::display.color565(255, 128, 0)
);
}
if (error) {
delete handle;
Expand All @@ -98,6 +118,11 @@ void select_file(String path) {
if (retCode) {
lilka::ui_alert("Lua", String("Увага!\nКод завершення: ") + retCode);
}
} else if (path.endsWith(".js")) {
int retCode = lilka::mjs_run(path);
if (retCode) {
lilka::ui_alert("Lua", String("Увага!\nКод завершення: ") + retCode);
}
} else {
// Get file size
FILE *file = fopen(path.c_str(), "r");
Expand All @@ -112,18 +137,6 @@ void select_file(String path) {
}
}

const menu_icon_t *get_file_icon(const String &filename) {
if (filename.endsWith(".rom") || filename.endsWith(".nes")) {
return &nes;
} else if (filename.endsWith(".bin")) {
return &bin;
} else if (filename.endsWith(".lua")) {
return &lua;
} else {
return &file;
}
}

void sd_browser_menu(String path) {
if (!lilka::sdcard.available()) {
lilka::ui_alert("Помилка", "SD-карта не знайдена");
Expand Down Expand Up @@ -194,7 +207,8 @@ void spiffs_browser_menu() {

void system_utils_menu() {
String menu[] = {
"Перезавантаження", "Deep Sleep", "Версія SDK", "Версія ESP-IDF", "Інфо про пристрій", "Таблиця розділів", "<< Назад",
"Перезавантаження", "Deep Sleep", "Версія SDK", "Версія ESP-IDF",
"Інфо про пристрій", "Таблиця розділів", "<< Назад",
};
int cursor = 0;
int count = sizeof(menu) / sizeof(menu[0]);
Expand All @@ -210,14 +224,17 @@ void system_utils_menu() {
lilka::ui_alert("Версія ESP-IDF", "Версія: " + String(esp_get_idf_version()));
} else if (cursor == 4) {
char buf[256];
sprintf(buf,
"Модель: %s\n"
"Ревізія: %d\n"
"Версія SDK: %s\n"
"Версія ESP-IDF: %s\n"
"Частота: %d МГц\n"
"Кількість ядер: %d\n",
ESP.getChipModel(), ESP.getChipRevision(), ESP.getSdkVersion(), esp_get_idf_version(), ESP.getCpuFreqMHz(), ESP.getChipCores());
sprintf(
buf,
"Модель: %s\n"
"Ревізія: %d\n"
"Версія SDK: %s\n"
"Версія ESP-IDF: %s\n"
"Частота: %d МГц\n"
"Кількість ядер: %d\n",
ESP.getChipModel(), ESP.getChipRevision(), ESP.getSdkVersion(), esp_get_idf_version(),
ESP.getCpuFreqMHz(), ESP.getChipCores()
);
lilka::ui_alert("Інфо про пристрій", buf);
} else if (cursor == 5) {
String labels[16];
Expand Down
1 change: 1 addition & 0 deletions sdk/lib/lilka/src/lilka.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "lilka/sys.h"
#include "lilka/resources.h"
#include "lua/luarunner.h"
#include "mjs/mjsrunner.h"

namespace lilka {
void begin();
Expand Down
12 changes: 12 additions & 0 deletions sdk/lib/lilka/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Default setup & loop functions (weak symbols)

#include <Arduino.h>
#include "lilka.h"

void __attribute__((weak)) setup() {
lilka::begin();
}

void __attribute__((weak)) loop() {
lilka::ui_alert("Лілка", "Ця програма не має жодного коду.");
}
Loading

0 comments on commit 3ce9eea

Please sign in to comment.