From 7c3fbd75ac8268587ff87a56b1b4dbdc296801f9 Mon Sep 17 00:00:00 2001 From: Milk-Cool Date: Fri, 15 Sep 2023 21:53:40 +0300 Subject: [PATCH] well, input works now --- Makefile | 12 +++++----- README.md | 5 +++-- flipper/furi.c | 1 - flipper/furi.h | 1 + flipper/gui/gui.c | 56 +++++++++++++++++++++++------------------------ helpers/crash.c | 4 +++- index.js | 10 ++++++--- package-lock.json | 40 --------------------------------- package.json | 5 +---- 9 files changed, 49 insertions(+), 85 deletions(-) diff --git a/Makefile b/Makefile index 23237c7..394bb59 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,18 @@ HELPERS = helpers/ APP = flippulator_app_copy/ SOURCES = $(shell find $(LIBS) -name "*.c") $(shell find $(HELPERS) -name "*.c") SRC_APP = $(shell find $(APP) -name "*.c") -OBJECTS = ${subst .c,.o,$(SOURCES)} +#OBJECTS = ${subst .c,.o,$(SOURCES)} OUT_APP = out -OUT_LIB_NAME = flipper -OUT_LIB = lib$(OUT_LIB_NAME).a -CC_PREFIX = gcc -c -Wall# -fPIC +#OUT_LIB_NAME = flipper +#OUT_LIB = lib$(OUT_LIB_NAME).a +#CC_PREFIX = gcc -c -Wall# -fPIC CC_PREFIX_FINAL = gcc -Wall -Wno-main #CC_PREFIX = clang -c all: $(OUT_APP) $(OUT_APP):# $(OUT_LIB)# - $(CC_PREFIX_FINAL) -I$(LIBS) -I$(HELPERS) $(SRC_APP) $(SOURCES) -o $(OUT_APP) + $(CC_PREFIX_FINAL) -I$(LIBS) -I$(HELPERS) $(SRC_APP) $(SOURCES) -lncurses -o $(OUT_APP) #$(OUT_LIB): $(OBJECTS) # ar rcs $(OUT_LIB) $(OBJECTS) @@ -25,4 +25,4 @@ $(OUT_APP):# $(OUT_LIB)# # $(CC_PREFIX) -I$(HELPERS) -g $< -o $@ clean: - rm -rf $(OBJECTS) $(OUT_APP) $(OUT_LIB) \ No newline at end of file + rm -rf $(OUT_APP) $(APP) \ No newline at end of file diff --git a/README.md b/README.md index 21e2324..ba23de1 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ Based on [Flipper Zero Firmware](https://github.com/flipperdevices/flipperzero-f ## Requirements A linux system\ -Packages `make`, `gcc` +Packages `make`, `gcc`, `libncurses5` ## Usage ## Limitations * The main function cannot be called `main` -* `furi.h` must be included \ No newline at end of file +* `furi.h` must be included +* `furi.h` includes `ncurses.h`, which reserves some function names \ No newline at end of file diff --git a/flipper/furi.c b/flipper/furi.c index 15388d4..953a3fd 100644 --- a/flipper/furi.c +++ b/flipper/furi.c @@ -1,5 +1,4 @@ #include "furi.h" -#include /*void furi_assert(void* expr) { if(!expr) diff --git a/flipper/furi.h b/flipper/furi.h index 8a6f794..543477d 100644 --- a/flipper/furi.h +++ b/flipper/furi.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "core/base.h" #include "core/message_queue.h" diff --git a/flipper/gui/gui.c b/flipper/gui/gui.c index f7c82e3..773d04d 100644 --- a/flipper/gui/gui.c +++ b/flipper/gui/gui.c @@ -1,9 +1,11 @@ #include "gui_i.h" #include -#include +#include #include +#include + Gui* gui_alloc() { Gui* gui = malloc(sizeof(Gui)); gui->canvas = canvas_init(); @@ -15,31 +17,19 @@ void* handle_input(void* _view_port) { ViewPort* view_port = _view_port; while(true) { char c; - scanf("%c", &c); + c = getch(); InputEvent* event = malloc(sizeof(InputEvent)); event->type = InputTypePress; - if(c == 27) { - scanf("%c", &c); - if(c == 91) { - scanf("%c", &c); - switch(c) { - case 65: // Up - event->key = InputKeyUp; - break; - case 66: // Down - event->key = InputKeyDown; - break; - case 67: // Right - event->key = InputKeyLeft; - break; - case 68: // Left - event->key = InputKeyRight; - break; - } - } - } + if(c == KEY_UP) event->key = InputKeyUp; + else if(c == KEY_DOWN) event->key = InputKeyDown; + else if(c == KEY_LEFT) event->key = InputKeyLeft; + else if(c == KEY_RIGHT) event->key = InputKeyRight; else if(c == 122) event->key = InputKeyOk; else if(c == 120) event->key = InputKeyBack; + else if(c == 113) { + endwin(); + exit(0); + } view_port->input_callback(event, view_port->input_callback_context); } return NULL; @@ -48,11 +38,16 @@ void* handle_gui(void* _view_port) { ViewPort* view_port = _view_port; while(true) { clock_t delay_start = clock(); - view_port->draw_callback(view_port->gui->canvas, view_port->draw_callback_context); - printf("\e[1;1H\e[2J"); - for(uint8_t x = 0; x < view_port->gui->canvas->width; x++) + if(view_port->draw_callback != NULL) + view_port->draw_callback(view_port->gui->canvas, view_port->draw_callback_context); + clear(); + + for(uint8_t x = 0; x < view_port->gui->canvas->width; x++) { for(uint8_t y = 0; y < view_port->gui->canvas->height; y++) - printf("%s", view_port->gui->canvas->fb[x][y] ? "⣿" : "⠀"); + printw("%s", view_port->gui->canvas->fb[x][y] ? "⣿" : "⠀"); + printw("%s", "\r\n"); + } + refresh(); while(clock() < delay_start + 1); } return NULL; @@ -64,10 +59,15 @@ void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) { gui->view_port = view_port; view_port->gui = gui; - pthread_t input_thread_id; - pthread_create(&input_thread_id, NULL, handle_input, view_port); + initscr(); + noecho(); + cbreak(); + keypad(stdscr, TRUE); + pthread_t draw_thread_id; pthread_create(&draw_thread_id, NULL, handle_gui, view_port); + pthread_t input_thread_id; + pthread_create(&input_thread_id, NULL, handle_input, view_port); } void gui_remove_view_port(Gui* gui, ViewPort* view_port) { // TODO diff --git a/helpers/crash.c b/helpers/crash.c index 61370d0..beac401 100644 --- a/helpers/crash.c +++ b/helpers/crash.c @@ -1,6 +1,8 @@ #include "crash.h" +#include -void crash(uint8_t code, const char* msg) { +void crash(uint8_t code, const char* msg) { + endwin(); printf("\e[1;91mCRASHED DUE TO: %s\e[0m\r\n", msg); exit(code); } \ No newline at end of file diff --git a/index.js b/index.js index db7b214..62d3dc3 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const util = require("node:util"); const exec = util.promisify(require("node:child_process").exec); const { spawn } = require("node:child_process"); const readline = require("readline"); -const fs = require("fs-extra"); +const fs = require("fs"); const { join } = require("path"); const rl = readline.createInterface({ @@ -26,15 +26,19 @@ const APP_COPY = "flippulator_app_copy"; console.log("Manifest does not exist!"); process.exit(2); } - fs.copySync(folder, APP_COPY, { "overwrite": true }); + await exec("make clean"); + // fs.copySync(folder, APP_COPY, { "overwrite": true }); + fs.mkdirSync(APP_COPY); + await exec(`cp -r "${folder}"/* "${APP_COPY}"`); const { stdout } = await exec("python3 manifest.py " + join(APP_COPY, "application.fam")); const manifest = JSON.parse(stdout.trim()); fs.appendFileSync(join(APP_COPY, manifest.appid + ".c"), ` int main() { furi_init(); ${manifest.entry_point}(NULL); + endwin(); + return 0; }`); - await exec("make clean"); spawn("make", [], { "cwd": process.cwd(), "detached": false, diff --git a/package-lock.json b/package-lock.json index ae26541..5e035e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,49 +8,9 @@ "name": "flippulator", "version": "0.1.0", "license": "MIT", - "dependencies": { - "fs-extra": "^11.1.1" - }, "bin": { "flippulator": "index.js" } - }, - "node_modules/fs-extra": { - "version": "11.1.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz", - "integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, - "node_modules/graceful-fs": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" - }, - "node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "engines": { - "node": ">= 10.0.0" - } } } } diff --git a/package.json b/package.json index aca0349..893e622 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,5 @@ "bugs": { "url": "https://github.com/Milk-Cool/flippulator/issues" }, - "homepage": "https://github.com/Milk-Cool/flippulator#readme", - "dependencies": { - "fs-extra": "^11.1.1" - } + "homepage": "https://github.com/Milk-Cool/flippulator#readme" }