summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-28 21:21:07 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-28 21:21:07 +0100
commit3d67aa36fdf8164cf367acc71b8d7fe55fd10cc6 (patch)
tree712c4e4a692a81cc6710d0ed551851f188911b0a /fw
parent82a6206422ed658a99716fbd18e33942cebc833b (diff)
refacotr app/ api
Diffstat (limited to 'fw')
-rw-r--r--fw/fe310/eos/app/Makefile2
-rw-r--r--fw/fe310/eos/app/app_screen.c94
-rw-r--r--fw/fe310/eos/app/app_screen.h9
-rw-r--r--fw/fe310/eos/app/app_status.c (renamed from fw/fe310/eos/app/status.c)3
-rw-r--r--fw/fe310/eos/app/app_status.h (renamed from fw/fe310/eos/app/status.h)0
-rw-r--r--fw/fe310/eos/app/root.c169
-rw-r--r--fw/fe310/eos/app/root.h16
-rw-r--r--fw/fe310/test/cell_pdp.c3
-rw-r--r--fw/fe310/test/main.c3
-rw-r--r--fw/fe310/test/modem.c3
-rw-r--r--fw/fe310/test/phone.c3
-rw-r--r--fw/fe310/test/status.c3
-rw-r--r--fw/fe310/test/wifi.c3
13 files changed, 117 insertions, 194 deletions
diff --git a/fw/fe310/eos/app/Makefile b/fw/fe310/eos/app/Makefile
index 7bb9951..f1dbf70 100644
--- a/fw/fe310/eos/app/Makefile
+++ b/fw/fe310/eos/app/Makefile
@@ -2,7 +2,7 @@ include ../../common.mk
CFLAGS += -I..
-obj = root.o status.o
+obj = app_screen.o app_status.o app_form.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/app/app_screen.c b/fw/fe310/eos/app/app_screen.c
new file mode 100644
index 0000000..f94e477
--- /dev/null
+++ b/fw/fe310/eos/app/app_screen.c
@@ -0,0 +1,94 @@
+#include <stdlib.h>
+
+#include "net.h"
+#include "unicode.h"
+
+#include "eve/eve.h"
+#include "eve/eve_kbd.h"
+#include "eve/eve_font.h"
+
+#include "eve/screen/screen.h"
+#include "eve/screen/window.h"
+#include "eve/screen/view.h"
+#include "eve/screen/page.h"
+#include "eve/screen/form.h"
+
+#include "eve/widget/widgets.h"
+
+#include "app_status.h"
+#include "app_screen.h"
+
+static EVEKbd kbd;
+static EVEScreen screen;
+static EVEWindow win_status;
+static EVEWindow win_main;
+static EVEWindow win_kbd;
+static EVEView view_kbd;
+static EVEView view_status;
+static EVEViewStack view_stack;
+
+EVEScreen *app_screen(void) {
+ return &screen;
+}
+
+static int kbd_touch(EVEView *v, uint8_t tag0, int touch_idx) {
+ EVEKbd *kbd = v->param;
+
+ return eve_kbd_touch(kbd, tag0, touch_idx);
+}
+
+static uint8_t kbd_draw(EVEView *v, uint8_t tag0) {
+ EVEKbd *kbd = v->param;
+
+ eve_kbd_draw(kbd);
+ return tag0;
+}
+
+void app_screen_refresh(void) {
+ eve_spi_start();
+ eve_screen_draw(app_screen());
+ eve_spi_stop();
+}
+
+void app_screen_init(eve_view_constructor_t home_page) {
+ EVERect g;
+
+ eve_spi_start();
+
+ eve_brightness(0x40);
+
+ eve_screen_init(&screen, APP_SCREEN_W, APP_SCREEN_H);
+
+ eve_kbd_init(&kbd, NULL, screen.mem_next, &screen.mem_next);
+ eve_screen_set_kbd(&screen, &kbd);
+
+ g.x = 0;
+ g.y = 0;
+ g.w = APP_SCREEN_W;
+ g.h = APP_STATUS_H;
+ eve_window_init(&win_status, &g, &screen, "status");
+ eve_view_init(&view_status, &win_status, app_status_touch, app_status_draw, NULL);
+
+ 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, &screen, "main");
+
+ eve_window_init(&win_kbd, &kbd.g, &screen, "kbd");
+ eve_view_init(&view_kbd, &win_kbd, kbd_touch, kbd_draw, &kbd);
+
+ eve_view_stack_init(&view_stack);
+ eve_view_create(&win_main, &view_stack, home_page);
+
+ eve_window_append(&win_status);
+ eve_window_append(&win_main);
+ eve_window_append(&win_kbd);
+
+ eve_screen_hide_kbd(&screen);
+ eve_screen_draw(&screen);
+
+ eve_spi_stop();
+
+ eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1);
+}
diff --git a/fw/fe310/eos/app/app_screen.h b/fw/fe310/eos/app/app_screen.h
new file mode 100644
index 0000000..1e266d4
--- /dev/null
+++ b/fw/fe310/eos/app/app_screen.h
@@ -0,0 +1,9 @@
+#include <stdint.h>
+
+#define APP_SCREEN_W 480
+#define APP_SCREEN_H 800
+#define APP_STATUS_H 60
+
+EVEScreen *app_screen(void);
+void app_screen_init(eve_view_constructor_t home_page);
+void app_screen_refresh(void);
diff --git a/fw/fe310/eos/app/status.c b/fw/fe310/eos/app/app_status.c
index 3a41ff2..3ebfba9 100644
--- a/fw/fe310/eos/app/status.c
+++ b/fw/fe310/eos/app/app_status.c
@@ -1,4 +1,3 @@
-
#include <stdlib.h>
#include "unicode.h"
@@ -10,7 +9,7 @@
#include "eve/screen/window.h"
#include "eve/screen/view.h"
-#include "status.h"
+#include "app_status.h"
int app_status_touch(EVEView *v, uint8_t tag0, int touch_idx) {
return 0;
diff --git a/fw/fe310/eos/app/status.h b/fw/fe310/eos/app/app_status.h
index a121b13..a121b13 100644
--- a/fw/fe310/eos/app/status.h
+++ b/fw/fe310/eos/app/app_status.h
diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c
deleted file mode 100644
index ec0e4ea..0000000
--- a/fw/fe310/eos/app/root.c
+++ /dev/null
@@ -1,169 +0,0 @@
-#include <stdlib.h>
-
-#include "net.h"
-#include "unicode.h"
-
-#include "eve/eve.h"
-#include "eve/eve_kbd.h"
-#include "eve/eve_font.h"
-
-#include "eve/screen/screen.h"
-#include "eve/screen/window.h"
-#include "eve/screen/view.h"
-#include "eve/screen/page.h"
-#include "eve/screen/form.h"
-
-#include "eve/widget/widgets.h"
-
-#include "status.h"
-#include "root.h"
-
-static EVEKbd kbd;
-static EVEFont font;
-static EVEScreen screen;
-static EVEWindow win_status;
-static EVEWindow win_main;
-static EVEWindow win_kbd;
-static EVEView view_kbd;
-static EVEView view_status;
-static EVEViewStack view_stack;
-
-EVEScreen *app_screen(void) {
- return &screen;
-}
-
-static int kbd_touch(EVEView *v, uint8_t tag0, int touch_idx) {
- EVEKbd *kbd = v->param;
-
- return eve_kbd_touch(kbd, tag0, touch_idx);
-}
-
-static uint8_t kbd_draw(EVEView *v, uint8_t tag0) {
- EVEKbd *kbd = v->param;
-
- eve_kbd_draw(kbd);
- return tag0;
-}
-
-void app_screen_init(eve_view_constructor_t home_page) {
- EVERect g;
-
- eve_spi_start();
-
- eve_brightness(0x40);
-
- eve_font_init(&font, APP_FONT_HANDLE);
- eve_screen_init(&screen, APP_SCREEN_W, APP_SCREEN_H);
-
- eve_kbd_init(&kbd, NULL, screen.mem_next, &screen.mem_next);
- eve_screen_set_kbd(&screen, &kbd);
-
- g.x = 0;
- g.y = 0;
- g.w = APP_SCREEN_W;
- g.h = APP_STATUS_H;
- eve_window_init(&win_status, &g, &screen, "status");
- eve_view_init(&view_status, &win_status, app_status_touch, app_status_draw, NULL);
-
- 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, &screen, "main");
-
- eve_window_init(&win_kbd, &kbd.g, &screen, "kbd");
- eve_view_init(&view_kbd, &win_kbd, kbd_touch, kbd_draw, &kbd);
-
- eve_view_stack_init(&view_stack);
- eve_view_create(&win_main, &view_stack, home_page);
-
- eve_window_append(&win_status);
- eve_window_append(&win_main);
- eve_window_append(&win_kbd);
-
- eve_screen_hide_kbd(&screen);
- eve_screen_draw(&screen);
-
- eve_spi_stop();
-
- eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1);
-}
-
-void app_screen_refresh(void) {
- eve_spi_start();
- eve_screen_draw(app_screen());
- eve_spi_stop();
-}
-
-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);
- widget = eve_widget_next(widget);
- }
-}
-
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor) {
- EVEWidget *widgets;
- EVEWidget *widget;
- EVELabel *label;
- EVEForm *form;
- EVEFont *_font;
- 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(EVEForm));
- 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++) {
- _font = spec[i].widget.font ? spec[i].widget.font : &font;
- r = eve_widget_create(widget, spec[i].widget.type, &spec[i].widget.g, _font, &spec[i].widget.spec);
- if (r) {
- widgets_destroy(widgets, i);
- eve_free(widgets);
- eve_free(form);
- return NULL;
- }
- if (spec[i].label.title) {
- _font = spec[i].label.font ? spec[i].label.font : &font;
- label = eve_malloc(sizeof(EVELabel));
- 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, _font, spec[i].label.title);
- eve_widget_set_label(widget, label);
- }
- if (widget->label && (widget->label->g.w == 0)) eve_font_str_w(label->font, label->title) + APP_LABEL_MARGIN;
- if (widget->g.w == 0) widget->g.w = APP_SCREEN_W - (widget->label ? widget->label->g.w : 0);
- widget = eve_widget_next(widget);
- }
-
- if (destructor == NULL) destructor = app_form_destroy;
- eve_form_init(form, window, stack, widgets, spec_size, action, destructor);
-
- return form;
-}
-
-void app_form_destroy(EVEForm *form) {
- widgets_destroy(form->widget, form->widget_size);
- eve_free(form->widget);
- eve_free(form);
-}
diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h
deleted file mode 100644
index 9468e6e..0000000
--- a/fw/fe310/eos/app/root.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdint.h>
-
-#define APP_SCREEN_W 480
-#define APP_SCREEN_H 800
-#define APP_STATUS_H 60
-
-#define APP_FONT_HANDLE 31
-
-#define APP_LABEL_MARGIN 10
-
-EVEScreen *app_screen(void);
-void app_screen_init(eve_view_constructor_t home_page);
-void app_screen_refresh(void);
-
-EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, EVEWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor);
-void app_form_destroy(EVEForm *form);
diff --git a/fw/fe310/test/cell_pdp.c b/fw/fe310/test/cell_pdp.c
index 43c8579..2225f6a 100644
--- a/fw/fe310/test/cell_pdp.c
+++ b/fw/fe310/test/cell_pdp.c
@@ -24,7 +24,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "status.h"
#include "cell_pdp.h"
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
index 934995c..dc43473 100644
--- a/fw/fe310/test/main.c
+++ b/fw/fe310/test/main.c
@@ -24,7 +24,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "status.h"
#include "cell_dev.h"
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
index 4ed7c81..9fab383 100644
--- a/fw/fe310/test/modem.c
+++ b/fw/fe310/test/modem.c
@@ -25,7 +25,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "modem.h"
diff --git a/fw/fe310/test/phone.c b/fw/fe310/test/phone.c
index b3a08b1..442fcae 100644
--- a/fw/fe310/test/phone.c
+++ b/fw/fe310/test/phone.c
@@ -24,7 +24,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "status.h"
#include "phone.h"
diff --git a/fw/fe310/test/status.c b/fw/fe310/test/status.c
index b61fc13..2500838 100644
--- a/fw/fe310/test/status.c
+++ b/fw/fe310/test/status.c
@@ -24,7 +24,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "phone.h"
#include "status.h"
diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c
index f7ca24d..cf2f0be 100644
--- a/fw/fe310/test/wifi.c
+++ b/fw/fe310/test/wifi.c
@@ -24,7 +24,8 @@
#include <eve/widget/widgets.h>
-#include <app/root.h>
+#include <app/app_screen.h>
+#include <app/app_form.h>
#include "status.h"
#include "wifi.h"