Преглед изворни кода

add power consumption monitor

karasevIA пре 2 година
родитељ
комит
4500353761
5 измењених фајлова са 112 додато и 35 уклоњено
  1. 1 0
      application.fam
  2. 90 35
      finik_eth_app.c
  3. 21 0
      finik_eth_app.h
  4. BIN
      images/exit_128x64px.png
  5. BIN
      images/main_128x64px.png

+ 1 - 0
application.fam

@@ -6,6 +6,7 @@ App(
 	cdefines=["FINIK_ETH"],
 	cdefines=["FINIK_ETH"],
 	requires=[
 	requires=[
 		"gui",
 		"gui",
+        "power",
 	],
 	],
 	stack_size=10 * 1024,
 	stack_size=10 * 1024,
 	order=90,
 	order=90,

+ 90 - 35
finik_eth_app.c

@@ -11,6 +11,41 @@
 
 
 #define TAG "FinikEthApp"
 #define TAG "FinikEthApp"
 
 
+static void draw_process_selector(Canvas* canvas, DrawProcess selector, CursorPosition cursor) {
+    uint8_t y = 0;
+    if(selector == PROCESS_INIT) y = 11;
+    if(selector == PROCESS_DHCP) y = 22;
+    if(selector == PROCESS_STATIC) y = 34;
+    if(selector == PROCESS_PING) y = 44;
+    if(selector == PROCESS_RESET) y = 55;
+
+    if(cursor != CURSOR_INSIDE_PROCESS) {
+        canvas_draw_line(canvas, 0, y + 1, 0, y + 7);
+        canvas_draw_line(canvas, 23, y + 1, 23, y + 7);
+    }
+
+    canvas_draw_line(canvas, 1, y, 22, y);
+    canvas_draw_line(canvas, 1, y + 8, 22, y + 8);
+
+    if(cursor == CURSOR_CLICK_PROCESS) {
+        canvas_draw_box(canvas, 1, y, 22, 9);
+    }
+}
+
+static void draw_battery_cunsumption(Canvas* canvas, double cons) {
+    FuriString* string = furi_string_alloc_set("aaaaaaaa");
+    if(cons >= 0) {
+        furi_string_printf(string, "--");
+    } else if(cons < -1) {
+        furi_string_printf(string, "%1.1fk", -cons);
+    } else {
+        furi_string_printf(string, "%3.f", -(cons * 1000));
+    }
+
+    canvas_draw_str(canvas, 112, 7, furi_string_get_cstr(string));
+    furi_string_free(string);
+}
+
 static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
 static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
     furi_assert(ctx);
     furi_assert(ctx);
     FinikEthApp* app = ctx;
     FinikEthApp* app = ctx;
@@ -18,22 +53,27 @@ static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) {
     canvas_clear(canvas);
     canvas_clear(canvas);
 
 
     DrawMode mode = app->draw_mode;
     DrawMode mode = app->draw_mode;
-    if(mode == DRAW_ONLY_PICTURES || mode == DRAW_ALL)
-        canvas_draw_icon(canvas, 0, 29, &I_amperka_ru_logo_128x35px);
-    if(mode == DRAW_ONLY_TEXT || mode == DRAW_ALL) {
-        canvas_set_font(canvas, FontPrimary);
-        canvas_draw_str(canvas, 4, 8, "This is an example app!");
-        canvas_set_font(canvas, FontSecondary);
-        elements_multiline_text_aligned(
-            canvas,
-            127,
-            15,
-            AlignRight,
-            AlignTop,
-            "Some long long long long \n aligned multiline text");
+    DrawProcess process = app->draw_process;
+    CursorPosition cursor = app->cursor_position;
+    float consumption = app->info.current_gauge;
+
+    canvas_set_font(canvas, FontSecondary);
+
+    if(cursor == CURSOR_EXIT_APP) {
+        canvas_draw_icon(canvas, 0, 0, &I_exit_128x64px);
+    } else {
+        canvas_draw_icon(canvas, 0, 0, &I_main_128x64px);
+        draw_process_selector(canvas, process, cursor);
+        draw_battery_cunsumption(canvas, (double)consumption);
     }
     }
 }
 }
 
 
+static void finik_eth_battery_info_update_model(void* ctx) {
+    furi_assert(ctx);
+    FinikEthApp* app = ctx;
+    power_get_info(app->power, &app->info);
+}
+
 static void finik_eth_app_input_callback(InputEvent* input_event, void* ctx) {
 static void finik_eth_app_input_callback(InputEvent* input_event, void* ctx) {
     furi_assert(ctx);
     furi_assert(ctx);
 
 
@@ -55,9 +95,10 @@ FinikEthApp* finik_eth_app_alloc() {
 
 
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
 
 
-    app->eth_worker = eth_worker_alloc();
-    
-    eth_worker_task(app->eth_worker);
+    app->power = furi_record_open(RECORD_POWER);
+    //app->eth_worker = eth_worker_alloc();
+
+    //eth_worker_task(app->eth_worker);
 
 
     return app;
     return app;
 }
 }
@@ -75,6 +116,10 @@ void finik_eth_app_free(FinikEthApp* app) {
     furi_record_close(RECORD_NOTIFICATION);
     furi_record_close(RECORD_NOTIFICATION);
 }
 }
 
 
+void finik_eth_update_consumtion(FinikEthApp* app) {
+    furi_assert(app);
+}
+
 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();
@@ -82,27 +127,37 @@ int32_t finik_eth_app(void* p) {
     InputEvent event;
     InputEvent event;
 
 
     while(1) {
     while(1) {
-        if(furi_message_queue_get(app->event_queue, &event, 100) == FuriStatusOk) {
+        finik_eth_battery_info_update_model(app);
+        if(furi_message_queue_get(app->event_queue, &event, 300) == FuriStatusOk) {
             if(event.type == InputTypePress) {
             if(event.type == InputTypePress) {
-                if(event.key == InputKeyBack)
-                    break;
-                else if(event.key == InputKeyUp) {
-                    FURI_LOG_I(TAG, "example_led_sequence");
-                    notification_message(app->notifications, &example_led_sequence);
-                } else if(event.key == InputKeyDown) {
-                    FURI_LOG_I(TAG, "example_vibro_sequence");
-                    notification_message(app->notifications, &example_vibro_sequence);
-                } else if(event.key == InputKeyOk) {
-                    FURI_LOG_I(TAG, "example_sound_sequence");
-                    notification_message(app->notifications, &example_sound_sequence);
+                if(app->cursor_position == CURSOR_CHOOSE_PROCESS) {
+                    if(event.key == InputKeyUp) {
+                        app->draw_process =
+                            (app->draw_process + PROCESS_RESET) % (PROCESS_RESET + 1);
+                    } else if(event.key == InputKeyDown) {
+                        app->draw_process =
+                            (app->draw_process + PROCESS_RESET + 2) % (PROCESS_RESET + 1);
+                    } else if(event.key == InputKeyRight) {
+                        app->cursor_position = CURSOR_INSIDE_PROCESS;
+                    } else if(event.key == InputKeyOk) {
+                        app->cursor_position = CURSOR_CLICK_PROCESS;
+                        view_port_update(app->view_port);
+                        furi_delay_ms(150);
+                        app->cursor_position = CURSOR_INSIDE_PROCESS;
+                    } else if(event.key == InputKeyBack) {
+                        app->cursor_position = CURSOR_EXIT_APP;
+                    }
+                } else if(app->cursor_position == CURSOR_INSIDE_PROCESS) {
+                    if(event.key == InputKeyLeft || event.key == InputKeyBack) {
+                        app->cursor_position = CURSOR_CHOOSE_PROCESS;
+                    }
+                } else if(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) {
-                DrawMode mode = app->draw_mode;
-                if(event.key == InputKeyLeft)
-                    app->draw_mode = (mode - 1 + TOTAL_DRAW_MODES) % TOTAL_DRAW_MODES;
-                else if(event.key == InputKeyRight)
-                    app->draw_mode = (mode + 1) % TOTAL_DRAW_MODES;
-
                 view_port_update(app->view_port);
                 view_port_update(app->view_port);
             }
             }
         }
         }

+ 21 - 0
finik_eth_app.h

@@ -3,6 +3,7 @@
 #include <furi.h>
 #include <furi.h>
 #include <gui/gui.h>
 #include <gui/gui.h>
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
+#include <power/power_service/power.h>
 
 
 #include "eth_worker.h"
 #include "eth_worker.h"
 #include "finik_eth_icons.h"
 #include "finik_eth_icons.h"
@@ -14,6 +15,21 @@ typedef enum {
     TOTAL_DRAW_MODES = 3,
     TOTAL_DRAW_MODES = 3,
 } DrawMode;
 } DrawMode;
 
 
+typedef enum {
+    PROCESS_INIT,
+    PROCESS_DHCP,
+    PROCESS_STATIC,
+    PROCESS_PING,
+    PROCESS_RESET,
+} DrawProcess;
+
+typedef enum {
+    CURSOR_CHOOSE_PROCESS,
+    CURSOR_CLICK_PROCESS,
+    CURSOR_INSIDE_PROCESS,
+    CURSOR_EXIT_APP,
+} CursorPosition;
+
 struct FinikEthApp {
 struct FinikEthApp {
     Gui* gui;
     Gui* gui;
     ViewPort* view_port;
     ViewPort* view_port;
@@ -21,7 +37,12 @@ struct FinikEthApp {
     NotificationApp* notifications;
     NotificationApp* notifications;
     EthWorker* eth_worker;
     EthWorker* eth_worker;
 
 
+    Power* power;
+    PowerInfo info;
+
     DrawMode draw_mode;
     DrawMode draw_mode;
+    DrawProcess draw_process;
+    CursorPosition cursor_position;
 };
 };
 
 
 typedef struct FinikEthApp FinikEthApp;
 typedef struct FinikEthApp FinikEthApp;

BIN
images/exit_128x64px.png


BIN
images/main_128x64px.png