Skip to content

Commit

Permalink
new screens add
Browse files Browse the repository at this point in the history
  • Loading branch information
karasevia committed Jul 3, 2023
1 parent 1f050d4 commit 688a8af
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 57 deletions.
15 changes: 15 additions & 0 deletions eth_view_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions eth_view_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
44 changes: 33 additions & 11 deletions eth_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions eth_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ typedef enum {
EthWorkerStateStop,
} EthWorkerState;

typedef enum {
EthWorkerProcessInit,
EthWorkerProcessDHCP,
EthWorkerProcessStatic,
EthWorkerProcessPing,
EthWorkerProcessReset,
} EthWorkerProcess;

typedef enum {
EthWorkerSubstateInProcess = 0,
EthWorkerSubStateSuccess,
Expand All @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions eth_worker_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
91 changes: 45 additions & 46 deletions finik_eth_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 688a8af

Please sign in to comment.