diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 7f99fea..ed6b225 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,7 @@ "name": "Default", "intelliSenseMode": "gcc-x64", "includePath": ["${workspaceFolder}/flipper", "${workspaceFolder}/helpers", - "${workspaceFolder}/lib"] + "${workspaceFolder}/lib", "${workspaceFolder}/flipper_hal"] } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index c7d3297..c14bacf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,9 @@ "u8g2_glue.h": "c", "u8x8.h": "c", "icon.h": "c", - "timer.h": "c" + "timer.h": "c", + "sdl.h": "c", + "sdl_ttf.h": "c" }, "[python]": { "editor.defaultFormatter": "ms-python.autopep8" diff --git a/Makefile b/Makefile index 64d2b31..73262a8 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ LIBS = flipper/ +LIBS_HAL = flipper_hal/ EXT_LIB_ALL = lib/ #EXT_LIB_u8g2 = lib/u8g2/ HELPERS = helpers/ APP = flippulator_app_copy/ -SOURCES = $(shell find $(LIBS) -name "*.c") $(shell find $(HELPERS) -name "*.c") $(shell find $(EXT_LIB_ALL) -name "*.c") +SOURCES = $(shell find $(LIBS) -name "*.c") $(shell find $(LIBS_HAL) -name "*.c") $(shell find $(HELPERS) -name "*.c") $(shell find $(EXT_LIB_ALL) -name "*.c") SRC_APP = $(shell find $(APP) -name "*.c") #OBJECTS = ${subst .c,.o,$(SOURCES)} OUT_APP = out @@ -18,7 +19,7 @@ BUILD_LIB_heatshrink = $(BUILD_LIB_heatshrink_PATH)libheatshrink_static.a $(BUIL all: $(OUT_APP) $(OUT_APP): $(BUILD_LIB_heatshrink) - $(CC_PREFIX_FINAL) -I$(LIBS) -I$(HELPERS) -I$(EXT_LIB_ALL) $(SRC_APP) $(SOURCES) -lSDL2 -o $(OUT_APP) + $(CC_PREFIX_FINAL) -I$(LIBS) -I$(LIBS_HAL) -I$(HELPERS) -I$(EXT_LIB_ALL) $(SRC_APP) $(SOURCES) -lSDL2 -lSDL2_ttf -o $(OUT_APP) $(BUILD_LIB_heatshrink): make -C lib/heatshrink libraries diff --git a/README.md b/README.md index 5b8b1ff..c8bddce 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,7 @@ Packages `make`, `gcc`, `libncurses5` ### Uhm, akstually, it is not an emulator 🤓☝️... -Yes, it is not. It just compiles flipper applications for your computer. \ No newline at end of file +Yes, it is not. It just compiles flipper applications for your computer. + +## Credits and copyrights +The FontStruction “HaxrCorp 4089” (https://fontstruct.com/fontstructions/show/192981) by “sahwar” is licensed under a Creative Commons Attribution Share Alike license (http://creativecommons.org/licenses/by-sa/3.0/). \ No newline at end of file diff --git a/flipper/globals/vibro.c b/flipper/globals/vibro.c new file mode 100644 index 0000000..3f79a19 --- /dev/null +++ b/flipper/globals/vibro.c @@ -0,0 +1,2 @@ +#include +bool global_vibro_on = false; \ No newline at end of file diff --git a/flipper/gui/gui.c b/flipper/gui/gui.c index 0b27d69..211d603 100644 --- a/flipper/gui/gui.c +++ b/flipper/gui/gui.c @@ -7,11 +7,18 @@ #include #endif #include +#include + +#define FLIPPULATOR_FONT_SIZE 16 + +extern bool global_vibro_on; static SDL_Renderer* renderer; static SDL_Window* window; static SDL_Rect rect; static SDL_Event event; +static TTF_Font* HaxrCorp4089; +static SDL_Color Black = { 0x00, 0x00, 0x00 }; static bool running = true; #include @@ -54,6 +61,29 @@ static void* handle_input(void* _view_port) { } return NULL; } + +static void renderMessage( + char* msg, + int x, + int y, + int width +) { + SDL_Surface* surfaceMessage = TTF_RenderText_Solid(HaxrCorp4089, msg, Black); + SDL_Texture* message = SDL_CreateTextureFromSurface(renderer, surfaceMessage); + SDL_Rect message_rect = { x, y, NULL, NULL }; + + TTF_SizeText(HaxrCorp4089, msg, &message_rect.w, &message_rect.h); + + message_rect.w *= 2; + message_rect.h *= 2; + + SDL_RenderCopy(renderer, message, NULL, &message_rect); + + SDL_FreeSurface(surfaceMessage); + SDL_DestroyTexture(message); +} + +// TODO: multiple viewports support static void* handle_gui(void* _view_port) { ViewPort* view_port = _view_port; while(running) { @@ -64,6 +94,17 @@ static void* handle_gui(void* _view_port) { SDL_RenderClear(renderer); SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xff); + rect.x = 0; + rect.y = 320; + rect.w = 640; + rect.h = 3; + SDL_RenderDrawRect(renderer, &rect); + SDL_RenderFillRect(renderer, &rect); + + char* msg_vibro = malloc(sizeof(char) * 12); + snprintf(msg_vibro, 12, "Vibro: %s", global_vibro_on ? "On" : "Off"); + renderMessage(msg_vibro, 20, 340, 100); + for(uint8_t x = 0; x < view_port->width / 8; x++) // Tile X for(uint8_t y = 0; y < view_port->height / 8; y++) // Tile Y //if(canvas_get_buffer(view_port->gui->canvas)[view_port->gui->canvas->offset_x + x + (view_port->gui->canvas->offset_y + y) * view_port->width] != 1) @@ -90,14 +131,18 @@ static void* handle_gui(void* _view_port) { } void gui_add_view_port(Gui* gui, ViewPort* view_port, GuiLayer layer) { UNUSED(layer); - furi_assert(gui); // <-- + furi_assert(gui); furi_assert(view_port); gui->view_port = view_port; view_port->gui = gui; + TTF_Init(); + + HaxrCorp4089 = TTF_OpenFont("haxrcorp-4089.ttf", FLIPPULATOR_FONT_SIZE); + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); SDL_Init(SDL_INIT_VIDEO); - SDL_CreateWindowAndRenderer(640, 320, 0, &window, &renderer); + SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer); SDL_SetWindowTitle(window, "Flippulator"); pthread_t draw_thread_id; diff --git a/flipper_hal/furi_hal.h b/flipper_hal/furi_hal.h new file mode 100644 index 0000000..d435c5d --- /dev/null +++ b/flipper_hal/furi_hal.h @@ -0,0 +1,3 @@ +#pragma once + +#include "furi_hal_vibro.h" \ No newline at end of file diff --git a/flipper_hal/furi_hal_vibro.c b/flipper_hal/furi_hal_vibro.c new file mode 100644 index 0000000..c00a487 --- /dev/null +++ b/flipper_hal/furi_hal_vibro.c @@ -0,0 +1,5 @@ +#include "furi_hal_vibro.h" + +void furi_hal_vibro_on(bool value) { + global_vibro_on = value; +} \ No newline at end of file diff --git a/flipper_hal/furi_hal_vibro.h b/flipper_hal/furi_hal_vibro.h new file mode 100644 index 0000000..0f278e7 --- /dev/null +++ b/flipper_hal/furi_hal_vibro.h @@ -0,0 +1,14 @@ +#pragma once + +#include +extern bool global_vibro_on; + +/** Initialize vibro + */ +// void furi_hal_vibro_init(); // Not to be used in programs + +/** Turn on/off vibro + * + * @param[in] value new state + */ +void furi_hal_vibro_on(bool value); \ No newline at end of file diff --git a/haxrcorp-4089.ttf b/haxrcorp-4089.ttf new file mode 100644 index 0000000..dcff161 Binary files /dev/null and b/haxrcorp-4089.ttf differ