Skip to content

Commit

Permalink
Merge branch 'dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Feb 16, 2022
2 parents d4aeee6 + 2422419 commit 57689a1
Show file tree
Hide file tree
Showing 43 changed files with 806 additions and 544 deletions.
5 changes: 0 additions & 5 deletions applications/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern int32_t gui_srv(void* p);
extern int32_t input_srv(void* p);
extern int32_t loader_srv(void* p);
extern int32_t notification_srv(void* p);
extern int32_t power_observer_srv(void* p);
extern int32_t power_srv(void* p);
extern int32_t storage_srv(void* p);
extern int32_t desktop_srv(void* p);
Expand Down Expand Up @@ -115,10 +114,6 @@ const FlipperApplication FLIPPER_SERVICES[] = {
{.app = power_srv, .name = "PowerSrv", .stack_size = 1024, .icon = NULL},
#endif

#ifdef SRV_POWER_OBSERVER
{.app = power_observer_srv, .name = "PowerAuditSrv", .stack_size = 1024, .icon = NULL},
#endif

#ifdef SRV_STORAGE
{.app = storage_srv, .name = "StorageSrv", .stack_size = 3072, .icon = NULL},
#endif
Expand Down
8 changes: 0 additions & 8 deletions applications/applications.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SRV_INPUT = 1
SRV_LOADER = 1
SRV_NOTIFICATION = 1
SRV_POWER = 1
SRV_POWER_OBSERVER = 1
SRV_RPC = 1
SRV_STORAGE = 1

Expand Down Expand Up @@ -256,13 +255,6 @@ endif
endif


SRV_POWER_OBSERVER ?= 0
ifeq ($(SRV_POWER_OBSERVER), 1)
CFLAGS += -DSRV_POWER_OBSERVER
SRV_POWER = 1
endif


SRV_POWER ?= 0
ifeq ($(SRV_POWER), 1)
CFLAGS += -DSRV_POWER
Expand Down
152 changes: 78 additions & 74 deletions applications/gui/elements.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "elements.h"
#include "m-core.h"
#include <assets_icons.h>
#include "furi_hal_resources.h"
#include <furi_hal.h>
Expand Down Expand Up @@ -36,30 +37,15 @@ void elements_progress_bar(
furi_assert(canvas);
furi_assert(total > 0);
uint8_t height = 9;
uint8_t marker_width = 7;
furi_assert(width > marker_width);

uint8_t progress_length = ((float)progress / total) * (width - marker_width - 2);

// rframe doesnt work if (radius * 2) > any rect side, so write manually
uint8_t x_max = x + width - 1;
uint8_t y_max = y + height - 1;
canvas_draw_line(canvas, x + 3, y, x_max - 3, y);
canvas_draw_line(canvas, x_max - 3, y, x_max, y + 3);
canvas_draw_line(canvas, x_max, y + 3, x_max, y_max - 3);
canvas_draw_line(canvas, x_max, y_max - 3, x_max - 3, y_max);
canvas_draw_line(canvas, x_max - 3, y_max, x + 3, y_max);
canvas_draw_line(canvas, x + 3, y_max, x, y_max - 3);
canvas_draw_line(canvas, x, y_max - 3, x, y + 3);
canvas_draw_line(canvas, x, y + 3, x + 3, y);

canvas_draw_rbox(canvas, x + 1, y + 1, marker_width + progress_length, height - 2, 3);
canvas_invert_color(canvas);
canvas_draw_dot(canvas, x + progress_length + 3, y + 2);
canvas_draw_dot(canvas, x + progress_length + 4, y + 2);
canvas_draw_dot(canvas, x + progress_length + 5, y + 3);
canvas_draw_dot(canvas, x + progress_length + 6, y + 4);
canvas_invert_color(canvas);

uint8_t progress_length = roundf(((float)progress / total) * (width - 2));

canvas_set_color(canvas, ColorWhite);
canvas_draw_box(canvas, x + 1, y + 1, width - 2, height - 2);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, x, y, width, height, 3);

canvas_draw_box(canvas, x + 1, y + 1, progress_length, height - 2);
}

void elements_scrollbar_pos(
Expand Down Expand Up @@ -202,6 +188,48 @@ void elements_button_center(Canvas* canvas, const char* str) {
canvas_invert_color(canvas);
}

static size_t
elements_get_max_chars_to_fit(Canvas* canvas, Align horizontal, const char* text, uint8_t x) {
const char* end = strchr(text, '\n');
if(end == NULL) {
end = text + strlen(text);
}
size_t text_size = end - text;
string_t str;
string_init_set_str(str, text);
string_left(str, text_size);
size_t result = 0;

uint16_t len_px = canvas_string_width(canvas, string_get_cstr(str));
uint8_t px_left = 0;
if(horizontal == AlignCenter) {
px_left = canvas_width(canvas) - (x - len_px / 2);
} else if(horizontal == AlignLeft) {
px_left = canvas_width(canvas) - x;
} else if(horizontal == AlignRight) {
px_left = x;
} else {
furi_assert(0);
}

if(len_px > px_left) {
uint8_t excess_symbols_approximately =
((float)len_px - px_left) / ((float)len_px / text_size);
// reduce to 5 to be sure dash fit, and next line will be at least 5 symbols long
excess_symbols_approximately = MAX(excess_symbols_approximately, 5);
if(text_size > (excess_symbols_approximately + 5)) {
result = text_size - excess_symbols_approximately - 5;
} else {
result = text_size - 1;
}
} else {
result = text_size;
}

string_clear(str);
return result;
}

void elements_multiline_text_aligned(
Canvas* canvas,
uint8_t x,
Expand All @@ -212,64 +240,40 @@ void elements_multiline_text_aligned(
furi_assert(canvas);
furi_assert(text);

uint8_t lines_count = 0;
uint8_t font_height = canvas_current_font_height(canvas);
string_t str;
string_init(str);
const char* start = text;
char* end;
string_t line;

/* go through text line by line and count lines */
for(const char* start = text; start[0];) {
size_t chars_fit = elements_get_max_chars_to_fit(canvas, horizontal, start, x);
++lines_count;
start += chars_fit;
start += start[0] == '\n' ? 1 : 0;
}

// get lines count
uint8_t i, lines_count;
for(i = 0, lines_count = 0; text[i]; i++) lines_count += (text[i] == '\n');

switch(vertical) {
case AlignBottom:
y -= font_height * lines_count;
break;
case AlignCenter:
y -= (font_height * lines_count) / 2;
break;
case AlignTop:
default:
break;
if(vertical == AlignBottom) {
y -= font_height * (lines_count - 1);
} else if(vertical == AlignCenter) {
y -= (font_height * (lines_count - 1)) / 2;
}

do {
end = strchr(start, '\n');
/* go through text line by line and print them */
for(const char* start = text; start[0];) {
size_t chars_fit = elements_get_max_chars_to_fit(canvas, horizontal, start, x);

if(end) {
string_set_strn(str, start, end - start);
if((start[chars_fit] == '\n') || (start[chars_fit] == 0)) {
string_init_printf(line, "%.*s", chars_fit, start);
} else {
string_set_str(str, start);
string_init_printf(line, "%.*s-\n", chars_fit, start);
}

uint16_t len_px = canvas_string_width(canvas, string_get_cstr(str));
uint8_t px_left =
canvas_width(canvas) - (x - (horizontal == AlignCenter ? len_px / 2 : 0));

// hacky
if(len_px > px_left) {
string_t buff;
string_init_set(buff, str);
size_t s_len = string_size(str);
uint8_t end_pos = s_len - ((len_px - px_left) / (len_px / s_len) + 5);

string_left(buff, end_pos);
string_cat(buff, "-");
string_right(str, end_pos);

canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(buff));
string_clear(buff);

start = end + 1;
y += font_height;
}

canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(str));
start = end + 1;
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(line));
string_clear(line);
y += font_height;
} while(end);
string_clear(str);

start += chars_fit;
start += start[0] == '\n' ? 1 : 0;
}
}

void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text) {
Expand Down
16 changes: 9 additions & 7 deletions applications/gui/modules/button_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
furi_assert(_model);

ButtonMenuModel* model = (ButtonMenuModel*)_model;

canvas_clear(canvas);
canvas_set_font(canvas, FontSecondary);

uint8_t item_position = 0;
Expand All @@ -117,11 +115,14 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_icon(canvas, 28, 123, &I_IrdaArrowDown_4x8);
}

string_t disp_str;
string_init_set_str(disp_str, model->header);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(canvas, 32, 10, AlignCenter, AlignCenter, string_get_cstr(disp_str));
string_clear(disp_str);
if(model->header) {
string_t disp_str;
string_init_set_str(disp_str, model->header);
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
canvas_draw_str_aligned(
canvas, 32, 10, AlignCenter, AlignCenter, string_get_cstr(disp_str));
string_clear(disp_str);
}

for(ButtonMenuItemArray_it(it, model->items); !ButtonMenuItemArray_end_p(it);
ButtonMenuItemArray_next(it), ++item_position) {
Expand Down Expand Up @@ -248,6 +249,7 @@ void button_menu_reset(ButtonMenu* button_menu) {
button_menu->view, (ButtonMenuModel * model) {
ButtonMenuItemArray_reset(model->items);
model->position = 0;
model->header = NULL;
return true;
});
}
Expand Down
90 changes: 1 addition & 89 deletions applications/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,91 +40,6 @@ void input_isr(void* _ctx) {
osThreadFlagsSet(input->thread, INPUT_THREAD_FLAG_ISR);
}

#ifdef SRV_CLI
void input_cli_send(Cli* cli, string_t args, void* context) {
InputEvent event;

// Get first word as key name
string_t key_name;
string_init(key_name);
size_t ws = string_search_char(args, ' ');
if(ws == STRING_FAILURE) {
printf("Invalid arguments. Use `input_send KEY TYPE`.");
string_clear(key_name);
return;
} else {
string_set_n(key_name, args, 0, ws);
string_right(args, ws);
string_strim(args);
}
// Check key name and set event key
if(!string_cmp(key_name, "up")) {
event.key = InputKeyUp;
} else if(!string_cmp(key_name, "down")) {
event.key = InputKeyDown;
} else if(!string_cmp(key_name, "left")) {
event.key = InputKeyLeft;
} else if(!string_cmp(key_name, "right")) {
event.key = InputKeyRight;
} else if(!string_cmp(key_name, "ok")) {
event.key = InputKeyOk;
} else if(!string_cmp(key_name, "back")) {
event.key = InputKeyBack;
} else {
printf("Invalid key name. Valid keys: `up`, `down`, `left`, `right`, `back`, `ok`.");
string_clear(key_name);
return;
}
string_clear(key_name);
// Check the rest of args string and set event type
if(!string_cmp(args, "press")) {
event.type = InputTypePress;
} else if(!string_cmp(args, "release")) {
event.type = InputTypeRelease;
} else if(!string_cmp(args, "short")) {
event.type = InputTypeShort;
} else if(!string_cmp(args, "long")) {
event.type = InputTypeLong;
} else {
printf("Ivalid type. Valid types: `press`, `release`, `short`, `long`.");
return;
}
// Publish input event
furi_pubsub_publish(input->event_pubsub, &event);
}

static void input_cli_dump_events_callback(const void* value, void* ctx) {
furi_assert(value);
furi_assert(ctx);
osMessageQueueId_t input_queue = ctx;
osMessageQueuePut(input_queue, value, 0, osWaitForever);
}

static void input_cli_dump(Cli* cli, string_t args, void* context) {
osMessageQueueId_t input_queue = osMessageQueueNew(8, sizeof(InputEvent), NULL);
FuriPubSubSubscription* input_subscription =
furi_pubsub_subscribe(input->event_pubsub, input_cli_dump_events_callback, input_queue);

bool stop = false;
InputEvent input_event;
while(!stop) {
if(osMessageQueueGet(input_queue, &input_event, NULL, 100) == osOK) {
printf(
"key: %s type: %s\r\n",
input_get_key_name(input_event.key),
input_get_type_name(input_event.type));
}

if(cli_cmd_interrupt_received(cli)) {
stop = true;
}
}

furi_pubsub_unsubscribe(input->event_pubsub, input_subscription);
osMessageQueueDelete(input_queue);
}
#endif

const char* input_get_key_name(InputKey key) {
for(size_t i = 0; i < input_pins_count; i++) {
if(input_pins[i].key == key) {
Expand Down Expand Up @@ -159,10 +74,7 @@ int32_t input_srv() {
#ifdef SRV_CLI
input->cli = furi_record_open("cli");
if(input->cli) {
cli_add_command(
input->cli, "input_send", CliCommandFlagParallelSafe, input_cli_send, NULL);
cli_add_command(
input->cli, "input_dump", CliCommandFlagParallelSafe, input_cli_dump, NULL);
cli_add_command(input->cli, "input", CliCommandFlagParallelSafe, input_cli, input);
}
#endif

Expand Down
Loading

0 comments on commit 57689a1

Please sign in to comment.