diff --git a/application.fam b/application.fam index 020ae2d478e..9613ae82550 100644 --- a/application.fam +++ b/application.fam @@ -8,7 +8,7 @@ App( "gui", "power", ], - stack_size=10 * 1024, + stack_size=20 * 1024, order=90, fap_icon="ehternet_icon_10x10px.png", fap_category="GPIO", diff --git a/eth_view_process.c b/eth_view_process.c new file mode 100644 index 00000000000..512129f7804 --- /dev/null +++ b/eth_view_process.c @@ -0,0 +1,101 @@ +#include "eth_view_process.h" +#include "eth_worker.h" +#include "eth_worker_i.h" +#include +#include +#include +#include "u8g2.h" + +void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) { + furi_assert(canvas); + furi_assert(process); + canvas_set_font(canvas, FontSecondary); + + const uint8_t x = process->x; + const uint8_t y = process->y; + const uint8_t str_height = 11; + const uint8_t str_count = (64 - y) / str_height; + + int8_t position = process->position; + uint8_t carriage = process->carriage; + + if(process->autofill) { + if(carriage > str_count) { + position = carriage - str_count; + } else { + position = 0; + } + } + + 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]); + } +} + +void ethernet_view_process_move(EthViewProcess* process, int8_t shift) { + furi_assert(process); + if(shift <= -SCREEN_STRINGS_COUNT) { + process->position = 0; + } else if(shift >= SCREEN_STRINGS_COUNT) { + process->position = process->carriage - 1; + } else { + process->position = + (process->position + (SCREEN_STRINGS_COUNT + shift)) % SCREEN_STRINGS_COUNT; + } + + process->autofill = !shift; +} + +void ethernet_view_process_autofill(EthViewProcess* process, uint8_t state) { + furi_assert(process); + process->autofill = state; +} + +static uint16_t get_string_with_width(const char* str, uint16_t width) { + u8g2_t canvas_memory[3]; + Canvas* canvas = &canvas_memory; // grazniy hack + canvas_set_font(canvas, FontSecondary); + + uint8_t end = 0; + char copy[SCREEN_SYMBOLS_WIDTH + 1] = {0}; + + for(;;) { + if(str[end] == '\0') { + break; + } + if(end == SCREEN_SYMBOLS_WIDTH) { + break; + } + copy[end] = str[end]; + if(canvas_string_width(canvas, copy) > width) { + end -= 1; + break; + } + end += 1; + } + + return end; +} + +void ethernet_view_process_print(EthViewProcess* process, const char* str) { + furi_assert(process); + + uint16_t max_width = 126 - process->x; + uint16_t ptr = 0; + uint16_t len = strlen(str); + + while(ptr < len) { + uint16_t start = ptr; + 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; + } + } +} \ No newline at end of file diff --git a/eth_view_process.h b/eth_view_process.h new file mode 100644 index 00000000000..2b71c33f093 --- /dev/null +++ b/eth_view_process.h @@ -0,0 +1,11 @@ +#pragma once + +#include "eth_worker.h" +#include + +#define SCREEN_SYMBOLS_WIDTH 30 +#define SCREEN_STRINGS_COUNT 40 + +void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas); +void ethernet_view_process_print(EthViewProcess* process, const char* str); +void ethernet_view_process_move(EthViewProcess* process, int8_t shift); diff --git a/eth_worker.c b/eth_worker.c index de275b7eae0..e8d6d108b79 100644 --- a/eth_worker.c +++ b/eth_worker.c @@ -21,6 +21,15 @@ EthWorker* eth_worker_alloc() { eth_worker_change_state(eth_worker, EthWorkerStateModuleInit); + eth_worker->init_process = malloc(sizeof(EthViewProcess)); + memset(eth_worker->init_process, 0, sizeof(EthViewProcess)); + + eth_worker->init_process->autofill = 1; + eth_worker->init_process->carriage = 0; + eth_worker->init_process->position = 0; + eth_worker->init_process->x = 27; + eth_worker->init_process->y = 6; + //eth_worker->callback = eth_worker_change_state; return eth_worker; @@ -29,6 +38,7 @@ EthWorker* eth_worker_alloc() { void eth_worker_free(EthWorker* eth_worker) { furi_assert(eth_worker); furi_thread_free(eth_worker->thread); + free(eth_worker->init_process); free(eth_worker); } diff --git a/eth_worker.h b/eth_worker.h index 2396fedcc12..e1b77045189 100644 --- a/eth_worker.h +++ b/eth_worker.h @@ -1,6 +1,7 @@ #pragma once typedef struct EthWorker EthWorker; +typedef struct EthViewProcess EthViewProcess; typedef enum { EthWorkerStateNotInited = 0, @@ -51,4 +52,5 @@ void eth_worker_start( void eth_worker_stop(EthWorker* eth_worker); void eth_worker_dhcp(EthWorker* eth_worker); -void eth_worker_w5500(EthWorker* eth_worker); \ No newline at end of file +void eth_worker_w5500(EthWorker* eth_worker); +void eth_worker_init_process(EthWorker* eth_worker); \ No newline at end of file diff --git a/eth_worker_i.h b/eth_worker_i.h index c893743dc68..0a22acfc3c3 100644 --- a/eth_worker_i.h +++ b/eth_worker_i.h @@ -2,15 +2,34 @@ #include #include "eth_worker.h" +#include "eth_view_process.h" + +struct EthWorkerNetConf { + uint8_t mac[6]; + uint8_t ip[4]; + uint8_t mask[4]; + uint8_t gateway[4]; + uint8_t dns[4]; + uint8_t fifo_sizes[16]; + uint8_t is_dhcp; +}; + +struct EthViewProcess { + char fifo[SCREEN_STRINGS_COUNT][SCREEN_SYMBOLS_WIDTH]; + uint8_t x; + uint8_t y; + uint8_t carriage; + uint8_t position; + uint8_t autofill; +}; struct EthWorker { FuriThread* thread; void* context; + EthViewProcess* init_process; EthWorkerState state; EthWorkerSubState sub_state; - char state_string[64]; - EthWorkerCallback callback; }; diff --git a/finik_eth_app.c b/finik_eth_app.c index 64008eaa26b..82c75906fda 100644 --- a/finik_eth_app.c +++ b/finik_eth_app.c @@ -8,6 +8,8 @@ #include #include "eth_worker.h" +#include "eth_worker_i.h" +#include "eth_view_process.h" #define TAG "FinikEthApp" @@ -71,6 +73,7 @@ static void finik_eth_app_draw_callback(Canvas* canvas, void* ctx) { canvas_draw_icon(canvas, 0, 0, &I_main_128x64px); draw_process_selector(canvas, process, cursor); draw_battery_cunsumption(canvas, (double)consumption); + ethernet_view_process_draw(app->eth_worker->init_process, canvas); } } @@ -102,7 +105,8 @@ FinikEthApp* finik_eth_app_alloc() { app->notifications = furi_record_open(RECORD_NOTIFICATION); app->power = furi_record_open(RECORD_POWER); - //app->eth_worker = eth_worker_alloc(); + + app->eth_worker = eth_worker_alloc(); //eth_worker_task(app->eth_worker); @@ -120,15 +124,13 @@ void finik_eth_app_free(FinikEthApp* app) { furi_record_close(RECORD_GUI); furi_record_close(RECORD_NOTIFICATION); -} - -void finik_eth_update_consumtion(FinikEthApp* app) { - furi_assert(app); + furi_record_close(RECORD_POWER); } int32_t finik_eth_app(void* p) { UNUSED(p); FinikEthApp* app = finik_eth_app_alloc(); + uint8_t cnt = 0; InputEvent event; @@ -149,13 +151,22 @@ int32_t finik_eth_app(void* p) { app->cursor_position = CURSOR_CLICK_PROCESS; view_port_update(app->view_port); furi_delay_ms(150); + char str[] = "test string 0 test long string for flipper"; + str[12] += cnt % 10; + cnt += 1; + ethernet_view_process_print(app->eth_worker->init_process, str); 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) { + ethernet_view_process_move(app->eth_worker->init_process, 0); app->cursor_position = CURSOR_CHOOSE_PROCESS; + } else if(event.key == InputKeyUp) { + ethernet_view_process_move(app->eth_worker->init_process, -1); + } else if(event.key == InputKeyDown) { + ethernet_view_process_move(app->eth_worker->init_process, 1); } } else if(app->cursor_position == CURSOR_EXIT_APP) { if(event.key == InputKeyBack) {