From 4500353761dd331c946c6edc9dac179ba85bf915 Mon Sep 17 00:00:00 2001 From: karasevIA Date: Sun, 2 Jul 2023 16:34:46 +0300 Subject: [PATCH] add power consumption monitor --- application.fam | 1 + finik_eth_app.c | 125 ++++++++++++++++++++++++++++----------- finik_eth_app.h | 21 +++++++ images/exit_128x64px.png | Bin 0 -> 893 bytes images/main_128x64px.png | Bin 0 -> 924 bytes 5 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 images/exit_128x64px.png create mode 100644 images/main_128x64px.png diff --git a/application.fam b/application.fam index dbe6b0ef70e..020ae2d478e 100644 --- a/application.fam +++ b/application.fam @@ -6,6 +6,7 @@ App( cdefines=["FINIK_ETH"], requires=[ "gui", + "power", ], stack_size=10 * 1024, order=90, diff --git a/finik_eth_app.c b/finik_eth_app.c index a7f8960df6c..22acd87320a 100644 --- a/finik_eth_app.c +++ b/finik_eth_app.c @@ -11,6 +11,41 @@ #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) { furi_assert(ctx); FinikEthApp* app = ctx; @@ -18,22 +53,27 @@ static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) { canvas_clear(canvas); 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) { furi_assert(ctx); @@ -55,9 +95,10 @@ FinikEthApp* finik_eth_app_alloc() { 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; } @@ -75,6 +116,10 @@ void finik_eth_app_free(FinikEthApp* app) { furi_record_close(RECORD_NOTIFICATION); } +void finik_eth_update_consumtion(FinikEthApp* app) { + furi_assert(app); +} + int32_t finik_eth_app(void* p) { UNUSED(p); FinikEthApp* app = finik_eth_app_alloc(); @@ -82,27 +127,37 @@ int32_t finik_eth_app(void* p) { InputEvent event; 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.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); } } diff --git a/finik_eth_app.h b/finik_eth_app.h index d87e34772c3..6c4d9205410 100644 --- a/finik_eth_app.h +++ b/finik_eth_app.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "eth_worker.h" #include "finik_eth_icons.h" @@ -14,6 +15,21 @@ typedef enum { TOTAL_DRAW_MODES = 3, } 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 { Gui* gui; ViewPort* view_port; @@ -21,7 +37,12 @@ struct FinikEthApp { NotificationApp* notifications; EthWorker* eth_worker; + Power* power; + PowerInfo info; + DrawMode draw_mode; + DrawProcess draw_process; + CursorPosition cursor_position; }; typedef struct FinikEthApp FinikEthApp; diff --git a/images/exit_128x64px.png b/images/exit_128x64px.png new file mode 100644 index 0000000000000000000000000000000000000000..73537df242b1a45fed959f768c470e715eeb8bf4 GIT binary patch literal 893 zcmV-@1A_dCP)Px&H%UZ6RCr$PoZ*)0APj`J@Bh$s>k&_kAtWu(Nap_YiV!j%L+GO0zVG`V{-w>p z1_07(|C~4g$gO`&0Jd%Wk_9`}7*azyKoMRNTYGOzYI5`%27p6g%PP0F%OT(OS%v_B zi`o)ddcXAng2z5DjYGO~R*04!EN0|1)z^Z?MJtk|^nf7HskpwerpPl36vf83G7b$i)07;@IE)|Qe zP7MODom=42_HVkPk9fI@NO1!IBLKB3-m(g<*4G079;ek6tTFylJM$J$CRJP6#co@x zioP#dw3fWq%Jys}JWf6@oC1gvqb;zu4R9DV_P(0Y08B`72nWzam0ST3^n-610A@k4+C`Du0pJNOY)g0bs2gb4 z%=)d5@1ACXHgXOhwUwm?pjEl|DmJ%p>24z-L@+L zt(D3_p|33f@D-|kQN(&J-2!h7D6iQ3`9=g6=nBA0001N z0m&Hv0001|fXocQ0WzzPA~3o70001B3rNlY0000u1!QIb4v<-W6oJXr|DXN?cC#RT T2Tt%300000NkvXXu0mjfvHg!% literal 0 HcmV?d00001 diff --git a/images/main_128x64px.png b/images/main_128x64px.png new file mode 100644 index 0000000000000000000000000000000000000000..8fe1f0dec34a38cea865eb4c830217dc022e74c9 GIT binary patch literal 924 zcmV;N17rM&P)Px&R!KxbRCr$PTw#}lAPB7g|D(ItzO!e90%k-y_vPBn1ZE~wtX-F7*_QvmZ95K^ zbzOhortkL8(sAmi<$to5Y?kb`^etWUmTk^%j`@B}+eook&+ja6lvoaYjR5jCW=ArC zrNEyQ9QE(%_&7Wyo6>nJ#;gxL1#rh9PCPUV-RWPtmfH8QEfMUI1-oVd3FO*&jsPwL z+_9mx?*Y6f%X#?m6M$w8kdH?@G29)3A;2b2DFc+|0C#Y{41M_!U~?a>M?l~-1dI?6 zVz42w9!mh*b!a^Z0;f5^ATc2f0|G7?py#B;5F45*5P$#_AdTGQ5J2rNy}KSo28b&m za|UQ3v*nt&kd5WpB?EAq4~f9mjR^=Ku4q^RXf}r|Awd8Zw0zq_0KRyKvjzc#qr}%C z2*4NbaMsMLfR+d_2WUaf=NbsW2j{R>Ab_yc_&5du_~0DY3M+uT@RL6&+!_Vu0IkS9 ze;owyJjS6doCH8iy`|DGeI8IM5hDY{)d0I2$PEG3@A8l#fI$V2!jiU&A%H;zP|FI) z0C7n_ag#q3%FO{vuV?L@`_hU*NH|A@|)wG!e?{HzF4iJtKUxy$7U%bOvg8;%&;_J}uLXgH?%mFkgz0(F6 z;2qqI