diff --git a/eth_view_process.c b/eth_view_process.c index 4da3adfce7b..d7fcf6e4320 100644 --- a/eth_view_process.c +++ b/eth_view_process.c @@ -11,6 +11,20 @@ #define TAG "EthView" +EthViewProcess* ethernet_view_process_malloc() { + EthViewProcess* evp = malloc(sizeof(EthViewProcess)); + evp->autofill = 1; + evp->carriage = 0; + evp->position = 0; + evp->x = 27; + evp->y = 6; + return evp; +} + +void ethernet_view_process_free(EthViewProcess* evp) { + free(evp); +} + void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) { furi_assert(canvas); furi_assert(process); @@ -92,6 +106,7 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) { uint8_t carriage = process->carriage; uint8_t carriage1 = (carriage + 1) % SCREEN_STRINGS_COUNT; uint8_t carriage2 = (carriage + 2) % SCREEN_STRINGS_COUNT; + FURI_LOG_I(TAG, "print %d %d %d %d %d", max_width, len, start, carriage, carriage1); memset(process->fifo[carriage], 0, SCREEN_SYMBOLS_WIDTH); memset(process->fifo[carriage1], 0, SCREEN_SYMBOLS_WIDTH); memset(process->fifo[carriage2], 0, SCREEN_SYMBOLS_WIDTH); diff --git a/eth_view_process.h b/eth_view_process.h index 2b71c33f093..a6998acc03e 100644 --- a/eth_view_process.h +++ b/eth_view_process.h @@ -6,6 +6,9 @@ #define SCREEN_SYMBOLS_WIDTH 30 #define SCREEN_STRINGS_COUNT 40 +EthViewProcess* ethernet_view_process_malloc(); +void ethernet_view_process_free(EthViewProcess* evp); + 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 e8d6d108b79..3337e3a60c2 100644 --- a/eth_worker.c +++ b/eth_worker.c @@ -21,14 +21,12 @@ 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->init_process = ethernet_view_process_malloc(); + eth_worker->dhcp_process = ethernet_view_process_malloc(); + eth_worker->stat_process = ethernet_view_process_malloc(); + eth_worker->ping_process = ethernet_view_process_malloc(); + eth_worker->reset_process = ethernet_view_process_malloc(); + eth_worker->active_process = eth_worker->init_process; //eth_worker->callback = eth_worker_change_state; @@ -38,7 +36,11 @@ 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); + ethernet_view_process_free(eth_worker->init_process); + ethernet_view_process_free(eth_worker->dhcp_process); + ethernet_view_process_free(eth_worker->stat_process); + ethernet_view_process_free(eth_worker->ping_process); + ethernet_view_process_free(eth_worker->reset_process); free(eth_worker); } @@ -47,6 +49,27 @@ void eth_worker_change_state(EthWorker* eth_worker, EthWorkerState state) { eth_worker->state = state; } +void eth_worker_set_active_process(EthWorker* eth_worker, EthWorkerProcess state) { + furi_assert(eth_worker); + switch(state) { + case EthWorkerProcessInit: + eth_worker->active_process = eth_worker->init_process; + break; + case EthWorkerProcessDHCP: + eth_worker->active_process = eth_worker->dhcp_process; + break; + case EthWorkerProcessStatic: + eth_worker->active_process = eth_worker->stat_process; + break; + case EthWorkerProcessPing: + eth_worker->active_process = eth_worker->ping_process; + break; + case EthWorkerProcessReset: + eth_worker->active_process = eth_worker->reset_process; + break; + } +} + /************************** Ethernet Worker Thread *****************************/ int32_t eth_worker_task(void* context) { @@ -169,8 +192,7 @@ void eth_worker_dhcp(EthWorker* eth_worker) { uint8_t dhcp_buffer[2000]; - FURI_LOG_I(TAG, "Ehtping_Init\r\n"); - FURI_LOG_I(TAG, "Registering W5500 callbacks\r\n"); + FURI_LOG_I(TAG, "registering W5500 callbacks\r\n"); FURI_LOG_I(TAG, "sizeof %d", sizeof(gWIZNETINFO)); reg_wizchip_spi_cbfunc(W5500_ReadByte, W5500_WriteByte); diff --git a/eth_worker.h b/eth_worker.h index e1b77045189..2337aa5ef96 100644 --- a/eth_worker.h +++ b/eth_worker.h @@ -15,6 +15,14 @@ typedef enum { EthWorkerStateStop, } EthWorkerState; +typedef enum { + EthWorkerProcessInit, + EthWorkerProcessDHCP, + EthWorkerProcessStatic, + EthWorkerProcessPing, + EthWorkerProcessReset, +} EthWorkerProcess; + typedef enum { EthWorkerSubstateInProcess = 0, EthWorkerSubStateSuccess, @@ -41,6 +49,7 @@ typedef void (*EthWorkerCallback)(EthCustomEvent event, void* context); EthWorker* eth_worker_alloc(); EthWorkerState eth_worker_get_state(EthWorker* eth_worker); +void eth_worker_set_active_process(EthWorker* eth_worker, EthWorkerProcess state); void eth_worker_free(EthWorker* eth_worker); diff --git a/eth_worker_i.h b/eth_worker_i.h index 0a22acfc3c3..d0da79d8255 100644 --- a/eth_worker_i.h +++ b/eth_worker_i.h @@ -27,6 +27,11 @@ struct EthWorker { FuriThread* thread; void* context; EthViewProcess* init_process; + EthViewProcess* dhcp_process; + EthViewProcess* stat_process; + EthViewProcess* ping_process; + EthViewProcess* reset_process; + EthViewProcess* active_process; EthWorkerState state; EthWorkerSubState sub_state; diff --git a/finik_eth_app.c b/finik_eth_app.c index dc09a49fff4..c47b00ff288 100644 --- a/finik_eth_app.c +++ b/finik_eth_app.c @@ -73,7 +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); + ethernet_view_process_draw(app->eth_worker->active_process, canvas); } } @@ -140,61 +140,60 @@ int32_t finik_eth_app(void* p) { while(1) { finik_eth_battery_info_update_model(app); if(furi_message_queue_get(app->event_queue, &event, 300) == FuriStatusOk) { - if(event.type == InputTypePress) { - 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); - 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) { - break; - } else if(event.key == InputKeyOk) { - app->cursor_position = CURSOR_CHOOSE_PROCESS; - } + 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 W5500 Test BIG CHARACTERS AND long string"; + 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 == InputKeyRight) { + app->cursor_position = CURSOR_INSIDE_PROCESS; + } else if(event.key == InputKeyBack) { + app->cursor_position = CURSOR_EXIT_APP; } - 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.type == InputTypePress && app->cursor_position == CURSOR_INSIDE_PROCESS) { + if(event.key == InputKeyLeft) { + app->cursor_position = CURSOR_CHOOSE_PROCESS; + } else if(event.key == InputKeyBack) { + ethernet_view_process_move(app->eth_worker->active_process, 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) { - long_press = 1; - long_press_dir = 1; + ethernet_view_process_move(app->eth_worker->active_process, 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) { + long_press = 1; + long_press_dir = -1; + } else if(event.type == InputTypeLong && 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); + ethernet_view_process_move(app->eth_worker->active_process, long_press_dir); } + view_port_update(app->view_port); } finik_eth_app_free(app);