karasevIA 2 سال پیش
والد
کامیت
772839fae1
3فایلهای تغییر یافته به همراه72 افزوده شده و 67 حذف شده
  1. 6 1
      eth_view_process.c
  2. 64 65
      finik_eth_app.c
  3. 2 1
      finik_eth_app.h

+ 6 - 1
eth_view_process.c

@@ -279,10 +279,15 @@ void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
             mac_change_hex_digit(mac, octet, 1);
         } else if(key == InputKeyDown) {
             mac_change_hex_digit(mac, octet, -1);
-        } else if(key == InputKeyOk) {
+        } else if(key == InputKeyOk || key == InputKeyBack) {
             process->editing = 0;
         }
         ((EthViewDrawInit*)process->draw_struct)->current_octet = octet;
+    } else if(process->type == EthWorkerProcessDHCP) {
+        process->editing = 0;
+        if(key == InputKeyUp || key == InputKeyDown) {
+            ethernet_view_process_move(process, (key == InputKeyDown) ? 1 : -1);
+        }
     } else if(process->type == EthWorkerProcessStatic) {
         uint8_t digit = ((EthViewDrawStatic*)process->draw_struct)->current_digit;
         uint8_t mode = ((EthViewDrawStatic*)process->draw_struct)->current_mode;

+ 64 - 65
finik_eth_app.c

@@ -67,7 +67,7 @@ static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
 
     canvas_set_font(canvas, FontSecondary);
 
-    if(cursor == CURSOR_EXIT_APP) {
+    if(cursor == CURSOR_EXIT_ICON) {
         canvas_draw_icon(canvas, 0, 0, &I_exit_128x64px);
     } else {
         canvas_draw_icon(canvas, 0, 0, &I_main_128x64px);
@@ -127,84 +127,83 @@ void finik_eth_app_free(FinikEthApp* app) {
     furi_record_close(RECORD_POWER);
 }
 
+void finit_eth_app_key_handler(FinikEthApp* app, InputKey key) {
+    if(app->cursor_position == CURSOR_CHOOSE_PROCESS) {
+        if(key == InputKeyUp || key == InputKeyDown) {
+            app->draw_process =
+                (app->draw_process + PROCESS_RESET + (key == InputKeyDown ? 2 : 0)) %
+                (PROCESS_RESET + 1);
+            eth_worker_set_active_process(app->eth_worker, (EthWorkerProcess)app->draw_process);
+        } else if(key == InputKeyOk) {
+            ethernet_view_process_move(app->eth_worker->active_process, 0);
+            app->cursor_position = CURSOR_CLICK_PROCESS;
+            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);
+            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");
+            ethernet_view_process_print(app->eth_worker->ping_process, "ping");
+            app->cursor_position = CURSOR_CHOOSE_PROCESS;
+        } else if(key == InputKeyRight) {
+            eth_worker_set_active_process(app->eth_worker, (EthWorkerProcess)app->draw_process);
+            app->cursor_position = CURSOR_INSIDE_PROCESS;
+        } else if(key == InputKeyBack) {
+            app->cursor_position = CURSOR_EXIT_ICON;
+        }
+    } else if(app->cursor_position == CURSOR_INSIDE_PROCESS) {
+        if(app->eth_worker->active_process->editing) {
+            ethernet_view_process_keyevent(app->eth_worker->active_process, key);
+        } else if(key == InputKeyLeft) {
+            app->eth_worker->active_process->editing = 0;
+            app->cursor_position = CURSOR_CHOOSE_PROCESS;
+        } else if(key == InputKeyBack) {
+            ethernet_view_process_move(app->eth_worker->active_process, 0);
+            app->eth_worker->active_process->editing = 0;
+            app->cursor_position = CURSOR_CHOOSE_PROCESS;
+        } else if(key == InputKeyUp) {
+            ethernet_view_process_move(app->eth_worker->active_process, -1);
+        } else if(key == InputKeyDown) {
+            ethernet_view_process_move(app->eth_worker->active_process, 1);
+        } else if(key == InputKeyOk || key == InputKeyRight) {
+            app->eth_worker->active_process->editing = 1;
+        }
+    } else if(app->cursor_position == CURSOR_EXIT_ICON) {
+        if(key == InputKeyBack) {
+            app->cursor_position = CURSOR_EXIT;
+        } else if(key == InputKeyOk) {
+            app->cursor_position = CURSOR_CHOOSE_PROCESS;
+        }
+    }
+}
+
 int32_t finik_eth_app(void* p) {
     UNUSED(p);
     FinikEthApp* app = finik_eth_app_alloc();
-    uint8_t cnt = 0;
 
     InputEvent event;
-
     uint8_t long_press = 0;
-    int8_t long_press_dir = 0;
+    InputKey long_press_key = 0;
 
     while(1) {
         finik_eth_battery_info_update_model(app);
-        if(furi_message_queue_get(app->event_queue, &event, 300) == FuriStatusOk) {
-            if(event.type == InputTypePress && app->cursor_position == CURSOR_CHOOSE_PROCESS) {
-                if(event.key == InputKeyUp || event.key == InputKeyDown) {
-                    app->draw_process =
-                        (app->draw_process + PROCESS_RESET + (event.key == InputKeyDown ? 2 : 0)) %
-                        (PROCESS_RESET + 1);
-                    eth_worker_set_active_process(
-                        app->eth_worker, (EthWorkerProcess)app->draw_process);
-                } else if(event.key == InputKeyOk) {
-                    ethernet_view_process_move(app->eth_worker->active_process, 0);
-                    app->cursor_position = CURSOR_CLICK_PROCESS;
-                    view_port_update(app->view_port);
-                    furi_delay_ms(150);
-                    char str[] = "test string 0 with some parameters";
-                    str[12] += cnt % 10;
-                    cnt += 1;
-                    ethernet_view_process_print(app->eth_worker->init_process, str);
-                    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");
-                    ethernet_view_process_print(app->eth_worker->ping_process, "ping");
-                    app->cursor_position = CURSOR_CHOOSE_PROCESS;
-                } else if(event.key == InputKeyRight) {
-                    eth_worker_set_active_process(
-                        app->eth_worker, (EthWorkerProcess)app->draw_process);
-                    app->cursor_position = CURSOR_INSIDE_PROCESS;
-                } else if(event.key == InputKeyBack) {
-                    app->cursor_position = CURSOR_EXIT_APP;
-                }
-            } else if(event.type == InputTypePress && app->cursor_position == CURSOR_INSIDE_PROCESS) {
-                if(app->eth_worker->active_process->editing) {
-                    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;
-                } else if(event.key == InputKeyBack) {
-                    ethernet_view_process_move(app->eth_worker->active_process, 0);
-                    app->eth_worker->active_process->editing = 0;
-                    app->cursor_position = CURSOR_CHOOSE_PROCESS;
-                } else if(event.key == InputKeyUp) {
-                    ethernet_view_process_move(app->eth_worker->active_process, -1);
-                } else if(event.key == InputKeyDown) {
-                    ethernet_view_process_move(app->eth_worker->active_process, 1);
-                } else if(event.key == InputKeyOk || event.key == InputKeyRight) {
-                    app->eth_worker->active_process->editing = 1;
-                }
-            } else if(event.type == InputTypePress && app->cursor_position == CURSOR_EXIT_APP) {
-                if(event.key == InputKeyBack) {
-                    break;
-                } else if(event.key == InputKeyOk) {
-                    app->cursor_position = CURSOR_CHOOSE_PROCESS;
-                }
-            } else if(event.type == InputTypeLong && event.key == InputKeyUp) {
+        if(furi_message_queue_get(app->event_queue, &event, 200) == FuriStatusOk) {
+            if(event.type == InputTypePress) {
+                finit_eth_app_key_handler(app, event.key);
+            } else if(event.type == InputTypeLong) {
                 long_press = 1;
-                long_press_dir = -1;
-            } else if(event.type == InputTypeLong && event.key == InputKeyDown) {
-                long_press = 1;
-                long_press_dir = 1;
+                long_press_key = event.key;
             } else if(event.type == InputTypeRelease) {
                 long_press = 0;
-                long_press_dir = 0;
+                long_press_key = 0;
             }
         }
-        if(long_press) {
-            ethernet_view_process_move(app->eth_worker->active_process, long_press_dir);
+        if(long_press && long_press_key != InputKeyBack) {
+            finit_eth_app_key_handler(app, long_press_key);
+        }
+        if(app->cursor_position == CURSOR_EXIT) {
+            break;
         }
         view_port_update(app->view_port);
     }

+ 2 - 1
finik_eth_app.h

@@ -27,7 +27,8 @@ typedef enum {
     CURSOR_CHOOSE_PROCESS,
     CURSOR_CLICK_PROCESS,
     CURSOR_INSIDE_PROCESS,
-    CURSOR_EXIT_APP,
+    CURSOR_EXIT_ICON,
+    CURSOR_EXIT,
 } CursorPosition;
 
 struct FinikEthApp {