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

Commit

Permalink
added vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
Milk-Cool committed Sep 18, 2023
1 parent 6edac6a commit 84e8225
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Default",
"intelliSenseMode": "gcc-x64",
"includePath": ["${workspaceFolder}/flipper", "${workspaceFolder}/helpers",
"${workspaceFolder}/lib"]
"${workspaceFolder}/lib", "${workspaceFolder}/flipper_hal"]
}
],
"version": 4
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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/).
2 changes: 2 additions & 0 deletions flipper/globals/vibro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <stdbool.h>
bool global_vibro_on = false;
49 changes: 47 additions & 2 deletions flipper/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
#include <unistd.h>
#endif
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>

#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 <stdio.h>
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions flipper_hal/furi_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include "furi_hal_vibro.h"
5 changes: 5 additions & 0 deletions flipper_hal/furi_hal_vibro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "furi_hal_vibro.h"

void furi_hal_vibro_on(bool value) {
global_vibro_on = value;
}
14 changes: 14 additions & 0 deletions flipper_hal/furi_hal_vibro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <stdbool.h>
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);
Binary file added haxrcorp-4089.ttf
Binary file not shown.

0 comments on commit 84e8225

Please sign in to comment.