Просмотр исходного кода

evp_printf, dinamic strings count

karasevIA 2 лет назад
Родитель
Сommit
096c0ba4bd
4 измененных файлов с 47 добавлено и 25 удалено
  1. 28 11
      eth_view_process.c
  2. 18 1
      eth_view_process.h
  3. 0 12
      eth_worker_i.h
  4. 1 1
      finik_eth_app.c

+ 28 - 11
eth_view_process.c

@@ -20,6 +20,7 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
     evp->position = 0;
     evp->x = 27;
     evp->y = 6;
+    evp->strings_cnt = 10;
 
     if(type == EthWorkerProcessInit) {
         evp->y += 22;
@@ -53,6 +54,9 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
         stat->dns[2] = 0;
         stat->dns[3] = 1;
         evp->draw_struct = stat;
+        evp->strings_cnt = 20;
+    } else if(type == EthWorkerProcessDHCP) {
+        evp->strings_cnt = 20;
     } else if(type == EthWorkerProcessPing) {
         evp->y += 11;
         EthViewDrawPing* ping = malloc(sizeof(EthViewDrawPing));
@@ -62,11 +66,15 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
         ping->ip[2] = 8;
         ping->ip[3] = 8;
         evp->draw_struct = ping;
+        evp->strings_cnt = 20;
     }
+
+    evp->fifo = malloc(sizeof(EthViewProcessLine) * evp->strings_cnt);
     return evp;
 }
 
 void ethernet_view_process_free(EthViewProcess* evp) {
+    free(evp->fifo);
     if(evp->type == EthWorkerProcessInit || evp->type == EthWorkerProcessStatic ||
        evp->type == EthWorkerProcessPing) {
         free(evp->draw_struct);
@@ -162,13 +170,13 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
     uint8_t position = process->position;
 
     if(process->autofill) {
-        position = (carriage + SCREEN_STRINGS_COUNT - str_count) % SCREEN_STRINGS_COUNT;
+        position = (carriage + process->strings_cnt - str_count) % process->strings_cnt;
         process->position = position;
     }
 
     for(uint8_t i = 0; i < str_count; ++i) {
         uint8_t y1 = y + (i + 1) * str_height;
-        canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % SCREEN_STRINGS_COUNT]);
+        canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % process->strings_cnt].data);
     }
 
     if(process->type == EthWorkerProcessInit) {
@@ -360,12 +368,12 @@ void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
     furi_assert(process);
     uint8_t position = process->position;
-    if(shift <= -SCREEN_STRINGS_COUNT) {
+    if(shift <= -process->strings_cnt) {
         position = 0;
-    } else if(shift >= SCREEN_STRINGS_COUNT) {
+    } else if(shift >= process->strings_cnt) {
         position = process->carriage - 1;
     } else {
-        position = (position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT;
+        position = (position + (process->strings_cnt + shift)) % process->strings_cnt;
     }
     process->position = position;
     process->autofill = !shift;
@@ -402,6 +410,15 @@ static uint16_t get_string_with_width(const char* str, uint16_t width) {
     return end;
 }
 
+void evp_printf(EthViewProcess* process, const char* format, ...) {
+    va_list args;
+    va_start(args, format);
+    FuriString* fstring = furi_string_alloc_vprintf(format, args);
+    va_end(args);
+    ethernet_view_process_print(process, furi_string_get_cstr(fstring));
+    furi_string_free(fstring);
+}
+
 void ethernet_view_process_print(EthViewProcess* process, const char* str) {
     furi_assert(process);
 
@@ -413,13 +430,13 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) {
         uint16_t start = ptr;
         ptr += get_string_with_width(str + ptr, max_width);
         uint8_t carriage = process->carriage;
-        uint8_t carriage1 = (carriage + 1) % SCREEN_STRINGS_COUNT;
-        uint8_t carriage2 = (carriage + 2) % SCREEN_STRINGS_COUNT;
+        uint8_t carriage1 = (carriage + 1) % process->strings_cnt;
+        uint8_t carriage2 = (carriage + 2) % process->strings_cnt;
         FURI_LOG_I(TAG, "print %d %d %d %d %d", max_width, len, start, carriage, carriage1);
-        memset(process->fifo[carriage], 0, SCREEN_SYMBOLS_WIDTH);
-        memset(process->fifo[carriage1], 0, SCREEN_SYMBOLS_WIDTH);
-        memset(process->fifo[carriage2], 0, SCREEN_SYMBOLS_WIDTH);
-        memcpy(process->fifo[carriage], str + start, ptr - start);
+        memset(process->fifo[carriage].data, 0, SCREEN_SYMBOLS_WIDTH);
+        memset(process->fifo[carriage1].data, 0, SCREEN_SYMBOLS_WIDTH);
+        memset(process->fifo[carriage2].data, 0, SCREEN_SYMBOLS_WIDTH);
+        memcpy(process->fifo[carriage].data, str + start, ptr - start);
         process->carriage = carriage1;
     }
 }

+ 18 - 1
eth_view_process.h

@@ -4,7 +4,6 @@
 #include <gui/gui.h>
 
 #define SCREEN_SYMBOLS_WIDTH 30
-#define SCREEN_STRINGS_COUNT 8
 
 EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type);
 void ethernet_view_process_free(EthViewProcess* evp);
@@ -13,6 +12,24 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas);
 void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key);
 void ethernet_view_process_print(EthViewProcess* process, const char* str);
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift);
+void evp_printf(EthViewProcess* process, const char* format, ...);
+
+typedef struct EthViewProcessLine {
+    char data[SCREEN_SYMBOLS_WIDTH];
+} EthViewProcessLine;
+
+struct EthViewProcess {
+    EthViewProcessLine* fifo;
+    uint8_t strings_cnt;
+    uint8_t x;
+    uint8_t y;
+    uint8_t carriage;
+    uint8_t position;
+    uint8_t autofill;
+    uint8_t editing;
+    EthWorkerProcess type;
+    void* draw_struct;
+};
 
 typedef struct EthViewDrawInit {
     uint8_t mac[6];

+ 0 - 12
eth_worker_i.h

@@ -14,18 +14,6 @@ struct EthWorkerNetConf {
     uint8_t is_dhcp;
 };
 
-struct EthViewProcess {
-    char fifo[SCREEN_STRINGS_COUNT][SCREEN_SYMBOLS_WIDTH];
-    uint8_t x;
-    uint8_t y;
-    uint8_t carriage;
-    uint8_t position;
-    uint8_t autofill;
-    uint8_t editing;
-    EthWorkerProcess type;
-    void* draw_struct;
-};
-
 struct EthWorker {
     FuriThread* thread;
     void* context;

+ 1 - 1
finik_eth_app.c

@@ -140,7 +140,7 @@ void finit_eth_app_key_handler(FinikEthApp* app, InputKey key) {
             view_port_update(app->view_port);
             furi_delay_ms(150);
             char str[] = "test string 0 with some parameters";
-            ethernet_view_process_print(app->eth_worker->init_process, str);
+            evp_printf(app->eth_worker->init_process, "test promt %d %s", 112, "ivan");
             ethernet_view_process_print(app->eth_worker->stat_process, str);
             ethernet_view_process_print(
                 app->eth_worker->dhcp_process, "test dhcp process string. loooooong world");