瀏覽代碼

fix memory

karasevIA 2 年之前
父節點
當前提交
1f050d4d52
共有 2 個文件被更改,包括 41 次插入24 次删除
  1. 24 24
      eth_view_process.c
  2. 17 0
      finik_eth_app.c

+ 24 - 24
eth_view_process.c

@@ -1,11 +1,16 @@
 #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 <furi_hal.h>
 #include <gui/gui.h>
 #include <gui/gui.h>
 #include <gui/canvas.h>
 #include <gui/canvas.h>
 #include <string.h>
 #include <string.h>
+
 #include "u8g2.h"
 #include "u8g2.h"
 
 
+#define TAG "EthView"
+
 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);
@@ -15,38 +20,31 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
     const uint8_t y = process->y;
     const uint8_t y = process->y;
     const uint8_t str_height = 11;
     const uint8_t str_height = 11;
     const uint8_t str_count = (64 - y) / str_height;
     const uint8_t str_count = (64 - y) / str_height;
-
-    int8_t position = process->position;
     uint8_t carriage = process->carriage;
     uint8_t carriage = process->carriage;
+    uint8_t position = process->position;
 
 
     if(process->autofill) {
     if(process->autofill) {
-        if(carriage > str_count) {
-            position = carriage - str_count;
-        } else {
-            position = 0;
-        }
+        position = (carriage + SCREEN_STRINGS_COUNT - str_count) % SCREEN_STRINGS_COUNT;
+        process->position = position;
     }
     }
 
 
     for(uint8_t i = 0; i < str_count; ++i) {
     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]);
+        uint8_t y1 = y + (i + 1) * str_height;
+        canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % SCREEN_STRINGS_COUNT]);
     }
     }
 }
 }
 
 
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
 void ethernet_view_process_move(EthViewProcess* process, int8_t shift) {
     furi_assert(process);
     furi_assert(process);
+    uint8_t position = process->position;
     if(shift <= -SCREEN_STRINGS_COUNT) {
     if(shift <= -SCREEN_STRINGS_COUNT) {
-        process->position = 0;
+        position = 0;
     } else if(shift >= SCREEN_STRINGS_COUNT) {
     } else if(shift >= SCREEN_STRINGS_COUNT) {
-        process->position = process->carriage - 1;
+        position = process->carriage - 1;
     } else {
     } else {
-        process->position =
-            (process->position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT;
+        position = (position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT;
     }
     }
-
+    process->position = position;
     process->autofill = !shift;
     process->autofill = !shift;
 }
 }
 
 
@@ -56,7 +54,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[3];
+    u8g2_t canvas_memory;
     Canvas* canvas = &canvas_memory; // grazniy hack
     Canvas* canvas = &canvas_memory; // grazniy hack
     canvas_set_font(canvas, FontSecondary);
     canvas_set_font(canvas, FontSecondary);
 
 
@@ -91,11 +89,13 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) {
     while(ptr < len) {
     while(ptr < len) {
         uint16_t start = ptr;
         uint16_t start = ptr;
         ptr += get_string_with_width(str + ptr, max_width);
         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;
-        }
+        uint8_t carriage = process->carriage;
+        uint8_t carriage1 = (carriage + 1) % SCREEN_STRINGS_COUNT;
+        uint8_t carriage2 = (carriage + 2) % SCREEN_STRINGS_COUNT;
+        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);
+        process->carriage = carriage1;
     }
     }
 }
 }

+ 17 - 0
finik_eth_app.c

@@ -134,6 +134,9 @@ int32_t finik_eth_app(void* p) {
 
 
     InputEvent event;
     InputEvent event;
 
 
+    uint8_t long_press = 0;
+    int8_t long_press_dir = 0;
+
     while(1) {
     while(1) {
         finik_eth_battery_info_update_model(app);
         finik_eth_battery_info_update_model(app);
         if(furi_message_queue_get(app->event_queue, &event, 300) == FuriStatusOk) {
         if(furi_message_queue_get(app->event_queue, &event, 300) == FuriStatusOk) {
@@ -176,8 +179,22 @@ int32_t finik_eth_app(void* p) {
                     }
                     }
                 }
                 }
                 view_port_update(app->view_port);
                 view_port_update(app->view_port);
+            } else if(event.type == InputTypeLong) {
+                if(event.key == InputKeyUp) {
+                    long_press = 1;
+                    long_press_dir = -1;
+                } else if(event.key == InputKeyDown) {
+                    long_press = 1;
+                    long_press_dir = 1;
+                }
+            } else if(event.type == InputTypeRelease) {
+                long_press = 0;
+                long_press_dir = 0;
             }
             }
         }
         }
+        if(long_press) {
+            ethernet_view_process_move(app->eth_worker->init_process, long_press_dir);
+        }
     }
     }
 
 
     finik_eth_app_free(app);
     finik_eth_app_free(app);