karasevIA 2 лет назад
Родитель
Сommit
c217027d69
7 измененных файлов с 105 добавлено и 10 удалено
  1. 73 3
      eth_view_process.c
  2. 7 1
      eth_view_process.h
  3. 5 5
      eth_worker.c
  4. 3 0
      eth_worker.h
  5. 3 0
      eth_worker_i.h
  6. 14 1
      finik_eth_app.c
  7. BIN
      images/init_100x19px.png

+ 73 - 3
eth_view_process.c

@@ -1,6 +1,7 @@
 #include "eth_view_process.h"
 #include "eth_view_process.h"
 #include "eth_worker.h"
 #include "eth_worker.h"
 #include "eth_worker_i.h"
 #include "eth_worker_i.h"
+#include "finik_eth_icons.h"
 
 
 #include <furi_hal.h>
 #include <furi_hal.h>
 #include <gui/gui.h>
 #include <gui/gui.h>
@@ -11,20 +12,44 @@
 
 
 #define TAG "EthView"
 #define TAG "EthView"
 
 
-EthViewProcess* ethernet_view_process_malloc() {
+EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
     EthViewProcess* evp = malloc(sizeof(EthViewProcess));
     EthViewProcess* evp = malloc(sizeof(EthViewProcess));
+    evp->type = type;
     evp->autofill = 1;
     evp->autofill = 1;
     evp->carriage = 0;
     evp->carriage = 0;
     evp->position = 0;
     evp->position = 0;
     evp->x = 27;
     evp->x = 27;
     evp->y = 6;
     evp->y = 6;
+
+    if(type == EthWorkerProcessInit) {
+        evp->y += 22;
+        evp->draw_struct = malloc(sizeof(EthViewDrawInit));
+        memset(evp->draw_struct, 0, sizeof(EthViewDrawInit));
+    }
     return evp;
     return evp;
 }
 }
 
 
 void ethernet_view_process_free(EthViewProcess* evp) {
 void ethernet_view_process_free(EthViewProcess* evp) {
+    if(evp->type == EthWorkerProcessInit) {
+        free(evp->draw_struct);
+    }
     free(evp);
     free(evp);
 }
 }
 
 
+static void draw_hex_digit(Canvas* canvas, uint8_t x, uint8_t y, uint8_t digit) {
+    char digit_str[] = "0";
+    if(digit < 0xA) {
+        digit_str[0] += digit;
+    } else if(digit < 0x10) {
+        digit_str[0] = 'A';
+        digit_str[0] += digit - 0xA;
+    } else {
+        return;
+    }
+
+    canvas_draw_str(canvas, x, y, digit_str);
+}
+
 void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
 void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
     furi_assert(canvas);
     furi_assert(canvas);
     furi_assert(process);
     furi_assert(process);
@@ -46,6 +71,51 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
         uint8_t y1 = y + (i + 1) * str_height;
         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) % SCREEN_STRINGS_COUNT]);
     }
     }
+
+    if(process->type == EthWorkerProcessInit) {
+        uint8_t editing = process->editing;
+        canvas_draw_icon(canvas, 27, 10, &I_init_100x19px);
+        for(uint8_t i = 0; i < 6; ++i) {
+            uint8_t x1 = 29 + i * 17;
+            uint8_t x2 = x1 + 6;
+            uint8_t mac = ((EthViewDrawInit*)process->draw_struct)->mac[i];
+            uint8_t octet = ((EthViewDrawInit*)process->draw_struct)->current_octet;
+            draw_hex_digit(canvas, x1, 25, (mac & 0x0F));
+            draw_hex_digit(canvas, x2, 25, (mac & 0xF0) >> 4);
+            if(editing && (octet / 2 == i)) {
+                uint8_t x = octet & 1 ? x2 : x1;
+                canvas_draw_line(canvas, x, 26, x + 4, 26);
+                canvas_draw_line(canvas, x, 27, x + 4, 27);
+            }
+        }
+    }
+}
+
+static void mac_change_hex_digit(uint8_t* mac, uint8_t octet, int8_t diff) {
+    uint8_t digit = (octet & 1) ? (mac[octet / 2] >> 4) : (mac[octet / 2]);
+    digit = (digit + diff) & 0xF;
+    mac[octet / 2] = (mac[octet / 2] & ((octet & 1) ? 0x0F : 0xF0)) |
+                     (digit << ((octet & 1) ? 4 : 0));
+}
+
+void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
+    furi_assert(process);
+    if(process->type == EthWorkerProcessInit) {
+        uint8_t octet = ((EthViewDrawInit*)process->draw_struct)->current_octet;
+        uint8_t* mac = ((EthViewDrawInit*)process->draw_struct)->mac;
+        if(key == InputKeyLeft) {
+            if(octet > 0) octet -= 1;
+        } else if(key == InputKeyRight) {
+            if(octet < 12) octet += 1;
+        } else if(key == InputKeyUp) {
+            mac_change_hex_digit(mac, octet, 1);
+        } else if(key == InputKeyDown) {
+            mac_change_hex_digit(mac, octet, -1);
+        } else if(key == InputKeyOk) {
+            process->editing = 0;
+        }
+        ((EthViewDrawInit*)process->draw_struct)->current_octet = octet;
+    }
 }
 }
 
 
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
@@ -69,7 +139,7 @@ void ethernet_view_process_autofill(EthViewProcess* process, uint8_t state) {
 
 
 static uint16_t get_string_with_width(const char* str, uint16_t width) {
 static uint16_t get_string_with_width(const char* str, uint16_t width) {
     u8g2_t canvas_memory;
     u8g2_t canvas_memory;
-    Canvas* canvas = &canvas_memory; // grazniy hack
+    Canvas* canvas = (Canvas*)&canvas_memory; // grazniy hack
     canvas_set_font(canvas, FontSecondary);
     canvas_set_font(canvas, FontSecondary);
 
 
     uint8_t end = 0;
     uint8_t end = 0;
@@ -113,4 +183,4 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) {
         memcpy(process->fifo[carriage], str + start, ptr - start);
         memcpy(process->fifo[carriage], str + start, ptr - start);
         process->carriage = carriage1;
         process->carriage = carriage1;
     }
     }
-}
+}

+ 7 - 1
eth_view_process.h

@@ -6,9 +6,15 @@
 #define SCREEN_SYMBOLS_WIDTH 30
 #define SCREEN_SYMBOLS_WIDTH 30
 #define SCREEN_STRINGS_COUNT 40
 #define SCREEN_STRINGS_COUNT 40
 
 
-EthViewProcess* ethernet_view_process_malloc();
+EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type);
 void ethernet_view_process_free(EthViewProcess* evp);
 void ethernet_view_process_free(EthViewProcess* evp);
 
 
 void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas);
 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_print(EthViewProcess* process, const char* str);
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift);
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift);
+
+struct EthViewDrawInit {
+    uint8_t mac[6];
+    uint8_t current_octet;
+};

+ 5 - 5
eth_worker.c

@@ -21,11 +21,11 @@ EthWorker* eth_worker_alloc() {
 
 
     eth_worker_change_state(eth_worker, EthWorkerStateModuleInit);
     eth_worker_change_state(eth_worker, EthWorkerStateModuleInit);
 
 
-    eth_worker->init_process = ethernet_view_process_malloc();
-    eth_worker->dhcp_process = ethernet_view_process_malloc();
-    eth_worker->stat_process = ethernet_view_process_malloc();
-    eth_worker->ping_process = ethernet_view_process_malloc();
-    eth_worker->reset_process = ethernet_view_process_malloc();
+    eth_worker->init_process = ethernet_view_process_malloc(EthWorkerProcessInit);
+    eth_worker->dhcp_process = ethernet_view_process_malloc(EthWorkerProcessDHCP);
+    eth_worker->stat_process = ethernet_view_process_malloc(EthWorkerProcessStatic);
+    eth_worker->ping_process = ethernet_view_process_malloc(EthWorkerProcessPing);
+    eth_worker->reset_process = ethernet_view_process_malloc(EthWorkerProcessReset);
     eth_worker->active_process = eth_worker->init_process;
     eth_worker->active_process = eth_worker->init_process;
 
 
     //eth_worker->callback = eth_worker_change_state;
     //eth_worker->callback = eth_worker_change_state;

+ 3 - 0
eth_worker.h

@@ -1,7 +1,10 @@
 #pragma once
 #pragma once
 
 
+#include <stdint.h>
+
 typedef struct EthWorker EthWorker;
 typedef struct EthWorker EthWorker;
 typedef struct EthViewProcess EthViewProcess;
 typedef struct EthViewProcess EthViewProcess;
+typedef struct EthViewDrawInit EthViewDrawInit;
 
 
 typedef enum {
 typedef enum {
     EthWorkerStateNotInited = 0,
     EthWorkerStateNotInited = 0,

+ 3 - 0
eth_worker_i.h

@@ -21,6 +21,9 @@ struct EthViewProcess {
     uint8_t carriage;
     uint8_t carriage;
     uint8_t position;
     uint8_t position;
     uint8_t autofill;
     uint8_t autofill;
+    uint8_t editing;
+    EthWorkerProcess type;
+    void* draw_struct;
 };
 };
 
 
 struct EthWorker {
 struct EthWorker {

+ 14 - 1
finik_eth_app.c

@@ -152,26 +152,39 @@ 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);
+                    app->eth_worker->active_process->editing = 1;
                     char str[] = "test string 0 W5500 Test BIG CHARACTERS AND long string";
                     char str[] = "test string 0 W5500 Test BIG CHARACTERS AND long string";
                     str[12] += cnt % 10;
                     str[12] += cnt % 10;
                     cnt += 1;
                     cnt += 1;
                     ethernet_view_process_print(app->eth_worker->init_process, str);
                     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 == InputKeyRight) {
                 } else if(event.key == InputKeyRight) {
+                    eth_worker_set_active_process(
+                        app->eth_worker, (EthWorkerProcess)app->draw_process);
                     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(event.type == InputTypePress && app->cursor_position == CURSOR_INSIDE_PROCESS) {
             } else if(event.type == InputTypePress && app->cursor_position == CURSOR_INSIDE_PROCESS) {
-                if(event.key == InputKeyLeft) {
+                if(app->eth_worker->active_process->editing) {
+                    if(event.key == InputKeyBack) {
+                        app->eth_worker->active_process->editing = 0;
+                    } else {
+                        ethernet_view_process_keyevent(app->eth_worker->active_process, event.key);
+                    }
+                } else if(event.key == InputKeyLeft) {
+                    app->eth_worker->active_process->editing = 0;
                     app->cursor_position = CURSOR_CHOOSE_PROCESS;
                     app->cursor_position = CURSOR_CHOOSE_PROCESS;
                 } else if(event.key == InputKeyBack) {
                 } else if(event.key == InputKeyBack) {
                     ethernet_view_process_move(app->eth_worker->active_process, 0);
                     ethernet_view_process_move(app->eth_worker->active_process, 0);
+                    app->eth_worker->active_process->editing = 0;
                     app->cursor_position = CURSOR_CHOOSE_PROCESS;
                     app->cursor_position = CURSOR_CHOOSE_PROCESS;
                 } else if(event.key == InputKeyUp) {
                 } else if(event.key == InputKeyUp) {
                     ethernet_view_process_move(app->eth_worker->active_process, -1);
                     ethernet_view_process_move(app->eth_worker->active_process, -1);
                 } else if(event.key == InputKeyDown) {
                 } else if(event.key == InputKeyDown) {
                     ethernet_view_process_move(app->eth_worker->active_process, 1);
                     ethernet_view_process_move(app->eth_worker->active_process, 1);
+                } else if(event.key == InputKeyOk) {
+                    app->eth_worker->active_process->editing = 1;
                 }
                 }
             } else if(event.type == InputTypePress && app->cursor_position == CURSOR_EXIT_APP) {
             } else if(event.type == InputTypePress && app->cursor_position == CURSOR_EXIT_APP) {
                 if(event.key == InputKeyBack) {
                 if(event.key == InputKeyBack) {

BIN
images/init_100x19px.png