karasevIA 2 лет назад
Родитель
Сommit
1a7afc60d4
7 измененных файлов с 163 добавлено и 9 удалено
  1. 1 1
      application.fam
  2. 101 0
      eth_view_process.c
  3. 11 0
      eth_view_process.h
  4. 10 0
      eth_worker.c
  5. 3 1
      eth_worker.h
  6. 21 2
      eth_worker_i.h
  7. 16 5
      finik_eth_app.c

+ 1 - 1
application.fam

@@ -8,7 +8,7 @@ App(
 		"gui",
 		"gui",
         "power",
         "power",
 	],
 	],
-	stack_size=10 * 1024,
+	stack_size=20 * 1024,
 	order=90,
 	order=90,
 	fap_icon="ehternet_icon_10x10px.png",
 	fap_icon="ehternet_icon_10x10px.png",
     fap_category="GPIO",
     fap_category="GPIO",

+ 101 - 0
eth_view_process.c

@@ -0,0 +1,101 @@
+#include "eth_view_process.h"
+#include "eth_worker.h"
+#include "eth_worker_i.h"
+#include <gui/gui.h>
+#include <gui/canvas.h>
+#include <string.h>
+#include "u8g2.h"
+
+void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
+    furi_assert(canvas);
+    furi_assert(process);
+    canvas_set_font(canvas, FontSecondary);
+
+    const uint8_t x = process->x;
+    const uint8_t y = process->y;
+    const uint8_t str_height = 11;
+    const uint8_t str_count = (64 - y) / str_height;
+
+    int8_t position = process->position;
+    uint8_t carriage = process->carriage;
+
+    if(process->autofill) {
+        if(carriage > str_count) {
+            position = carriage - str_count;
+        } else {
+            position = 0;
+        }
+    }
+
+    for(uint8_t i = 0; i < str_count; ++i) {
+        canvas_draw_str(
+            canvas,
+            x,
+            y + (i + 1) * str_height,
+            process->fifo[(position + i) % SCREEN_STRINGS_COUNT]);
+    }
+}
+
+void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
+    furi_assert(process);
+    if(shift <= -SCREEN_STRINGS_COUNT) {
+        process->position = 0;
+    } else if(shift >= SCREEN_STRINGS_COUNT) {
+        process->position = process->carriage - 1;
+    } else {
+        process->position =
+            (process->position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT;
+    }
+
+    process->autofill = !shift;
+}
+
+void ethernet_view_process_autofill(EthViewProcess* process, uint8_t state) {
+    furi_assert(process);
+    process->autofill = state;
+}
+
+static uint16_t get_string_with_width(const char* str, uint16_t width) {
+    u8g2_t canvas_memory[3];
+    Canvas* canvas = &canvas_memory; // grazniy hack
+    canvas_set_font(canvas, FontSecondary);
+
+    uint8_t end = 0;
+    char copy[SCREEN_SYMBOLS_WIDTH + 1] = {0};
+
+    for(;;) {
+        if(str[end] == '\0') {
+            break;
+        }
+        if(end == SCREEN_SYMBOLS_WIDTH) {
+            break;
+        }
+        copy[end] = str[end];
+        if(canvas_string_width(canvas, copy) > width) {
+            end -= 1;
+            break;
+        }
+        end += 1;
+    }
+
+    return end;
+}
+
+void ethernet_view_process_print(EthViewProcess* process, const char* str) {
+    furi_assert(process);
+
+    uint16_t max_width = 126 - process->x;
+    uint16_t ptr = 0;
+    uint16_t len = strlen(str);
+
+    while(ptr < len) {
+        uint16_t start = ptr;
+        ptr += get_string_with_width(str + ptr, max_width);
+        memset(process->fifo[process->carriage % SCREEN_STRINGS_COUNT], 0, SCREEN_SYMBOLS_WIDTH);
+        memcpy(process->fifo[process->carriage % SCREEN_STRINGS_COUNT], str + start, ptr - start);
+        process->carriage += 1;
+        if(process->carriage > SCREEN_STRINGS_COUNT * 2) {
+            process->carriage -= SCREEN_STRINGS_COUNT;
+        }
+    }
+}

+ 11 - 0
eth_view_process.h

@@ -0,0 +1,11 @@
+#pragma once
+
+#include "eth_worker.h"
+#include <gui/gui.h>
+
+#define SCREEN_SYMBOLS_WIDTH 30
+#define SCREEN_STRINGS_COUNT 40
+
+void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas);
+void ethernet_view_process_print(EthViewProcess* process, const char* str);
+void ethernet_view_process_move(EthViewProcess* process, int8_t shift);

+ 10 - 0
eth_worker.c

@@ -21,6 +21,15 @@ EthWorker* eth_worker_alloc() {
 
 
     eth_worker_change_state(eth_worker, EthWorkerStateModuleInit);
     eth_worker_change_state(eth_worker, EthWorkerStateModuleInit);
 
 
+    eth_worker->init_process = malloc(sizeof(EthViewProcess));
+    memset(eth_worker->init_process, 0, sizeof(EthViewProcess));
+
+    eth_worker->init_process->autofill = 1;
+    eth_worker->init_process->carriage = 0;
+    eth_worker->init_process->position = 0;
+    eth_worker->init_process->x = 27;
+    eth_worker->init_process->y = 6;
+
     //eth_worker->callback = eth_worker_change_state;
     //eth_worker->callback = eth_worker_change_state;
 
 
     return eth_worker;
     return eth_worker;
@@ -29,6 +38,7 @@ EthWorker* eth_worker_alloc() {
 void eth_worker_free(EthWorker* eth_worker) {
 void eth_worker_free(EthWorker* eth_worker) {
     furi_assert(eth_worker);
     furi_assert(eth_worker);
     furi_thread_free(eth_worker->thread);
     furi_thread_free(eth_worker->thread);
+    free(eth_worker->init_process);
     free(eth_worker);
     free(eth_worker);
 }
 }
 
 

+ 3 - 1
eth_worker.h

@@ -1,6 +1,7 @@
 #pragma once
 #pragma once
 
 
 typedef struct EthWorker EthWorker;
 typedef struct EthWorker EthWorker;
+typedef struct EthViewProcess EthViewProcess;
 
 
 typedef enum {
 typedef enum {
     EthWorkerStateNotInited = 0,
     EthWorkerStateNotInited = 0,
@@ -51,4 +52,5 @@ void eth_worker_start(
 
 
 void eth_worker_stop(EthWorker* eth_worker);
 void eth_worker_stop(EthWorker* eth_worker);
 void eth_worker_dhcp(EthWorker* eth_worker);
 void eth_worker_dhcp(EthWorker* eth_worker);
-void eth_worker_w5500(EthWorker* eth_worker);
+void eth_worker_w5500(EthWorker* eth_worker);
+void eth_worker_init_process(EthWorker* eth_worker);

+ 21 - 2
eth_worker_i.h

@@ -2,15 +2,34 @@
 
 
 #include <furi.h>
 #include <furi.h>
 #include "eth_worker.h"
 #include "eth_worker.h"
+#include "eth_view_process.h"
+
+struct EthWorkerNetConf {
+    uint8_t mac[6];
+    uint8_t ip[4];
+    uint8_t mask[4];
+    uint8_t gateway[4];
+    uint8_t dns[4];
+    uint8_t fifo_sizes[16];
+    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;
+};
 
 
 struct EthWorker {
 struct EthWorker {
     FuriThread* thread;
     FuriThread* thread;
     void* context;
     void* context;
+    EthViewProcess* init_process;
 
 
     EthWorkerState state;
     EthWorkerState state;
     EthWorkerSubState sub_state;
     EthWorkerSubState sub_state;
-    char state_string[64];
-
     EthWorkerCallback callback;
     EthWorkerCallback callback;
 };
 };
 
 

+ 16 - 5
finik_eth_app.c

@@ -8,6 +8,8 @@
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
 
 
 #include "eth_worker.h"
 #include "eth_worker.h"
+#include "eth_worker_i.h"
+#include "eth_view_process.h"
 
 
 #define TAG "FinikEthApp"
 #define TAG "FinikEthApp"
 
 
@@ -71,6 +73,7 @@ static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
         canvas_draw_icon(canvas, 0, 0, &I_main_128x64px);
         canvas_draw_icon(canvas, 0, 0, &I_main_128x64px);
         draw_process_selector(canvas, process, cursor);
         draw_process_selector(canvas, process, cursor);
         draw_battery_cunsumption(canvas, (double)consumption);
         draw_battery_cunsumption(canvas, (double)consumption);
+        ethernet_view_process_draw(app->eth_worker->init_process, canvas);
     }
     }
 }
 }
 
 
@@ -102,7 +105,8 @@ FinikEthApp* finik_eth_app_alloc() {
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
 
 
     app->power = furi_record_open(RECORD_POWER);
     app->power = furi_record_open(RECORD_POWER);
-    //app->eth_worker = eth_worker_alloc();
+
+    app->eth_worker = eth_worker_alloc();
 
 
     //eth_worker_task(app->eth_worker);
     //eth_worker_task(app->eth_worker);
 
 
@@ -120,15 +124,13 @@ void finik_eth_app_free(FinikEthApp* app) {
 
 
     furi_record_close(RECORD_GUI);
     furi_record_close(RECORD_GUI);
     furi_record_close(RECORD_NOTIFICATION);
     furi_record_close(RECORD_NOTIFICATION);
-}
-
-void finik_eth_update_consumtion(FinikEthApp* app) {
-    furi_assert(app);
+    furi_record_close(RECORD_POWER);
 }
 }
 
 
 int32_t finik_eth_app(void* p) {
 int32_t finik_eth_app(void* p) {
     UNUSED(p);
     UNUSED(p);
     FinikEthApp* app = finik_eth_app_alloc();
     FinikEthApp* app = finik_eth_app_alloc();
+    uint8_t cnt = 0;
 
 
     InputEvent event;
     InputEvent event;
 
 
@@ -149,13 +151,22 @@ int32_t finik_eth_app(void* p) {
                         app->cursor_position = CURSOR_CLICK_PROCESS;
                         app->cursor_position = CURSOR_CLICK_PROCESS;
                         view_port_update(app->view_port);
                         view_port_update(app->view_port);
                         furi_delay_ms(150);
                         furi_delay_ms(150);
+                        char str[] = "test string 0 test long string for flipper";
+                        str[12] += cnt % 10;
+                        cnt += 1;
+                        ethernet_view_process_print(app->eth_worker->init_process, str);
                         app->cursor_position = CURSOR_INSIDE_PROCESS;
                         app->cursor_position = CURSOR_INSIDE_PROCESS;
                     } else if(event.key == InputKeyBack) {
                     } else if(event.key == InputKeyBack) {
                         app->cursor_position = CURSOR_EXIT_APP;
                         app->cursor_position = CURSOR_EXIT_APP;
                     }
                     }
                 } else if(app->cursor_position == CURSOR_INSIDE_PROCESS) {
                 } else if(app->cursor_position == CURSOR_INSIDE_PROCESS) {
                     if(event.key == InputKeyLeft || event.key == InputKeyBack) {
                     if(event.key == InputKeyLeft || event.key == InputKeyBack) {
+                        ethernet_view_process_move(app->eth_worker->init_process, 0);
                         app->cursor_position = CURSOR_CHOOSE_PROCESS;
                         app->cursor_position = CURSOR_CHOOSE_PROCESS;
+                    } else if(event.key == InputKeyUp) {
+                        ethernet_view_process_move(app->eth_worker->init_process, -1);
+                    } else if(event.key == InputKeyDown) {
+                        ethernet_view_process_move(app->eth_worker->init_process, 1);
                     }
                     }
                 } else if(app->cursor_position == CURSOR_EXIT_APP) {
                 } else if(app->cursor_position == CURSOR_EXIT_APP) {
                     if(event.key == InputKeyBack) {
                     if(event.key == InputKeyBack) {