Skip to content

Commit

Permalink
add static menu
Browse files Browse the repository at this point in the history
  • Loading branch information
karasevia committed Jul 5, 2023
1 parent c217027 commit 0234554
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 12 deletions.
155 changes: 149 additions & 6 deletions eth_view_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type) {
evp->y += 22;
evp->draw_struct = malloc(sizeof(EthViewDrawInit));
memset(evp->draw_struct, 0, sizeof(EthViewDrawInit));
} else if(type == EthWorkerProcessStatic) {
evp->y += 22;
evp->draw_struct = malloc(sizeof(EthViewDrawStatic));
memset(evp->draw_struct, 0, sizeof(EthViewDrawStatic));
}
return evp;
}

void ethernet_view_process_free(EthViewProcess* evp) {
if(evp->type == EthWorkerProcessInit) {
if(evp->type == EthWorkerProcessInit || evp->type == EthWorkerProcessStatic) {
free(evp->draw_struct);
}
free(evp);
Expand All @@ -50,6 +54,67 @@ static void draw_hex_digit(Canvas* canvas, uint8_t x, uint8_t y, uint8_t digit)
canvas_draw_str(canvas, x, y, digit_str);
}

static void draw_dec_number(Canvas* canvas, uint8_t x, uint8_t y, uint8_t num) {
char num_str[] = "0";
{
num_str[0] = '0' + num % 10;
canvas_draw_str(canvas, x + 6 + 6, y, num_str);
}
if(num >= 10) {
num_str[0] = '0' + num / 10 - (num / 100) * 10;
canvas_draw_str(canvas, x + 6, y, num_str);
}
if(num >= 100) {
num_str[0] = '0' + num / 100;
canvas_draw_str(canvas, x, y, num_str);
}
}

static void draw_static_mode(Canvas* canvas, uint8_t mode) {
const uint8_t s1 = 13;
const uint8_t s2 = 30;
const uint8_t s3 = 17;
const uint8_t s4 = 20;
const uint8_t s = 40;
const uint8_t h = 7;
const uint8_t y = 10;
const uint8_t y1 = 15;

if(mode == EthViewDrawStaticModeIp) {
canvas_invert_color(canvas);
canvas_draw_box(canvas, s, y, s1, h);
canvas_invert_color(canvas);
canvas_draw_str(canvas, 43, y1, "ip");
}
if(mode == EthViewDrawStaticModeMask) {
canvas_invert_color(canvas);
canvas_draw_box(canvas, s + s1, y, s2, h);
canvas_invert_color(canvas);
canvas_draw_str(canvas, 57, y1, "mask");
}
if(mode == EthViewDrawStaticModeGateway) {
canvas_invert_color(canvas);
canvas_draw_box(canvas, s + s1 + s2, y, s3, h);
canvas_invert_color(canvas);
canvas_draw_str(canvas, 85, y1, "gw");
}
if(mode == EthViewDrawStaticModeDNS) {
canvas_invert_color(canvas);
canvas_draw_box(canvas, s + s1 + s2 + s3, y, s4, h);
canvas_invert_color(canvas);
canvas_draw_str(canvas, 104, y1, "dns");
}
}

static uint8_t* draw_static_get_current_adress(EthViewDrawStatic* evds) {
furi_assert(evds);
if(evds->current_mode == EthViewDrawStaticModeIp) return evds->ip;
if(evds->current_mode == EthViewDrawStaticModeMask) return evds->mask;
if(evds->current_mode == EthViewDrawStaticModeGateway) return evds->gateway;
if(evds->current_mode == EthViewDrawStaticModeDNS) return evds->dns;
return evds->ip;
}

void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
furi_assert(canvas);
furi_assert(process);
Expand All @@ -75,19 +140,47 @@ void ethernet_view_process_draw(EthViewProcess* process, Canvas* canvas) {
if(process->type == EthWorkerProcessInit) {
uint8_t editing = process->editing;
canvas_draw_icon(canvas, 27, 10, &I_init_100x19px);
uint8_t octet = ((EthViewDrawInit*)process->draw_struct)->current_octet;
uint8_t* mac = ((EthViewDrawInit*)process->draw_struct)->mac;
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);
draw_hex_digit(canvas, x1, 25, (mac[i] & 0x0F));
draw_hex_digit(canvas, x2, 25, (mac[i] & 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);
}
}
} else if(process->type == EthWorkerProcessStatic) {
canvas_draw_frame(canvas, 36, 18, 21, 13);
canvas_draw_frame(canvas, 59, 18, 21, 13);
canvas_draw_frame(canvas, 82, 18, 21, 13);
canvas_draw_frame(canvas, 105, 18, 21, 13);
canvas_draw_box(canvas, 36, 10, 90, 7);
uint8_t mode = ((EthViewDrawStatic*)process->draw_struct)->current_mode;
uint8_t current_digit = ((EthViewDrawStatic*)process->draw_struct)->current_digit;
uint8_t* adress = draw_static_get_current_adress((EthViewDrawStatic*)process->draw_struct);
uint8_t editing = ((EthViewDrawStatic*)process->draw_struct)->editing;
for(uint8_t i = 0; i < 4; ++i) {
if(i == mode) {
draw_static_mode(canvas, mode);
} else {
canvas_invert_color(canvas);
draw_static_mode(canvas, i);
canvas_invert_color(canvas);
}
}
for(uint8_t i = 0; i < 4; ++i) {
uint8_t x = 38 + i * 23;
draw_dec_number(canvas, x, 27, adress[i]);
if(editing && (current_digit / 3 == i)) {
uint8_t x1 = x + 6 * (current_digit % 3);
canvas_draw_line(canvas, x1, 28, x1 + 4, 28);
canvas_draw_line(canvas, x1, 29, x1 + 4, 29);
}
}
}
}

Expand All @@ -98,6 +191,22 @@ static void mac_change_hex_digit(uint8_t* mac, uint8_t octet, int8_t diff) {
(digit << ((octet & 1) ? 4 : 0));
}

static void adress_change_dec_digit(uint8_t* ip, uint8_t digit, int8_t diff) {
{
uint8_t k = 0;
k = (digit % 3 == 0) ? 100 : k;
k = (digit % 3 == 1) ? 10 : k;
k = (digit % 3 == 2) ? 1 : k;
diff *= k;
}
{
int16_t ip1 = ip[digit / 3];
if(diff > 0 && ((0x100 - ip1) > diff)) ip1 += diff;
if(diff < 0 && (ip1 + diff >= 0)) ip1 += diff;
ip[digit / 3] = ip1;
}
}

void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
furi_assert(process);
if(process->type == EthWorkerProcessInit) {
Expand All @@ -106,7 +215,7 @@ void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
if(key == InputKeyLeft) {
if(octet > 0) octet -= 1;
} else if(key == InputKeyRight) {
if(octet < 12) octet += 1;
if(octet < 11) octet += 1;
} else if(key == InputKeyUp) {
mac_change_hex_digit(mac, octet, 1);
} else if(key == InputKeyDown) {
Expand All @@ -115,6 +224,40 @@ void ethernet_view_process_keyevent(EthViewProcess* process, InputKey key) {
process->editing = 0;
}
((EthViewDrawInit*)process->draw_struct)->current_octet = octet;
} else if(process->type == EthWorkerProcessStatic) {
uint8_t digit = ((EthViewDrawStatic*)process->draw_struct)->current_digit;
uint8_t mode = ((EthViewDrawStatic*)process->draw_struct)->current_mode;
uint8_t* adress = draw_static_get_current_adress((EthViewDrawStatic*)process->draw_struct);
uint8_t editing = ((EthViewDrawStatic*)process->draw_struct)->editing;
if(editing) {
if(key == InputKeyLeft) {
if(digit > 0) digit -= 1;
} else if(key == InputKeyRight) {
if(digit < 11) digit += 1;
} else if(key == InputKeyUp) {
adress_change_dec_digit(adress, digit, 1);
} else if(key == InputKeyDown) {
adress_change_dec_digit(adress, digit, -1);
} else if(key == InputKeyOk) {
((EthViewDrawStatic*)process->draw_struct)->editing = 0;
}
} else {
if(key == InputKeyLeft) {
if(mode > 0) {
mode -= 1;
} else {
process->editing = 0;
}
} else if(key == InputKeyRight) {
if(mode < 3) {
mode += 1;
}
} else if(key == InputKeyUp || key == InputKeyDown) {
((EthViewDrawStatic*)process->draw_struct)->editing = 1;
}
}
((EthViewDrawStatic*)process->draw_struct)->current_mode = mode;
((EthViewDrawStatic*)process->draw_struct)->current_digit = digit;
}
}

Expand Down
22 changes: 19 additions & 3 deletions eth_view_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <gui/gui.h>

#define SCREEN_SYMBOLS_WIDTH 30
#define SCREEN_STRINGS_COUNT 40
#define SCREEN_STRINGS_COUNT 8

EthViewProcess* ethernet_view_process_malloc(EthWorkerProcess type);
void ethernet_view_process_free(EthViewProcess* evp);
Expand All @@ -14,7 +14,23 @@ 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 {
typedef struct EthViewDrawInit {
uint8_t mac[6];
uint8_t current_octet;
};
} EthViewDrawInit;

typedef enum {
EthViewDrawStaticModeIp,
EthViewDrawStaticModeMask,
EthViewDrawStaticModeGateway,
EthViewDrawStaticModeDNS
} EthViewDrawStaticMode;
typedef struct EthViewDrawStatic {
uint8_t ip[4];
uint8_t mask[4];
uint8_t gateway[4];
uint8_t dns[4];
EthViewDrawStaticMode current_mode;
uint8_t current_digit;
uint8_t editing;
} EthViewDrawStatic;
1 change: 0 additions & 1 deletion eth_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

typedef struct EthWorker EthWorker;
typedef struct EthViewProcess EthViewProcess;
typedef struct EthViewDrawInit EthViewDrawInit;

typedef enum {
EthWorkerStateNotInited = 0,
Expand Down
8 changes: 6 additions & 2 deletions finik_eth_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ int32_t finik_eth_app(void* p) {
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";
char str[] = "test string 0 with some parameters";
str[12] += cnt % 10;
cnt += 1;
ethernet_view_process_print(app->eth_worker->init_process, str);
ethernet_view_process_print(app->eth_worker->stat_process, str);
ethernet_view_process_print(
app->eth_worker->dhcp_process,
"test dhcp process string. loooooong world");
app->cursor_position = CURSOR_INSIDE_PROCESS;
} else if(event.key == InputKeyRight) {
eth_worker_set_active_process(
Expand All @@ -183,7 +187,7 @@ int32_t finik_eth_app(void* p) {
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) {
} else if(event.key == InputKeyOk || event.key == InputKeyRight) {
app->eth_worker->active_process->editing = 1;
}
} else if(event.type == InputTypePress && app->cursor_position == CURSOR_EXIT_APP) {
Expand Down

0 comments on commit 0234554

Please sign in to comment.