Skip to content

Commit 096c0ba

Browse files
committed
evp_printf, dinamic strings count
1 parent dbd1112 commit 096c0ba

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

eth_view_process.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
2020
evp->position = 0;
2121
evp->x = 27;
2222
evp->y = 6;
23+
evp->strings_cnt = 10;
2324

2425
if(type == EthWorkerProcessInit) {
2526
evp->y += 22;
@@ -53,6 +54,9 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
5354
stat->dns[2] = 0;
5455
stat->dns[3] = 1;
5556
evp->draw_struct = stat;
57+
evp->strings_cnt = 20;
58+
} else if(type == EthWorkerProcessDHCP) {
59+
evp->strings_cnt = 20;
5660
} else if(type == EthWorkerProcessPing) {
5761
evp->y += 11;
5862
EthViewDrawPing* ping = malloc(sizeof(EthViewDrawPing));
@@ -62,11 +66,15 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
6266
ping->ip[2] = 8;
6367
ping->ip[3] = 8;
6468
evp->draw_struct = ping;
69+
evp->strings_cnt = 20;
6570
}
71+
72+
evp->fifo = malloc(sizeof(EthViewProcessLine) * evp->strings_cnt);
6673
return evp;
6774
}
6875

6976
void ethernet_view_process_free(EthViewProcess* evp) {
77+
free(evp->fifo);
7078
if(evp->type == EthWorkerProcessInit || evp->type == EthWorkerProcessStatic ||
7179
evp->type == EthWorkerProcessPing) {
7280
free(evp->draw_struct);
@@ -162,13 +170,13 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
162170
uint8_t position = process->position;
163171

164172
if(process->autofill) {
165-
position = (carriage + SCREEN_STRINGS_COUNT - str_count) % SCREEN_STRINGS_COUNT;
173+
position = (carriage + process->strings_cnt - str_count) % process->strings_cnt;
166174
process->position = position;
167175
}
168176

169177
for(uint8_t i = 0; i < str_count; ++i) {
170178
uint8_t y1 = y + (i + 1) * str_height;
171-
canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % SCREEN_STRINGS_COUNT]);
179+
canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % process->strings_cnt].data);
172180
}
173181

174182
if(process->type == EthWorkerProcessInit) {
@@ -360,12 +368,12 @@ void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
360368
void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
361369
furi_assert(process);
362370
uint8_t position = process->position;
363-
if(shift <= -SCREEN_STRINGS_COUNT) {
371+
if(shift <= -process->strings_cnt) {
364372
position = 0;
365-
} else if(shift >= SCREEN_STRINGS_COUNT) {
373+
} else if(shift >= process->strings_cnt) {
366374
position = process->carriage - 1;
367375
} else {
368-
position = (position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT;
376+
position = (position + (process->strings_cnt + shift)) % process->strings_cnt;
369377
}
370378
process->position = position;
371379
process->autofill = !shift;
@@ -402,6 +410,15 @@ static uint16_t get_string_with_width(const char* str, uint16_t width) {
402410
return end;
403411
}
404412

413+
void evp_printf(EthViewProcess* process, const char* format, ...) {
414+
va_list args;
415+
va_start(args, format);
416+
FuriString* fstring = furi_string_alloc_vprintf(format, args);
417+
va_end(args);
418+
ethernet_view_process_print(process, furi_string_get_cstr(fstring));
419+
furi_string_free(fstring);
420+
}
421+
405422
void ethernet_view_process_print(EthViewProcess* process, const char* str) {
406423
furi_assert(process);
407424

@@ -413,13 +430,13 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) {
413430
uint16_t start = ptr;
414431
ptr += get_string_with_width(str + ptr, max_width);
415432
uint8_t carriage = process->carriage;
416-
uint8_t carriage1 = (carriage + 1) % SCREEN_STRINGS_COUNT;
417-
uint8_t carriage2 = (carriage + 2) % SCREEN_STRINGS_COUNT;
433+
uint8_t carriage1 = (carriage + 1) % process->strings_cnt;
434+
uint8_t carriage2 = (carriage + 2) % process->strings_cnt;
418435
FURI_LOG_I(TAG, "print %d %d %d %d %d", max_width, len, start, carriage, carriage1);
419-
memset(process->fifo[carriage], 0, SCREEN_SYMBOLS_WIDTH);
420-
memset(process->fifo[carriage1], 0, SCREEN_SYMBOLS_WIDTH);
421-
memset(process->fifo[carriage2], 0, SCREEN_SYMBOLS_WIDTH);
422-
memcpy(process->fifo[carriage], str + start, ptr - start);
436+
memset(process->fifo[carriage].data, 0, SCREEN_SYMBOLS_WIDTH);
437+
memset(process->fifo[carriage1].data, 0, SCREEN_SYMBOLS_WIDTH);
438+
memset(process->fifo[carriage2].data, 0, SCREEN_SYMBOLS_WIDTH);
439+
memcpy(process->fifo[carriage].data, str + start, ptr - start);
423440
process->carriage = carriage1;
424441
}
425442
}

eth_view_process.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <gui/gui.h>
55

66
#define SCREEN_SYMBOLS_WIDTH 30
7-
#define SCREEN_STRINGS_COUNT 8
87

98
EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type);
109
void ethernet_view_process_free(EthViewProcess* evp);
@@ -13,6 +12,24 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas);
1312
void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key);
1413
void ethernet_view_process_print(EthViewProcess* process, const char* str);
1514
void ethernet_view_process_move(EthViewProcess* process, int8_t shift);
15+
void evp_printf(EthViewProcess* process, const char* format, ...);
16+
17+
typedef struct EthViewProcessLine {
18+
char data[SCREEN_SYMBOLS_WIDTH];
19+
} EthViewProcessLine;
20+
21+
struct EthViewProcess {
22+
EthViewProcessLine* fifo;
23+
uint8_t strings_cnt;
24+
uint8_t x;
25+
uint8_t y;
26+
uint8_t carriage;
27+
uint8_t position;
28+
uint8_t autofill;
29+
uint8_t editing;
30+
EthWorkerProcess type;
31+
void* draw_struct;
32+
};
1633

1734
typedef struct EthViewDrawInit {
1835
uint8_t mac[6];

eth_worker_i.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ struct EthWorkerNetConf {
1414
uint8_t is_dhcp;
1515
};
1616

17-
struct EthViewProcess {
18-
char fifo[SCREEN_STRINGS_COUNT][SCREEN_SYMBOLS_WIDTH];
19-
uint8_t x;
20-
uint8_t y;
21-
uint8_t carriage;
22-
uint8_t position;
23-
uint8_t autofill;
24-
uint8_t editing;
25-
EthWorkerProcess type;
26-
void* draw_struct;
27-
};
28-
2917
struct EthWorker {
3018
FuriThread* thread;
3119
void* context;

finik_eth_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void finit_eth_app_key_handler(FinikEthApp* app, InputKey key) {
140140
view_port_update(app->view_port);
141141
furi_delay_ms(150);
142142
char str[] = "test string 0 with some parameters";
143-
ethernet_view_process_print(app->eth_worker->init_process, str);
143+
evp_printf(app->eth_worker->init_process, "test promt %d %s", 112, "ivan");
144144
ethernet_view_process_print(app->eth_worker->stat_process, str);
145145
ethernet_view_process_print(
146146
app->eth_worker->dhcp_process, "test dhcp process string. loooooong world");

0 commit comments

Comments
 (0)