Skip to content

Commit

Permalink
new gui iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
karasevia committed Jul 3, 2023
1 parent 4d0e1d2 commit 1a7afc6
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 9 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
101 changes: 101 additions & 0 deletions eth_view_process.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "eth_view_process.h"
#include "eth_worker.h"
#include "eth_worker_i.h"
#include <gui/gui.h>
#include <gui/canvas.h>
#include <string.h>
#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;
}
}
}
11 changes: 11 additions & 0 deletions eth_view_process.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "eth_worker.h"
#include <gui/gui.h>

#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);
10 changes: 10 additions & 0 deletions eth_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion eth_worker.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

typedef struct EthWorker EthWorker;
typedef struct EthViewProcess EthViewProcess;

typedef enum {
EthWorkerStateNotInited = 0,
Expand Down Expand Up @@ -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);
void eth_worker_w5500(EthWorker* eth_worker);
void eth_worker_init_process(EthWorker* eth_worker);
23 changes: 21 additions & 2 deletions eth_worker_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

#include <furi.h>
#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;
};

Expand Down
21 changes: 16 additions & 5 deletions finik_eth_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <notification/notification_messages.h>

#include "eth_worker.h"
#include "eth_worker_i.h"
#include "eth_view_process.h"

#define TAG "FinikEthApp"

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

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

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

Expand All @@ -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) {
Expand Down

0 comments on commit 1a7afc6

Please sign in to comment.