Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
well, input works now
Browse files Browse the repository at this point in the history
  • Loading branch information
Milk-Cool committed Sep 15, 2023
1 parent 7043941 commit 7c3fbd7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 85 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,4 +25,4 @@ $(OUT_APP):# $(OUT_LIB)#
# $(CC_PREFIX) -I$(HELPERS) -g $< -o $@

clean:
rm -rf $(OBJECTS) $(OUT_APP) $(OUT_LIB)
rm -rf $(OUT_APP) $(APP)
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* `furi.h` must be included
* `furi.h` includes `ncurses.h`, which reserves some function names
1 change: 0 additions & 1 deletion flipper/furi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "furi.h"
#include <stdio.h>

/*void furi_assert(void* expr) {
if(!expr)
Expand Down
1 change: 1 addition & 0 deletions flipper/furi.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <stdlib.h>
#include <ncurses.h>

#include "core/base.h"
#include "core/message_queue.h"
Expand Down
56 changes: 28 additions & 28 deletions flipper/gui/gui.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "gui_i.h"

#include <pthread.h>
#include <stdio.h>
#include <ncurses.h>
#include <time.h>

#include <stdio.h>

Gui* gui_alloc() {
Gui* gui = malloc(sizeof(Gui));
gui->canvas = canvas_init();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion helpers/crash.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "crash.h"
#include <ncurses.h>

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);
}
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
40 changes: 0 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 7c3fbd7

Please sign in to comment.