diff --git a/eth_view_process.c b/eth_view_process.c index d7fcf6e4320..ebcc5c8e0a1 100644 --- a/eth_view_process.c +++ b/eth_view_process.c @@ -1,6 +1,7 @@ #include "eth_view_process.h" #include "eth_worker.h" #include "eth_worker_i.h" +#include "finik_eth_icons.h" #include #include @@ -11,20 +12,44 @@ #define TAG "EthView" -EthViewProcess* ethernet_view_process_malloc() { +EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) { EthViewProcess* evp = malloc(sizeof(EthViewProcess)); + evp->type = type; evp->autofill = 1; evp->carriage = 0; evp->position = 0; evp->x = 27; evp->y = 6; + + if(type == EthWorkerProcessInit) { + evp->y += 22; + evp->draw_struct = malloc(sizeof(EthViewDrawInit)); + memset(evp->draw_struct, 0, sizeof(EthViewDrawInit)); + } return evp; } void ethernet_view_process_free(EthViewProcess* evp) { + if(evp->type == EthWorkerProcessInit) { + free(evp->draw_struct); + } free(evp); } +static void draw_hex_digit(Canvas* canvas, uint8_t x, uint8_t y, uint8_t digit) { + char digit_str[] = "0"; + if(digit < 0xA) { + digit_str[0] += digit; + } else if(digit < 0x10) { + digit_str[0] = 'A'; + digit_str[0] += digit - 0xA; + } else { + return; + } + + canvas_draw_str(canvas, x, y, digit_str); +} + void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) { furi_assert(canvas); furi_assert(process); @@ -46,6 +71,51 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) { uint8_t y1 = y + (i + 1) * str_height; canvas_draw_str(canvas, x, y1, process->fifo[(position + i) % SCREEN_STRINGS_COUNT]); } + + if(process->type == EthWorkerProcessInit) { + uint8_t editing = process->editing; + canvas_draw_icon(canvas, 27, 10, &I_init_100x19px); + for(uint8_t i = 0; i < 6; ++i) { + uint8_t x1 = 29 + i * 17; + uint8_t x2 = x1 + 6; + uint8_t mac = ((EthViewDrawInit*)process->draw_struct)->mac[i]; + uint8_t octet = ((EthViewDrawInit*)process->draw_struct)->current_octet; + draw_hex_digit(canvas, x1, 25, (mac & 0x0F)); + draw_hex_digit(canvas, x2, 25, (mac & 0xF0) >> 4); + if(editing && (octet / 2 == i)) { + uint8_t x = octet & 1 ? x2 : x1; + canvas_draw_line(canvas, x, 26, x + 4, 26); + canvas_draw_line(canvas, x, 27, x + 4, 27); + } + } + } +} + +static void mac_change_hex_digit(uint8_t* mac, uint8_t octet, int8_t diff) { + uint8_t digit = (octet & 1) ? (mac[octet / 2] >> 4) : (mac[octet / 2]); + digit = (digit + diff) & 0xF; + mac[octet / 2] = (mac[octet / 2] & ((octet & 1) ? 0x0F : 0xF0)) | + (digit << ((octet & 1) ? 4 : 0)); +} + +void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) { + furi_assert(process); + if(process->type == EthWorkerProcessInit) { + uint8_t octet = ((EthViewDrawInit*)process->draw_struct)->current_octet; + uint8_t* mac = ((EthViewDrawInit*)process->draw_struct)->mac; + if(key == InputKeyLeft) { + if(octet > 0) octet -= 1; + } else if(key == InputKeyRight) { + if(octet < 12) octet += 1; + } else if(key == InputKeyUp) { + mac_change_hex_digit(mac, octet, 1); + } else if(key == InputKeyDown) { + mac_change_hex_digit(mac, octet, -1); + } else if(key == InputKeyOk) { + process->editing = 0; + } + ((EthViewDrawInit*)process->draw_struct)->current_octet = octet; + } } void ethernet_view_process_move(EthViewProcess* process, int8_t shift) { @@ -69,7 +139,7 @@ void ethernet_view_process_autofill(EthViewProcess* process, uint8_t state) { static uint16_t get_string_with_width(const char* str, uint16_t width) { u8g2_t canvas_memory; - Canvas* canvas = &canvas_memory; // grazniy hack + Canvas* canvas = (Canvas*)&canvas_memory; // grazniy hack canvas_set_font(canvas, FontSecondary); uint8_t end = 0; @@ -113,4 +183,4 @@ void ethernet_view_process_print(EthViewProcess* process, const char* str) { memcpy(process->fifo[carriage], str + start, ptr - start); process->carriage = carriage1; } -} \ No newline at end of file +} diff --git a/eth_view_process.h b/eth_view_process.h index a6998acc03e..076c8e81f48 100644 --- a/eth_view_process.h +++ b/eth_view_process.h @@ -6,9 +6,15 @@ #define SCREEN_SYMBOLS_WIDTH 30 #define SCREEN_STRINGS_COUNT 40 -EthViewProcess* ethernet_view_process_malloc(); +EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type); void ethernet_view_process_free(EthViewProcess* evp); void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas); +void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key); void ethernet_view_process_print(EthViewProcess* process, const char* str); void ethernet_view_process_move(EthViewProcess* process, int8_t shift); + +struct EthViewDrawInit { + uint8_t mac[6]; + uint8_t current_octet; +}; diff --git a/eth_worker.c b/eth_worker.c index 3337e3a60c2..d9227b24087 100644 --- a/eth_worker.c +++ b/eth_worker.c @@ -21,11 +21,11 @@ EthWorker* eth_worker_alloc() { eth_worker_change_state(eth_worker, EthWorkerStateModuleInit); - 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->init_process = ethernet_view_process_malloc(EthWorkerProcessInit); + eth_worker->dhcp_process = ethernet_view_process_malloc(EthWorkerProcessDHCP); + eth_worker->stat_process = ethernet_view_process_malloc(EthWorkerProcessStatic); + eth_worker->ping_process = ethernet_view_process_malloc(EthWorkerProcessPing); + eth_worker->reset_process = ethernet_view_process_malloc(EthWorkerProcessReset); eth_worker->active_process = eth_worker->init_process; //eth_worker->callback = eth_worker_change_state; diff --git a/eth_worker.h b/eth_worker.h index 2337aa5ef96..4b00f547492 100644 --- a/eth_worker.h +++ b/eth_worker.h @@ -1,7 +1,10 @@ #pragma once +#include + typedef struct EthWorker EthWorker; typedef struct EthViewProcess EthViewProcess; +typedef struct EthViewDrawInit EthViewDrawInit; typedef enum { EthWorkerStateNotInited = 0, diff --git a/eth_worker_i.h b/eth_worker_i.h index d0da79d8255..c5198e69fb1 100644 --- a/eth_worker_i.h +++ b/eth_worker_i.h @@ -21,6 +21,9 @@ struct EthViewProcess { uint8_t carriage; uint8_t position; uint8_t autofill; + uint8_t editing; + EthWorkerProcess type; + void* draw_struct; }; struct EthWorker { diff --git a/finik_eth_app.c b/finik_eth_app.c index c47b00ff288..8b65903e40b 100644 --- a/finik_eth_app.c +++ b/finik_eth_app.c @@ -152,26 +152,39 @@ int32_t finik_eth_app(void* p) { app->cursor_position = CURSOR_CLICK_PROCESS; view_port_update(app->view_port); furi_delay_ms(150); + app->eth_worker->active_process->editing = 1; 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) { + eth_worker_set_active_process( + app->eth_worker, (EthWorkerProcess)app->draw_process); app->cursor_position = CURSOR_INSIDE_PROCESS; } else if(event.key == InputKeyBack) { app->cursor_position = CURSOR_EXIT_APP; } } else if(event.type == InputTypePress && app->cursor_position == CURSOR_INSIDE_PROCESS) { - if(event.key == InputKeyLeft) { + if(app->eth_worker->active_process->editing) { + if(event.key == InputKeyBack) { + app->eth_worker->active_process->editing = 0; + } else { + ethernet_view_process_keyevent(app->eth_worker->active_process, event.key); + } + } else if(event.key == InputKeyLeft) { + app->eth_worker->active_process->editing = 0; app->cursor_position = CURSOR_CHOOSE_PROCESS; } else if(event.key == InputKeyBack) { ethernet_view_process_move(app->eth_worker->active_process, 0); + app->eth_worker->active_process->editing = 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) { ethernet_view_process_move(app->eth_worker->active_process, 1); + } else if(event.key == InputKeyOk) { + app->eth_worker->active_process->editing = 1; } } else if(event.type == InputTypePress && app->cursor_position == CURSOR_EXIT_APP) { if(event.key == InputKeyBack) { diff --git a/images/init_100x19px.png b/images/init_100x19px.png new file mode 100644 index 00000000000..b683adf5401 Binary files /dev/null and b/images/init_100x19px.png differ