diff options
author | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2020-08-23 22:37:16 +0200 |
commit | 1e5eb7cb910e6f23c69c2c986b6373e9f9abb980 (patch) | |
tree | 5e8ed0ad6b2fcba747c626c1c51afebbf76b3b9d /fw/fe310/eos/app | |
parent | 57c1824affca858023c65c84e188ea7dc6c0a5f2 (diff) |
dynamic memory alloc for gui added; page navigation added
Diffstat (limited to 'fw/fe310/eos/app')
-rw-r--r-- | fw/fe310/eos/app/Makefile | 17 | ||||
-rw-r--r-- | fw/fe310/eos/app/root.c | 133 | ||||
-rw-r--r-- | fw/fe310/eos/app/root.h | 27 | ||||
-rw-r--r-- | fw/fe310/eos/app/status.c | 23 | ||||
-rw-r--r-- | fw/fe310/eos/app/status.h | 4 |
5 files changed, 204 insertions, 0 deletions
diff --git a/fw/fe310/eos/app/Makefile b/fw/fe310/eos/app/Makefile new file mode 100644 index 0000000..7bb9951 --- /dev/null +++ b/fw/fe310/eos/app/Makefile @@ -0,0 +1,17 @@ +include ../../common.mk + +CFLAGS += -I.. + +obj = root.o status.o + + +%.o: %.c %.h + $(CC) $(CFLAGS) -c $< + +%.o: %.S + $(CC) $(CFLAGS) -c $< + +all: $(obj) + +clean: + rm -f *.o diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c new file mode 100644 index 0000000..160316f --- /dev/null +++ b/fw/fe310/eos/app/root.c @@ -0,0 +1,133 @@ +#include <stdlib.h> + +#include "net.h" +#include "unicode.h" + +#include "eve/eve.h" +#include "eve/eve_kbd.h" + +#include "eve/screen/screen.h" +#include "eve/screen/window.h" +#include "eve/screen/kbdwin.h" +#include "eve/screen/page.h" +#include "eve/screen/form.h" + +#include "eve/widget/widgets.h" + +#include "status.h" +#include "root.h" + +EVEFont _app_font_default; +extern eve_page_constructor_t _app_home_page; + +static EVEScreen screen; +static EVEWindow win_status; +static EVEWindow win_main; +static EVEKbdWin win_kbd; +static EVEView view_status = { + app_status_touch, + app_status_draw, + NULL +}; +static EVEPageStack page_stack; + +static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) { + int i; + + for (i=0; i<widget_size; i++) { + if (widget->label) eve_free(widget->label); + eve_widget_destroy(widget); + } +} + +EVEForm *app_form_create(EVEWindow *window, EVEPageStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor) { + EVEWidget *widgets; + EVEWidget *widget; + EVELabel *label; + EVEForm *form; + int w_size = 0; + int i, r; + + for (i=0; i<spec_size; i++) { + w_size += eve_widget_size(spec[i].widget.type); + } + form = eve_malloc(sizeof(form)); + if (form == NULL) { + return NULL; + } + + widgets = eve_malloc(w_size); + if (widgets == NULL) { + eve_free(form); + return NULL; + } + + widget = widgets; + for (i=0; i<spec_size; i++) { + r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, &spec[i].widget.spec); + if (r) { + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; + } + if (spec[i].label.title) { + label = eve_malloc(sizeof(label)); + if (label == NULL) { + eve_widget_destroy(widget); + widgets_destroy(widgets, i); + eve_free(widgets); + eve_free(form); + return NULL; + } + eve_label_init(label, &spec[i].label.g, spec[i].label.font, spec[i].label.title); + eve_widget_set_label(widget, label); + } + widget = eve_widget_next(widget); + } + + if (destructor == NULL) destructor = (eve_page_destructor_t)app_form_destroy; + eve_form_init(form, window, stack, widgets, spec_size, destructor); + + return form; +} + +void app_form_destroy(EVEForm *form) { + widgets_destroy(form->widget, form->widget_size); + eve_free(form->widget); + eve_free(form); +} + +void app_root_init(void) { + EVERect g; + + eos_spi_dev_start(EOS_DEV_DISP); + + eve_brightness(0x40); + eve_font_init(&_app_font_default, APP_FONT_HANDLE); + eve_screen_init(&screen, APP_SCREEN_W, APP_SCREEN_H); + + g.x = 0; + g.y = 0; + g.w = APP_SCREEN_W; + g.h = APP_STATUS_H; + eve_window_init(&win_status, &g, &view_status, &screen); + g.x = 0; + g.y = APP_STATUS_H; + g.w = APP_SCREEN_W; + g.h = APP_SCREEN_H - APP_STATUS_H; + eve_window_init(&win_main, &g, NULL, &screen); + eve_kbdwin_init(&win_kbd, &screen); + + eve_page_stack_init(&page_stack); + eve_page_create(&win_main, &page_stack, _app_home_page); + + eve_window_append(&win_status); + eve_window_append(&win_main); + eve_kbdwin_append(&win_kbd); + eve_screen_draw(&screen); + + eos_spi_dev_stop(); + + eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1); +} diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h new file mode 100644 index 0000000..09284e2 --- /dev/null +++ b/fw/fe310/eos/app/root.h @@ -0,0 +1,27 @@ +#include <stdint.h> + +#define APP_SCREEN_W 480 +#define APP_SCREEN_H 800 +#define APP_STATUS_H 60 + +#define APP_FONT_HANDLE 31 + +typedef struct APPLabelSpec { + EVERect g; + EVEFont *font; + char *title; +} APPLabelSpec; + +typedef struct APPWidgetSpec { + APPLabelSpec label; + struct { + EVERect g; + EVEWidgetSpec spec; + uint8_t type; + } widget; +} APPWidgetSpec; + + +void app_root_init(void); +EVEForm *app_form_create(EVEWindow *window, EVEPageStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_page_destructor_t destructor); +void app_form_destroy(EVEForm *form);
\ No newline at end of file diff --git a/fw/fe310/eos/app/status.c b/fw/fe310/eos/app/status.c new file mode 100644 index 0000000..39c471e --- /dev/null +++ b/fw/fe310/eos/app/status.c @@ -0,0 +1,23 @@ + +#include <stdlib.h> + +#include "unicode.h" + +#include "eve/eve.h" +#include "eve/eve_kbd.h" + +#include "eve/screen/screen.h" +#include "eve/screen/window.h" +#include "eve/screen/page.h" + +#include "status.h" + +int app_status_touch(EVEView *v, uint8_t tag0, int touch_idx) { + return 0; +} + +uint8_t app_status_draw(EVEView *v, uint8_t tag0) { + return tag0; +} + + diff --git a/fw/fe310/eos/app/status.h b/fw/fe310/eos/app/status.h new file mode 100644 index 0000000..a121b13 --- /dev/null +++ b/fw/fe310/eos/app/status.h @@ -0,0 +1,4 @@ +#include <stdint.h> + +int app_status_touch(EVEView *v, uint8_t tag0, int touch_idx); +uint8_t app_status_draw(EVEView *v, uint8_t tag0); |